diff options
Diffstat (limited to 'views')
-rw-r--r-- | views/controls/menu/menu_controller.cc | 14 | ||||
-rw-r--r-- | views/controls/menu/menu_item_view.cc | 30 | ||||
-rw-r--r-- | views/controls/menu/menu_item_view.h | 8 |
3 files changed, 49 insertions, 3 deletions
diff --git a/views/controls/menu/menu_controller.cc b/views/controls/menu/menu_controller.cc index af43934..ae099f7 100644 --- a/views/controls/menu/menu_controller.cc +++ b/views/controls/menu/menu_controller.cc @@ -244,6 +244,9 @@ MenuItemView* MenuController::Run(gfx::NativeWindow parent, owner_ = parent; + if (button) + button->NotifyAccessibilityEvent(AccessibilityTypes::EVENT_MENUPOPUPSTART); + // Set the selection, which opens the initial menu. SetSelection(root, true, true); @@ -370,6 +373,17 @@ void MenuController::SetSelection(MenuItemView* menu_item, CommitPendingSelection(); else StartShowTimer(); + + // Notify an accessibility focus event on all menu items except for the root. + if (menu_item && + (MenuDepth(menu_item) != 1 || + menu_item->GetType() != MenuItemView::SUBMENU)) + menu_item->NotifyAccessibilityEvent(AccessibilityTypes::EVENT_FOCUS); + + if (menu_button_ && !menu_item && exit_type_ != EXIT_DESTROYED) { + menu_button_-> + NotifyAccessibilityEvent(AccessibilityTypes::EVENT_MENUPOPUPEND); + } } void MenuController::Cancel(ExitType type) { diff --git a/views/controls/menu/menu_item_view.cc b/views/controls/menu/menu_item_view.cc index 1d3d9da..31f33a7 100644 --- a/views/controls/menu/menu_item_view.cc +++ b/views/controls/menu/menu_item_view.cc @@ -100,6 +100,11 @@ bool MenuItemView::GetAccessibleRole(AccessibilityTypes::Role* role) { return true; } +bool MenuItemView::GetAccessibleState(AccessibilityTypes::State* state) { + *state = 0; + return true; +} + void MenuItemView::RunMenuAt(gfx::NativeWindow parent, MenuButton* button, const gfx::Rect& bounds, @@ -208,6 +213,31 @@ SubmenuView* MenuItemView::CreateSubmenu() { return submenu_; } +void MenuItemView::SetTitle(const std::wstring& title) { + title_ = title; + std::wstring accessible_title(title); + + // Filter out the "&" for accessibility clients. + size_t index = 0; + while ((index = accessible_title.find(L"&", index)) != std::wstring::npos && + index + 1 < accessible_title.length()) { + accessible_title.replace(index, accessible_title.length() - index, + accessible_title.substr(index + 1)); + + // Special case for "&&" (escaped for "&"). + if (accessible_title[index] == '&') + ++index; + } + + if (!GetAcceleratorText().empty()) { + std::wstring accelerator_text(L" "); + accelerator_text.append(GetAcceleratorText()); + accessible_title.append(accelerator_text); + } + + SetAccessibleName(accessible_title); +} + void MenuItemView::SetSelected(bool selected) { selected_ = selected; SchedulePaint(); diff --git a/views/controls/menu/menu_item_view.h b/views/controls/menu/menu_item_view.h index eb4f251..87ef1f6 100644 --- a/views/controls/menu/menu_item_view.h +++ b/views/controls/menu/menu_item_view.h @@ -83,6 +83,7 @@ class MenuItemView : public View { // Overridden from View: virtual bool GetTooltipText(const gfx::Point& p, std::wstring* tooltip); virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); + virtual bool GetAccessibleState(AccessibilityTypes::State* state); // Returns the preferred height of menu items. This is only valid when the // menu is about to be shown. @@ -183,13 +184,14 @@ class MenuItemView : public View { MenuItemView* GetParentMenuItem() const { return parent_menu_item_; } // Sets the title - void SetTitle(const std::wstring& title) { - title_ = title; - } + void SetTitle(const std::wstring& title); // Returns the title. const std::wstring& GetTitle() const { return title_; } + // Returns the type of this menu. + const Type& GetType() { return type_; } + // Sets whether this item is selected. This is invoked as the user moves // the mouse around the menu while open. void SetSelected(bool selected); |