From 029e781319bd855f115c2be72312b76d1e27a0ac Mon Sep 17 00:00:00 2001 From: MSFT-Tilia Date: Wed, 24 Feb 2021 13:56:04 +0800 Subject: [PATCH] only use the hack when Narrator is turn on --- src/Calculator/Controls/MathRichEditBox.cpp | 15 ++++++++++++--- src/Calculator/Controls/MathRichEditBox.h | 2 ++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Calculator/Controls/MathRichEditBox.cpp b/src/Calculator/Controls/MathRichEditBox.cpp index d1dab624..872a9b18 100644 --- a/src/Calculator/Controls/MathRichEditBox.cpp +++ b/src/Calculator/Controls/MathRichEditBox.cpp @@ -12,6 +12,7 @@ using namespace std; using namespace Windows::ApplicationModel; using namespace Windows::UI::Core; using namespace Windows::UI::Xaml; +using namespace Windows::UI::Xaml::Automation::Peers; using namespace Windows::UI::Xaml::Input; using namespace Windows::UI::Xaml::Controls; using namespace Windows::UI::Text; @@ -118,9 +119,12 @@ void MathRichEditBox::OnGotFocus(Platform::Object ^ sender, Windows::UI::Xaml::R // [BUG 28498627][GithubIssue #1380] // below directives on Selection are going to engage Narrator to announce the content of this richedit // this is a workaround since richedit doesn't announce its content automatically. - this->Document->Selection->EndKey(TextRangeUnit::Line, false); - this->Document->Selection->HomeKey(TextRangeUnit::Line, false); - this->Document->Selection->MoveLeft(TextRangeUnit::Character, 1, false); + if (IsUIAccessibilityVoiceOverRunning()) + { + this->Document->Selection->EndKey(TextRangeUnit::Line, false); + this->Document->Selection->HomeKey(TextRangeUnit::Line, false); + this->Document->Selection->MoveLeft(TextRangeUnit::Character, 1, false); + } } void MathRichEditBox::OnLosingFocus(UIElement ^ sender, LosingFocusEventArgs ^ args) @@ -238,3 +242,8 @@ void MathRichEditBox::SubmitEquation(EquationSubmissionSource source) EquationSubmitted(this, ref new MathRichEditBoxSubmission(false, source)); } } + +bool MathRichEditBox::IsUIAccessibilityVoiceOverRunning() const +{ + return AutomationPeer::ListenerExists(AutomationEvents::PropertyChanged); +} diff --git a/src/Calculator/Controls/MathRichEditBox.h b/src/Calculator/Controls/MathRichEditBox.h index bfeb72db..76cf5b4d 100644 --- a/src/Calculator/Controls/MathRichEditBox.h +++ b/src/Calculator/Controls/MathRichEditBox.h @@ -70,6 +70,8 @@ namespace CalculatorApp void OnGotFocus(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); void OnLosingFocus(Windows::UI::Xaml::UIElement ^ sender, Windows::UI::Xaml::Input::LosingFocusEventArgs ^ args); void OnKeyUp(Platform::Object ^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs ^ e); + + bool IsUIAccessibilityVoiceOverRunning() const; }; } }