Skip to content

Commit 3d10001

Browse files
author
reunion-maestro-bot
committed
Syncing content from committish ad6b41f8923522a5ab752dddbe32ac9f38460afd
1 parent c8bd154 commit 3d10001

27 files changed

+748
-174
lines changed

controls/dev/CommandBarFlyout/CommandBarFlyoutCommandBar.cpp

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ CommandBarFlyoutCommandBar::CommandBarFlyoutCommandBar()
128128
PopulateAccessibleControls();
129129
UpdateFlowsFromAndFlowsTo();
130130
UpdateUI(!m_commandBarFlyoutIsOpening);
131+
AttachItemEventHandlers();
131132
}
132133
});
133134

@@ -141,6 +142,7 @@ CommandBarFlyoutCommandBar::CommandBarFlyoutCommandBar()
141142
PopulateAccessibleControls();
142143
UpdateFlowsFromAndFlowsTo();
143144
UpdateUI(!m_commandBarFlyoutIsOpening);
145+
AttachItemEventHandlers();
144146
}
145147
});
146148
}
@@ -260,7 +262,8 @@ void CommandBarFlyoutCommandBar::OnApplyTemplate()
260262
// primary commands's corner radius.
261263
BindOwningFlyoutPresenterToCornerRadius();
262264

263-
AttachEventHandlers();
265+
AttachControlEventHandlers();
266+
AttachItemEventHandlers();
264267
PopulateAccessibleControls();
265268
UpdateFlowsFromAndFlowsTo();
266269
UpdateUI(false /* useTransitions */);
@@ -273,7 +276,7 @@ void CommandBarFlyoutCommandBar::SetOwningFlyout(
273276
m_owningFlyout = owningFlyout;
274277
}
275278

276-
void CommandBarFlyoutCommandBar::AttachEventHandlers()
279+
void CommandBarFlyoutCommandBar::AttachControlEventHandlers()
277280
{
278281
COMMANDBARFLYOUT_TRACE_INFO(*this, TRACE_MSG_METH, METH_NAME, this);
279282

@@ -349,6 +352,37 @@ void CommandBarFlyoutCommandBar::AttachEventHandlers()
349352
}
350353
}
351354

