summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authordtseng@chromium.org <dtseng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-01 22:28:09 +0000
committerdtseng@chromium.org <dtseng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-01 22:28:09 +0000
commit66bc725eb396ef3ed84c071c992a32a397ddb21d (patch)
treea5732ed6287f311eb23749859bd732ed3b11d370 /views
parent0f9141e83df10e173bc04fa57b11483ab4d5bde3 (diff)
downloadchromium_src-66bc725eb396ef3ed84c071c992a32a397ddb21d.zip
chromium_src-66bc725eb396ef3ed84c071c992a32a397ddb21d.tar.gz
chromium_src-66bc725eb396ef3ed84c071c992a32a397ddb21d.tar.bz2
Hook up the MenuViewItem objects to a widget so that they may send accessibility focus events.
BUG=47585 TEST=none Review URL: http://codereview.chromium.org/2872022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51436 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/controls/menu/menu_controller.cc14
-rw-r--r--views/controls/menu/menu_item_view.cc30
-rw-r--r--views/controls/menu/menu_item_view.h8
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);