mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
[Keyboard Manager] Fix focusable elements should have different names accessibility issue (#6672)
* Add listview * Added row index to accessible names * Cleanup rowIndex * Fixed accessibility issue with ComboBox * Updated comments
This commit is contained in:
@@ -36,8 +36,15 @@ 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)));
|
||||
// To set the accessible name of the combo-box (by default index 1)
|
||||
SetAccessibleNameForComboBox(dropDown.as<ComboBox>(), 1);
|
||||
}
|
||||
|
||||
// Function to set accessible name for combobox
|
||||
void KeyDropDownControl::SetAccessibleNameForComboBox(ComboBox dropDown, int index)
|
||||
{
|
||||
// Display name with drop down index (where this indexing will start from 1) - Used by narrator
|
||||
dropDown.SetValue(Automation::AutomationProperties::NameProperty(), box_value(GET_RESOURCE_STRING(IDS_KEY_DROPDOWN_COMBOBOX) + L" " + std::to_wstring(index)));
|
||||
}
|
||||
|
||||
// Function to check if the layout has changed and accordingly update the drop down list
|
||||
@@ -67,7 +74,8 @@ void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel singleKeyCo
|
||||
bool indexFound = table.Children().IndexOf(singleKeyControl, controlIndex);
|
||||
if (indexFound)
|
||||
{
|
||||
int rowIndex = (controlIndex - KeyboardManagerConstants::RemapTableHeaderCount) / KeyboardManagerConstants::RemapTableColCount;
|
||||
// GetRow will give the row index including the table header
|
||||
int rowIndex = table.GetRow(singleKeyControl) - 1;
|
||||
|
||||
// Validate current remap selection
|
||||
KeyboardManagerHelper::ErrorType errorType = BufferValidationHelpers::ValidateAndUpdateKeyBufferElement(rowIndex, colIndex, selectedKeyIndex, keyCodeList, singleKeyRemapBuffer);
|
||||
@@ -109,14 +117,8 @@ std::pair<KeyboardManagerHelper::ErrorType, int> KeyDropDownControl::ValidateSho
|
||||
|
||||
if (controlIindexFound)
|
||||
{
|
||||
if (isSingleKeyWindow)
|
||||
{
|
||||
rowIndex = (controlIndex - KeyboardManagerConstants::RemapTableHeaderCount) / KeyboardManagerConstants::RemapTableColCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
rowIndex = (controlIndex - KeyboardManagerConstants::ShortcutTableHeaderCount) / KeyboardManagerConstants::ShortcutTableColCount;
|
||||
}
|
||||
// GetRow will give the row index including the table header
|
||||
rowIndex = table.GetRow(shortcutControl) - 1;
|
||||
|
||||
std::vector<int32_t> selectedIndices = GetSelectedIndicesFromStackPanel(parent);
|
||||
|
||||
@@ -136,7 +138,7 @@ std::pair<KeyboardManagerHelper::ErrorType, int> KeyDropDownControl::ValidateSho
|
||||
}
|
||||
else if (validationResult.second == BufferValidationHelpers::DropDownAction::ClearUnusedDropDowns)
|
||||
{
|
||||
// remove all the drop downs after the current index
|
||||
// remove all the drop downs after the current index (accessible names do not have to be updated since drop downs at the end of the list are getting removed)
|
||||
int elementsToBeRemoved = parent.Children().Size() - dropDownIndex - 1;
|
||||
for (int i = 0; i < elementsToBeRemoved; i++)
|
||||
{
|
||||
@@ -154,6 +156,13 @@ std::pair<KeyboardManagerHelper::ErrorType, int> KeyDropDownControl::ValidateSho
|
||||
// Handle None case if there are no other errors
|
||||
else if (validationResult.second == BufferValidationHelpers::DropDownAction::DeleteDropDown)
|
||||
{
|
||||
// Update accessible names for drop downs appearing after the deleted one
|
||||
for (uint32_t i = dropDownIndex + 1; i < keyDropDownControlObjects.size(); i++)
|
||||
{
|
||||
// Update accessible name (row index will become i-1 for this element, so the display name would be i (display name indexing from 1)
|
||||
SetAccessibleNameForComboBox(keyDropDownControlObjects[i]->GetComboBox(), i);
|
||||
}
|
||||
|
||||
parent.Children().RemoveAt(dropDownIndex);
|
||||
// delete drop down control object from the vector so that it can be destructed
|
||||
keyDropDownControlObjects.erase(keyDropDownControlObjects.begin() + dropDownIndex);
|
||||
@@ -265,6 +274,9 @@ void KeyDropDownControl::AddDropDown(Grid table, StackPanel shortcutControl, Sta
|
||||
parent.Children().Append(keyDropDownControlObjects[keyDropDownControlObjects.size() - 1]->GetComboBox());
|
||||
keyDropDownControlObjects[keyDropDownControlObjects.size() - 1]->SetSelectionHandler(table, shortcutControl, parent, colIndex, shortcutRemapBuffer, keyDropDownControlObjects, targetApp, isHybridControl, isSingleKeyWindow);
|
||||
parent.UpdateLayout();
|
||||
|
||||
// Update accessible name
|
||||
SetAccessibleNameForComboBox(keyDropDownControlObjects[keyDropDownControlObjects.size() - 1]->GetComboBox(), (int)keyDropDownControlObjects.size());
|
||||
}
|
||||
|
||||
// Function to get the list of key codes from the shortcut combo box stack panel
|
||||
|
||||
Reference in New Issue
Block a user