From cd29bf314a888d18e7702fc857b193e2cb96302e Mon Sep 17 00:00:00 2001 From: T Paine Date: Wed, 5 Dec 2018 16:50:01 -0800 Subject: [PATCH] Add F4 behavior and remove unneeded items from accessible tree. (#37) --- .../InteractionTests/SplitButtonTests.cs | 82 +++++++------------ dev/SplitButton/SplitButton.cpp | 19 +++-- dev/SplitButton/SplitButton.h | 1 - dev/SplitButton/SplitButton.xaml | 6 +- dev/SplitButton/SplitButton_rs1.xaml | 13 ++- 5 files changed, 54 insertions(+), 67 deletions(-) diff --git a/dev/SplitButton/InteractionTests/SplitButtonTests.cs b/dev/SplitButton/InteractionTests/SplitButtonTests.cs index 1f4b553..8a418fc 100644 --- a/dev/SplitButton/InteractionTests/SplitButtonTests.cs +++ b/dev/SplitButton/InteractionTests/SplitButtonTests.cs @@ -56,24 +56,18 @@ namespace Windows.UI.Xaml.Tests.MUXControls.InteractionTests using (var setup = new TestSetupHelper("SplitButton Tests")) { SplitButton splitButton = FindElement.ByName("TestSplitButton"); - Button primaryButton = GetPrimaryButton(splitButton); - Button secondaryButton = GetSecondaryButton(splitButton); TextBlock clickCountTextBlock = FindElement.ByName("ClickCountTextBlock"); TextBlock flyoutOpenedCountTextBlock = FindElement.ByName("FlyoutOpenedCountTextBlock"); TextBlock flyoutClosedCountTextBlock = FindElement.ByName("FlyoutClosedCountTextBlock"); Verify.AreEqual("0", clickCountTextBlock.DocumentText); - Log.Comment("Click primary button"); - primaryButton.Click(); - Wait.ForIdle(); + ClickPrimaryButton(splitButton); Verify.AreEqual("1", clickCountTextBlock.DocumentText); VerifyElement.NotFound("TestFlyout", FindBy.Name); Verify.AreEqual("0", flyoutOpenedCountTextBlock.DocumentText); - Log.Comment("Click secondary button"); - secondaryButton.Click(); - Wait.ForIdle(); + ClickSecondaryButton(splitButton); Verify.AreEqual("1", flyoutOpenedCountTextBlock.DocumentText); VerifyElement.Found("TestFlyout", FindBy.Name); @@ -91,30 +85,24 @@ namespace Windows.UI.Xaml.Tests.MUXControls.InteractionTests using (var setup = new TestSetupHelper("SplitButton Tests")) { SplitButton splitButton = FindElement.ByName("CommandSplitButton"); - Button primaryButton = GetPrimaryButton(splitButton); - Button secondaryButton = GetSecondaryButton(splitButton); CheckBox canExecuteCheckBox = FindElement.ByName("CanExecuteCheckBox"); TextBlock executeCountTextBlock = FindElement.ByName("ExecuteCountTextBlock"); Log.Comment("Verify that the control starts out enabled"); Verify.AreEqual(ToggleState.On, canExecuteCheckBox.ToggleState); - Verify.AreEqual(true, primaryButton.IsEnabled); - Verify.AreEqual(true, secondaryButton.IsEnabled); + Verify.AreEqual(true, splitButton.IsEnabled); Verify.AreEqual("0", executeCountTextBlock.DocumentText); Log.Comment("Click primary button to execute command"); - InputHelper.MoveMouse(primaryButton, 0, 0); - Wait.ForIdle(); - primaryButton.Click(); - Wait.ForIdle(); + ClickPrimaryButton(splitButton); Verify.AreEqual("1", executeCountTextBlock.DocumentText); Log.Comment("Verify that setting CanExecute to false disables the primary button"); canExecuteCheckBox.Uncheck(); Wait.ForIdle(); - Verify.AreEqual(false, primaryButton.IsEnabled); - Verify.AreEqual(true, secondaryButton.IsEnabled); + ClickPrimaryButton(splitButton); + Verify.AreEqual("1", executeCountTextBlock.DocumentText); } } @@ -125,8 +113,6 @@ namespace Windows.UI.Xaml.Tests.MUXControls.InteractionTests using (var setup = new TestSetupHelper("SplitButton Tests")) { SplitButton splitButton = FindElement.ByName("TestSplitButton"); - Button primaryButton = GetPrimaryButton(splitButton); - Button secondaryButton = GetSecondaryButton(splitButton); CheckBox simulateTouchCheckBox = FindElement.ByName("SimulateTouchCheckBox"); @@ -141,8 +127,7 @@ namespace Windows.UI.Xaml.Tests.MUXControls.InteractionTests Verify.AreEqual("0", flyoutOpenedCountTextBlock.DocumentText); Log.Comment("Click primary button to open flyout in touch mode"); - primaryButton.Click(); - Wait.ForIdle(); + ClickPrimaryButton(splitButton); Verify.AreEqual("0", clickCountTextBlock.DocumentText); Verify.AreEqual("1", flyoutOpenedCountTextBlock.DocumentText); @@ -165,6 +150,9 @@ namespace Windows.UI.Xaml.Tests.MUXControls.InteractionTests TextBlock flyoutOpenedCountTextBlock = FindElement.ByName("FlyoutOpenedCountTextBlock"); TextBlock flyoutClosedCountTextBlock = FindElement.ByName("FlyoutClosedCountTextBlock"); + Log.Comment("Verify that SplitButton has no accessible children"); + Verify.AreEqual(0, splitButton.Children.Count); + Verify.AreEqual("0", clickCountTextBlock.DocumentText); Log.Comment("Verify that invoking the SplitButton causes a click"); splitButton.InvokeAndWait(); @@ -174,11 +162,13 @@ namespace Windows.UI.Xaml.Tests.MUXControls.InteractionTests Log.Comment("Verify that expanding the SplitButton opens the flyout"); splitButton.ExpandAndWait(); Verify.AreEqual("1", flyoutOpenedCountTextBlock.DocumentText); + Verify.AreEqual(ExpandCollapseState.Expanded, splitButton.ExpandCollapseState); Verify.AreEqual("0", flyoutClosedCountTextBlock.DocumentText); Log.Comment("Verify that collapsing the SplitButton closes the flyout"); splitButton.CollapseAndWait(); Verify.AreEqual("1", flyoutClosedCountTextBlock.DocumentText); + Verify.AreEqual(ExpandCollapseState.Collapsed, splitButton.ExpandCollapseState); } } @@ -210,10 +200,17 @@ namespace Windows.UI.Xaml.Tests.MUXControls.InteractionTests Verify.AreEqual("1", flyoutOpenedCountTextBlock.DocumentText); Verify.AreEqual("0", flyoutClosedCountTextBlock.DocumentText); - Log.Comment("Verify that press escape closes the flyout"); + Log.Comment("Verify that pressing escape closes the flyout"); KeyboardHelper.PressKey(Key.Escape); Wait.ForIdle(); Verify.AreEqual("1", flyoutClosedCountTextBlock.DocumentText); + + Log.Comment("Verify that F4 opens the flyout"); + splitButton.SetFocus(); + Wait.ForIdle(); + TextInput.SendText("{F4}"); + Wait.ForIdle(); + Verify.AreEqual("2", flyoutOpenedCountTextBlock.DocumentText); } } @@ -223,8 +220,6 @@ namespace Windows.UI.Xaml.Tests.MUXControls.InteractionTests using (var setup = new TestSetupHelper("SplitButton Tests")) { SplitButton splitButton = FindElement.ByName("ToggleSplitButton"); - Button primaryButton = GetPrimaryButton(splitButton); - Button secondaryButton = GetSecondaryButton(splitButton); TextBlock toggleStateTextBlock = FindElement.ByName("ToggleStateTextBlock"); TextBlock toggleStateOnClickTextBlock = FindElement.ByName("ToggleStateOnClickTextBlock"); @@ -233,22 +228,19 @@ namespace Windows.UI.Xaml.Tests.MUXControls.InteractionTests Verify.AreEqual("Unchecked", toggleStateOnClickTextBlock.DocumentText); Log.Comment("Click primary button to check button"); - primaryButton.Click(); - Wait.ForIdle(); + ClickPrimaryButton(splitButton); Verify.AreEqual("Checked", toggleStateTextBlock.DocumentText); Verify.AreEqual("Checked", toggleStateOnClickTextBlock.DocumentText); Log.Comment("Click primary button to uncheck button"); - primaryButton.Click(); - Wait.ForIdle(); + ClickPrimaryButton(splitButton); Verify.AreEqual("Unchecked", toggleStateTextBlock.DocumentText); Verify.AreEqual("Unchecked", toggleStateOnClickTextBlock.DocumentText); Log.Comment("Clicking secondary button should not change toggle state"); - secondaryButton.Click(); - Wait.ForIdle(); + ClickSecondaryButton(splitButton); Verify.AreEqual("Unchecked", toggleStateTextBlock.DocumentText); Verify.AreEqual("Unchecked", toggleStateOnClickTextBlock.DocumentText); @@ -276,30 +268,18 @@ namespace Windows.UI.Xaml.Tests.MUXControls.InteractionTests } } - public Button GetPrimaryButton(SplitButton splitButton) + public void ClickPrimaryButton(SplitButton splitButton) { - return new Button(FindDescendant(splitButton, "PrimaryButton")); + Log.Comment("Click primary button area"); + splitButton.Click(PointerButtons.Primary, 5, splitButton.BoundingRectangle.Height / 2); + Wait.ForIdle(); } - public Button GetSecondaryButton(SplitButton splitButton) + public void ClickSecondaryButton(SplitButton splitButton) { - return new Button(FindDescendant(splitButton, "SecondaryButton")); - } - - public UIObject FindDescendant(UIObject parent, string id) - { - UIObject child = null; - - foreach (UIObject o in parent.Descendants) - { - if (o.AutomationId == id) - { - Log.Comment("Found " + id); - child = o; - } - } - - return child; + Log.Comment("Click secondary button area"); + splitButton.Click(PointerButtons.Primary, splitButton.BoundingRectangle.Width - 5, splitButton.BoundingRectangle.Height / 2); + Wait.ForIdle(); } } } diff --git a/dev/SplitButton/SplitButton.cpp b/dev/SplitButton/SplitButton.cpp index c13b47a..d8a290f 100644 --- a/dev/SplitButton/SplitButton.cpp +++ b/dev/SplitButton/SplitButton.cpp @@ -297,10 +297,6 @@ void SplitButton::OnSplitButtonKeyDown(const winrt::IInspectable& sender, const m_isKeyDown = true; UpdateVisualStates(); } - else if (key == winrt::VirtualKey::Menu) - { - m_isAltKeyDown = true; - } } void SplitButton::OnSplitButtonKeyUp(const winrt::IInspectable& sender, const winrt::KeyRoutedEventArgs& args) @@ -318,19 +314,24 @@ void SplitButton::OnSplitButtonKeyUp(const winrt::IInspectable& sender, const wi args.Handled(true); } } - else if (key == winrt::VirtualKey::Menu) - { - m_isAltKeyDown = false; - } else if (key == winrt::VirtualKey::Down) { - if (IsEnabled() && m_isAltKeyDown) + winrt::CoreVirtualKeyStates menuState = winrt::CoreWindow::GetForCurrentThread().GetKeyState(winrt::VirtualKey::Menu); + bool menuKeyDown = (menuState & winrt::CoreVirtualKeyStates::Down) == winrt::CoreVirtualKeyStates::Down; + + if (IsEnabled() && menuKeyDown) { // Open the menu on alt-down OpenFlyout(); args.Handled(true); } } + else if (key == winrt::VirtualKey::F4 && IsEnabled()) + { + // Open the menu on F4 + OpenFlyout(); + args.Handled(true); + } } void SplitButton::UnregisterEvents() diff --git a/dev/SplitButton/SplitButton.h b/dev/SplitButton/SplitButton.h index 60c056e..435db8e 100644 --- a/dev/SplitButton/SplitButton.h +++ b/dev/SplitButton/SplitButton.h @@ -65,7 +65,6 @@ private: bool m_isFlyoutOpen{ false }; winrt::PointerDeviceType m_lastPointerDeviceType{ winrt::PointerDeviceType::Mouse }; bool m_isKeyDown{ false }; - bool m_isAltKeyDown{ false }; winrt::UIElement::KeyDown_revoker m_keyDownRevoker{}; winrt::UIElement::KeyUp_revoker m_keyUpRevoker{}; diff --git a/dev/SplitButton/SplitButton.xaml b/dev/SplitButton/SplitButton.xaml index 9810562..9349335 100644 --- a/dev/SplitButton/SplitButton.xaml +++ b/dev/SplitButton/SplitButton.xaml @@ -252,7 +252,8 @@ HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Padding="{TemplateBinding Padding}" - IsTabStop="False"/> + IsTabStop="False" + AutomationProperties.AccessibilityView="Raw"/>