only use the hack when Narrator is turn on

This commit is contained in:
MSFT-Tilia 2021-02-24 13:56:04 +08:00
commit 029e781319
2 changed files with 14 additions and 3 deletions

View file

@ -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,10 +119,13 @@ 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.
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);
}

View file

@ -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;
};
}
}