355+
void CommandBarFlyoutCommandBar::AttachItemEventHandlers()
356+
{
357+
m_itemLoadedRevokerVector.clear();
358+
359+
for (auto const& command : PrimaryCommands())
360+
{
361+
if (auto commandAsFE = command.try_as<winrt::FrameworkElement>())
362+
{
363+
m_itemLoadedRevokerVector.push_back(commandAsFE.Loaded(winrt::auto_revoke, {
364+
[this](winrt::IInspectable const& sender, auto const&)
365+
{
366+
UpdateItemVisualState(sender.as<winrt::Control>(), true /* isPrimaryControl */);
367+
}
368+
}));
369+
}
370+
}
371+
372+
for (auto const& command : SecondaryCommands())
373+
{
374+
if (auto commandAsFE = command.try_as<winrt::FrameworkElement>())
375+
{
376+
m_itemLoadedRevokerVector.push_back(commandAsFE.Loaded(winrt::auto_revoke, {
377+
[this](winrt::IInspectable const& sender, auto const&)
378+
{
379+
UpdateItemVisualState(sender.as<winrt::Control>(), false /* isPrimaryControl */);
380+
}
381+
}));
382+
}
383+
}
384+
}
385+
352386
void CommandBarFlyoutCommandBar::DetachEventHandlers()
353387
{
354388
COMMANDBARFLYOUT_TRACE_INFO(*this, TRACE_MSG_METH, METH_NAME, this);
@@ -357,6 +391,7 @@ void CommandBarFlyoutCommandBar::DetachEventHandlers()
357391
m_secondaryItemsRootPreviewKeyDownRevoker.revoke();
358392
m_secondaryItemsRootSizeChangedRevoker.revoke();
359393
m_firstItemLoadedRevoker.revoke();
394+
m_itemLoadedRevokerVector.clear();
360395
m_openingStoryboardCompletedRevoker.revoke();
361396
m_closingStoryboardCompletedCallbackRevoker.revoke();
362397
m_expandedUpToCollapsedStoryboardRevoker.revoke();
@@ -677,20 +712,12 @@ void CommandBarFlyoutCommandBar::UpdateVisualState(
677712
placementVisual.Clip(rectangleClip);
678713
}
679714

680-
auto hasVisibleLabel = []<class TCommand>(TCommand const& command)
681-
{
682-
return command &&
683-
command.Label().size() > 0 &&
684-
command.Visibility() == winrt::Visibility::Visible &&
685-
command.LabelPosition() == winrt::CommandBarLabelPosition::Default;
686-
};
687-
688715
// 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.
689716
bool hasPrimaryCommandLabels = false;
690717
for (auto const& primaryCommand : PrimaryCommands())
691718
{
692-
if (hasVisibleLabel(primaryCommand.try_as<winrt::AppBarButton>()) ||
693-
hasVisibleLabel(primaryCommand.try_as<winrt::AppBarToggleButton>()))
719+
if (HasVisibleLabel(primaryCommand.try_as<winrt::AppBarButton>()) ||
720+
HasVisibleLabel(primaryCommand.try_as<winrt::AppBarToggleButton>()))
694721
{
695722
hasPrimaryCommandLabels = true;
696723
break;
@@ -717,6 +744,29 @@ void CommandBarFlyoutCommandBar::UpdateVisualState(
717744
winrt::VisualStateManager::GoToState(*this, hasPrimaryCommandLabels ? L"HasPrimaryLabels" : L"NoPrimaryLabels", useTransitions);
718745
}
719746

747+
void CommandBarFlyoutCommandBar::UpdateItemVisualState(winrt::Control const& item, bool isPrimaryItem)
748+
{
749+
if (isPrimaryItem)
750+
{
751+
bool hasPrimaryCommandLabels = false;
752+
for (auto const& primaryCommand : PrimaryCommands())
753+
{
754+
if (HasVisibleLabel(primaryCommand.try_as<winrt::AppBarButton>()) ||
755+
HasVisibleLabel(primaryCommand.try_as<winrt::AppBarToggleButton>()))
756+
{
757+
hasPrimaryCommandLabels = true;
758+
break;
759+
}
760+
}
761+
762+
winrt::VisualStateManager::GoToState(item, hasPrimaryCommandLabels ? L"HasPrimaryLabels" : L"NoPrimaryLabels", false /* useTransitions */);
763+
}
764+
else
765+
{
766+
winrt::VisualStateManager::GoToState(item, L"NoPrimaryLabels", false /* useTransitions */);
767+
}
768+
}
769+
720770
void CommandBarFlyoutCommandBar::UpdateTemplateSettings()
721771
{
722772
COMMANDBARFLYOUT_TRACE_INFO(*this, TRACE_MSG_METH_INT, METH_NAME, this, IsOpen());

controls/dev/CommandBarFlyout/CommandBarFlyoutCommandBar.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@ class CommandBarFlyoutCommandBar :
5151
void ClearLocalizedStringResourceCache();
5252

5353
private:
54-
void AttachEventHandlers();
54+
void AttachControlEventHandlers();
55+
void AttachItemEventHandlers();
5556
void DetachEventHandlers();
5657

5758
void UpdateFlowsFromAndFlowsTo();
5859
void UpdateUI(bool useTransitions = true, bool isForSizeChange = false);
5960
void UpdateVisualState(bool useTransitions, bool isForSizeChange = false);
61+
void UpdateItemVisualState(winrt::Control const& item, bool isPrimaryItem);
6062
void UpdateTemplateSettings();
6163
void EnsureAutomationSetCountAndPosition();
6264
void EnsureLocalizedControlTypes();
@@ -65,6 +67,15 @@ class CommandBarFlyoutCommandBar :
6567

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

70+
template<class TCommand>
71+
bool HasVisibleLabel(TCommand const& command)
72+
{
73+
return command &&
74+
command.Label().size() > 0 &&
75+
command.Visibility() == winrt::Visibility::Visible &&
76+
command.LabelPosition() == winrt::CommandBarLabelPosition::Default;
77+
};
78+
6879
static bool IsControlFocusable(
6980
winrt::Control const& control,
7081
bool checkTabStop);
@@ -95,6 +106,7 @@ class CommandBarFlyoutCommandBar :
95106
winrt::UIElement::PreviewKeyDown_revoker m_secondaryItemsRootPreviewKeyDownRevoker{};
96107
winrt::FrameworkElement::SizeChanged_revoker m_secondaryItemsRootSizeChangedRevoker{};
97108
winrt::FrameworkElement::Loaded_revoker m_firstItemLoadedRevoker{};
109+
std::vector<winrt::FrameworkElement::Loaded_revoker> m_itemLoadedRevokerVector{};
98110

99111
// We need to manually connect the end element of the primary items to the start element of the secondary items
100112
// for the purposes of UIA items navigation. To ensure that we only have the current start and end elements registered

controls/dev/ItemsView/ItemsView.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,32 +2083,42 @@ void ItemsView::SetItemsViewItemContainerRevokers(
20832083

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

2086-
m_itemContainersWithRevokers.insert(itemContainer);
2086+
m_itemContainersWithRevokers.insert(tracker_ref<winrt::ItemContainer>{ this, itemContainer });
20872087
}
20882088

20892089
void ItemsView::ClearItemsViewItemContainerRevokers(
20902090
const winrt::ItemContainer& itemContainer)
20912091
{
2092-
RevokeItemsViewItemContainerRevokers(itemContainer);
2093-
itemContainer.SetValue(s_ItemsViewItemContainerRevokersProperty, nullptr);
2094-
m_itemContainersWithRevokers.erase(itemContainer);
2092+
const auto& itemContainerRef = tracker_ref<winrt::ItemContainer>{ this, itemContainer };
2093+
const auto& itemContainerSafe = itemContainerRef.safe_get();
2094+
if (itemContainerSafe)
2095+
{
2096+
RevokeItemsViewItemContainerRevokers(itemContainerSafe);
2097+
itemContainerSafe.SetValue(s_ItemsViewItemContainerRevokersProperty, nullptr);
2098+
}
2099+
const bool removed = static_cast<bool>(m_itemContainersWithRevokers.erase(itemContainerRef));
2100+
MUX_ASSERT(removed);
20952101
}
20962102

20972103
void ItemsView::ClearAllItemsViewItemContainerRevokers() noexcept
20982104
{
2099-
for (const auto& itemContainer : m_itemContainersWithRevokers)
2105+
for (const auto& itemContainerTracker : m_itemContainersWithRevokers)
21002106
{
2107+
const auto& itemContainer = itemContainerTracker.safe_get();
21012108
// ClearAllItemsViewItemContainerRevokers is only called in the destructor, where exceptions cannot be thrown.
21022109
// If the associated ItemsView items have not yet been cleaned up, we must detach these revokers or risk a call into freed
21032110
// memory being made. However if they have been cleaned up these calls will throw. In this case we can ignore
21042111
// those exceptions.
2105-
try
2106-
{
2107-
RevokeItemsViewItemContainerRevokers(itemContainer);
2108-
itemContainer.SetValue(s_ItemsViewItemContainerRevokersProperty, nullptr);
2109-
}
2110-
catch (...)
2112+
if (itemContainer)
21112113
{
2114+
try
2115+
{
2116+
RevokeItemsViewItemContainerRevokers(itemContainer);
2117+
itemContainer.SetValue(s_ItemsViewItemContainerRevokersProperty, nullptr);
2118+
}
2119+
catch (...)
2120+
{
2121+
}
21122122
}
21132123
}
21142124
m_itemContainersWithRevokers.clear();

controls/dev/ItemsView/ItemsView.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,5 @@ class ItemsView :
399399
tracker_ref<winrt::UIElement> m_bringIntoViewElement{ this };
400400

401401
std::list<winrt::VirtualKey> m_navigationKeysToProcess;
402-
std::set<winrt::ItemContainer> m_itemContainersWithRevokers;
403-
std::map<winrt::ItemContainer, std::shared_ptr<PointerInfo<ItemsView>>> m_itemContainersPointerInfos;
402+
std::set<tracker_ref<winrt::ItemContainer>> m_itemContainersWithRevokers;
404403
};

controls/dev/MapControl/MapControl.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@
1515
#include "MapControlMapServiceErrorOccurredEventArgs.h"
1616
#include "MapElementsLayer.h"
1717
#include "Vector.h"
18-
19-
18+
#include "MuxcTraceLogging.h"
2019

2120
winrt::hstring MapControl::s_mapHtmlContent{};
2221

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

4342
m_webviewWebMessageReceivedRevoker = webview.WebMessageReceived(winrt::auto_revoke, { this, &MapControl::WebMessageReceived });
44-
m_webviewNavigationCompletedRevoker = webview.NavigationCompleted(winrt::auto_revoke,{
43+
m_webviewNavigationCompletedRevoker = webview.NavigationCompleted(winrt::auto_revoke, {
4544
[this](auto const&, winrt::CoreWebView2NavigationCompletedEventArgs const& args)
4645
{
46+
XamlTelemetry::MapControl_WebViewNavigationCompleted(reinterpret_cast<uint64_t>(this));
4747
InitializeWebMap();
4848
}});
4949

5050
SetUpWebView();
51-
}
51+
}
5252
}
5353

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

7676
winrt::IAsyncOperation<winrt::hstring> MapControl::InitializeWebMap()
7777
{
78+
XamlTelemetry::MapControl_InitializeWebMap(true, reinterpret_cast<uint64_t>(this));
79+
7880
winrt::hstring returnedValue{};
7981
auto center = Center();
8082
winrt::hstring pos = L"0,0";
@@ -100,6 +102,8 @@ winrt::IAsyncOperation<winrt::hstring> MapControl::InitializeWebMap()
100102
}
101103
}
102104
UpdateControlsInWebPage();
105+
106+
XamlTelemetry::MapControl_InitializeWebMap(false, reinterpret_cast<uint64_t>(this));
103107
co_return returnedValue;
104108
}
105109

@@ -128,8 +132,11 @@ void MapControl::OnPropertyChanged(const winrt::DependencyPropertyChangedEventAr
128132
}
129133
}
130134

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

