Skip to content

Commit

Permalink
Fix KBM Accessibility issues (#6379)
Browse files Browse the repository at this point in the history
* Added an accessible name for the combo box

* Add name for the type shortcut button

* Add accessible name for the add new remapping button in both key remapping as well as shortcut remapping windows

* Set accessible names for the delete button

* Set the accessible name to the remapped to icon

* Fix the font icon issue faced while using narrator

* Fix accessible name for Add shortcut remapping button

* Set the accessible name for the target app text box when it loses focus

* fix comment
  • Loading branch information
alekhyareddy28 committed Sep 8, 2020
1 parent 8ea8db7 commit 1a51f77
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/modules/keyboardmanager/dll/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,22 @@
<data name="ErrorMessage_Default" xml:space="preserve">
<value>Unexpected error</value>
</data>
<data name="Key_DropDown_Combobox" xml:space="preserve">
<value>Key Drop Down</value>
</data>
<data name="Add_Key_Remap_Button" xml:space="preserve">
<value>Add Key Remap</value>
</data>
<data name="Add_Shortcut_Button" xml:space="preserve">
<value>Add Shortcut Remapping</value>
</data>
<data name="Delete_Remapping_Button" xml:space="preserve">
<value>Delete Remapping</value>
</data>
<data name="Remapped_To" xml:space="preserve">
<value>Remapped To</value>
</data>
<data name="Target_Application" xml:space="preserve">
<value>For Target Application </value>
</data>
</root>
2 changes: 2 additions & 0 deletions src/modules/keyboardmanager/ui/EditKeyboardWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan
// Whenever a remap is added move to the bottom of the screen
scrollViewer.ChangeView(nullptr, scrollViewer.ScrollableHeight(), nullptr);
});
// Set accessible name for the addRemapKey button
addRemapKey.SetValue(Automation::AutomationProperties::NameProperty(), box_value(GET_RESOURCE_STRING(IDS_ADD_KEY_REMAP_BUTTON)));

StackPanel mappingsPanel;
mappingsPanel.Children().Append(keyRemapInfoHeader);
Expand Down
2 changes: 2 additions & 0 deletions src/modules/keyboardmanager/ui/EditShortcutsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa
// Whenever a remap is added move to the bottom of the screen
scrollViewer.ChangeView(nullptr, scrollViewer.ScrollableHeight(), nullptr);
});
// Set accessible name for the add shortcut button
addShortcut.SetValue(Automation::AutomationProperties::NameProperty(), box_value(GET_RESOURCE_STRING(IDS_ADD_SHORTCUT_BUTTON)));

StackPanel mappingsPanel;
mappingsPanel.Children().Append(shortcutRemapInfoHeader);
Expand Down
2 changes: 2 additions & 0 deletions src/modules/keyboardmanager/ui/KeyDropDownControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ void KeyDropDownControl::SetDefaultProperties(bool isShortcut)
// Attach flyout to the drop down
warningFlyout.as<Flyout>().Content(warningMessage.as<TextBlock>());
dropDown.as<ComboBox>().ContextFlyout().SetAttachedFlyout((FrameworkElement)dropDown.as<ComboBox>(), warningFlyout.as<Flyout>());
// To set the accessible name of the combo-box
dropDown.as<ComboBox>().SetValue(Automation::AutomationProperties::NameProperty(), box_value(GET_RESOURCE_STRING(IDS_KEY_DROPDOWN_COMBOBOX)));
}

// Function to check if the layout has changed and accordingly update the drop down list
Expand Down
23 changes: 23 additions & 0 deletions src/modules/keyboardmanager/ui/ShortcutControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ ShortcutControl::ShortcutControl(Grid table, const int colIndex, TextBox targetA
// Using the XamlRoot of the typeShortcut to get the root of the XAML host
createDetectShortcutWindow(sender, sender.as<Button>().XamlRoot(), *keyboardManagerState, colIndex, table, keyDropDownControlObjects, shortcutControlLayout.as<StackPanel>(), targetApp, isHybridControl, false, EditShortcutsWindowHandle, shortcutRemapBuffer);
});
// Set an accessible name for the type shortcut button
typeShortcut.as<Button>().SetValue(Automation::AutomationProperties::NameProperty(), box_value(GET_RESOURCE_STRING(IDS_TYPE_BUTTON)));

shortcutControlLayout.as<StackPanel>().Margin({ 0, 0, 0, 10 });
shortcutControlLayout.as<StackPanel>().Spacing(KeyboardManagerConstants::ShortcutTableDropDownSpacing);
Expand All @@ -40,6 +42,18 @@ ShortcutControl::ShortcutControl(Grid table, const int colIndex, TextBox targetA
shortcutControlLayout.as<StackPanel>().UpdateLayout();
}

// Function to set the accessible name of the target App text box
void ShortcutControl::SetAccessibleNameForTextBox(TextBox targetAppTextBox)
{
// To set the accessible name of the target App text box by adding the string `All Apps` if the text box is empty, if not the application name is read by narrator.
std::wstring targetAppTextBoxAccessibleName = GET_RESOURCE_STRING(IDS_TARGET_APPLICATION);
if (targetAppTextBox.Text() == L"")
{
targetAppTextBoxAccessibleName += GET_RESOURCE_STRING(IDS_EDITSHORTCUTS_ALLAPPS);
}
targetAppTextBox.SetValue(Automation::AutomationProperties::NameProperty(), box_value(targetAppTextBoxAccessibleName));
}

