mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-24 01:54:22 +00:00
Accessibility: Improved PopupMenu focus handling when opening and added support for submenus
This commit is contained in:
parent
4849b9ffcf
commit
b6bb2f4882
1 changed files with 35 additions and 12 deletions
|
|
@ -233,13 +233,18 @@ private:
|
|||
.addAction (AccessibilityActionType::toggle, std::move (onToggle));
|
||||
|
||||
if (hasActiveSubMenu (item.item))
|
||||
actions.addAction (AccessibilityActionType::showMenu, [&item]
|
||||
{
|
||||
item.parentWindow.showSubMenuFor (&item);
|
||||
{
|
||||
auto showSubMenu = [&item]
|
||||
{
|
||||
item.parentWindow.showSubMenuFor (&item);
|
||||
|
||||
if (auto* subMenu = item.parentWindow.activeSubMenu.get())
|
||||
subMenu->setCurrentlyHighlightedChild (subMenu->items.getFirst());
|
||||
});
|
||||
if (auto* subMenu = item.parentWindow.activeSubMenu.get())
|
||||
subMenu->setCurrentlyHighlightedChild (subMenu->items.getFirst());
|
||||
};
|
||||
|
||||
actions.addAction (AccessibilityActionType::press, showSubMenu);
|
||||
actions.addAction (AccessibilityActionType::showMenu, showSubMenu);
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
|
@ -519,6 +524,24 @@ struct MenuWindow : public Component
|
|||
|
||||
float getDesktopScaleFactor() const override { return scaleFactor * Desktop::getInstance().getGlobalScaleFactor(); }
|
||||
|
||||
void visibilityChanged() override
|
||||
{
|
||||
if (! isShowing())
|
||||
return;
|
||||
|
||||
auto* accessibleFocus = [this]
|
||||
{
|
||||
if (currentChild != nullptr)
|
||||
if (auto* childHandler = currentChild->getAccessibilityHandler())
|
||||
return childHandler;
|
||||
|
||||
return getAccessibilityHandler();
|
||||
}();
|
||||
|
||||
if (accessibleFocus != nullptr)
|
||||
accessibleFocus->grabFocus();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
bool keyPressed (const KeyPress& key) override
|
||||
{
|
||||
|
|
@ -1100,9 +1123,6 @@ struct MenuWindow : public Component
|
|||
|
||||
void setCurrentlyHighlightedChild (ItemComponent* child)
|
||||
{
|
||||
if (currentChild == child)
|
||||
return;
|
||||
|
||||
if (currentChild != nullptr)
|
||||
currentChild->setHighlighted (false);
|
||||
|
||||
|
|
@ -1217,8 +1237,14 @@ struct MenuWindow : public Component
|
|||
AccessibilityActions().addAction (AccessibilityActionType::focus, [this]
|
||||
{
|
||||
if (currentChild != nullptr)
|
||||
{
|
||||
if (auto* handler = currentChild->getAccessibilityHandler())
|
||||
handler->grabFocus();
|
||||
}
|
||||
else
|
||||
{
|
||||
selectNextItem (MenuSelectionDirection::forwards);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
@ -2028,9 +2054,6 @@ int PopupMenu::showWithOptionalCallback (const Options& options,
|
|||
window->toFront (false); // need to do this after making it modal, or it could
|
||||
// be stuck behind other comps that are already modal..
|
||||
|
||||
if (auto* handler = window->getAccessibilityHandler())
|
||||
handler->grabFocus();
|
||||
|
||||
#if JUCE_MODAL_LOOPS_PERMITTED
|
||||
if (userCallback == nullptr && canBeModal)
|
||||
return window->runModalLoop();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue