diff --git a/dev/PipsPager/InteractionTests/PipsPagerElements.cs b/dev/PipsPager/InteractionTests/PipsPagerElements.cs index 7535fc76f2..94c663a6a9 100755 --- a/dev/PipsPager/InteractionTests/PipsPagerElements.cs +++ b/dev/PipsPager/InteractionTests/PipsPagerElements.cs @@ -19,6 +19,7 @@ public class PipsPagerElements private UIObject PipsPager; private UIObject NextPageButton; private UIObject PreviousPageButton; + private Button RetrievePipsPagerButtonSizesButton; private ComboBox PreviousPageButtonVisibilityComboBox; private ComboBox NextPageButtonVisibilityComboBox; private ComboBox NumberOfPagesComboBox; @@ -33,7 +34,10 @@ public class PipsPagerElements private TextBlock CurrentNumberOfPagesTextBlock; private TextBlock CurrentMaxVisualIndicatorsTextBlock; private TextBlock CurrentOrientationTextBlock; - + private TextBlock HorizontalOrientationPipsPagerButtonWidthTextBlock; + private TextBlock HorizontalOrientationPipsPagerButtonHeightTextBlock; + private TextBlock VerticalOrientationPipsPagerButtonWidthTextBlock; + private TextBlock VerticalOrientationPipsPagerButtonHeightTextBlock; public UIObject GetPipsPager() { return GetElement(ref PipsPager, "TestPipsPager"); @@ -113,6 +117,28 @@ public TextBlock GetCurrentOrientationTextBlock() return GetElement(ref CurrentOrientationTextBlock, "CurrentOrientationTextBlock"); } + public TextBlock GetHorizontalOrientationPipsPagerButtonWidthTextBlock() + { + return GetElement(ref HorizontalOrientationPipsPagerButtonWidthTextBlock, "HorizontalOrientationPipsPagerButtonWidthTextBlock"); + } + public TextBlock GetHorizontalOrientationPipsPagerButtonHeightTextBlock() + { + return GetElement(ref HorizontalOrientationPipsPagerButtonHeightTextBlock, "HorizontalOrientationPipsPagerButtonHeightTextBlock"); + } + public TextBlock GetVerticalOrientationPipsPagerButtonWidthTextBlock() + { + return GetElement(ref VerticalOrientationPipsPagerButtonWidthTextBlock, "VerticalOrientationPipsPagerButtonWidthTextBlock"); + } + public TextBlock GetVerticalOrientationPipsPagerButtonHeightTextBlock() + { + return GetElement(ref VerticalOrientationPipsPagerButtonHeightTextBlock, "VerticalOrientationPipsPagerButtonHeightTextBlock"); + } + + public Button GetPipsPagerButtonSizesButton() + { + return GetElement(ref RetrievePipsPagerButtonSizesButton, "GetPipsPagersButtonSizesButton"); + } + public UIObject GetPipWithPageNumber(string elementName) { foreach (var element in GetPipsPager().Children) diff --git a/dev/PipsPager/InteractionTests/PipsPagerTests.cs b/dev/PipsPager/InteractionTests/PipsPagerTests.cs index 91779db175..7fb218abfa 100755 --- a/dev/PipsPager/InteractionTests/PipsPagerTests.cs +++ b/dev/PipsPager/InteractionTests/PipsPagerTests.cs @@ -4,6 +4,8 @@ using Windows.UI.Xaml.Tests.MUXControls.InteractionTests.Infra; using Windows.UI.Xaml.Tests.MUXControls.InteractionTests.Common; using Common; +using Microsoft.Windows.Apps.Test.Foundation.Controls; +using Microsoft.Windows.Apps.Test.Foundation; #if USING_TAEF using WEX.TestExecution; using WEX.TestExecution.Markup; @@ -315,5 +317,52 @@ public void KeyboardPageSelectTest() VerifySelectedPageIndex(2); } } + [TestMethod] + [TestProperty("TestSuite", "F")] + public void PipSizeWithDifferentOrientationsTest() + { + using (var setup = new TestSetupHelper("PipsPager Tests")) + { + elements = new PipsPagerElements(); + Button getButtonSizesButton = elements.GetPipsPagerButtonSizesButton(); + getButtonSizesButton.InvokeAndWait(); + + TextBlock horizontalOrientationPipsPagerButtonWidth = elements.GetHorizontalOrientationPipsPagerButtonWidthTextBlock(); + TextBlock horizontalOrientationPipsPagerButtonHeight = elements.GetHorizontalOrientationPipsPagerButtonHeightTextBlock(); + + TextBlock verticalOrientationPipsPagerButtonWidth = elements.GetVerticalOrientationPipsPagerButtonWidthTextBlock(); + TextBlock verticalOrientationPipsPagerButtonHeight = elements.GetVerticalOrientationPipsPagerButtonHeightTextBlock(); + + Verify.AreEqual("12", horizontalOrientationPipsPagerButtonWidth.DocumentText); + Verify.AreEqual("20", horizontalOrientationPipsPagerButtonHeight.DocumentText); + Verify.AreEqual("20", verticalOrientationPipsPagerButtonWidth.DocumentText); + Verify.AreEqual("12", verticalOrientationPipsPagerButtonHeight.DocumentText); + } + } + + [TestMethod] + [TestProperty("TestSuite", "F")] + public void PipSizeAfterOrientationChangeTest() + { + using (var setup = new TestSetupHelper("PipsPager Tests")) + { + elements = new PipsPagerElements(); + Button getButtonSizesButton = elements.GetPipsPagerButtonSizesButton(); + getButtonSizesButton.InvokeAndWait(); + + TextBlock horizontalOrientationPipsPagerButtonWidth = elements.GetHorizontalOrientationPipsPagerButtonWidthTextBlock(); + TextBlock horizontalOrientationPipsPagerButtonHeight = elements.GetHorizontalOrientationPipsPagerButtonHeightTextBlock(); + Verify.AreEqual("12", horizontalOrientationPipsPagerButtonWidth.DocumentText); + Verify.AreEqual("20", horizontalOrientationPipsPagerButtonHeight.DocumentText); + + SetOrientation(Microsoft.Windows.Apps.Test.Automation.OrientationType.Vertical); + VerifyOrientationChanged(Microsoft.Windows.Apps.Test.Automation.OrientationType.Vertical); + + getButtonSizesButton.InvokeAndWait(); + + Verify.AreEqual("20", horizontalOrientationPipsPagerButtonWidth.DocumentText); + Verify.AreEqual("12", horizontalOrientationPipsPagerButtonHeight.DocumentText); + } + } } } diff --git a/dev/PipsPager/PipsPager.cpp b/dev/PipsPager/PipsPager.cpp index 826efbe22e..35af8e9f66 100755 --- a/dev/PipsPager/PipsPager.cpp +++ b/dev/PipsPager/PipsPager.cpp @@ -35,12 +35,19 @@ constexpr auto c_nextPageButtonName = L"NextPageButton"sv; constexpr auto c_pipsPagerRepeaterName = L"PipsPagerItemsRepeater"sv; constexpr auto c_pipsPagerScrollViewerName = L"PipsPagerScrollViewer"sv; -constexpr auto c_pipsPagerButtonWidthPropertyName = L"PipsPagerButtonWidth"sv; -constexpr auto c_pipsPagerButtonHeightPropertyName = L"PipsPagerButtonHeight"sv; +constexpr auto c_pipsPagerVerticalOrientationButtonWidthPropertyName = L"PipsPagerVerticalOrientationButtonWidth"sv; +constexpr auto c_pipsPagerVerticalOrientationButtonHeightPropertyName = L"PipsPagerVerticalOrientationButtonHeight"sv; + +constexpr auto c_pipsPagerHorizontalOrientationButtonWidthPropertyName = L"PipsPagerHorizontalOrientationButtonWidth"sv; +constexpr auto c_pipsPagerHorizontalOrientationButtonHeightPropertyName = L"PipsPagerHorizontalOrientationButtonHeight"sv; constexpr auto c_pipsPagerHorizontalOrientationVisualState = L"HorizontalOrientationView"sv; constexpr auto c_pipsPagerVerticalOrientationVisualState = L"VerticalOrientationView"sv; +constexpr auto c_pipsPagerButtonVerticalOrientationVisualState = L"VerticalOrientation"sv; +constexpr auto c_pipsPagerButtonHorizontalOrientationVisualState = L"HorizontalOrientation"sv; + + PipsPager::PipsPager() { __RP_Marker_ClassById(RuntimeProfiler::ProfId_PipsPager); @@ -124,7 +131,7 @@ void PipsPager::OnApplyTemplate() void PipsPager::RaiseSelectedIndexChanged() { - const auto args = winrt::make_self(m_lastSelectedPageIndex, SelectedPageIndex()); + const auto args = winrt::make_self(); m_selectedIndexChangedEventSource(*this, *args); } @@ -135,16 +142,14 @@ winrt::Size PipsPager::GetDesiredPipSize(const winrt::Style& style) { { if (auto const element = itemTemplate.LoadContent().try_as()) { - element.Style(style); + ApplyStyleToPipAndUpdateOrientation(element, style); element.Measure({ std::numeric_limits::infinity(), std::numeric_limits::infinity() }); return element.DesiredSize(); } } } - /* Extract default sizes and return in case the code above fails */ - auto pipHeight = unbox_value(ResourceAccessor::ResourceLookup(*this, box_value(c_pipsPagerButtonHeightPropertyName))); - auto pipWidth = unbox_value(ResourceAccessor::ResourceLookup(*this, box_value(c_pipsPagerButtonWidthPropertyName))); - return { static_cast(pipWidth), static_cast(pipHeight) }; + + return { 0.0, 0.0 }; } void PipsPager::OnKeyDown(const winrt::KeyRoutedEventArgs& args) { @@ -267,14 +272,14 @@ void PipsPager::UpdateSelectedPip(const int index) { if (const auto repeater = m_pipsPagerRepeater.get()) { repeater.UpdateLayout(); - if (const auto element = repeater.TryGetElement(m_lastSelectedPageIndex).try_as()) + if (const auto pip = repeater.TryGetElement(m_lastSelectedPageIndex).try_as()) { - element.Style(NormalPipStyle()); + ApplyStyleToPipAndUpdateOrientation(pip, NormalPipStyle()); } - if (const auto element = repeater.GetOrCreateElement(index).try_as()) + if (const auto pip = repeater.GetOrCreateElement(index).try_as()) { - element.Style(SelectedPipStyle()); - ScrollToCenterOfViewport(element, index); + ApplyStyleToPipAndUpdateOrientation(pip, SelectedPipStyle()); + ScrollToCenterOfViewport(pip, index); } } } @@ -356,21 +361,18 @@ void PipsPager::UpdatePipsItems(const int numberOfPages, int maxVisualIndicators void PipsPager::OnElementPrepared(winrt::ItemsRepeater sender, winrt::ItemsRepeaterElementPreparedEventArgs args) { - if (auto const element = args.Element()) + if (auto const element = args.Element().try_as()) { - if (const auto pip = element.try_as()) - { - auto const index = args.Index(); - if (index != SelectedPageIndex()) - { - pip.Style(NormalPipStyle()); - } + auto const index = args.Index(); + auto const style = index == SelectedPageIndex() ? SelectedPipStyle() : NormalPipStyle(); + ApplyStyleToPipAndUpdateOrientation(element, style); - // Narrator says: Page 5, Button 5 of 30. Is it expected behavior? - winrt::AutomationProperties::SetName(pip, ResourceAccessor::GetLocalizedStringResource(SR_PipsPagerPageText) + L" " + winrt::to_hstring(index + 1)); - winrt::AutomationProperties::SetPositionInSet(pip, index + 1); - winrt::AutomationProperties::SetSizeOfSet(pip, NumberOfPages()); + winrt::AutomationProperties::SetName(element, ResourceAccessor::GetLocalizedStringResource(SR_PipsPagerPageText) + L" " + winrt::to_hstring(index + 1)); + winrt::AutomationProperties::SetPositionInSet(element, index + 1); + winrt::AutomationProperties::SetSizeOfSet(element, NumberOfPages()); + if (const auto pip = element.try_as()) + { auto pciRevokers = winrt::make_self(); pciRevokers->clickRevoker = pip.Click(winrt::auto_revoke, [this, index](auto const& sender, auto const& args) @@ -468,9 +470,49 @@ void PipsPager::OnOrientationChanged() { winrt::VisualStateManager::GoToState(*this, c_pipsPagerVerticalOrientationVisualState, false); } + if (const auto repeater = m_pipsPagerRepeater.get()) + { + if (const auto itemsSourceView = repeater.ItemsSourceView()) + { + const auto itemCount = itemsSourceView.Count(); + for (int i = 0; i < itemCount; i++) + { + if (const auto pip = repeater.TryGetElement(i).try_as()) + { + UpdatePipOrientation(pip); + } + } + } + } + m_defaultPipSize = GetDesiredPipSize(NormalPipStyle()); + m_selectedPipSize = GetDesiredPipSize(SelectedPipStyle()); SetScrollViewerMaxSize(); - UpdateSelectedPip(SelectedPageIndex()); + if (const auto selectedPip = GetSelectedItem()) + { + ScrollToCenterOfViewport(selectedPip, SelectedPageIndex()); + } +} +void PipsPager::ApplyStyleToPipAndUpdateOrientation(const winrt::FrameworkElement& pip, const winrt::Style& style) +{ + pip.Style(style); + if (const auto control = pip.try_as()) + { + control.ApplyTemplate(); + UpdatePipOrientation(control); + } +} + +void PipsPager::UpdatePipOrientation(const winrt::Control& pip) +{ + if (Orientation() == winrt::Orientation::Horizontal) + { + winrt::VisualStateManager::GoToState(pip, c_pipsPagerButtonHorizontalOrientationVisualState, false); + } + else + { + winrt::VisualStateManager::GoToState(pip, c_pipsPagerButtonVerticalOrientationVisualState, false); + } } void PipsPager::OnNavigationButtonVisibilityChanged(const ButtonVisibility visibility, const wstring_view& collapsedStateName, const wstring_view& disabledStateName) { @@ -692,6 +734,14 @@ void PipsPager::OnPropertyChanged(const winrt::DependencyPropertyChangedEventArg } } +winrt::UIElement PipsPager::GetSelectedItem() { + if (auto const repeater = m_pipsPagerRepeater.get()) + { + return repeater.TryGetElement(SelectedPageIndex()); + } + return nullptr; +} + winrt::AutomationPeer PipsPager::OnCreateAutomationPeer() { return winrt::make(*this); diff --git a/dev/PipsPager/PipsPager.h b/dev/PipsPager/PipsPager.h index 44aaf6331c..4451b3c3d5 100755 --- a/dev/PipsPager/PipsPager.h +++ b/dev/PipsPager/PipsPager.h @@ -47,6 +47,8 @@ class PipsPager : const wstring_view& disabledStateName); void OnOrientationChanged(); + winrt::UIElement GetSelectedItem(); + /* Dependency property for pip buttons revokers */ GlobalDependencyProperty s_pipButtonHandlersProperty; @@ -66,7 +68,8 @@ class PipsPager : void ScrollToCenterOfViewport(const winrt::UIElement sender, const int index); double CalculateScrollViewerSize(const double defaultPipSize, const double selectedPipSize, const int numberOfPages, int maxVisualIndicators); void UpdateSelectedPip(const int index); - + void UpdatePipOrientation(const winrt::Control& pip); + void ApplyStyleToPipAndUpdateOrientation(const winrt::FrameworkElement& pip, const winrt::Style& style); /* Eventing */ void RaiseSelectedIndexChanged(); diff --git a/dev/PipsPager/PipsPager.xaml b/dev/PipsPager/PipsPager.xaml index f81c440e4a..6ba2039880 100755 --- a/dev/PipsPager/PipsPager.xaml +++ b/dev/PipsPager/PipsPager.xaml @@ -88,13 +88,20 @@