From bdaebad20b21c0145335a0314eb789986b89739d Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Wed, 8 Jan 2025 15:28:12 -0800 Subject: [PATCH] Make SUI previews readable by screen readers --- .../TerminalSettingsEditor/Appearances.cpp | 42 +++++++++++ .../TerminalSettingsEditor/Appearances.h | 1 + .../TerminalSettingsEditor/Appearances.idl | 1 + .../TerminalSettingsEditor/Appearances.xaml | 6 ++ .../TerminalSettingsEditor/Launch.xaml | 2 + .../LaunchViewModel.cpp | 9 +++ .../TerminalSettingsEditor/LaunchViewModel.h | 1 + .../LaunchViewModel.idl | 1 + .../ProfileViewModel.cpp | 9 +++ .../TerminalSettingsEditor/ProfileViewModel.h | 1 + .../ProfileViewModel.idl | 2 + .../TerminalSettingsEditor/Profiles_Base.xaml | 4 +- .../Resources/en-US/Resources.resw | 6 +- .../SettingContainer.cpp | 72 ++++++++++++++++--- .../TerminalSettingsEditor/SettingContainer.h | 4 ++ .../SettingContainer.idl | 3 + .../SettingContainerStyle.xaml | 3 + 17 files changed, 156 insertions(+), 11 deletions(-) diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.cpp b/src/cascadia/TerminalSettingsEditor/Appearances.cpp index bf85a5db29d..38904487e4b 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.cpp +++ b/src/cascadia/TerminalSettingsEditor/Appearances.cpp @@ -221,6 +221,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation // box, prevent it from ever being changed again. _NotifyChanges(L"UseDesktopBGImage", L"BackgroundImageSettingsVisible"); } + else if (viewModelProperty == L"BackgroundImageAlignment") + { + _NotifyChanges(L"BackgroundImageAlignmentCurrentValue"); + } else if (viewModelProperty == L"Foreground") { _NotifyChanges(L"ForegroundPreview"); @@ -912,6 +916,44 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation BackgroundImagePath(path); } + hstring AppearanceViewModel::BackgroundImageAlignmentCurrentValue() const + { + const auto alignment = BackgroundImageAlignment(); + hstring alignmentResourceKey = L"Profile_BackgroundImageAlignment"; + if (alignment == (ConvergedAlignment::Vertical_Center | ConvergedAlignment::Horizontal_Center)) + { + alignmentResourceKey = alignmentResourceKey + L"Center"; + } + else + { + // Append vertical alignment to the resource key + switch (alignment & static_cast(0x0F)) + { + case ConvergedAlignment::Vertical_Bottom: + alignmentResourceKey = alignmentResourceKey + L"Bottom"; + break; + case ConvergedAlignment::Vertical_Top: + alignmentResourceKey = alignmentResourceKey + L"Top"; + break; + } + + // Append horizontal alignment to the resource key + switch (alignment & static_cast(0xF0)) + { + case ConvergedAlignment::Horizontal_Left: + alignmentResourceKey = alignmentResourceKey + L"Left"; + break; + case ConvergedAlignment::Horizontal_Right: + alignmentResourceKey = alignmentResourceKey + L"Right"; + break; + } + } + alignmentResourceKey = alignmentResourceKey + L"/[using:Windows.UI.Xaml.Controls]ToolTipService/ToolTip"; + + // We can't use the RS_ macro here because the resource key is dynamic + return GetLibraryResourceString(alignmentResourceKey); + } + bool AppearanceViewModel::UseDesktopBGImage() { return BackgroundImagePath() == L"desktopWallpaper"; diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.h b/src/cascadia/TerminalSettingsEditor/Appearances.h index c31c1269cf1..989f278c567 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.h +++ b/src/cascadia/TerminalSettingsEditor/Appearances.h @@ -125,6 +125,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation bool BackgroundImageSettingsVisible(); void SetBackgroundImageOpacityFromPercentageValue(double percentageValue); void SetBackgroundImagePath(winrt::hstring path); + hstring BackgroundImageAlignmentCurrentValue() const; void ClearColorScheme(); Editor::ColorSchemeViewModel CurrentColorScheme() const; diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.idl b/src/cascadia/TerminalSettingsEditor/Appearances.idl index 68cbd4ee76b..89096d857ad 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.idl +++ b/src/cascadia/TerminalSettingsEditor/Appearances.idl @@ -40,6 +40,7 @@ namespace Microsoft.Terminal.Settings.Editor Boolean UseDesktopBGImage; Boolean BackgroundImageSettingsVisible { get; }; + String BackgroundImageAlignmentCurrentValue { get; }; void ClearColorScheme(); ColorSchemeViewModel CurrentColorScheme; diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.xaml b/src/cascadia/TerminalSettingsEditor/Appearances.xaml index 9789ac91450..d4cff695602 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.xaml +++ b/src/cascadia/TerminalSettingsEditor/Appearances.xaml @@ -73,6 +73,7 @@ @@ -209,6 +210,7 @@ x:Uid="Profile_Foreground" ClearSettingValue="{x:Bind Appearance.ClearForeground}" CurrentValue="{x:Bind Appearance.ForegroundPreview, Mode=OneWay}" + CurrentValueAccessibleName="{x:Bind Appearance.ForegroundPreview, Converter={StaticResource ColorToStringConverter}, Mode=OneWay}" CurrentValueTemplate="{StaticResource ColorPreviewTemplate}" HasSettingValue="{x:Bind Appearance.HasForeground, Mode=OneWay}" SettingOverrideSource="{x:Bind Appearance.ForegroundOverrideSource, Mode=OneWay}" @@ -224,6 +226,7 @@ x:Uid="Profile_Background" ClearSettingValue="{x:Bind Appearance.ClearBackground}" CurrentValue="{x:Bind Appearance.BackgroundPreview, Mode=OneWay}" + CurrentValueAccessibleName="{x:Bind Appearance.BackgroundPreview, Converter={StaticResource ColorToStringConverter}, Mode=OneWay}" CurrentValueTemplate="{StaticResource ColorPreviewTemplate}" HasSettingValue="{x:Bind Appearance.HasBackground, Mode=OneWay}" SettingOverrideSource="{x:Bind Appearance.BackgroundOverrideSource, Mode=OneWay}" @@ -239,6 +242,7 @@ x:Uid="Profile_SelectionBackground" ClearSettingValue="{x:Bind Appearance.ClearSelectionBackground}" CurrentValue="{x:Bind Appearance.SelectionBackgroundPreview, Mode=OneWay}" + CurrentValueAccessibleName="{x:Bind Appearance.SelectionBackgroundPreview, Converter={StaticResource ColorToStringConverter}, Mode=OneWay}" CurrentValueTemplate="{StaticResource ColorPreviewTemplate}" HasSettingValue="{x:Bind Appearance.HasSelectionBackground, Mode=OneWay}" SettingOverrideSource="{x:Bind Appearance.SelectionBackgroundOverrideSource, Mode=OneWay}" @@ -508,6 +512,7 @@ x:Uid="Profile_CursorColor" ClearSettingValue="{x:Bind Appearance.ClearCursorColor}" CurrentValue="{x:Bind Appearance.CursorColorPreview, Mode=OneWay}" + CurrentValueAccessibleName="{x:Bind Appearance.CursorColorPreview, Converter={StaticResource ColorToStringConverter}, Mode=OneWay}" CurrentValueTemplate="{StaticResource ColorPreviewTemplate}" HasSettingValue="{x:Bind Appearance.HasCursorColor, Mode=OneWay}" SettingOverrideSource="{x:Bind Appearance.CursorColorOverrideSource, Mode=OneWay}" @@ -568,6 +573,7 @@ + diff --git a/src/cascadia/TerminalSettingsEditor/LaunchViewModel.cpp b/src/cascadia/TerminalSettingsEditor/LaunchViewModel.cpp index 856f78a0dce..7b37863ef3a 100644 --- a/src/cascadia/TerminalSettingsEditor/LaunchViewModel.cpp +++ b/src/cascadia/TerminalSettingsEditor/LaunchViewModel.cpp @@ -62,6 +62,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation { _NotifyChanges(L"LaunchParametersCurrentValue"); } + else if (viewModelProperty == L"InitialCols" || viewModelProperty == L"InitialRows") + { + _NotifyChanges(L"LaunchSizeCurrentValue"); + } }); } @@ -205,6 +209,11 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation } } + winrt::hstring LaunchViewModel::LaunchSizeCurrentValue() const + { + return winrt::hstring{ fmt::format(FMT_COMPILE(L"{} × {}"), InitialCols(), InitialRows()) }; + } + winrt::hstring LaunchViewModel::LaunchParametersCurrentValue() { const auto launchModeString = CurrentLaunchMode().as()->EnumName(); diff --git a/src/cascadia/TerminalSettingsEditor/LaunchViewModel.h b/src/cascadia/TerminalSettingsEditor/LaunchViewModel.h index be4ba46728c..bd6df9299d3 100644 --- a/src/cascadia/TerminalSettingsEditor/LaunchViewModel.h +++ b/src/cascadia/TerminalSettingsEditor/LaunchViewModel.h @@ -24,6 +24,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation winrt::Windows::Foundation::IInspectable CurrentLanguage(); void CurrentLanguage(const winrt::Windows::Foundation::IInspectable& tag); + winrt::hstring LaunchSizeCurrentValue() const; winrt::hstring LaunchParametersCurrentValue(); double InitialPosX(); double InitialPosY(); diff --git a/src/cascadia/TerminalSettingsEditor/LaunchViewModel.idl b/src/cascadia/TerminalSettingsEditor/LaunchViewModel.idl index da1cebfe630..ffe2b6b4821 100644 --- a/src/cascadia/TerminalSettingsEditor/LaunchViewModel.idl +++ b/src/cascadia/TerminalSettingsEditor/LaunchViewModel.idl @@ -19,6 +19,7 @@ namespace Microsoft.Terminal.Settings.Editor IInspectable CurrentDefaultInputScope; IObservableVector DefaultInputScopeList { get; }; + String LaunchSizeCurrentValue { get; }; String LaunchParametersCurrentValue { get; }; Double InitialPosX; Double InitialPosY; diff --git a/src/cascadia/TerminalSettingsEditor/ProfileViewModel.cpp b/src/cascadia/TerminalSettingsEditor/ProfileViewModel.cpp index 1d0272a10db..c4323039d8b 100644 --- a/src/cascadia/TerminalSettingsEditor/ProfileViewModel.cpp +++ b/src/cascadia/TerminalSettingsEditor/ProfileViewModel.cpp @@ -488,6 +488,15 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation return _profile.Orphaned(); } + hstring ProfileViewModel::TabTitlePreview() const + { + if (const auto tabTitle{ TabTitle() }; !tabTitle.empty()) + { + return tabTitle; + } + return RS_(L"Profile_TabTitleNone"); + } + Editor::AppearanceViewModel ProfileViewModel::DefaultAppearance() { return _defaultAppearanceViewModel; diff --git a/src/cascadia/TerminalSettingsEditor/ProfileViewModel.h b/src/cascadia/TerminalSettingsEditor/ProfileViewModel.h index 4b70acaacc2..eb1cb864b0d 100644 --- a/src/cascadia/TerminalSettingsEditor/ProfileViewModel.h +++ b/src/cascadia/TerminalSettingsEditor/ProfileViewModel.h @@ -115,6 +115,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation bool RepositionCursorWithMouseAvailable() const noexcept; bool Orphaned() const; + hstring TabTitlePreview() const; til::typed_event DeleteProfileRequested; diff --git a/src/cascadia/TerminalSettingsEditor/ProfileViewModel.idl b/src/cascadia/TerminalSettingsEditor/ProfileViewModel.idl index 0b58480053a..5d686b1c1d0 100644 --- a/src/cascadia/TerminalSettingsEditor/ProfileViewModel.idl +++ b/src/cascadia/TerminalSettingsEditor/ProfileViewModel.idl @@ -118,6 +118,8 @@ namespace Microsoft.Terminal.Settings.Editor IInspectable CurrentBuiltInIcon; Windows.Foundation.Collections.IVector BuiltInIcons { get; }; + String TabTitlePreview { get; }; + void CreateUnfocusedAppearance(); void DeleteUnfocusedAppearance(); diff --git a/src/cascadia/TerminalSettingsEditor/Profiles_Base.xaml b/src/cascadia/TerminalSettingsEditor/Profiles_Base.xaml index 75c4f31420f..a048a8dba5e 100644 --- a/src/cascadia/TerminalSettingsEditor/Profiles_Base.xaml +++ b/src/cascadia/TerminalSettingsEditor/Profiles_Base.xaml @@ -102,6 +102,7 @@ @@ -110,6 +111,7 @@ diff --git a/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw b/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw index d7a0c3efe36..6b09102f28b 100644 --- a/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw @@ -2316,4 +2316,8 @@ Indicates the software that originally created this profile. - + + None + Text displayed when the tab title is not defined. + + \ No newline at end of file diff --git a/src/cascadia/TerminalSettingsEditor/SettingContainer.cpp b/src/cascadia/TerminalSettingsEditor/SettingContainer.cpp index a3302bdb443..d197475e02a 100644 --- a/src/cascadia/TerminalSettingsEditor/SettingContainer.cpp +++ b/src/cascadia/TerminalSettingsEditor/SettingContainer.cpp @@ -15,6 +15,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation DependencyProperty SettingContainer::_FontIconGlyphProperty{ nullptr }; DependencyProperty SettingContainer::_CurrentValueProperty{ nullptr }; DependencyProperty SettingContainer::_CurrentValueTemplateProperty{ nullptr }; + DependencyProperty SettingContainer::_CurrentValueAccessibleNameProperty{ nullptr }; DependencyProperty SettingContainer::_HasSettingValueProperty{ nullptr }; DependencyProperty SettingContainer::_SettingOverrideSourceProperty{ nullptr }; DependencyProperty SettingContainer::_StartExpandedProperty{ nullptr }; @@ -63,7 +64,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation L"CurrentValue", xaml_typename(), xaml_typename(), - PropertyMetadata{ nullptr }); + PropertyMetadata{ nullptr, PropertyChangedCallback{ &SettingContainer::_OnCurrentValueChanged } }); } if (!_CurrentValueTemplateProperty) { @@ -74,6 +75,15 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation xaml_typename(), PropertyMetadata{ nullptr }); } + if (!_CurrentValueAccessibleNameProperty) + { + _CurrentValueAccessibleNameProperty = + DependencyProperty::Register( + L"CurrentValueAccessibleName", + xaml_typename(), + xaml_typename(), + PropertyMetadata{ box_value(L""), PropertyChangedCallback{ &SettingContainer::_OnCurrentValueChanged } }); + } if (!_HasSettingValueProperty) { _HasSettingValueProperty = @@ -103,6 +113,12 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation } } + void SettingContainer::_OnCurrentValueChanged(const Windows::UI::Xaml::DependencyObject& d, const Windows::UI::Xaml::DependencyPropertyChangedEventArgs& /*e*/) + { + const auto& obj{ d.try_as() }; + get_self(obj)->_UpdateCurrentValueAutoProp(); + } + void SettingContainer::_OnHasSettingValueChanged(const DependencyObject& d, const DependencyPropertyChangedEventArgs& /*args*/) { // update visibility for override message and reset button @@ -174,14 +190,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation for (const auto& obj : base) { - // apply header as name (automation property) - if (const auto& header{ Header() }) - { - if (const auto headerText{ header.try_as() }) - { - Automation::AutomationProperties::SetName(obj, *headerText); - } - } + // apply header and current value as name (automation property) + Automation::AutomationProperties::SetName(obj, _GenerateAccessibleName()); // apply help text as tooltip and full description (automation property) if (const auto& helpText{ HelpText() }; !helpText.empty()) @@ -247,6 +257,17 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation } } + void SettingContainer::_UpdateCurrentValueAutoProp() + { + if (const auto& child{ GetTemplateChild(L"Expander") }) + { + if (const auto& expander{ child.try_as() }) + { + Automation::AutomationProperties::SetName(expander, _GenerateAccessibleName()); + } + } + } + // Method Description: // - Helper function for generating the override message // Arguments: @@ -279,4 +300,37 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation } return RS_(L"SettingContainer_OverrideMessageBaseLayer"); } + + // Method Description: + // - Helper function for generating the accessible name + // Return Value: + // - text specifying the accessible name. Includes header and current value, if available. + hstring SettingContainer::_GenerateAccessibleName() + { + hstring name{}; + if (const auto& header{ Header() }) + { + if (const auto headerText{ header.try_as() }) + { + name = *headerText; + } + + // append current value to the name, if it exists + if (const auto currentValAccessibleName{ CurrentValueAccessibleName() }; !currentValAccessibleName.empty()) + { + // prefer CurrentValueAccessibleName, if it exists + name = name + L": " + currentValAccessibleName; + } + else if (const auto& currentVal{ CurrentValue() }) + { + // the accessible name was not defined, so try to + // extract the value directly from the CurrentValue property + if (const auto currentValText{ currentVal.try_as() }) + { + name = name + L": " + *currentValText; + } + } + } + return name; + } } diff --git a/src/cascadia/TerminalSettingsEditor/SettingContainer.h b/src/cascadia/TerminalSettingsEditor/SettingContainer.h index 1242e4bb898..862d3e8660e 100644 --- a/src/cascadia/TerminalSettingsEditor/SettingContainer.h +++ b/src/cascadia/TerminalSettingsEditor/SettingContainer.h @@ -38,15 +38,19 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation DEPENDENCY_PROPERTY(hstring, FontIconGlyph); DEPENDENCY_PROPERTY(Windows::Foundation::IInspectable, CurrentValue); DEPENDENCY_PROPERTY(Windows::UI::Xaml::DataTemplate, CurrentValueTemplate); + DEPENDENCY_PROPERTY(hstring, CurrentValueAccessibleName); DEPENDENCY_PROPERTY(bool, HasSettingValue); DEPENDENCY_PROPERTY(bool, StartExpanded); DEPENDENCY_PROPERTY(IInspectable, SettingOverrideSource); private: static void _InitializeProperties(); + static void _OnCurrentValueChanged(const Windows::UI::Xaml::DependencyObject& d, const Windows::UI::Xaml::DependencyPropertyChangedEventArgs& e); static void _OnHasSettingValueChanged(const Windows::UI::Xaml::DependencyObject& d, const Windows::UI::Xaml::DependencyPropertyChangedEventArgs& e); static hstring _GenerateOverrideMessage(const IInspectable& settingOrigin); + hstring _GenerateAccessibleName(); void _UpdateOverrideSystem(); + void _UpdateCurrentValueAutoProp(); }; } diff --git a/src/cascadia/TerminalSettingsEditor/SettingContainer.idl b/src/cascadia/TerminalSettingsEditor/SettingContainer.idl index 7b46a9c20ef..143d49b919f 100644 --- a/src/cascadia/TerminalSettingsEditor/SettingContainer.idl +++ b/src/cascadia/TerminalSettingsEditor/SettingContainer.idl @@ -24,6 +24,9 @@ namespace Microsoft.Terminal.Settings.Editor Windows.UI.Xaml.DataTemplate CurrentValueTemplate; static Windows.UI.Xaml.DependencyProperty CurrentValueTemplateProperty { get; }; + String CurrentValueAccessibleName; + static Windows.UI.Xaml.DependencyProperty CurrentValueAccessibleNameProperty { get; }; + Boolean HasSettingValue; static Windows.UI.Xaml.DependencyProperty HasSettingValueProperty { get; }; diff --git a/src/cascadia/TerminalSettingsEditor/SettingContainerStyle.xaml b/src/cascadia/TerminalSettingsEditor/SettingContainerStyle.xaml index 58c9ae497df..5ef4acd978d 100644 --- a/src/cascadia/TerminalSettingsEditor/SettingContainerStyle.xaml +++ b/src/cascadia/TerminalSettingsEditor/SettingContainerStyle.xaml @@ -282,6 +282,7 @@ TargetType="local:SettingContainer"> + @@ -333,6 +334,7 @@ TargetType="local:SettingContainer"> + @@ -383,6 +385,7 @@ TargetType="local:SettingContainer"> +