135142
// Updates Azure Maps Authentication Key on WebView
@@ -147,7 +154,7 @@ winrt::fire_and_forget MapControl::UpdateMapServiceTokenInWebPage()
147154
winrt::MapElementsLayer layer = Layers().GetAt(i).try_as<winrt::MapElementsLayer>();
148155
OnLayerAdded(layer);
149156
}
150-
157+
151158
UpdateControlsInWebPage();
152159
UpdateCenterInWebPage();
153160
UpdateZoomLevelInWebPage();
@@ -199,8 +206,8 @@ void MapControl::WebMessageReceived(winrt::WebView2 sender, winrt::CoreWebView2W
199206
if (type.GetString() == L"pushpinClickEvent")
200207
{
201208
auto clickedLayer = Layers().GetAt(static_cast<uint32_t>(obj.GetNamedObject(L"layer").GetNumber())).try_as<MapElementsLayer>();
202-
auto location = winrt::Geopoint{ winrt::BasicGeoposition{
203-
obj.GetNamedObject(L"coordinate").GetNamedValue(L"longitude").GetNumber(),
209+
auto location = winrt::Geopoint{ winrt::BasicGeoposition{
210+
obj.GetNamedObject(L"coordinate").GetNamedValue(L"longitude").GetNumber(),
204211
obj.GetNamedObject(L"coordinate").GetNamedValue(L"latitude").GetNumber() }};
205212

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

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

@@ -272,7 +280,7 @@ void MapControl::OnLayersVectorChanged(const winrt::IObservableVector<winrt::Map
272280
}
273281
else if (args.CollectionChange() == winrt::Collections::CollectionChange::ItemRemoved)
274282
{
275-
283+
276284
if (winrt::MapElementsLayer elementLayer = Layers().GetAt(args.Index()).try_as<winrt::MapElementsLayer>())
277285
{
278286
auto layerId = winrt::get_self<MapElementsLayer>(elementLayer)->Id;
@@ -309,7 +317,7 @@ winrt::IAsyncOperation<winrt::hstring> MapControl::AddMapIcon(winrt::Geopoint ma
309317
if (auto webView = m_webView.get())
310318
{
311319
auto core = co_await GetCoreWebView2();
312-
320+
313321
const auto mapIconPosition = mapIconPoint.Position();
314322
const auto latitude = winrt::to_hstring(mapIconPosition.Latitude);
315323
const auto longitude = winrt::to_hstring(mapIconPosition.Longitude);

0 commit comments

Comments
 (0)