Skip to content

Commit

Permalink
Syncing content from committish ad6b41f8923522a5ab752dddbe32ac9f38460afd
Browse files Browse the repository at this point in the history
  • Loading branch information
reunion-maestro-bot committed Mar 12, 2024
1 parent c8bd154 commit 3d10001
Show file tree
Hide file tree
Showing 27 changed files with 748 additions and 174 deletions.
74 changes: 62 additions & 12 deletions controls/dev/CommandBarFlyout/CommandBarFlyoutCommandBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ CommandBarFlyoutCommandBar::CommandBarFlyoutCommandBar()
PopulateAccessibleControls();
UpdateFlowsFromAndFlowsTo();
UpdateUI(!m_commandBarFlyoutIsOpening);
AttachItemEventHandlers();
}
});

Expand All @@ -141,6 +142,7 @@ CommandBarFlyoutCommandBar::CommandBarFlyoutCommandBar()
PopulateAccessibleControls();
UpdateFlowsFromAndFlowsTo();
UpdateUI(!m_commandBarFlyoutIsOpening);
AttachItemEventHandlers();
}
});
}
Expand Down Expand Up @@ -260,7 +262,8 @@ void CommandBarFlyoutCommandBar::OnApplyTemplate()
// primary commands's corner radius.
BindOwningFlyoutPresenterToCornerRadius();

AttachEventHandlers();
AttachControlEventHandlers();
AttachItemEventHandlers();
PopulateAccessibleControls();
UpdateFlowsFromAndFlowsTo();
UpdateUI(false /* useTransitions */);
Expand All @@ -273,7 +276,7 @@ void CommandBarFlyoutCommandBar::SetOwningFlyout(
m_owningFlyout = owningFlyout;
}

void CommandBarFlyoutCommandBar::AttachEventHandlers()
void CommandBarFlyoutCommandBar::AttachControlEventHandlers()
{
COMMANDBARFLYOUT_TRACE_INFO(*this, TRACE_MSG_METH, METH_NAME, this);

Expand Down Expand Up @@ -349,6 +352,37 @@ void CommandBarFlyoutCommandBar::AttachEventHandlers()
}
}

void CommandBarFlyoutCommandBar::AttachItemEventHandlers()
{
m_itemLoadedRevokerVector.clear();

for (auto const& command : PrimaryCommands())
{
if (auto commandAsFE = command.try_as<winrt::FrameworkElement>())
{
m_itemLoadedRevokerVector.push_back(commandAsFE.Loaded(winrt::auto_revoke, {
[this](winrt::IInspectable const& sender, auto const&)
{
UpdateItemVisualState(sender.as<winrt::Control>(), true /* isPrimaryControl */);
}
}));
}
}

for (auto const& command : SecondaryCommands())
{
if (auto commandAsFE = command.try_as<winrt::FrameworkElement>())
{
m_itemLoadedRevokerVector.push_back(commandAsFE.Loaded(winrt::auto_revoke, {
[this](winrt::IInspectable const& sender, auto const&)
{
UpdateItemVisualState(sender.as<winrt::Control>(), false /* isPrimaryControl */);
}
}));
}
}
}

