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/renderer/accessibility/render_accessibility_impl.h" | 5 #include "content/renderer/accessibility/render_accessibility_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <queue> | 10 #include <queue> |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 AXContentTreeUpdate* response) { | 51 AXContentTreeUpdate* response) { |
52 DCHECK(render_frame); | 52 DCHECK(render_frame); |
53 DCHECK(response); | 53 DCHECK(response); |
54 if (!render_frame->GetWebFrame()) | 54 if (!render_frame->GetWebFrame()) |
55 return; | 55 return; |
56 | 56 |
57 WebDocument document = render_frame->GetWebFrame()->document(); | 57 WebDocument document = render_frame->GetWebFrame()->document(); |
58 WebScopedAXContext context(document); | 58 WebScopedAXContext context(document); |
59 BlinkAXTreeSource tree_source(render_frame); | 59 BlinkAXTreeSource tree_source(render_frame); |
60 tree_source.SetRoot(context.root()); | 60 tree_source.SetRoot(context.root()); |
| 61 ScopedFreezeBlinkAXTreeSource freeze(&tree_source); |
61 BlinkAXTreeSerializer serializer(&tree_source); | 62 BlinkAXTreeSerializer serializer(&tree_source); |
62 serializer.set_max_node_count(kMaxSnapshotNodeCount); | 63 serializer.set_max_node_count(kMaxSnapshotNodeCount); |
63 serializer.SerializeChanges(context.root(), response); | 64 serializer.SerializeChanges(context.root(), response); |
64 } | 65 } |
65 | 66 |
66 RenderAccessibilityImpl::RenderAccessibilityImpl(RenderFrameImpl* render_frame) | 67 RenderAccessibilityImpl::RenderAccessibilityImpl(RenderFrameImpl* render_frame) |
67 : RenderFrameObserver(render_frame), | 68 : RenderFrameObserver(render_frame), |
68 render_frame_(render_frame), | 69 render_frame_(render_frame), |
69 tree_source_(render_frame), | 70 tree_source_(render_frame), |
70 serializer_(&tree_source_), | 71 serializer_(&tree_source_), |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 int RenderAccessibilityImpl::GenerateAXID() { | 238 int RenderAccessibilityImpl::GenerateAXID() { |
238 WebAXObject root = tree_source_.GetRoot(); | 239 WebAXObject root = tree_source_.GetRoot(); |
239 return root.generateAXID(); | 240 return root.generateAXID(); |
240 } | 241 } |
241 | 242 |
242 void RenderAccessibilityImpl::SetPdfTreeSource( | 243 void RenderAccessibilityImpl::SetPdfTreeSource( |
243 RenderAccessibilityImpl::PdfAXTreeSource* pdf_tree_source) { | 244 RenderAccessibilityImpl::PdfAXTreeSource* pdf_tree_source) { |
244 pdf_tree_source_ = pdf_tree_source; | 245 pdf_tree_source_ = pdf_tree_source; |
245 pdf_serializer_.reset(new PdfAXTreeSerializer(pdf_tree_source_)); | 246 pdf_serializer_.reset(new PdfAXTreeSerializer(pdf_tree_source_)); |
246 | 247 |
| 248 ScopedFreezeBlinkAXTreeSource freeze(&tree_source_); |
247 WebAXObject root = tree_source_.GetRoot(); | 249 WebAXObject root = tree_source_.GetRoot(); |
248 if (!root.updateLayoutAndCheckValidity()) | 250 if (!root.updateLayoutAndCheckValidity()) |
249 return; | 251 return; |
250 | 252 |
251 std::queue<WebAXObject> objs_to_explore; | 253 std::queue<WebAXObject> objs_to_explore; |
252 objs_to_explore.push(root); | 254 objs_to_explore.push(root); |
253 while (objs_to_explore.size()) { | 255 while (objs_to_explore.size()) { |
254 WebAXObject obj = objs_to_explore.front(); | 256 WebAXObject obj = objs_to_explore.front(); |
255 objs_to_explore.pop(); | 257 objs_to_explore.pop(); |
256 | 258 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 WebAXObject obj = document.accessibilityObjectFromID(event.id); | 310 WebAXObject obj = document.accessibilityObjectFromID(event.id); |
309 | 311 |
310 // Make sure the object still exists. | 312 // Make sure the object still exists. |
311 if (!obj.updateLayoutAndCheckValidity()) | 313 if (!obj.updateLayoutAndCheckValidity()) |
312 continue; | 314 continue; |
313 | 315 |
314 // If it's ignored, find the first ancestor that's not ignored. | 316 // If it's ignored, find the first ancestor that's not ignored. |
315 while (!obj.isDetached() && obj.accessibilityIsIgnored()) | 317 while (!obj.isDetached() && obj.accessibilityIsIgnored()) |
316 obj = obj.parentObject(); | 318 obj = obj.parentObject(); |
317 | 319 |
| 320 ScopedFreezeBlinkAXTreeSource freeze(&tree_source_); |
| 321 |
318 // Make sure it's a descendant of our root node - exceptions include the | 322 // Make sure it's a descendant of our root node - exceptions include the |
319 // scroll area that's the parent of the main document (we ignore it), and | 323 // scroll area that's the parent of the main document (we ignore it), and |
320 // possibly nodes attached to a different document. | 324 // possibly nodes attached to a different document. |
321 if (!tree_source_.IsInTree(obj)) | 325 if (!tree_source_.IsInTree(obj)) |
322 continue; | 326 continue; |
323 | 327 |
324 AccessibilityHostMsg_EventParams event_msg; | 328 AccessibilityHostMsg_EventParams event_msg; |
325 event_msg.event_type = event.event_type; | 329 event_msg.event_type = event.event_type; |
326 event_msg.id = event.id; | 330 event_msg.id = event.id; |
327 if (!serializer_.SerializeChanges(obj, &event_msg.update)) { | 331 if (!serializer_.SerializeChanges(obj, &event_msg.update)) { |
(...skipping 22 matching lines...) Expand all Loading... |
350 reset_token_ = 0; | 354 reset_token_ = 0; |
351 | 355 |
352 if (had_layout_complete_messages) | 356 if (had_layout_complete_messages) |
353 SendLocationChanges(); | 357 SendLocationChanges(); |
354 } | 358 } |
355 | 359 |
356 void RenderAccessibilityImpl::SendLocationChanges() { | 360 void RenderAccessibilityImpl::SendLocationChanges() { |
357 std::vector<AccessibilityHostMsg_LocationChangeParams> messages; | 361 std::vector<AccessibilityHostMsg_LocationChangeParams> messages; |
358 | 362 |
359 // Update layout on the root of the tree. | 363 // Update layout on the root of the tree. |
| 364 ScopedFreezeBlinkAXTreeSource freeze(&tree_source_); |
360 WebAXObject root = tree_source_.GetRoot(); | 365 WebAXObject root = tree_source_.GetRoot(); |
361 if (!root.updateLayoutAndCheckValidity()) | 366 if (!root.updateLayoutAndCheckValidity()) |
362 return; | 367 return; |
363 | 368 |
364 // Do a breadth-first explore of the whole blink AX tree. | 369 // Do a breadth-first explore of the whole blink AX tree. |
365 base::hash_map<int, gfx::RectF> new_locations; | 370 base::hash_map<int, gfx::RectF> new_locations; |
366 std::queue<WebAXObject> objs_to_explore; | 371 std::queue<WebAXObject> objs_to_explore; |
367 objs_to_explore.push(root); | 372 objs_to_explore.push(root); |
368 while (objs_to_explore.size()) { | 373 while (objs_to_explore.size()) { |
369 WebAXObject obj = objs_to_explore.front(); | 374 WebAXObject obj = objs_to_explore.front(); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 return; | 439 return; |
435 | 440 |
436 WebAXObject obj = root_obj.hitTest(point); | 441 WebAXObject obj = root_obj.hitTest(point); |
437 if (obj.isDetached()) | 442 if (obj.isDetached()) |
438 return; | 443 return; |
439 | 444 |
440 // If the object that was hit has a child frame, we have to send a | 445 // If the object that was hit has a child frame, we have to send a |
441 // message back to the browser to do the hit test in the child frame, | 446 // message back to the browser to do the hit test in the child frame, |
442 // recursively. | 447 // recursively. |
443 AXContentNodeData data; | 448 AXContentNodeData data; |
| 449 ScopedFreezeBlinkAXTreeSource freeze(&tree_source_); |
444 tree_source_.SerializeNode(obj, &data); | 450 tree_source_.SerializeNode(obj, &data); |
445 if (data.HasContentIntAttribute(AX_CONTENT_ATTR_CHILD_ROUTING_ID) || | 451 if (data.HasContentIntAttribute(AX_CONTENT_ATTR_CHILD_ROUTING_ID) || |
446 data.HasContentIntAttribute( | 452 data.HasContentIntAttribute( |
447 AX_CONTENT_ATTR_CHILD_BROWSER_PLUGIN_INSTANCE_ID)) { | 453 AX_CONTENT_ATTR_CHILD_BROWSER_PLUGIN_INSTANCE_ID)) { |
448 Send(new AccessibilityHostMsg_ChildFrameHitTestResult(routing_id(), point, | 454 Send(new AccessibilityHostMsg_ChildFrameHitTestResult(routing_id(), point, |
449 obj.axID())); | 455 obj.axID())); |
450 return; | 456 return; |
451 } | 457 } |
452 | 458 |
453 // Otherwise, send a HOVER event on the node that was hit. | 459 // Otherwise, send a HOVER event on the node that was hit. |
454 HandleAXEvent(obj, ui::AX_EVENT_HOVER); | 460 HandleAXEvent(obj, ui::AX_EVENT_HOVER); |
455 } | 461 } |
456 | 462 |
457 void RenderAccessibilityImpl::OnSetAccessibilityFocus(int acc_obj_id) { | 463 void RenderAccessibilityImpl::OnSetAccessibilityFocus(int acc_obj_id) { |
| 464 ScopedFreezeBlinkAXTreeSource freeze(&tree_source_); |
458 if (tree_source_.accessibility_focus_id() == acc_obj_id) | 465 if (tree_source_.accessibility_focus_id() == acc_obj_id) |
459 return; | 466 return; |
460 | 467 |
461 tree_source_.set_accessibility_focus_id(acc_obj_id); | 468 tree_source_.set_accessibility_focus_id(acc_obj_id); |
462 | 469 |
463 const WebDocument& document = GetMainDocument(); | 470 const WebDocument& document = GetMainDocument(); |
464 if (document.isNull()) | 471 if (document.isNull()) |
465 return; | 472 return; |
466 | 473 |
467 WebAXObject obj = document.accessibilityObjectFromID(acc_obj_id); | 474 WebAXObject obj = document.accessibilityObjectFromID(acc_obj_id); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 size_t new_count = pdf_update.nodes.size(); | 679 size_t new_count = pdf_update.nodes.size(); |
673 update->nodes.resize(old_count + new_count); | 680 update->nodes.resize(old_count + new_count); |
674 for (size_t i = 0; i < new_count; ++i) | 681 for (size_t i = 0; i < new_count; ++i) |
675 update->nodes[old_count + i] = pdf_update.nodes[i]; | 682 update->nodes[old_count + i] = pdf_update.nodes[i]; |
676 break; | 683 break; |
677 } | 684 } |
678 } | 685 } |
679 } | 686 } |
680 | 687 |
681 } // namespace content | 688 } // namespace content |
OLD | NEW |