// Function to add a new row to the shortcut table. If the originalKeys and newKeys args are provided, then the displayed shortcuts are set to those values.
void ShortcutControl::AddNewShortcutControlRow(Grid& parent, std::vector<std::vector<std::unique_ptr<ShortcutControl>>>& keyboardRemapControlObjects, const Shortcut& originalKeys, const std::variant<DWORD, Shortcut>& newKeys, const std::wstring& targetAppName)
{
Expand Down Expand Up @@ -71,6 +85,8 @@ void ShortcutControl::AddNewShortcutControlRow(Grid& parent, std::vector<std::ve
parent.SetRow(arrowIcon, parent.RowDefinitions().Size() - 1);
parent.Children().Append(arrowIcon);

// To set the accessible name of the arrow icon by setting the accessible name of the remapped shortcut
keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][1]->getShortcutControl().SetValue(Automation::AutomationProperties::NameProperty(), box_value(GET_RESOURCE_STRING(IDS_REMAPPED_TO)));
// ShortcutControl for the new shortcut
parent.Children().Append(keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][1]->getShortcutControl());

Expand All @@ -80,6 +96,8 @@ void ShortcutControl::AddNewShortcutControlRow(Grid& parent, std::vector<std::ve
targetAppTextBox.HorizontalAlignment(HorizontalAlignment::Center);
targetAppTextBox.PlaceholderText(KeyboardManagerConstants::DefaultAppName);
targetAppTextBox.Text(targetAppName);
// Initialize the accessible name of the target app text box
ShortcutControl::SetAccessibleNameForTextBox(targetAppTextBox);

// LostFocus handler will be called whenever text is updated by a user and then they click something else or tab to another control. Does not get called if Text is updated while the TextBox isn't in focus (i.e. from code)
targetAppTextBox.LostFocus([&keyboardRemapControlObjects, parent, targetAppTextBox](auto const& sender, auto const& e) {
Expand Down Expand Up @@ -124,6 +142,9 @@ void ShortcutControl::AddNewShortcutControlRow(Grid& parent, std::vector<std::ve
{
shortcutRemapBuffer[rowIndex].second = targetAppTextBox.Text().c_str();
}

// To set the accessibile name of the target app text box when focus is lost
ShortcutControl::SetAccessibleNameForTextBox(targetAppTextBox);
});

parent.SetColumn(targetAppTextBox, KeyboardManagerConstants::ShortcutTableTargetAppColIndex);
Expand Down Expand Up @@ -166,6 +187,8 @@ void ShortcutControl::AddNewShortcutControlRow(Grid& parent, std::vector<std::ve
// delete the ShortcutControl objects so that they get destructed
keyboardRemapControlObjects.erase(keyboardRemapControlObjects.begin() + bufferIndex);
});
// To set the accessible name of the delete button
deleteShortcut.SetValue(Automation::AutomationProperties::NameProperty(), box_value(GET_RESOURCE_STRING(IDS_DELETE_REMAPPING_BUTTON)));
parent.SetColumn(deleteShortcut, KeyboardManagerConstants::ShortcutTableRemoveColIndex);
parent.SetRow(deleteShortcut, parent.RowDefinitions().Size() - 1);
parent.Children().Append(deleteShortcut);
Expand Down
3 changes: 3 additions & 0 deletions src/modules/keyboardmanager/ui/ShortcutControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class ShortcutControl
// StackPanel to parent the above controls
winrt::Windows::Foundation::IInspectable shortcutControlLayout;

// Function to set the accessible name of the target app text box
static void SetAccessibleNameForTextBox(TextBox targetAppTextBox);

public:
// Handle to the current Edit Shortcuts Window
static HWND EditShortcutsWindowHandle;
Expand Down
4 changes: 4 additions & 0 deletions src/modules/keyboardmanager/ui/SingleKeyRemapControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ void SingleKeyRemapControl::AddNewControlKeyRemapRow(Grid& parent, std::vector<s
parent.SetRow(arrowIcon, parent.RowDefinitions().Size() - 1);
parent.Children().Append(arrowIcon);

// To set the accessible name of the arrow icon by setting the accessible name of the remapped key
keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][1]->getSingleKeyRemapControl().SetValue(Automation::AutomationProperties::NameProperty(), box_value(GET_RESOURCE_STRING(IDS_REMAPPED_TO)));
// SingleKeyRemapControl for the new remap key
parent.Children().Append(keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][1]->getSingleKeyRemapControl());

Expand Down Expand Up @@ -159,6 +161,8 @@ void SingleKeyRemapControl::AddNewControlKeyRemapRow(Grid& parent, std::vector<s
// delete the SingleKeyRemapControl objects so that they get destructed
keyboardRemapControlObjects.erase(keyboardRemapControlObjects.begin() + bufferIndex);
});
// To set the accessible name of the delete button
deleteRemapKeys.SetValue(Automation::AutomationProperties::NameProperty(), box_value(GET_RESOURCE_STRING(IDS_DELETE_REMAPPING_BUTTON)));
parent.SetColumn(deleteRemapKeys, KeyboardManagerConstants::RemapTableRemoveColIndex);
parent.SetRow(deleteRemapKeys, parent.RowDefinitions().Size() - 1);
parent.Children().Append(deleteRemapKeys);
Expand Down
1 change: 1 addition & 0 deletions src/modules/keyboardmanager/ui/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <winrt/Windows.system.h>
#include <winrt/windows.ui.xaml.hosting.h>
#include <windows.ui.xaml.hosting.desktopwindowxamlsource.h>
#include <winrt/Windows.UI.Xaml.Automation.h>
#include <winrt/windows.ui.xaml.controls.h>
#include <winrt/Windows.ui.xaml.media.h>
#include <winrt/Windows.Foundation.Collections.h>
Expand Down

0 comments on commit 1a51f77

Please sign in to comment.