void CommandBarFlyoutCommandBar::DetachEventHandlers()
{
COMMANDBARFLYOUT_TRACE_INFO(*this, TRACE_MSG_METH, METH_NAME, this);
Expand All @@ -357,6 +391,7 @@ void CommandBarFlyoutCommandBar::DetachEventHandlers()
m_secondaryItemsRootPreviewKeyDownRevoker.revoke();
m_secondaryItemsRootSizeChangedRevoker.revoke();
m_firstItemLoadedRevoker.revoke();
m_itemLoadedRevokerVector.clear();
m_openingStoryboardCompletedRevoker.revoke();
m_closingStoryboardCompletedCallbackRevoker.revoke();
m_expandedUpToCollapsedStoryboardRevoker.revoke();
Expand Down Expand Up @@ -677,20 +712,12 @@ void CommandBarFlyoutCommandBar::UpdateVisualState(
placementVisual.Clip(rectangleClip);
}

auto hasVisibleLabel = []<class TCommand>(TCommand const& command)
{
return command &&
command.Label().size() > 0 &&
command.Visibility() == winrt::Visibility::Visible &&
command.LabelPosition() == winrt::CommandBarLabelPosition::Default;
};

// If no primary command has labels, then we'll shrink down the size of primary commands since the extra space to accommodate labels is unnecessary.
bool hasPrimaryCommandLabels = false;
for (auto const& primaryCommand : PrimaryCommands())
{
if (hasVisibleLabel(primaryCommand.try_as<winrt::AppBarButton>()) ||
hasVisibleLabel(primaryCommand.try_as<winrt::AppBarToggleButton>()))
if (HasVisibleLabel(primaryCommand.try_as<winrt::AppBarButton>()) ||
HasVisibleLabel(primaryCommand.try_as<winrt::AppBarToggleButton>()))
{
hasPrimaryCommandLabels = true;
break;
Expand All @@ -717,6 +744,29 @@ void CommandBarFlyoutCommandBar::UpdateVisualState(
winrt::VisualStateManager::GoToState(*this, hasPrimaryCommandLabels ? L"HasPrimaryLabels" : L"NoPrimaryLabels", useTransitions);
}

void CommandBarFlyoutCommandBar::UpdateItemVisualState(winrt::Control const& item, bool isPrimaryItem)
{
if (isPrimaryItem)
{
bool hasPrimaryCommandLabels = false;
for (auto const& primaryCommand : PrimaryCommands())
{
if (HasVisibleLabel(primaryCommand.try_as<winrt::AppBarButton>()) ||
HasVisibleLabel(primaryCommand.try_as<winrt::AppBarToggleButton>()))
{
hasPrimaryCommandLabels = true;
break;
}
}

winrt::VisualStateManager::GoToState(item, hasPrimaryCommandLabels ? L"HasPrimaryLabels" : L"NoPrimaryLabels", false /* useTransitions */);
}
else
{
winrt::VisualStateManager::GoToState(item, L"NoPrimaryLabels", false /* useTransitions */);
}
}

void CommandBarFlyoutCommandBar::UpdateTemplateSettings()
{
COMMANDBARFLYOUT_TRACE_INFO(*this, TRACE_MSG_METH_INT, METH_NAME, this, IsOpen());
Expand Down
14 changes: 13 additions & 1 deletion controls/dev/CommandBarFlyout/CommandBarFlyoutCommandBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ class CommandBarFlyoutCommandBar :
void ClearLocalizedStringResourceCache();

private:
void AttachEventHandlers();
void AttachControlEventHandlers();
void AttachItemEventHandlers();
void DetachEventHandlers();

void UpdateFlowsFromAndFlowsTo();
void UpdateUI(bool useTransitions = true, bool isForSizeChange = false);
void UpdateVisualState(bool useTransitions, bool isForSizeChange = false);
void UpdateItemVisualState(winrt::Control const& item, bool isPrimaryItem);
void UpdateTemplateSettings();
void EnsureAutomationSetCountAndPosition();
void EnsureLocalizedControlTypes();
Expand All @@ -65,6 +67,15 @@ class CommandBarFlyoutCommandBar :

void SetPresenterName(winrt::FlyoutPresenter const& presenter);

template<class TCommand>
bool HasVisibleLabel(TCommand const& command)
{
return command &&
command.Label().size() > 0 &&
command.Visibility() == winrt::Visibility::Visible &&
command.LabelPosition() == winrt::CommandBarLabelPosition::Default;
};

static bool IsControlFocusable(
winrt::Control const& control,
bool checkTabStop);
Expand Down Expand Up @@ -95,6 +106,7 @@ class CommandBarFlyoutCommandBar :
winrt::UIElement::PreviewKeyDown_revoker m_secondaryItemsRootPreviewKeyDownRevoker{};
winrt::FrameworkElement::SizeChanged_revoker m_secondaryItemsRootSizeChangedRevoker{};
winrt::FrameworkElement::Loaded_revoker m_firstItemLoadedRevoker{};
std::vector<winrt::FrameworkElement::Loaded_revoker> m_itemLoadedRevokerVector{};

// We need to manually connect the end element of the primary items to the start element of the secondary items
// for the purposes of UIA items navigation. To ensure that we only have the current start and end elements registered
Expand Down
32 changes: 21 additions & 11 deletions controls/dev/ItemsView/ItemsView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2083,32 +2083,42 @@ void ItemsView::SetItemsViewItemContainerRevokers(

itemContainer.SetValue(s_ItemsViewItemContainerRevokersProperty, itemContainerRevokers.as<winrt::IInspectable>());

m_itemContainersWithRevokers.insert(itemContainer);
m_itemContainersWithRevokers.insert(tracker_ref<winrt::ItemContainer>{ this, itemContainer });
}

void ItemsView::ClearItemsViewItemContainerRevokers(
const winrt::ItemContainer& itemContainer)
{
RevokeItemsViewItemContainerRevokers(itemContainer);
itemContainer.SetValue(s_ItemsViewItemContainerRevokersProperty, nullptr);
m_itemContainersWithRevokers.erase(itemContainer);
const auto& itemContainerRef = tracker_ref<winrt::ItemContainer>{ this, itemContainer };
const auto& itemContainerSafe = itemContainerRef.safe_get();
if (itemContainerSafe)
{
RevokeItemsViewItemContainerRevokers(itemContainerSafe);
itemContainerSafe.SetValue(s_ItemsViewItemContainerRevokersProperty, nullptr);
}
const bool removed = static_cast<bool>(m_itemContainersWithRevokers.erase(itemContainerRef));
MUX_ASSERT(removed);
}

void ItemsView::ClearAllItemsViewItemContainerRevokers() noexcept
{
for (const auto& itemContainer : m_itemContainersWithRevokers)
for (const auto& itemContainerTracker : m_itemContainersWithRevokers)
{
const auto& itemContainer = itemContainerTracker.safe_get();
// ClearAllItemsViewItemContainerRevokers is only called in the destructor, where exceptions cannot be thrown.
// If the associated ItemsView items have not yet been cleaned up, we must detach these revokers or risk a call into freed
// memory being made. However if they have been cleaned up these calls will throw. In this case we can ignore
// those exceptions.
try
{
RevokeItemsViewItemContainerRevokers(itemContainer);
itemContainer.SetValue(s_ItemsViewItemContainerRevokersProperty, nullptr);
}
catch (...)
if (itemContainer)
{
try
{
RevokeItemsViewItemContainerRevokers(itemContainer);
itemContainer.SetValue(s_ItemsViewItemContainerRevokersProperty, nullptr);
}
catch (...)
{
}
}
}
m_itemContainersWithRevokers.clear();
Expand Down
3 changes: 1 addition & 2 deletions controls/dev/ItemsView/ItemsView.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,5 @@ class ItemsView :
tracker_ref<winrt::UIElement> m_bringIntoViewElement{ this };

std::list<winrt::VirtualKey> m_navigationKeysToProcess;
std::set<winrt::ItemContainer> m_itemContainersWithRevokers;
std::map<winrt::ItemContainer, std::shared_ptr<PointerInfo<ItemsView>>> m_itemContainersPointerInfos;
std::set<tracker_ref<winrt::ItemContainer>> m_itemContainersWithRevokers;
};
34 changes: 21 additions & 13 deletions controls/dev/MapControl/MapControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
#include "MapControlMapServiceErrorOccurredEventArgs.h"
#include "MapElementsLayer.h"
#include "Vector.h"


#include "MuxcTraceLogging.h"

winrt::hstring MapControl::s_mapHtmlContent{};

MapControl::MapControl()
{
SetDefaultStyleKey(this);

// Create layers vector that can hold MapElements to display information and be interacted with on the map
auto layers = winrt::make<Vector<winrt::MapLayer>>().as<winrt::IObservableVector<winrt::MapLayer>>();
layers.VectorChanged({ this, &MapControl::OnLayersVectorChanged });
Expand All @@ -41,14 +40,15 @@ void MapControl::OnApplyTemplate()
m_webView.set(webview);

m_webviewWebMessageReceivedRevoker = webview.WebMessageReceived(winrt::auto_revoke, { this, &MapControl::WebMessageReceived });
m_webviewNavigationCompletedRevoker = webview.NavigationCompleted(winrt::auto_revoke,{
m_webviewNavigationCompletedRevoker = webview.NavigationCompleted(winrt::auto_revoke, {
[this](auto const&, winrt::CoreWebView2NavigationCompletedEventArgs const& args)
{
XamlTelemetry::MapControl_WebViewNavigationCompleted(reinterpret_cast<uint64_t>(this));
InitializeWebMap();
}});

SetUpWebView();
}
}
}

winrt::IAsyncOperation<winrt::CoreWebView2> MapControl::GetCoreWebView2()
Expand All @@ -75,6 +75,8 @@ winrt::fire_and_forget MapControl::SetUpWebView()

winrt::IAsyncOperation<winrt::hstring> MapControl::InitializeWebMap()
{
XamlTelemetry::MapControl_InitializeWebMap(true, reinterpret_cast<uint64_t>(this));

winrt::hstring returnedValue{};
auto center = Center();
winrt::hstring pos = L"0,0";
Expand All @@ -100,6 +102,8 @@ winrt::IAsyncOperation<winrt::hstring> MapControl::InitializeWebMap()
}
}
UpdateControlsInWebPage();

XamlTelemetry::MapControl_InitializeWebMap(false, reinterpret_cast<uint64_t>(this));
co_return returnedValue;
}

Expand Down Expand Up @@ -128,8 +132,11 @@ void MapControl::OnPropertyChanged(const winrt::DependencyPropertyChangedEventAr
}
}

bool MapControl::IsValidMapServiceToken() {
return !MapServiceToken().empty() && std::all_of(MapServiceToken().begin(), MapServiceToken().end(), ::isalnum);
bool MapControl::IsValidMapServiceToken()
{
// This token is passed as a JavaScript param in double quotes. Make sure the token itself doesn't contain any.
return !MapServiceToken().empty()
&& std::all_of(MapServiceToken().begin(), MapServiceToken().end(), [](wchar_t i){return i != '"';});
}

// Updates Azure Maps Authentication Key on WebView
Expand All @@ -147,7 +154,7 @@ winrt::fire_and_forget MapControl::UpdateMapServiceTokenInWebPage()
winrt::MapElementsLayer layer = Layers().GetAt(i).try_as<winrt::MapElementsLayer>();
OnLayerAdded(layer);
}

UpdateControlsInWebPage();
UpdateCenterInWebPage();
UpdateZoomLevelInWebPage();
Expand Down Expand Up @@ -199,8 +206,8 @@ void MapControl::WebMessageReceived(winrt::WebView2 sender, winrt::CoreWebView2W
if (type.GetString() == L"pushpinClickEvent")
{
auto clickedLayer = Layers().GetAt(static_cast<uint32_t>(obj.GetNamedObject(L"layer").GetNumber())).try_as<MapElementsLayer>();
auto location = winrt::Geopoint{ winrt::BasicGeoposition{
obj.GetNamedObject(L"coordinate").GetNamedValue(L"longitude").GetNumber(),
auto location = winrt::Geopoint{ winrt::BasicGeoposition{
obj.GetNamedObject(L"coordinate").GetNamedValue(L"longitude").GetNumber(),
obj.GetNamedObject(L"coordinate").GetNamedValue(L"latitude").GetNumber() }};

auto pointId = obj.GetNamedObject(L"point").GetString();
Expand All @@ -223,6 +230,7 @@ void MapControl::WebMessageReceived(winrt::WebView2 sender, winrt::CoreWebView2W
else if (type.GetString() == L"javascriptError")
{
auto errorArgs = winrt::make_self<MapControlMapServiceErrorOccurredEventArgs>(jsonAsString);
XamlTelemetry::MapControl_WebMessageReceived_Error(reinterpret_cast<uint64_t>(this), jsonAsString.data());
m_mapServiceErrorOccurredEventSource(*this, *errorArgs);
}
}
Expand All @@ -246,7 +254,7 @@ winrt::fire_and_forget MapControl::ResetLayerCollection()

for (uint32_t i = 0; i < Layers().Size(); i++)
{
winrt::MapElementsLayer layer = Layers().GetAt(i).as<winrt::MapElementsLayer>();
winrt::MapElementsLayer layer = Layers().GetAt(i).as<winrt::MapElementsLayer>();
auto layerId = winrt::get_self<MapElementsLayer>(layer)->Id;
co_await core.ExecuteScriptAsync(L"clearLayer(" + winrt::to_hstring(layerId) + L");");

Expand All @@ -272,7 +280,7 @@ void MapControl::OnLayersVectorChanged(const winrt::IObservableVector<winrt::Map
}
else if (args.CollectionChange() == winrt::Collections::CollectionChange::ItemRemoved)
{

if (winrt::MapElementsLayer elementLayer = Layers().GetAt(args.Index()).try_as<winrt::MapElementsLayer>())
{
auto layerId = winrt::get_self<MapElementsLayer>(elementLayer)->Id;
Expand Down Expand Up @@ -309,7 +317,7 @@ winrt::IAsyncOperation<winrt::hstring> MapControl::AddMapIcon(winrt::Geopoint ma
if (auto webView = m_webView.get())
{
auto core = co_await GetCoreWebView2();

const auto mapIconPosition = mapIconPoint.Position();
const auto latitude = winrt::to_hstring(mapIconPosition.Latitude);
const auto longitude = winrt::to_hstring(mapIconPosition.Longitude);
Expand Down
Loading

0 comments on commit 3d10001

Please sign in to comment.