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

Side by Side Diff: content/renderer/accessibility/render_accessibility_impl.cc

Issue 2205083002: Optimize BlinkAXTreeSource by adding freeze/thaw for things like root, focus. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix pdf accessibility Created 4 years, 3 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
« no previous file with comments | « content/renderer/accessibility/blink_ax_tree_source.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 if (!render_frame->GetWebFrame()) 56 if (!render_frame->GetWebFrame())
57 return; 57 return;
58 58
59 WebDocument document = render_frame->GetWebFrame()->document(); 59 WebDocument document = render_frame->GetWebFrame()->document();
60 WebScopedAXContext context(document); 60 WebScopedAXContext context(document);
61 WebAXObject root = context.root(); 61 WebAXObject root = context.root();
62 if (!root.updateLayoutAndCheckValidity()) 62 if (!root.updateLayoutAndCheckValidity())
63 return; 63 return;
64 BlinkAXTreeSource tree_source(render_frame); 64 BlinkAXTreeSource tree_source(render_frame);
65 tree_source.SetRoot(root); 65 tree_source.SetRoot(root);
66 ScopedFreezeBlinkAXTreeSource freeze(&tree_source);
66 BlinkAXTreeSerializer serializer(&tree_source); 67 BlinkAXTreeSerializer serializer(&tree_source);
67 serializer.set_max_node_count(kMaxSnapshotNodeCount); 68 serializer.set_max_node_count(kMaxSnapshotNodeCount);
68 serializer.SerializeChanges(context.root(), response); 69 serializer.SerializeChanges(context.root(), response);
69 } 70 }
70 71
71 RenderAccessibilityImpl::RenderAccessibilityImpl(RenderFrameImpl* render_frame) 72 RenderAccessibilityImpl::RenderAccessibilityImpl(RenderFrameImpl* render_frame)
72 : RenderFrameObserver(render_frame), 73 : RenderFrameObserver(render_frame),
73 render_frame_(render_frame), 74 render_frame_(render_frame),
74 tree_source_(render_frame), 75 tree_source_(render_frame),
75 serializer_(&tree_source_), 76 serializer_(&tree_source_),
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 int RenderAccessibilityImpl::GenerateAXID() { 243 int RenderAccessibilityImpl::GenerateAXID() {
243 WebAXObject root = tree_source_.GetRoot(); 244 WebAXObject root = tree_source_.GetRoot();
244 return root.generateAXID(); 245 return root.generateAXID();
245 } 246 }
246 247
247 void RenderAccessibilityImpl::SetPdfTreeSource( 248 void RenderAccessibilityImpl::SetPdfTreeSource(
248 RenderAccessibilityImpl::PdfAXTreeSource* pdf_tree_source) { 249 RenderAccessibilityImpl::PdfAXTreeSource* pdf_tree_source) {
249 pdf_tree_source_ = pdf_tree_source; 250 pdf_tree_source_ = pdf_tree_source;
250 pdf_serializer_.reset(new PdfAXTreeSerializer(pdf_tree_source_)); 251 pdf_serializer_.reset(new PdfAXTreeSerializer(pdf_tree_source_));
251 252
253 ScopedFreezeBlinkAXTreeSource freeze(&tree_source_);
252 WebAXObject root = tree_source_.GetRoot(); 254 WebAXObject root = tree_source_.GetRoot();
253 if (!root.updateLayoutAndCheckValidity()) 255 if (!root.updateLayoutAndCheckValidity())
254 return; 256 return;
255 257
256 std::queue<WebAXObject> objs_to_explore; 258 std::queue<WebAXObject> objs_to_explore;
257 objs_to_explore.push(root); 259 objs_to_explore.push(root);
258 while (objs_to_explore.size()) { 260 while (objs_to_explore.size()) {
259 WebAXObject obj = objs_to_explore.front(); 261 WebAXObject obj = objs_to_explore.front();
260 objs_to_explore.pop(); 262 objs_to_explore.pop();
261 263
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 WebAXObject obj = document.accessibilityObjectFromID(event.id); 315 WebAXObject obj = document.accessibilityObjectFromID(event.id);
314 316
315 // Make sure the object still exists. 317 // Make sure the object still exists.
316 if (!obj.updateLayoutAndCheckValidity()) 318 if (!obj.updateLayoutAndCheckValidity())
317 continue; 319 continue;
318 320
319 // If it's ignored, find the first ancestor that's not ignored. 321 // If it's ignored, find the first ancestor that's not ignored.
320 while (!obj.isDetached() && obj.accessibilityIsIgnored()) 322 while (!obj.isDetached() && obj.accessibilityIsIgnored())
321 obj = obj.parentObject(); 323 obj = obj.parentObject();
322 324
325 ScopedFreezeBlinkAXTreeSource freeze(&tree_source_);
326
323 // Make sure it's a descendant of our root node - exceptions include the 327 // Make sure it's a descendant of our root node - exceptions include the
324 // scroll area that's the parent of the main document (we ignore it), and 328 // scroll area that's the parent of the main document (we ignore it), and
325 // possibly nodes attached to a different document. 329 // possibly nodes attached to a different document.
326 if (!tree_source_.IsInTree(obj)) 330 if (!tree_source_.IsInTree(obj))
327 continue; 331 continue;
328 332
329 AccessibilityHostMsg_EventParams event_msg; 333 AccessibilityHostMsg_EventParams event_msg;
330 event_msg.event_type = event.event_type; 334 event_msg.event_type = event.event_type;
331 event_msg.id = event.id; 335 event_msg.id = event.id;
332 if (!serializer_.SerializeChanges(obj, &event_msg.update)) { 336 if (!serializer_.SerializeChanges(obj, &event_msg.update)) {
(...skipping 27 matching lines...) Expand all
360 reset_token_ = 0; 364 reset_token_ = 0;
361 365
362 if (had_layout_complete_messages) 366 if (had_layout_complete_messages)
363 SendLocationChanges(); 367 SendLocationChanges();
364 } 368 }
365 369
366 void RenderAccessibilityImpl::SendLocationChanges() { 370 void RenderAccessibilityImpl::SendLocationChanges() {
367 std::vector<AccessibilityHostMsg_LocationChangeParams> messages; 371 std::vector<AccessibilityHostMsg_LocationChangeParams> messages;
368 372
369 // Update layout on the root of the tree. 373 // Update layout on the root of the tree.
374 ScopedFreezeBlinkAXTreeSource freeze(&tree_source_);
370 WebAXObject root = tree_source_.GetRoot(); 375 WebAXObject root = tree_source_.GetRoot();
371 if (!root.updateLayoutAndCheckValidity()) 376 if (!root.updateLayoutAndCheckValidity())
372 return; 377 return;
373 378
374 // Do a breadth-first explore of the whole blink AX tree. 379 // Do a breadth-first explore of the whole blink AX tree.
375 base::hash_map<int, ui::AXRelativeBounds> new_locations; 380 base::hash_map<int, ui::AXRelativeBounds> new_locations;
376 std::queue<WebAXObject> objs_to_explore; 381 std::queue<WebAXObject> objs_to_explore;
377 objs_to_explore.push(root); 382 objs_to_explore.push(root);
378 while (objs_to_explore.size()) { 383 while (objs_to_explore.size()) {
379 WebAXObject obj = objs_to_explore.front(); 384 WebAXObject obj = objs_to_explore.front();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 return; 459 return;
455 460
456 WebAXObject obj = root_obj.hitTest(point); 461 WebAXObject obj = root_obj.hitTest(point);
457 if (obj.isDetached()) 462 if (obj.isDetached())
458 return; 463 return;
459 464
460 // If the object that was hit has a child frame, we have to send a 465 // If the object that was hit has a child frame, we have to send a
461 // message back to the browser to do the hit test in the child frame, 466 // message back to the browser to do the hit test in the child frame,
462 // recursively. 467 // recursively.
463 AXContentNodeData data; 468 AXContentNodeData data;
469 ScopedFreezeBlinkAXTreeSource freeze(&tree_source_);
464 tree_source_.SerializeNode(obj, &data); 470 tree_source_.SerializeNode(obj, &data);
465 if (data.HasContentIntAttribute(AX_CONTENT_ATTR_CHILD_ROUTING_ID) || 471 if (data.HasContentIntAttribute(AX_CONTENT_ATTR_CHILD_ROUTING_ID) ||
466 data.HasContentIntAttribute( 472 data.HasContentIntAttribute(
467 AX_CONTENT_ATTR_CHILD_BROWSER_PLUGIN_INSTANCE_ID)) { 473 AX_CONTENT_ATTR_CHILD_BROWSER_PLUGIN_INSTANCE_ID)) {
468 Send(new AccessibilityHostMsg_ChildFrameHitTestResult(routing_id(), point, 474 Send(new AccessibilityHostMsg_ChildFrameHitTestResult(routing_id(), point,
469 obj.axID())); 475 obj.axID()));
470 return; 476 return;
471 } 477 }
472 478
473 // Otherwise, send a HOVER event on the node that was hit. 479 // Otherwise, send a HOVER event on the node that was hit.
474 HandleAXEvent(obj, ui::AX_EVENT_HOVER); 480 HandleAXEvent(obj, ui::AX_EVENT_HOVER);
475 } 481 }
476 482
477 void RenderAccessibilityImpl::OnSetAccessibilityFocus(int acc_obj_id) { 483 void RenderAccessibilityImpl::OnSetAccessibilityFocus(int acc_obj_id) {
484 ScopedFreezeBlinkAXTreeSource freeze(&tree_source_);
478 if (tree_source_.accessibility_focus_id() == acc_obj_id) 485 if (tree_source_.accessibility_focus_id() == acc_obj_id)
479 return; 486 return;
480 487
481 tree_source_.set_accessibility_focus_id(acc_obj_id); 488 tree_source_.set_accessibility_focus_id(acc_obj_id);
482 489
483 const WebDocument& document = GetMainDocument(); 490 const WebDocument& document = GetMainDocument();
484 if (document.isNull()) 491 if (document.isNull())
485 return; 492 return;
486 493
487 WebAXObject obj = document.accessibilityObjectFromID(acc_obj_id); 494 WebAXObject obj = document.accessibilityObjectFromID(acc_obj_id);
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 size_t new_count = pdf_update.nodes.size(); 699 size_t new_count = pdf_update.nodes.size();
693 update->nodes.resize(old_count + new_count); 700 update->nodes.resize(old_count + new_count);
694 for (size_t i = 0; i < new_count; ++i) 701 for (size_t i = 0; i < new_count; ++i)
695 update->nodes[old_count + i] = pdf_update.nodes[i]; 702 update->nodes[old_count + i] = pdf_update.nodes[i];
696 break; 703 break;
697 } 704 }
698 } 705 }
699 } 706 }
700 707
701 } // namespace content 708 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/accessibility/blink_ax_tree_source.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698