OLD | NEW |
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 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 return bounds.Contains(touch_point); | 109 return bounds.Contains(touch_point); |
110 } | 110 } |
111 | 111 |
112 bool BrowserAccessibilityManager::UseRootScrollOffsetsWhenComputingBounds() { | 112 bool BrowserAccessibilityManager::UseRootScrollOffsetsWhenComputingBounds() { |
113 return true; | 113 return true; |
114 } | 114 } |
115 | 115 |
116 void BrowserAccessibilityManager::RemoveNode(BrowserAccessibility* node) { | 116 void BrowserAccessibilityManager::RemoveNode(BrowserAccessibility* node) { |
117 if (node == focus_) | 117 if (node == focus_) |
118 SetFocus(root_, false); | 118 SetFocus(root_, false); |
119 int renderer_id = node->renderer_id(); | 119 int renderer_id = node->GetId(); |
120 renderer_id_map_.erase(renderer_id); | 120 renderer_id_map_.erase(renderer_id); |
121 } | 121 } |
122 | 122 |
123 void BrowserAccessibilityManager::OnAccessibilityEvents( | 123 void BrowserAccessibilityManager::OnAccessibilityEvents( |
124 const std::vector<AccessibilityHostMsg_EventParams>& params) { | 124 const std::vector<AccessibilityHostMsg_EventParams>& params) { |
125 bool should_send_initial_focus = false; | 125 bool should_send_initial_focus = false; |
126 | 126 |
127 // Process all changes to the accessibility tree first. | 127 // Process all changes to the accessibility tree first. |
128 for (uint32 index = 0; index < params.size(); index++) { | 128 for (uint32 index = 0; index < params.size(); index++) { |
129 const AccessibilityHostMsg_EventParams& param = params[index]; | 129 const AccessibilityHostMsg_EventParams& param = params[index]; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 | 191 |
192 return NULL; | 192 return NULL; |
193 } | 193 } |
194 | 194 |
195 void BrowserAccessibilityManager::SetFocus( | 195 void BrowserAccessibilityManager::SetFocus( |
196 BrowserAccessibility* node, bool notify) { | 196 BrowserAccessibility* node, bool notify) { |
197 if (focus_ != node) | 197 if (focus_ != node) |
198 focus_ = node; | 198 focus_ = node; |
199 | 199 |
200 if (notify && node && delegate_) | 200 if (notify && node && delegate_) |
201 delegate_->SetAccessibilityFocus(node->renderer_id()); | 201 delegate_->SetAccessibilityFocus(node->GetId()); |
202 } | 202 } |
203 | 203 |
204 void BrowserAccessibilityManager::SetRoot(BrowserAccessibility* node) { | 204 void BrowserAccessibilityManager::SetRoot(BrowserAccessibility* node) { |
205 root_ = node; | 205 root_ = node; |
206 NotifyRootChanged(); | 206 NotifyRootChanged(); |
207 } | 207 } |
208 | 208 |
209 void BrowserAccessibilityManager::DoDefaultAction( | 209 void BrowserAccessibilityManager::DoDefaultAction( |
210 const BrowserAccessibility& node) { | 210 const BrowserAccessibility& node) { |
211 if (delegate_) | 211 if (delegate_) |
212 delegate_->AccessibilityDoDefaultAction(node.renderer_id()); | 212 delegate_->AccessibilityDoDefaultAction(node.GetId()); |
213 } | 213 } |
214 | 214 |
215 void BrowserAccessibilityManager::ScrollToMakeVisible( | 215 void BrowserAccessibilityManager::ScrollToMakeVisible( |
216 const BrowserAccessibility& node, gfx::Rect subfocus) { | 216 const BrowserAccessibility& node, gfx::Rect subfocus) { |
217 if (delegate_) { | 217 if (delegate_) { |
218 delegate_->AccessibilityScrollToMakeVisible(node.renderer_id(), subfocus); | 218 delegate_->AccessibilityScrollToMakeVisible(node.GetId(), subfocus); |
219 } | 219 } |
220 } | 220 } |
221 | 221 |
222 void BrowserAccessibilityManager::ScrollToPoint( | 222 void BrowserAccessibilityManager::ScrollToPoint( |
223 const BrowserAccessibility& node, gfx::Point point) { | 223 const BrowserAccessibility& node, gfx::Point point) { |
224 if (delegate_) { | 224 if (delegate_) { |
225 delegate_->AccessibilityScrollToPoint(node.renderer_id(), point); | 225 delegate_->AccessibilityScrollToPoint(node.GetId(), point); |
226 } | 226 } |
227 } | 227 } |
228 | 228 |
229 void BrowserAccessibilityManager::SetTextSelection( | 229 void BrowserAccessibilityManager::SetTextSelection( |
230 const BrowserAccessibility& node, int start_offset, int end_offset) { | 230 const BrowserAccessibility& node, int start_offset, int end_offset) { |
231 if (delegate_) { | 231 if (delegate_) { |
232 delegate_->AccessibilitySetTextSelection( | 232 delegate_->AccessibilitySetTextSelection( |
233 node.renderer_id(), start_offset, end_offset); | 233 node.GetId(), start_offset, end_offset); |
234 } | 234 } |
235 } | 235 } |
236 | 236 |
237 gfx::Rect BrowserAccessibilityManager::GetViewBounds() { | 237 gfx::Rect BrowserAccessibilityManager::GetViewBounds() { |
238 if (delegate_) | 238 if (delegate_) |
239 return delegate_->GetViewBounds(); | 239 return delegate_->GetViewBounds(); |
240 return gfx::Rect(); | 240 return gfx::Rect(); |
241 } | 241 } |
242 | 242 |
243 BrowserAccessibility* BrowserAccessibilityManager::NextInTreeOrder( | 243 BrowserAccessibility* BrowserAccessibilityManager::NextInTreeOrder( |
244 BrowserAccessibility* node) { | 244 BrowserAccessibility* node) { |
245 if (!node) | 245 if (!node) |
246 return NULL; | 246 return NULL; |
247 | 247 |
248 if (node->PlatformChildCount() > 0) | 248 if (node->PlatformChildCount() > 0) |
249 return node->PlatformGetChild(0); | 249 return node->PlatformGetChild(0); |
250 while (node) { | 250 while (node) { |
251 if (node->parent() && | 251 if (node->GetParent() && |
252 node->index_in_parent() < | 252 node->GetIndexInParent() < |
253 static_cast<int>(node->parent()->PlatformChildCount()) - 1) { | 253 static_cast<int>(node->GetParent()->PlatformChildCount()) - 1) { |
254 return node->parent()->PlatformGetChild(node->index_in_parent() + 1); | 254 return node->GetParent()->PlatformGetChild(node->GetIndexInParent() + 1); |
255 } | 255 } |
256 node = node->parent(); | 256 node = node->GetParent(); |
257 } | 257 } |
258 | 258 |
259 return NULL; | 259 return NULL; |
260 } | 260 } |
261 | 261 |
262 BrowserAccessibility* BrowserAccessibilityManager::PreviousInTreeOrder( | 262 BrowserAccessibility* BrowserAccessibilityManager::PreviousInTreeOrder( |
263 BrowserAccessibility* node) { | 263 BrowserAccessibility* node) { |
264 if (!node) | 264 if (!node) |
265 return NULL; | 265 return NULL; |
266 | 266 |
267 if (node->parent() && node->index_in_parent() > 0) { | 267 if (node->GetParent() && node->GetIndexInParent() > 0) { |
268 node = node->parent()->PlatformGetChild(node->index_in_parent() - 1); | 268 node = node->GetParent()->PlatformGetChild(node->GetIndexInParent() - 1); |
269 while (node->PlatformChildCount() > 0) | 269 while (node->PlatformChildCount() > 0) |
270 node = node->PlatformGetChild(node->PlatformChildCount() - 1); | 270 node = node->PlatformGetChild(node->PlatformChildCount() - 1); |
271 return node; | 271 return node; |
272 } | 272 } |
273 | 273 |
274 return node->parent(); | 274 return node->GetParent(); |
275 } | 275 } |
276 | 276 |
277 void BrowserAccessibilityManager::UpdateNodesForTesting( | 277 void BrowserAccessibilityManager::UpdateNodesForTesting( |
278 const ui::AXNodeData& node1, | 278 const ui::AXNodeData& node1, |
279 const ui::AXNodeData& node2 /* = ui::AXNodeData() */, | 279 const ui::AXNodeData& node2 /* = ui::AXNodeData() */, |
280 const ui::AXNodeData& node3 /* = ui::AXNodeData() */, | 280 const ui::AXNodeData& node3 /* = ui::AXNodeData() */, |
281 const ui::AXNodeData& node4 /* = ui::AXNodeData() */, | 281 const ui::AXNodeData& node4 /* = ui::AXNodeData() */, |
282 const ui::AXNodeData& node5 /* = ui::AXNodeData() */, | 282 const ui::AXNodeData& node5 /* = ui::AXNodeData() */, |
283 const ui::AXNodeData& node6 /* = ui::AXNodeData() */, | 283 const ui::AXNodeData& node6 /* = ui::AXNodeData() */, |
284 const ui::AXNodeData& node7 /* = ui::AXNodeData() */) { | 284 const ui::AXNodeData& node7 /* = ui::AXNodeData() */) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 int32 renderer_id, | 356 int32 renderer_id, |
357 int32 index_in_parent) { | 357 int32 index_in_parent) { |
358 BrowserAccessibility* node = factory_->Create(); | 358 BrowserAccessibility* node = factory_->Create(); |
359 node->InitializeTreeStructure( | 359 node->InitializeTreeStructure( |
360 this, parent, renderer_id, index_in_parent); | 360 this, parent, renderer_id, index_in_parent); |
361 AddNodeToMap(node); | 361 AddNodeToMap(node); |
362 return node; | 362 return node; |
363 } | 363 } |
364 | 364 |
365 void BrowserAccessibilityManager::AddNodeToMap(BrowserAccessibility* node) { | 365 void BrowserAccessibilityManager::AddNodeToMap(BrowserAccessibility* node) { |
366 renderer_id_map_[node->renderer_id()] = node; | 366 renderer_id_map_[node->GetId()] = node; |
367 } | 367 } |
368 | 368 |
369 bool BrowserAccessibilityManager::UpdateNode(const ui::AXNodeData& src) { | 369 bool BrowserAccessibilityManager::UpdateNode(const ui::AXNodeData& src) { |
370 // This method updates one node in the tree based on serialized data | 370 // This method updates one node in the tree based on serialized data |
371 // received from the renderer. | 371 // received from the renderer. |
372 | 372 |
373 // Create a set of child ids in |src| for fast lookup. If a duplicate id is | 373 // Create a set of child ids in |src| for fast lookup. If a duplicate id is |
374 // found, exit now with a fatal error before changing anything else. | 374 // found, exit now with a fatal error before changing anything else. |
375 std::set<int32> new_child_ids; | 375 std::set<int32> new_child_ids; |
376 for (size_t i = 0; i < src.child_ids.size(); ++i) { | 376 for (size_t i = 0; i < src.child_ids.size(); ++i) { |
(...skipping 24 matching lines...) Expand all Loading... |
401 // changed (but may have been reordered) and adding new empty | 401 // changed (but may have been reordered) and adding new empty |
402 // objects for new children. | 402 // objects for new children. |
403 // 3. Swap in the new children vector for the old one. | 403 // 3. Swap in the new children vector for the old one. |
404 | 404 |
405 // Delete any previous children of this instance that are no longer | 405 // Delete any previous children of this instance that are no longer |
406 // children first. We make a deletion-only pass first to prevent a | 406 // children first. We make a deletion-only pass first to prevent a |
407 // node that's being reparented from being the child of both its old | 407 // node that's being reparented from being the child of both its old |
408 // parent and new parent, which could lead to a double-free. | 408 // parent and new parent, which could lead to a double-free. |
409 // If a node is reparented, the renderer will always send us a fresh | 409 // If a node is reparented, the renderer will always send us a fresh |
410 // copy of the node. | 410 // copy of the node. |
411 const std::vector<BrowserAccessibility*>& old_children = instance->children(); | 411 const std::vector<BrowserAccessibility*>& old_children = |
| 412 instance->deprecated_children(); |
412 for (size_t i = 0; i < old_children.size(); ++i) { | 413 for (size_t i = 0; i < old_children.size(); ++i) { |
413 int old_id = old_children[i]->renderer_id(); | 414 int old_id = old_children[i]->GetId(); |
414 if (new_child_ids.find(old_id) == new_child_ids.end()) | 415 if (new_child_ids.find(old_id) == new_child_ids.end()) |
415 old_children[i]->Destroy(); | 416 old_children[i]->Destroy(); |
416 } | 417 } |
417 | 418 |
418 // Now build a vector of new children, reusing objects that were already | 419 // Now build a vector of new children, reusing objects that were already |
419 // children of this node before. | 420 // children of this node before. |
420 std::vector<BrowserAccessibility*> new_children; | 421 std::vector<BrowserAccessibility*> new_children; |
421 bool success = true; | 422 bool success = true; |
422 for (size_t i = 0; i < src.child_ids.size(); i++) { | 423 for (size_t i = 0; i < src.child_ids.size(); i++) { |
423 int32 child_renderer_id = src.child_ids[i]; | 424 int32 child_renderer_id = src.child_ids[i]; |
424 int32 index_in_parent = static_cast<int32>(i); | 425 int32 index_in_parent = static_cast<int32>(i); |
425 BrowserAccessibility* child = GetFromRendererID(child_renderer_id); | 426 BrowserAccessibility* child = GetFromRendererID(child_renderer_id); |
426 if (child) { | 427 if (child) { |
427 if (child->parent() != instance) { | 428 if (child->GetParent() != instance) { |
428 // This is a serious error - nodes should never be reparented. | 429 // This is a serious error - nodes should never be reparented. |
429 // If this case occurs, continue so this node isn't left in an | 430 // If this case occurs, continue so this node isn't left in an |
430 // inconsistent state, but return failure at the end. | 431 // inconsistent state, but return failure at the end. |
431 success = false; | 432 success = false; |
432 continue; | 433 continue; |
433 } | 434 } |
434 child->UpdateParent(instance, index_in_parent); | 435 child->UpdateParent(instance, index_in_parent); |
435 } else { | 436 } else { |
436 child = CreateNode(instance, child_renderer_id, index_in_parent); | 437 child = CreateNode(instance, child_renderer_id, index_in_parent); |
437 } | 438 } |
438 new_children.push_back(child); | 439 new_children.push_back(child); |
439 } | 440 } |
440 | 441 |
441 // Finally, swap in the new children vector for the old. | 442 // Finally, swap in the new children vector for the old. |
442 instance->SwapChildren(new_children); | 443 instance->SwapChildren(new_children); |
443 | 444 |
444 // Handle the case where this node is the new root of the tree. | 445 // Handle the case where this node is the new root of the tree. |
445 if (src.role == ui::AX_ROLE_ROOT_WEB_AREA && | 446 if (src.role == ui::AX_ROLE_ROOT_WEB_AREA && |
446 (!root_ || root_->renderer_id() != src.id)) { | 447 (!root_ || root_->GetId() != src.id)) { |
447 if (root_) | 448 if (root_) |
448 root_->Destroy(); | 449 root_->Destroy(); |
449 if (focus_ == root_) | 450 if (focus_ == root_) |
450 SetFocus(instance, false); | 451 SetFocus(instance, false); |
451 SetRoot(instance); | 452 SetRoot(instance); |
452 } | 453 } |
453 | 454 |
454 // Keep track of what node is focused. | 455 // Keep track of what node is focused. |
455 if (src.role != ui::AX_ROLE_ROOT_WEB_AREA && | 456 if (src.role != ui::AX_ROLE_ROOT_WEB_AREA && |
456 src.role != ui::AX_ROLE_WEB_AREA && | 457 src.role != ui::AX_ROLE_WEB_AREA && |
457 (src.state >> ui::AX_STATE_FOCUSED & 1)) { | 458 (src.state >> ui::AX_STATE_FOCUSED & 1)) { |
458 SetFocus(instance, false); | 459 SetFocus(instance, false); |
459 } | 460 } |
460 return success; | 461 return success; |
461 } | 462 } |
462 | 463 |
463 } // namespace content | 464 } // namespace content |
OLD | NEW |