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

Side by Side Diff: chrome/browser/ui/views/accessibility_event_router_views.cc

Issue 7327007: Moving notification types which are chrome specific to a new header file chrome_notification_type... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/accessibility_event_router_views.h" 5 #include "chrome/browser/ui/views/accessibility_event_router_views.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/extensions/extension_accessibility_api.h" 12 #include "chrome/browser/extensions/extension_accessibility_api.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/profiles/profile_manager.h" 14 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 15 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
16 #include "content/common/notification_type.h" 16 #include "chrome/common/chrome_notification_types.h"
17 #include "ui/base/models/combobox_model.h" 17 #include "ui/base/models/combobox_model.h"
18 #include "ui/base/accessibility/accessible_view_state.h" 18 #include "ui/base/accessibility/accessible_view_state.h"
19 #include "views/controls/button/checkbox.h" 19 #include "views/controls/button/checkbox.h"
20 #include "views/controls/button/custom_button.h" 20 #include "views/controls/button/custom_button.h"
21 #include "views/controls/button/menu_button.h" 21 #include "views/controls/button/menu_button.h"
22 #include "views/controls/combobox/combobox.h" 22 #include "views/controls/combobox/combobox.h"
23 #include "views/controls/link.h" 23 #include "views/controls/link.h"
24 #include "views/controls/menu/menu_item_view.h" 24 #include "views/controls/menu/menu_item_view.h"
25 #include "views/controls/menu/submenu_view.h" 25 #include "views/controls/menu/submenu_view.h"
26 #include "views/controls/textfield/textfield.h" 26 #include "views/controls/textfield/textfield.h"
(...skipping 19 matching lines...) Expand all
46 void AccessibilityEventRouterViews::HandleAccessibilityEvent( 46 void AccessibilityEventRouterViews::HandleAccessibilityEvent(
47 views::View* view, ui::AccessibilityTypes::Event event_type) { 47 views::View* view, ui::AccessibilityTypes::Event event_type) {
48 if (!ExtensionAccessibilityEventRouter::GetInstance()-> 48 if (!ExtensionAccessibilityEventRouter::GetInstance()->
49 IsAccessibilityEnabled()) { 49 IsAccessibilityEnabled()) {
50 return; 50 return;
51 } 51 }
52 52
53 switch (event_type) { 53 switch (event_type) {
54 case ui::AccessibilityTypes::EVENT_FOCUS: 54 case ui::AccessibilityTypes::EVENT_FOCUS:
55 DispatchAccessibilityNotification( 55 DispatchAccessibilityNotification(
56 view, NotificationType::ACCESSIBILITY_CONTROL_FOCUSED); 56 view, chrome::NOTIFICATION_ACCESSIBILITY_CONTROL_FOCUSED);
57 break; 57 break;
58 case ui::AccessibilityTypes::EVENT_MENUSTART: 58 case ui::AccessibilityTypes::EVENT_MENUSTART:
59 case ui::AccessibilityTypes::EVENT_MENUPOPUPSTART: 59 case ui::AccessibilityTypes::EVENT_MENUPOPUPSTART:
60 DispatchAccessibilityNotification( 60 DispatchAccessibilityNotification(
61 view, NotificationType::ACCESSIBILITY_MENU_OPENED); 61 view, chrome::NOTIFICATION_ACCESSIBILITY_MENU_OPENED);
62 break; 62 break;
63 case ui::AccessibilityTypes::EVENT_MENUEND: 63 case ui::AccessibilityTypes::EVENT_MENUEND:
64 case ui::AccessibilityTypes::EVENT_MENUPOPUPEND: 64 case ui::AccessibilityTypes::EVENT_MENUPOPUPEND:
65 DispatchAccessibilityNotification( 65 DispatchAccessibilityNotification(
66 view, NotificationType::ACCESSIBILITY_MENU_CLOSED); 66 view, chrome::NOTIFICATION_ACCESSIBILITY_MENU_CLOSED);
67 break; 67 break;
68 case ui::AccessibilityTypes::EVENT_TEXT_CHANGED: 68 case ui::AccessibilityTypes::EVENT_TEXT_CHANGED:
69 case ui::AccessibilityTypes::EVENT_SELECTION_CHANGED: 69 case ui::AccessibilityTypes::EVENT_SELECTION_CHANGED:
70 DispatchAccessibilityNotification( 70 DispatchAccessibilityNotification(
71 view, NotificationType::ACCESSIBILITY_TEXT_CHANGED); 71 view, chrome::NOTIFICATION_ACCESSIBILITY_TEXT_CHANGED);
72 break; 72 break;
73 case ui::AccessibilityTypes::EVENT_VALUE_CHANGED: 73 case ui::AccessibilityTypes::EVENT_VALUE_CHANGED:
74 DispatchAccessibilityNotification( 74 DispatchAccessibilityNotification(
75 view, NotificationType::ACCESSIBILITY_CONTROL_ACTION); 75 view, chrome::NOTIFICATION_ACCESSIBILITY_CONTROL_ACTION);
76 break; 76 break;
77 case ui::AccessibilityTypes::EVENT_ALERT: 77 case ui::AccessibilityTypes::EVENT_ALERT:
78 case ui::AccessibilityTypes::EVENT_NAME_CHANGED: 78 case ui::AccessibilityTypes::EVENT_NAME_CHANGED:
79 // TODO(dmazzoni): re-evaluate this list later and see 79 // TODO(dmazzoni): re-evaluate this list later and see
80 // if supporting any of these would be useful feature requests or 80 // if supporting any of these would be useful feature requests or
81 // they'd just be superfluous. 81 // they'd just be superfluous.
82 NOTIMPLEMENTED(); 82 NOTIMPLEMENTED();
83 break; 83 break;
84 } 84 }
85 } 85 }
(...skipping 12 matching lines...) Expand all
98 if (!most_recent_profile_) 98 if (!most_recent_profile_)
99 return; 99 return;
100 100
101 AccessibilityMenuItemInfo info( 101 AccessibilityMenuItemInfo info(
102 most_recent_profile_, 102 most_recent_profile_,
103 WideToUTF8(menu_item_name), 103 WideToUTF8(menu_item_name),
104 has_submenu, 104 has_submenu,
105 item_index, 105 item_index,
106 item_count); 106 item_count);
107 SendAccessibilityNotification( 107 SendAccessibilityNotification(
108 NotificationType::ACCESSIBILITY_CONTROL_FOCUSED, &info); 108 chrome::NOTIFICATION_ACCESSIBILITY_CONTROL_FOCUSED, &info);
109 } 109 }
110 110
111 // 111 //
112 // Private methods 112 // Private methods
113 // 113 //
114 114
115 std::string AccessibilityEventRouterViews::GetViewName(views::View* view) { 115 std::string AccessibilityEventRouterViews::GetViewName(views::View* view) {
116 ui::AccessibleViewState state; 116 ui::AccessibleViewState state;
117 view->GetAccessibleState(&state); 117 view->GetAccessibleState(&state);
118 return UTF16ToUTF8(state.name); 118 return UTF16ToUTF8(state.name);
119 } 119 }
120 120
121 void AccessibilityEventRouterViews::DispatchAccessibilityNotification( 121 void AccessibilityEventRouterViews::DispatchAccessibilityNotification(
122 views::View* view, NotificationType type) { 122 views::View* view, int type) {
123 // Get the profile associated with this view. If it's not found, use 123 // Get the profile associated with this view. If it's not found, use
124 // the most recent profile where accessibility events were sent, or 124 // the most recent profile where accessibility events were sent, or
125 // the default profile. 125 // the default profile.
126 Profile* profile = NULL; 126 Profile* profile = NULL;
127 views::Widget* widget = view->GetWidget(); 127 views::Widget* widget = view->GetWidget();
128 if (widget) { 128 if (widget) {
129 profile = reinterpret_cast<Profile*>( 129 profile = reinterpret_cast<Profile*>(
130 widget->GetNativeWindowProperty(Profile::kProfileKey)); 130 widget->GetNativeWindowProperty(Profile::kProfileKey));
131 } 131 }
132 if (!profile) 132 if (!profile)
133 profile = most_recent_profile_; 133 profile = most_recent_profile_;
134 if (!profile) 134 if (!profile)
135 profile = g_browser_process->profile_manager()->GetLastUsedProfile(); 135 profile = g_browser_process->profile_manager()->GetLastUsedProfile();
136 if (!profile) { 136 if (!profile) {
137 NOTREACHED(); 137 NOTREACHED();
138 return; 138 return;
139 } 139 }
140 140
141 most_recent_profile_ = profile; 141 most_recent_profile_ = profile;
142 std::string class_name = view->GetClassName(); 142 std::string class_name = view->GetClassName();
143 143
144 if (class_name == views::Checkbox::kViewClassName) { 144 if (class_name == views::Checkbox::kViewClassName) {
145 SendCheckboxNotification(view, type, profile); 145 SendCheckboxNotification(view, type, profile);
146 } else if (class_name == views::MenuButton::kViewClassName || 146 } else if (class_name == views::MenuButton::kViewClassName ||
147 type == NotificationType::ACCESSIBILITY_MENU_OPENED || 147 type == chrome::NOTIFICATION_ACCESSIBILITY_MENU_OPENED ||
148 type == NotificationType::ACCESSIBILITY_MENU_CLOSED) { 148 type == chrome::NOTIFICATION_ACCESSIBILITY_MENU_CLOSED) {
149 SendMenuNotification(view, type, profile); 149 SendMenuNotification(view, type, profile);
150 } else if (IsMenuEvent(view, type)) { 150 } else if (IsMenuEvent(view, type)) {
151 SendMenuItemNotification(view, type, profile); 151 SendMenuItemNotification(view, type, profile);
152 } else if (class_name == views::CustomButton::kViewClassName || 152 } else if (class_name == views::CustomButton::kViewClassName ||
153 class_name == views::NativeButton::kViewClassName || 153 class_name == views::NativeButton::kViewClassName ||
154 class_name == views::NativeTextButton::kViewClassName || 154 class_name == views::NativeTextButton::kViewClassName ||
155 class_name == views::TextButton::kViewClassName) { 155 class_name == views::TextButton::kViewClassName) {
156 SendButtonNotification(view, type, profile); 156 SendButtonNotification(view, type, profile);
157 } else if (class_name == views::Link::kViewClassName) { 157 } else if (class_name == views::Link::kViewClassName) {
158 SendLinkNotification(view, type, profile); 158 SendLinkNotification(view, type, profile);
159 } else if (class_name == LocationBarView::kViewClassName) { 159 } else if (class_name == LocationBarView::kViewClassName) {
160 SendLocationBarNotification(view, type, profile); 160 SendLocationBarNotification(view, type, profile);
161 } else if (class_name == views::Textfield::kViewClassName) { 161 } else if (class_name == views::Textfield::kViewClassName) {
162 SendTextfieldNotification(view, type, profile); 162 SendTextfieldNotification(view, type, profile);
163 } else if (class_name == views::Combobox::kViewClassName) { 163 } else if (class_name == views::Combobox::kViewClassName) {
164 SendComboboxNotification(view, type, profile); 164 SendComboboxNotification(view, type, profile);
165 } 165 }
166 } 166 }
167 167
168 void AccessibilityEventRouterViews::SendButtonNotification( 168 void AccessibilityEventRouterViews::SendButtonNotification(
169 views::View* view, NotificationType type, Profile* profile) { 169 views::View* view, int type, Profile* profile) {
170 AccessibilityButtonInfo info(profile, GetViewName(view)); 170 AccessibilityButtonInfo info(profile, GetViewName(view));
171 SendAccessibilityNotification(type, &info); 171 SendAccessibilityNotification(type, &info);
172 } 172 }
173 173
174 void AccessibilityEventRouterViews::SendLinkNotification( 174 void AccessibilityEventRouterViews::SendLinkNotification(
175 views::View* view, NotificationType type, Profile* profile) { 175 views::View* view, int type, Profile* profile) {
176 AccessibilityLinkInfo info(profile, GetViewName(view)); 176 AccessibilityLinkInfo info(profile, GetViewName(view));
177 SendAccessibilityNotification(type, &info); 177 SendAccessibilityNotification(type, &info);
178 } 178 }
179 179
180 void AccessibilityEventRouterViews::SendMenuNotification( 180 void AccessibilityEventRouterViews::SendMenuNotification(
181 views::View* view, NotificationType type, Profile* profile) { 181 views::View* view, int type, Profile* profile) {
182 AccessibilityMenuInfo info(profile, GetViewName(view)); 182 AccessibilityMenuInfo info(profile, GetViewName(view));
183 SendAccessibilityNotification(type, &info); 183 SendAccessibilityNotification(type, &info);
184 } 184 }
185 185
186 void AccessibilityEventRouterViews::SendMenuItemNotification( 186 void AccessibilityEventRouterViews::SendMenuItemNotification(
187 views::View* view, NotificationType type, Profile* profile) { 187 views::View* view, int type, Profile* profile) {
188 std::string name = GetViewName(view); 188 std::string name = GetViewName(view);
189 189
190 bool has_submenu = false; 190 bool has_submenu = false;
191 int index = -1; 191 int index = -1;
192 int count = -1; 192 int count = -1;
193 193
194 if (view->GetClassName() == views::MenuItemView::kViewClassName) 194 if (view->GetClassName() == views::MenuItemView::kViewClassName)
195 has_submenu = static_cast<views::MenuItemView*>(view)->HasSubmenu(); 195 has_submenu = static_cast<views::MenuItemView*>(view)->HasSubmenu();
196 196
197 views::View* parent_menu = view->parent(); 197 views::View* parent_menu = view->parent();
(...skipping 23 matching lines...) Expand all
221 (*count)++; 221 (*count)++;
222 } else if (child->GetClassName() == views::TextButton::kViewClassName) { 222 } else if (child->GetClassName() == views::TextButton::kViewClassName) {
223 if (item == child) 223 if (item == child)
224 *index = *count; 224 *index = *count;
225 (*count)++; 225 (*count)++;
226 } 226 }
227 } 227 }
228 } 228 }
229 229
230 bool AccessibilityEventRouterViews::IsMenuEvent( 230 bool AccessibilityEventRouterViews::IsMenuEvent(
231 views::View* view, NotificationType type) { 231 views::View* view, int type) {
232 if (type == NotificationType::ACCESSIBILITY_MENU_OPENED || 232 if (type == chrome::NOTIFICATION_ACCESSIBILITY_MENU_OPENED ||
233 type == NotificationType::ACCESSIBILITY_MENU_CLOSED) 233 type == chrome::NOTIFICATION_ACCESSIBILITY_MENU_CLOSED)
234 return true; 234 return true;
235 235
236 while (view) { 236 while (view) {
237 ui::AccessibleViewState state; 237 ui::AccessibleViewState state;
238 view->GetAccessibleState(&state); 238 view->GetAccessibleState(&state);
239 ui::AccessibilityTypes::Role role = state.role; 239 ui::AccessibilityTypes::Role role = state.role;
240 if (role == ui::AccessibilityTypes::ROLE_MENUITEM || 240 if (role == ui::AccessibilityTypes::ROLE_MENUITEM ||
241 role == ui::AccessibilityTypes::ROLE_MENUPOPUP) { 241 role == ui::AccessibilityTypes::ROLE_MENUPOPUP) {
242 return true; 242 return true;
243 } 243 }
244 view = view->parent(); 244 view = view->parent();
245 } 245 }
246 246
247 return false; 247 return false;
248 } 248 }
249 249
250 void AccessibilityEventRouterViews::SendLocationBarNotification( 250 void AccessibilityEventRouterViews::SendLocationBarNotification(
251 views::View* view, NotificationType type, Profile* profile) { 251 views::View* view, int type, Profile* profile) {
252 ui::AccessibleViewState state; 252 ui::AccessibleViewState state;
253 view->GetAccessibleState(&state); 253 view->GetAccessibleState(&state);
254 std::string name = UTF16ToUTF8(state.name); 254 std::string name = UTF16ToUTF8(state.name);
255 AccessibilityTextBoxInfo info(profile, name, false); 255 AccessibilityTextBoxInfo info(profile, name, false);
256 std::string value = UTF16ToUTF8(state.value); 256 std::string value = UTF16ToUTF8(state.value);
257 info.SetValue(value, state.selection_start, state.selection_end); 257 info.SetValue(value, state.selection_start, state.selection_end);
258 SendAccessibilityNotification(type, &info); 258 SendAccessibilityNotification(type, &info);
259 } 259 }
260 260
261 void AccessibilityEventRouterViews::SendTextfieldNotification( 261 void AccessibilityEventRouterViews::SendTextfieldNotification(
262 views::View* view, NotificationType type, Profile* profile) { 262 views::View* view, int type, Profile* profile) {
263 ui::AccessibleViewState state; 263 ui::AccessibleViewState state;
264 view->GetAccessibleState(&state); 264 view->GetAccessibleState(&state);
265 std::string name = UTF16ToUTF8(state.name); 265 std::string name = UTF16ToUTF8(state.name);
266 views::Textfield* textfield = static_cast<views::Textfield*>(view); 266 views::Textfield* textfield = static_cast<views::Textfield*>(view);
267 bool password = textfield->IsPassword(); 267 bool password = textfield->IsPassword();
268 AccessibilityTextBoxInfo info(profile, name, password); 268 AccessibilityTextBoxInfo info(profile, name, password);
269 std::string value = UTF16ToUTF8(state.value); 269 std::string value = UTF16ToUTF8(state.value);
270 info.SetValue(value, state.selection_start, state.selection_end); 270 info.SetValue(value, state.selection_start, state.selection_end);
271 SendAccessibilityNotification(type, &info); 271 SendAccessibilityNotification(type, &info);
272 } 272 }
273 273
274 void AccessibilityEventRouterViews::SendComboboxNotification( 274 void AccessibilityEventRouterViews::SendComboboxNotification(
275 views::View* view, NotificationType type, Profile* profile) { 275 views::View* view, int type, Profile* profile) {
276 ui::AccessibleViewState state; 276 ui::AccessibleViewState state;
277 view->GetAccessibleState(&state); 277 view->GetAccessibleState(&state);
278 std::string name = UTF16ToUTF8(state.name); 278 std::string name = UTF16ToUTF8(state.name);
279 std::string value = UTF16ToUTF8(state.value); 279 std::string value = UTF16ToUTF8(state.value);
280 AccessibilityComboBoxInfo info( 280 AccessibilityComboBoxInfo info(
281 profile, name, value, state.index, state.count); 281 profile, name, value, state.index, state.count);
282 SendAccessibilityNotification(type, &info); 282 SendAccessibilityNotification(type, &info);
283 } 283 }
284 284
285 void AccessibilityEventRouterViews::SendCheckboxNotification( 285 void AccessibilityEventRouterViews::SendCheckboxNotification(
286 views::View* view, NotificationType type, Profile* profile) { 286 views::View* view, int type, Profile* profile) {
287 ui::AccessibleViewState state; 287 ui::AccessibleViewState state;
288 view->GetAccessibleState(&state); 288 view->GetAccessibleState(&state);
289 std::string name = UTF16ToUTF8(state.name); 289 std::string name = UTF16ToUTF8(state.name);
290 std::string value = UTF16ToUTF8(state.value); 290 std::string value = UTF16ToUTF8(state.value);
291 AccessibilityCheckboxInfo info( 291 AccessibilityCheckboxInfo info(
292 profile, name, state.state == ui::AccessibilityTypes::STATE_CHECKED); 292 profile, name, state.state == ui::AccessibilityTypes::STATE_CHECKED);
293 SendAccessibilityNotification(type, &info); 293 SendAccessibilityNotification(type, &info);
294 } 294 }
295 295
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698