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

Side by Side Diff: content/browser/accessibility/browser_accessibility_manager.cc

Issue 116293005: Refactor content/ to use ui::AXNodeData instead of blink. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update content/DEPS instead of subdirs Created 6 years, 11 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/accessibility/browser_accessibility_manager.h" 5 #include "content/browser/accessibility/browser_accessibility_manager.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/browser/accessibility/browser_accessibility.h" 8 #include "content/browser/accessibility/browser_accessibility.h"
9 #include "content/common/accessibility_messages.h" 9 #include "content/common/accessibility_messages.h"
10 10
11 namespace content { 11 namespace content {
12 12
13 BrowserAccessibility* BrowserAccessibilityFactory::Create() { 13 BrowserAccessibility* BrowserAccessibilityFactory::Create() {
14 return BrowserAccessibility::Create(); 14 return BrowserAccessibility::Create();
15 } 15 }
16 16
17 #if !defined(OS_MACOSX) && \ 17 #if !defined(OS_MACOSX) && \
18 !defined(OS_WIN) && \ 18 !defined(OS_WIN) && \
19 !defined(TOOLKIT_GTK) && \ 19 !defined(TOOLKIT_GTK) && \
20 !defined(OS_ANDROID) \ 20 !defined(OS_ANDROID) \
21 // We have subclassess of BrowserAccessibilityManager on Mac, Linux/GTK, 21 // We have subclassess of BrowserAccessibilityManager on Mac, Linux/GTK,
22 // and Win. For any other platform, instantiate the base class. 22 // and Win. For any other platform, instantiate the base class.
23 // static 23 // static
24 BrowserAccessibilityManager* BrowserAccessibilityManager::Create( 24 BrowserAccessibilityManager* BrowserAccessibilityManager::Create(
25 const AccessibilityNodeData& src, 25 const ui::AXNodeData& src,
26 BrowserAccessibilityDelegate* delegate, 26 BrowserAccessibilityDelegate* delegate,
27 BrowserAccessibilityFactory* factory) { 27 BrowserAccessibilityFactory* factory) {
28 return new BrowserAccessibilityManager(src, delegate, factory); 28 return new BrowserAccessibilityManager(src, delegate, factory);
29 } 29 }
30 #endif 30 #endif
31 31
32 BrowserAccessibilityManager::BrowserAccessibilityManager( 32 BrowserAccessibilityManager::BrowserAccessibilityManager(
33 BrowserAccessibilityDelegate* delegate, 33 BrowserAccessibilityDelegate* delegate,
34 BrowserAccessibilityFactory* factory) 34 BrowserAccessibilityFactory* factory)
35 : delegate_(delegate), 35 : delegate_(delegate),
36 factory_(factory), 36 factory_(factory),
37 root_(NULL), 37 root_(NULL),
38 focus_(NULL), 38 focus_(NULL),
39 osk_state_(OSK_ALLOWED) { 39 osk_state_(OSK_ALLOWED) {
40 } 40 }
41 41
42 BrowserAccessibilityManager::BrowserAccessibilityManager( 42 BrowserAccessibilityManager::BrowserAccessibilityManager(
43 const AccessibilityNodeData& src, 43 const ui::AXNodeData& src,
44 BrowserAccessibilityDelegate* delegate, 44 BrowserAccessibilityDelegate* delegate,
45 BrowserAccessibilityFactory* factory) 45 BrowserAccessibilityFactory* factory)
46 : delegate_(delegate), 46 : delegate_(delegate),
47 factory_(factory), 47 factory_(factory),
48 root_(NULL), 48 root_(NULL),
49 focus_(NULL), 49 focus_(NULL),
50 osk_state_(OSK_ALLOWED) { 50 osk_state_(OSK_ALLOWED) {
51 Initialize(src); 51 Initialize(src);
52 } 52 }
53 53
54 BrowserAccessibilityManager::~BrowserAccessibilityManager() { 54 BrowserAccessibilityManager::~BrowserAccessibilityManager() {
55 if (root_) 55 if (root_)
56 root_->Destroy(); 56 root_->Destroy();
57 } 57 }
58 58
59 void BrowserAccessibilityManager::Initialize(const AccessibilityNodeData src) { 59 void BrowserAccessibilityManager::Initialize(const ui::AXNodeData src) {
60 std::vector<AccessibilityNodeData> nodes; 60 std::vector<ui::AXNodeData> nodes;
61 nodes.push_back(src); 61 nodes.push_back(src);
62 if (!UpdateNodes(nodes)) 62 if (!UpdateNodes(nodes))
63 return; 63 return;
64 if (!focus_) 64 if (!focus_)
65 SetFocus(root_, false); 65 SetFocus(root_, false);
66 } 66 }
67 67
68 // static 68 // static
69 AccessibilityNodeData BrowserAccessibilityManager::GetEmptyDocument() { 69 ui::AXNodeData BrowserAccessibilityManager::GetEmptyDocument() {
70 AccessibilityNodeData empty_document; 70 ui::AXNodeData empty_document;
71 empty_document.id = 0; 71 empty_document.id = 0;
72 empty_document.role = blink::WebAXRoleRootWebArea; 72 empty_document.role = ui::AX_ROLE_ROOT_WEB_AREA;
73 return empty_document; 73 return empty_document;
74 } 74 }
75 75
76 BrowserAccessibility* BrowserAccessibilityManager::GetRoot() { 76 BrowserAccessibility* BrowserAccessibilityManager::GetRoot() {
77 return root_; 77 return root_;
78 } 78 }
79 79
80 BrowserAccessibility* BrowserAccessibilityManager::GetFromRendererID( 80 BrowserAccessibility* BrowserAccessibilityManager::GetFromRendererID(
81 int32 renderer_id) { 81 int32 renderer_id) {
82 base::hash_map<int32, BrowserAccessibility*>::iterator iter = 82 base::hash_map<int32, BrowserAccessibility*>::iterator iter =
83 renderer_id_map_.find(renderer_id); 83 renderer_id_map_.find(renderer_id);
84 if (iter != renderer_id_map_.end()) 84 if (iter != renderer_id_map_.end())
85 return iter->second; 85 return iter->second;
86 return NULL; 86 return NULL;
87 } 87 }
88 88
89 void BrowserAccessibilityManager::GotFocus(bool touch_event_context) { 89 void BrowserAccessibilityManager::GotFocus(bool touch_event_context) {
90 if (!touch_event_context) 90 if (!touch_event_context)
91 osk_state_ = OSK_DISALLOWED_BECAUSE_TAB_JUST_APPEARED; 91 osk_state_ = OSK_DISALLOWED_BECAUSE_TAB_JUST_APPEARED;
92 92
93 if (!focus_) 93 if (!focus_)
94 return; 94 return;
95 95
96 NotifyAccessibilityEvent(blink::WebAXEventFocus, focus_); 96 NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, focus_);
97 } 97 }
98 98
99 void BrowserAccessibilityManager::WasHidden() { 99 void BrowserAccessibilityManager::WasHidden() {
100 osk_state_ = OSK_DISALLOWED_BECAUSE_TAB_HIDDEN; 100 osk_state_ = OSK_DISALLOWED_BECAUSE_TAB_HIDDEN;
101 } 101 }
102 102
103 void BrowserAccessibilityManager::GotMouseDown() { 103 void BrowserAccessibilityManager::GotMouseDown() {
104 osk_state_ = OSK_ALLOWED_WITHIN_FOCUSED_OBJECT; 104 osk_state_ = OSK_ALLOWED_WITHIN_FOCUSED_OBJECT;
105 NotifyAccessibilityEvent(blink::WebAXEventFocus, focus_); 105 NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, focus_);
106 } 106 }
107 107
108 bool BrowserAccessibilityManager::IsOSKAllowed(const gfx::Rect& bounds) { 108 bool BrowserAccessibilityManager::IsOSKAllowed(const gfx::Rect& bounds) {
109 if (!delegate_ || !delegate_->HasFocus()) 109 if (!delegate_ || !delegate_->HasFocus())
110 return false; 110 return false;
111 111
112 gfx::Point touch_point = delegate_->GetLastTouchEventLocation(); 112 gfx::Point touch_point = delegate_->GetLastTouchEventLocation();
113 return bounds.Contains(touch_point); 113 return bounds.Contains(touch_point);
114 } 114 }
115 115
(...skipping 12 matching lines...) Expand all
128 const std::vector<AccessibilityHostMsg_EventParams>& params) { 128 const std::vector<AccessibilityHostMsg_EventParams>& params) {
129 bool should_send_initial_focus = false; 129 bool should_send_initial_focus = false;
130 130
131 // Process all changes to the accessibility tree first. 131 // Process all changes to the accessibility tree first.
132 for (uint32 index = 0; index < params.size(); index++) { 132 for (uint32 index = 0; index < params.size(); index++) {
133 const AccessibilityHostMsg_EventParams& param = params[index]; 133 const AccessibilityHostMsg_EventParams& param = params[index];
134 if (!UpdateNodes(param.nodes)) 134 if (!UpdateNodes(param.nodes))
135 return; 135 return;
136 136
137 // Set initial focus when a page is loaded. 137 // Set initial focus when a page is loaded.
138 blink::WebAXEvent event_type = param.event_type; 138 ui::AXEvent event_type = param.event_type;
139 if (event_type == blink::WebAXEventLoadComplete) { 139 if (event_type == ui::AX_EVENT_LOAD_COMPLETE) {
140 if (!focus_) { 140 if (!focus_) {
141 SetFocus(root_, false); 141 SetFocus(root_, false);
142 should_send_initial_focus = true; 142 should_send_initial_focus = true;
143 } 143 }
144 } 144 }
145 } 145 }
146 146
147 if (should_send_initial_focus && 147 if (should_send_initial_focus &&
148 (!delegate_ || delegate_->HasFocus())) { 148 (!delegate_ || delegate_->HasFocus())) {
149 NotifyAccessibilityEvent(blink::WebAXEventFocus, focus_); 149 NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, focus_);
150 } 150 }
151 151
152 // Now iterate over the events again and fire the events. 152 // Now iterate over the events again and fire the events.
153 for (uint32 index = 0; index < params.size(); index++) { 153 for (uint32 index = 0; index < params.size(); index++) {
154 const AccessibilityHostMsg_EventParams& param = params[index]; 154 const AccessibilityHostMsg_EventParams& param = params[index];
155 155
156 // Find the node corresponding to the id that's the target of the 156 // Find the node corresponding to the id that's the target of the
157 // event (which may not be the root of the update tree). 157 // event (which may not be the root of the update tree).
158 BrowserAccessibility* node = GetFromRendererID(param.id); 158 BrowserAccessibility* node = GetFromRendererID(param.id);
159 if (!node) 159 if (!node)
160 continue; 160 continue;
161 161
162 blink::WebAXEvent event_type = param.event_type; 162 ui::AXEvent event_type = param.event_type;
163 if (event_type == blink::WebAXEventFocus || 163 if (event_type == ui::AX_EVENT_FOCUS ||
164 event_type == blink::WebAXEventBlur) { 164 event_type == ui::AX_EVENT_BLUR) {
165 SetFocus(node, false); 165 SetFocus(node, false);
166 166
167 if (osk_state_ != OSK_DISALLOWED_BECAUSE_TAB_HIDDEN && 167 if (osk_state_ != OSK_DISALLOWED_BECAUSE_TAB_HIDDEN &&
168 osk_state_ != OSK_DISALLOWED_BECAUSE_TAB_JUST_APPEARED) 168 osk_state_ != OSK_DISALLOWED_BECAUSE_TAB_JUST_APPEARED)
169 osk_state_ = OSK_ALLOWED; 169 osk_state_ = OSK_ALLOWED;
170 170
171 // Don't send a native focus event if the window itself doesn't 171 // Don't send a native focus event if the window itself doesn't
172 // have focus. 172 // have focus.
173 if (delegate_ && !delegate_->HasFocus()) 173 if (delegate_ && !delegate_->HasFocus())
174 continue; 174 continue;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 } 238 }
239 } 239 }
240 240
241 gfx::Rect BrowserAccessibilityManager::GetViewBounds() { 241 gfx::Rect BrowserAccessibilityManager::GetViewBounds() {
242 if (delegate_) 242 if (delegate_)
243 return delegate_->GetViewBounds(); 243 return delegate_->GetViewBounds();
244 return gfx::Rect(); 244 return gfx::Rect();
245 } 245 }
246 246
247 void BrowserAccessibilityManager::UpdateNodesForTesting( 247 void BrowserAccessibilityManager::UpdateNodesForTesting(
248 const AccessibilityNodeData& node1, 248 const ui::AXNodeData& node1,
249 const AccessibilityNodeData& node2 /* = AccessibilityNodeData() */, 249 const ui::AXNodeData& node2 /* = ui::AXNodeData() */,
250 const AccessibilityNodeData& node3 /* = AccessibilityNodeData() */, 250 const ui::AXNodeData& node3 /* = ui::AXNodeData() */,
251 const AccessibilityNodeData& node4 /* = AccessibilityNodeData() */, 251 const ui::AXNodeData& node4 /* = ui::AXNodeData() */,
252 const AccessibilityNodeData& node5 /* = AccessibilityNodeData() */, 252 const ui::AXNodeData& node5 /* = ui::AXNodeData() */,
253 const AccessibilityNodeData& node6 /* = AccessibilityNodeData() */, 253 const ui::AXNodeData& node6 /* = ui::AXNodeData() */,
254 const AccessibilityNodeData& node7 /* = AccessibilityNodeData() */) { 254 const ui::AXNodeData& node7 /* = ui::AXNodeData() */) {
255 std::vector<AccessibilityNodeData> nodes; 255 std::vector<ui::AXNodeData> nodes;
256 nodes.push_back(node1); 256 nodes.push_back(node1);
257 if (node2.id != AccessibilityNodeData().id) 257 if (node2.id != ui::AXNodeData().id)
258 nodes.push_back(node2); 258 nodes.push_back(node2);
259 if (node3.id != AccessibilityNodeData().id) 259 if (node3.id != ui::AXNodeData().id)
260 nodes.push_back(node3); 260 nodes.push_back(node3);
261 if (node4.id != AccessibilityNodeData().id) 261 if (node4.id != ui::AXNodeData().id)
262 nodes.push_back(node4); 262 nodes.push_back(node4);
263 if (node5.id != AccessibilityNodeData().id) 263 if (node5.id != ui::AXNodeData().id)
264 nodes.push_back(node5); 264 nodes.push_back(node5);
265 if (node6.id != AccessibilityNodeData().id) 265 if (node6.id != ui::AXNodeData().id)
266 nodes.push_back(node6); 266 nodes.push_back(node6);
267 if (node7.id != AccessibilityNodeData().id) 267 if (node7.id != ui::AXNodeData().id)
268 nodes.push_back(node7); 268 nodes.push_back(node7);
269 UpdateNodes(nodes); 269 UpdateNodes(nodes);
270 } 270 }
271 271
272 bool BrowserAccessibilityManager::UpdateNodes( 272 bool BrowserAccessibilityManager::UpdateNodes(
273 const std::vector<AccessibilityNodeData>& nodes) { 273 const std::vector<ui::AXNodeData>& nodes) {
274 bool success = true; 274 bool success = true;
275 275
276 // First, update all of the nodes in the tree. 276 // First, update all of the nodes in the tree.
277 for (size_t i = 0; i < nodes.size() && success; i++) { 277 for (size_t i = 0; i < nodes.size() && success; i++) {
278 if (!UpdateNode(nodes[i])) 278 if (!UpdateNode(nodes[i]))
279 success = false; 279 success = false;
280 } 280 }
281 281
282 // In a second pass, call PostInitialize on each one - this must 282 // In a second pass, call PostInitialize on each one - this must
283 // be called after all of each node's children are initialized too. 283 // be called after all of each node's children are initialized too.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 node->InitializeTreeStructure( 329 node->InitializeTreeStructure(
330 this, parent, renderer_id, index_in_parent); 330 this, parent, renderer_id, index_in_parent);
331 AddNodeToMap(node); 331 AddNodeToMap(node);
332 return node; 332 return node;
333 } 333 }
334 334
335 void BrowserAccessibilityManager::AddNodeToMap(BrowserAccessibility* node) { 335 void BrowserAccessibilityManager::AddNodeToMap(BrowserAccessibility* node) {
336 renderer_id_map_[node->renderer_id()] = node; 336 renderer_id_map_[node->renderer_id()] = node;
337 } 337 }
338 338
339 bool BrowserAccessibilityManager::UpdateNode(const AccessibilityNodeData& src) { 339 bool BrowserAccessibilityManager::UpdateNode(const ui::AXNodeData& src) {
340 // This method updates one node in the tree based on serialized data 340 // This method updates one node in the tree based on serialized data
341 // received from the renderer. 341 // received from the renderer.
342 342
343 // Create a set of child ids in |src| for fast lookup. If a duplicate id is 343 // Create a set of child ids in |src| for fast lookup. If a duplicate id is
344 // found, exit now with a fatal error before changing anything else. 344 // found, exit now with a fatal error before changing anything else.
345 std::set<int32> new_child_ids; 345 std::set<int32> new_child_ids;
346 for (size_t i = 0; i < src.child_ids.size(); ++i) { 346 for (size_t i = 0; i < src.child_ids.size(); ++i) {
347 if (new_child_ids.find(src.child_ids[i]) != new_child_ids.end()) 347 if (new_child_ids.find(src.child_ids[i]) != new_child_ids.end())
348 return false; 348 return false;
349 new_child_ids.insert(src.child_ids[i]); 349 new_child_ids.insert(src.child_ids[i]);
350 } 350 }
351 351
352 // Look up the node by id. If it's not found, then either the root 352 // Look up the node by id. If it's not found, then either the root
353 // of the tree is being swapped, or we're out of sync with the renderer 353 // of the tree is being swapped, or we're out of sync with the renderer
354 // and this is a serious error. 354 // and this is a serious error.
355 BrowserAccessibility* instance = GetFromRendererID(src.id); 355 BrowserAccessibility* instance = GetFromRendererID(src.id);
356 if (!instance) { 356 if (!instance) {
357 if (src.role != blink::WebAXRoleRootWebArea) 357 if (src.role != ui::AX_ROLE_ROOT_WEB_AREA)
358 return false; 358 return false;
359 instance = CreateNode(NULL, src.id, 0); 359 instance = CreateNode(NULL, src.id, 0);
360 } 360 }
361 361
362 // Update all of the node-specific data, like its role, state, name, etc. 362 // Update all of the node-specific data, like its role, state, name, etc.
363 instance->InitializeData(src); 363 instance->InitializeData(src);
364 364
365 // 365 //
366 // Update the children in three steps: 366 // Update the children in three steps:
367 // 367 //
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 } else { 405 } else {
406 child = CreateNode(instance, child_renderer_id, index_in_parent); 406 child = CreateNode(instance, child_renderer_id, index_in_parent);
407 } 407 }
408 new_children.push_back(child); 408 new_children.push_back(child);
409 } 409 }
410 410
411 // Finally, swap in the new children vector for the old. 411 // Finally, swap in the new children vector for the old.
412 instance->SwapChildren(new_children); 412 instance->SwapChildren(new_children);
413 413
414 // Handle the case where this node is the new root of the tree. 414 // Handle the case where this node is the new root of the tree.
415 if (src.role == blink::WebAXRoleRootWebArea && 415 if (src.role == ui::AX_ROLE_ROOT_WEB_AREA &&
416 (!root_ || root_->renderer_id() != src.id)) { 416 (!root_ || root_->renderer_id() != src.id)) {
417 if (root_) 417 if (root_)
418 root_->Destroy(); 418 root_->Destroy();
419 if (focus_ == root_) 419 if (focus_ == root_)
420 SetFocus(instance, false); 420 SetFocus(instance, false);
421 SetRoot(instance); 421 SetRoot(instance);
422 } 422 }
423 423
424 // Keep track of what node is focused. 424 // Keep track of what node is focused.
425 if (src.role != blink::WebAXRoleRootWebArea && 425 if (src.role != ui::AX_ROLE_ROOT_WEB_AREA &&
426 src.role != blink::WebAXRoleWebArea && 426 src.role != ui::AX_ROLE_WEB_AREA &&
427 (src.state >> blink::WebAXStateFocused & 1)) { 427 (src.state >> ui::AX_STATE_FOCUSED & 1)) {
428 SetFocus(instance, false); 428 SetFocus(instance, false);
429 } 429 }
430 return success; 430 return success;
431 } 431 }
432 432
433 } // namespace content 433 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698