Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Unified Diff: chrome/browser/ui/views/accessibility_event_router_views.cc

Issue 8850004: Add a context field to the accessibility extension API. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/accessibility_event_router_views.cc
===================================================================
--- chrome/browser/ui/views/accessibility_event_router_views.cc (revision 112880)
+++ chrome/browser/ui/views/accessibility_event_router_views.cc (working copy)
@@ -175,6 +175,7 @@
int type,
Profile* profile) {
AccessibilityButtonInfo info(profile, GetViewName(view));
+ AddContextInfo(view, &info);
SendAccessibilityNotification(type, &info);
}
@@ -183,6 +184,7 @@
int type,
Profile* profile) {
AccessibilityLinkInfo info(profile, GetViewName(view));
+ AddContextInfo(view, &info);
SendAccessibilityNotification(type, &info);
}
@@ -191,6 +193,7 @@
int type,
Profile* profile) {
AccessibilityMenuInfo info(profile, GetViewName(view));
+ AddContextInfo(view, &info);
SendAccessibilityNotification(type, &info);
}
@@ -218,6 +221,7 @@
}
AccessibilityMenuItemInfo info(profile, name, has_submenu, index, count);
+ AddContextInfo(view, &info);
SendAccessibilityNotification(type, &info);
}
@@ -233,6 +237,7 @@
AccessibilityTextBoxInfo info(profile, name, password);
std::string value = UTF16ToUTF8(state.value);
info.SetValue(value, state.selection_start, state.selection_end);
+ AddContextInfo(view, &info);
SendAccessibilityNotification(type, &info);
}
@@ -246,6 +251,7 @@
std::string value = UTF16ToUTF8(state.value);
AccessibilityComboBoxInfo info(
profile, name, value, state.index, state.count);
+ AddContextInfo(view, &info);
SendAccessibilityNotification(type, &info);
}
@@ -259,6 +265,7 @@
std::string value = UTF16ToUTF8(state.value);
AccessibilityCheckboxInfo info(
profile, name, state.state == ui::AccessibilityTypes::STATE_CHECKED);
+ AddContextInfo(view, &info);
SendAccessibilityNotification(type, &info);
}
@@ -289,6 +296,59 @@
return UTF16ToUTF8(state.name);
}
+void AccessibilityEventRouterViews::AddContextInfo(
sky 2011/12/07 22:01:55 Order should match header.
dmazzoni 2011/12/07 23:13:49 Done.
+ views::View* view, AccessibilityControlInfo* info) {
+ for (views::View* parent = view->parent();
+ parent;
+ parent = parent->parent()) {
+ ui::AccessibleViewState state;
+ parent->GetAccessibleState(&state);
+
+ // Two cases are handled right now. More could be added in the future
+ // depending on how the UI evolves.
+
+ // A control in a toolbar should use the toolbar's accessible name
+ // as the context.
+ if (state.role == ui::AccessibilityTypes::ROLE_TOOLBAR &&
+ !state.name.empty()) {
+ info->set_context(UTF16ToUTF8(state.name));
+ return;
+ }
+
+ // A control inside of an alert (like an infobar) should grab the
+ // first static text descendant as the context; that's the prompt.
+ if (state.role == ui::AccessibilityTypes::ROLE_ALERT) {
+ views::View* static_text_child = FindDescendantWithAccessibleRole(
+ parent, ui::AccessibilityTypes::ROLE_STATICTEXT);
+ if (static_text_child) {
sky 2011/12/07 22:01:55 I don't know this code well enough, so this might
dmazzoni 2011/12/07 23:13:49 That should never happen (multiple ALERTs in the p
+ ui::AccessibleViewState state;
+ static_text_child->GetAccessibleState(&state);
+ if (!state.name.empty()) {
+ info->set_context(UTF16ToUTF8(state.name));
+ return;
+ }
+ }
+ }
+ }
+}
+
+views::View* AccessibilityEventRouterViews::FindDescendantWithAccessibleRole(
sky 2011/12/07 22:01:55 Neither of these methods look like they need any s
dmazzoni 2011/12/07 23:13:49 Done - made a few more methods static too.
+ views::View* view, ui::AccessibilityTypes::Role role) {
+ ui::AccessibleViewState state;
+ view->GetAccessibleState(&state);
+ if (state.role == role)
+ return view;
+
+ for (int i = 0; i < view->child_count(); i++) {
+ views::View* child = view->child_at(i);
+ views::View* result = FindDescendantWithAccessibleRole(child, role);
+ if (result)
+ return result;
+ }
+
+ return NULL;
+}
+
bool AccessibilityEventRouterViews::IsMenuEvent(
views::View* view,
int type) {

Powered by Google App Engine
This is Rietveld 408576698