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

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

Issue 63253002: Rename WebKit namespace to blink (part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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/renderer/accessibility/renderer_accessibility_complete.h" 5 #include "content/renderer/accessibility/renderer_accessibility_complete.h"
6 6
7 #include <queue> 7 #include <queue>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "content/renderer/accessibility/accessibility_node_serializer.h" 11 #include "content/renderer/accessibility/accessibility_node_serializer.h"
12 #include "content/renderer/render_view_impl.h" 12 #include "content/renderer/render_view_impl.h"
13 #include "third_party/WebKit/public/web/WebAXObject.h" 13 #include "third_party/WebKit/public/web/WebAXObject.h"
14 #include "third_party/WebKit/public/web/WebDocument.h" 14 #include "third_party/WebKit/public/web/WebDocument.h"
15 #include "third_party/WebKit/public/web/WebFrame.h" 15 #include "third_party/WebKit/public/web/WebFrame.h"
16 #include "third_party/WebKit/public/web/WebInputElement.h" 16 #include "third_party/WebKit/public/web/WebInputElement.h"
17 #include "third_party/WebKit/public/web/WebNode.h" 17 #include "third_party/WebKit/public/web/WebNode.h"
18 #include "third_party/WebKit/public/web/WebView.h" 18 #include "third_party/WebKit/public/web/WebView.h"
19 19
20 using WebKit::WebAXObject; 20 using blink::WebAXObject;
21 using WebKit::WebDocument; 21 using blink::WebDocument;
22 using WebKit::WebFrame; 22 using blink::WebFrame;
23 using WebKit::WebNode; 23 using blink::WebNode;
24 using WebKit::WebPoint; 24 using blink::WebPoint;
25 using WebKit::WebRect; 25 using blink::WebRect;
26 using WebKit::WebSize; 26 using blink::WebSize;
27 using WebKit::WebView; 27 using blink::WebView;
28 28
29 namespace content { 29 namespace content {
30 30
31 RendererAccessibilityComplete::RendererAccessibilityComplete( 31 RendererAccessibilityComplete::RendererAccessibilityComplete(
32 RenderViewImpl* render_view) 32 RenderViewImpl* render_view)
33 : RendererAccessibility(render_view), 33 : RendererAccessibility(render_view),
34 weak_factory_(this), 34 weak_factory_(this),
35 browser_root_(NULL), 35 browser_root_(NULL),
36 last_scroll_offset_(gfx::Size()), 36 last_scroll_offset_(gfx::Size()),
37 ack_pending_(false) { 37 ack_pending_(false) {
38 WebAXObject::enableAccessibility(); 38 WebAXObject::enableAccessibility();
39 WebAXObject::enableInlineTextBoxAccessibility(); 39 WebAXObject::enableInlineTextBoxAccessibility();
40 40
41 const WebDocument& document = GetMainDocument(); 41 const WebDocument& document = GetMainDocument();
42 if (!document.isNull()) { 42 if (!document.isNull()) {
43 // It's possible that the webview has already loaded a webpage without 43 // It's possible that the webview has already loaded a webpage without
44 // accessibility being enabled. Initialize the browser's cached 44 // accessibility being enabled. Initialize the browser's cached
45 // accessibility tree by sending it a notification. 45 // accessibility tree by sending it a notification.
46 HandleWebAccessibilityEvent(document.accessibilityObject(), 46 HandleWebAccessibilityEvent(document.accessibilityObject(),
47 WebKit::WebAXEventLayoutComplete); 47 blink::WebAXEventLayoutComplete);
48 } 48 }
49 } 49 }
50 50
51 RendererAccessibilityComplete::~RendererAccessibilityComplete() { 51 RendererAccessibilityComplete::~RendererAccessibilityComplete() {
52 } 52 }
53 53
54 bool RendererAccessibilityComplete::OnMessageReceived( 54 bool RendererAccessibilityComplete::OnMessageReceived(
55 const IPC::Message& message) { 55 const IPC::Message& message) {
56 bool handled = true; 56 bool handled = true;
57 IPC_BEGIN_MESSAGE_MAP(RendererAccessibilityComplete, message) 57 IPC_BEGIN_MESSAGE_MAP(RendererAccessibilityComplete, message)
(...skipping 16 matching lines...) Expand all
74 74
75 void RendererAccessibilityComplete::FocusedNodeChanged(const WebNode& node) { 75 void RendererAccessibilityComplete::FocusedNodeChanged(const WebNode& node) {
76 const WebDocument& document = GetMainDocument(); 76 const WebDocument& document = GetMainDocument();
77 if (document.isNull()) 77 if (document.isNull())
78 return; 78 return;
79 79
80 if (node.isNull()) { 80 if (node.isNull()) {
81 // When focus is cleared, implicitly focus the document. 81 // When focus is cleared, implicitly focus the document.
82 // TODO(dmazzoni): Make WebKit send this notification instead. 82 // TODO(dmazzoni): Make WebKit send this notification instead.
83 HandleWebAccessibilityEvent(document.accessibilityObject(), 83 HandleWebAccessibilityEvent(document.accessibilityObject(),
84 WebKit::WebAXEventBlur); 84 blink::WebAXEventBlur);
85 } 85 }
86 } 86 }
87 87
88 void RendererAccessibilityComplete::DidFinishLoad(WebKit::WebFrame* frame) { 88 void RendererAccessibilityComplete::DidFinishLoad(blink::WebFrame* frame) {
89 const WebDocument& document = GetMainDocument(); 89 const WebDocument& document = GetMainDocument();
90 if (document.isNull()) 90 if (document.isNull())
91 return; 91 return;
92 92
93 // Check to see if the root accessibility object has changed, to work 93 // Check to see if the root accessibility object has changed, to work
94 // around WebKit bugs that cause AXObjectCache to be cleared 94 // around WebKit bugs that cause AXObjectCache to be cleared
95 // unnecessarily. 95 // unnecessarily.
96 // TODO(dmazzoni): remove this once rdar://5794454 is fixed. 96 // TODO(dmazzoni): remove this once rdar://5794454 is fixed.
97 WebAXObject new_root = document.accessibilityObject(); 97 WebAXObject new_root = document.accessibilityObject();
98 if (!browser_root_ || new_root.axID() != browser_root_->id) 98 if (!browser_root_ || new_root.axID() != browser_root_->id)
99 HandleWebAccessibilityEvent(new_root, WebKit::WebAXEventLayoutComplete); 99 HandleWebAccessibilityEvent(new_root, blink::WebAXEventLayoutComplete);
100 } 100 }
101 101
102 void RendererAccessibilityComplete::HandleWebAccessibilityEvent( 102 void RendererAccessibilityComplete::HandleWebAccessibilityEvent(
103 const WebKit::WebAXObject& obj, 103 const blink::WebAXObject& obj,
104 WebKit::WebAXEvent event) { 104 blink::WebAXEvent event) {
105 const WebDocument& document = GetMainDocument(); 105 const WebDocument& document = GetMainDocument();
106 if (document.isNull()) 106 if (document.isNull())
107 return; 107 return;
108 108
109 gfx::Size scroll_offset = document.frame()->scrollOffset(); 109 gfx::Size scroll_offset = document.frame()->scrollOffset();
110 if (scroll_offset != last_scroll_offset_) { 110 if (scroll_offset != last_scroll_offset_) {
111 // Make sure the browser is always aware of the scroll position of 111 // Make sure the browser is always aware of the scroll position of
112 // the root document element by posting a generic notification that 112 // the root document element by posting a generic notification that
113 // will update it. 113 // will update it.
114 // TODO(dmazzoni): remove this as soon as 114 // TODO(dmazzoni): remove this as soon as
115 // https://bugs.webkit.org/show_bug.cgi?id=73460 is fixed. 115 // https://bugs.webkit.org/show_bug.cgi?id=73460 is fixed.
116 last_scroll_offset_ = scroll_offset; 116 last_scroll_offset_ = scroll_offset;
117 if (!obj.equals(document.accessibilityObject())) { 117 if (!obj.equals(document.accessibilityObject())) {
118 HandleWebAccessibilityEvent( 118 HandleWebAccessibilityEvent(
119 document.accessibilityObject(), 119 document.accessibilityObject(),
120 WebKit::WebAXEventLayoutComplete); 120 blink::WebAXEventLayoutComplete);
121 } 121 }
122 } 122 }
123 123
124 // Add the accessibility object to our cache and ensure it's valid. 124 // Add the accessibility object to our cache and ensure it's valid.
125 AccessibilityHostMsg_EventParams acc_event; 125 AccessibilityHostMsg_EventParams acc_event;
126 acc_event.id = obj.axID(); 126 acc_event.id = obj.axID();
127 acc_event.event_type = event; 127 acc_event.event_type = event;
128 128
129 // Discard duplicate accessibility events. 129 // Discard duplicate accessibility events.
130 for (uint32 i = 0; i < pending_events_.size(); ++i) { 130 for (uint32 i = 0; i < pending_events_.size(); ++i) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 182
183 WebAXObject obj = document.accessibilityObjectFromID( 183 WebAXObject obj = document.accessibilityObjectFromID(
184 event.id); 184 event.id);
185 if (!obj.updateBackingStoreAndCheckValidity()) 185 if (!obj.updateBackingStoreAndCheckValidity())
186 continue; 186 continue;
187 187
188 // When we get a "selected children changed" event, WebKit 188 // When we get a "selected children changed" event, WebKit
189 // doesn't also send us events for each child that changed 189 // doesn't also send us events for each child that changed
190 // selection state, so make sure we re-send that whole subtree. 190 // selection state, so make sure we re-send that whole subtree.
191 if (event.event_type == 191 if (event.event_type ==
192 WebKit::WebAXEventSelectedChildrenChanged) { 192 blink::WebAXEventSelectedChildrenChanged) {
193 base::hash_map<int32, BrowserTreeNode*>::iterator iter = 193 base::hash_map<int32, BrowserTreeNode*>::iterator iter =
194 browser_id_map_.find(obj.axID()); 194 browser_id_map_.find(obj.axID());
195 if (iter != browser_id_map_.end()) 195 if (iter != browser_id_map_.end())
196 ClearBrowserTreeNode(iter->second); 196 ClearBrowserTreeNode(iter->second);
197 } 197 }
198 198
199 // The browser may not have this object yet, for example if we get a 199 // The browser may not have this object yet, for example if we get a
200 // event on an object that was recently added, or if we get a 200 // event on an object that was recently added, or if we get a
201 // event on a node before the page has loaded. Work our way 201 // event on a node before the page has loaded. Work our way
202 // up the parent chain until we find a node the browser has, or until 202 // up the parent chain until we find a node the browser has, or until
203 // we reach the root. 203 // we reach the root.
204 WebAXObject root_object = document.accessibilityObject(); 204 WebAXObject root_object = document.accessibilityObject();
205 int root_id = root_object.axID(); 205 int root_id = root_object.axID();
206 while (browser_id_map_.find(obj.axID()) == browser_id_map_.end() && 206 while (browser_id_map_.find(obj.axID()) == browser_id_map_.end() &&
207 !obj.isDetached() && 207 !obj.isDetached() &&
208 obj.axID() != root_id) { 208 obj.axID() != root_id) {
209 obj = obj.parentObject(); 209 obj = obj.parentObject();
210 if (event.event_type == 210 if (event.event_type ==
211 WebKit::WebAXEventChildrenChanged) { 211 blink::WebAXEventChildrenChanged) {
212 event.id = obj.axID(); 212 event.id = obj.axID();
213 } 213 }
214 } 214 }
215 215
216 if (obj.isDetached()) { 216 if (obj.isDetached()) {
217 #ifndef NDEBUG 217 #ifndef NDEBUG
218 if (logging_) 218 if (logging_)
219 LOG(WARNING) << "Got event on object that is invalid or has" 219 LOG(WARNING) << "Got event on object that is invalid or has"
220 << " invalid ancestor. Id: " << obj.axID(); 220 << " invalid ancestor. Id: " << obj.axID();
221 #endif 221 #endif
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 } 302 }
303 303
304 for (unsigned i = 0; i < obj.childCount(); ++i) 304 for (unsigned i = 0; i < obj.childCount(); ++i)
305 objs_to_explore.push(obj.childAt(i)); 305 objs_to_explore.push(obj.childAt(i));
306 } 306 }
307 307
308 if (location_changes.size() == 0) 308 if (location_changes.size() == 0)
309 return; 309 return;
310 310
311 AccessibilityHostMsg_EventParams event_msg; 311 AccessibilityHostMsg_EventParams event_msg;
312 event_msg.event_type = static_cast<WebKit::WebAXEvent>(-1); 312 event_msg.event_type = static_cast<blink::WebAXEvent>(-1);
313 event_msg.id = root_object.axID(); 313 event_msg.id = root_object.axID();
314 event_msg.nodes.resize(location_changes.size()); 314 event_msg.nodes.resize(location_changes.size());
315 for (size_t i = 0; i < location_changes.size(); i++) { 315 for (size_t i = 0; i < location_changes.size(); i++) {
316 AccessibilityNodeData& serialized_node = event_msg.nodes[i]; 316 AccessibilityNodeData& serialized_node = event_msg.nodes[i];
317 serialized_node.id = location_changes[i]->id; 317 serialized_node.id = location_changes[i]->id;
318 serialized_node.location = location_changes[i]->location; 318 serialized_node.location = location_changes[i]->location;
319 serialized_node.AddBoolAttribute( 319 serialized_node.AddBoolAttribute(
320 AccessibilityNodeData::ATTR_UPDATE_LOCATION_ONLY, true); 320 AccessibilityNodeData::ATTR_UPDATE_LOCATION_ONLY, true);
321 } 321 }
322 322
323 event_msgs->push_back(event_msg); 323 event_msgs->push_back(event_msg);
324 } 324 }
325 325
326 RendererAccessibilityComplete::BrowserTreeNode* 326 RendererAccessibilityComplete::BrowserTreeNode*
327 RendererAccessibilityComplete::CreateBrowserTreeNode() { 327 RendererAccessibilityComplete::CreateBrowserTreeNode() {
328 return new RendererAccessibilityComplete::BrowserTreeNode(); 328 return new RendererAccessibilityComplete::BrowserTreeNode();
329 } 329 }
330 330
331 void RendererAccessibilityComplete::SerializeChangedNodes( 331 void RendererAccessibilityComplete::SerializeChangedNodes(
332 const WebKit::WebAXObject& obj, 332 const blink::WebAXObject& obj,
333 std::vector<AccessibilityNodeData>* dst, 333 std::vector<AccessibilityNodeData>* dst,
334 std::set<int>* ids_serialized) { 334 std::set<int>* ids_serialized) {
335 if (ids_serialized->find(obj.axID()) != ids_serialized->end()) 335 if (ids_serialized->find(obj.axID()) != ids_serialized->end())
336 return; 336 return;
337 ids_serialized->insert(obj.axID()); 337 ids_serialized->insert(obj.axID());
338 338
339 // This method has three responsibilities: 339 // This method has three responsibilities:
340 // 1. Serialize |obj| into an AccessibilityNodeData, and append it to 340 // 1. Serialize |obj| into an AccessibilityNodeData, and append it to
341 // the end of the |dst| vector to be send to the browser process. 341 // the end of the |dst| vector to be send to the browser process.
342 // 2. Determine if |obj| has any new children that the browser doesn't 342 // 2. Determine if |obj| has any new children that the browser doesn't
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 browser_child_id_map[old_child_id] = old_child; 425 browser_child_id_map[old_child_id] = old_child;
426 } 426 }
427 } 427 }
428 428
429 // Serialize this node. This fills in all of the fields in 429 // Serialize this node. This fills in all of the fields in
430 // AccessibilityNodeData except child_ids, which we handle below. 430 // AccessibilityNodeData except child_ids, which we handle below.
431 dst->push_back(AccessibilityNodeData()); 431 dst->push_back(AccessibilityNodeData());
432 AccessibilityNodeData* serialized_node = &dst->back(); 432 AccessibilityNodeData* serialized_node = &dst->back();
433 SerializeAccessibilityNode(obj, serialized_node); 433 SerializeAccessibilityNode(obj, serialized_node);
434 if (serialized_node->id == browser_root_->id) 434 if (serialized_node->id == browser_root_->id)
435 serialized_node->role = WebKit::WebAXRoleRootWebArea; 435 serialized_node->role = blink::WebAXRoleRootWebArea;
436 436
437 // Iterate over the children, make note of the ones that are new 437 // Iterate over the children, make note of the ones that are new
438 // and need to be serialized, and update the BrowserTreeNode 438 // and need to be serialized, and update the BrowserTreeNode
439 // data structure to reflect the new tree. 439 // data structure to reflect the new tree.
440 std::vector<WebAXObject> children_to_serialize; 440 std::vector<WebAXObject> children_to_serialize;
441 int child_count = obj.childCount(); 441 int child_count = obj.childCount();
442 browser_node->children.reserve(child_count); 442 browser_node->children.reserve(child_count);
443 for (int i = 0; i < child_count; i++) { 443 for (int i = 0; i < child_count; i++) {
444 WebAXObject child = obj.childAt(i); 444 WebAXObject child = obj.childAt(i);
445 int child_id = child.axID(); 445 int child_id = child.axID();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 obj.scrollToMakeVisibleWithSubFocus( 521 obj.scrollToMakeVisibleWithSubFocus(
522 WebRect(subfocus.x(), subfocus.y(), 522 WebRect(subfocus.x(), subfocus.y(),
523 subfocus.width(), subfocus.height())); 523 subfocus.width(), subfocus.height()));
524 524
525 // Make sure the browser gets an event when the scroll 525 // Make sure the browser gets an event when the scroll
526 // position actually changes. 526 // position actually changes.
527 // TODO(dmazzoni): remove this once this bug is fixed: 527 // TODO(dmazzoni): remove this once this bug is fixed:
528 // https://bugs.webkit.org/show_bug.cgi?id=73460 528 // https://bugs.webkit.org/show_bug.cgi?id=73460
529 HandleWebAccessibilityEvent( 529 HandleWebAccessibilityEvent(
530 document.accessibilityObject(), 530 document.accessibilityObject(),
531 WebKit::WebAXEventLayoutComplete); 531 blink::WebAXEventLayoutComplete);
532 } 532 }
533 533
534 void RendererAccessibilityComplete::OnScrollToPoint( 534 void RendererAccessibilityComplete::OnScrollToPoint(
535 int acc_obj_id, gfx::Point point) { 535 int acc_obj_id, gfx::Point point) {
536 const WebDocument& document = GetMainDocument(); 536 const WebDocument& document = GetMainDocument();
537 if (document.isNull()) 537 if (document.isNull())
538 return; 538 return;
539 539
540 WebAXObject obj = document.accessibilityObjectFromID(acc_obj_id); 540 WebAXObject obj = document.accessibilityObjectFromID(acc_obj_id);
541 if (obj.isDetached()) { 541 if (obj.isDetached()) {
542 #ifndef NDEBUG 542 #ifndef NDEBUG
543 if (logging_) 543 if (logging_)
544 LOG(WARNING) << "ScrollToPoint on invalid object id " << acc_obj_id; 544 LOG(WARNING) << "ScrollToPoint on invalid object id " << acc_obj_id;
545 #endif 545 #endif
546 return; 546 return;
547 } 547 }
548 548
549 obj.scrollToGlobalPoint(WebPoint(point.x(), point.y())); 549 obj.scrollToGlobalPoint(WebPoint(point.x(), point.y()));
550 550
551 // Make sure the browser gets an event when the scroll 551 // Make sure the browser gets an event when the scroll
552 // position actually changes. 552 // position actually changes.
553 // TODO(dmazzoni): remove this once this bug is fixed: 553 // TODO(dmazzoni): remove this once this bug is fixed:
554 // https://bugs.webkit.org/show_bug.cgi?id=73460 554 // https://bugs.webkit.org/show_bug.cgi?id=73460
555 HandleWebAccessibilityEvent( 555 HandleWebAccessibilityEvent(
556 document.accessibilityObject(), 556 document.accessibilityObject(),
557 WebKit::WebAXEventLayoutComplete); 557 blink::WebAXEventLayoutComplete);
558 } 558 }
559 559
560 void RendererAccessibilityComplete::OnSetTextSelection( 560 void RendererAccessibilityComplete::OnSetTextSelection(
561 int acc_obj_id, int start_offset, int end_offset) { 561 int acc_obj_id, int start_offset, int end_offset) {
562 const WebDocument& document = GetMainDocument(); 562 const WebDocument& document = GetMainDocument();
563 if (document.isNull()) 563 if (document.isNull())
564 return; 564 return;
565 565
566 WebAXObject obj = document.accessibilityObjectFromID(acc_obj_id); 566 WebAXObject obj = document.accessibilityObjectFromID(acc_obj_id);
567 if (obj.isDetached()) { 567 if (obj.isDetached()) {
568 #ifndef NDEBUG 568 #ifndef NDEBUG
569 if (logging_) 569 if (logging_)
570 LOG(WARNING) << "SetTextSelection on invalid object id " << acc_obj_id; 570 LOG(WARNING) << "SetTextSelection on invalid object id " << acc_obj_id;
571 #endif 571 #endif
572 return; 572 return;
573 } 573 }
574 574
575 // TODO(dmazzoni): support elements other than <input>. 575 // TODO(dmazzoni): support elements other than <input>.
576 WebKit::WebNode node = obj.node(); 576 blink::WebNode node = obj.node();
577 if (!node.isNull() && node.isElementNode()) { 577 if (!node.isNull() && node.isElementNode()) {
578 WebKit::WebElement element = node.to<WebKit::WebElement>(); 578 blink::WebElement element = node.to<blink::WebElement>();
579 WebKit::WebInputElement* input_element = 579 blink::WebInputElement* input_element =
580 WebKit::toWebInputElement(&element); 580 blink::toWebInputElement(&element);
581 if (input_element && input_element->isTextField()) 581 if (input_element && input_element->isTextField())
582 input_element->setSelectionRange(start_offset, end_offset); 582 input_element->setSelectionRange(start_offset, end_offset);
583 } 583 }
584 } 584 }
585 585
586 void RendererAccessibilityComplete::OnEventsAck() { 586 void RendererAccessibilityComplete::OnEventsAck() {
587 DCHECK(ack_pending_); 587 DCHECK(ack_pending_);
588 ack_pending_ = false; 588 ack_pending_ = false;
589 SendPendingAccessibilityEvents(); 589 SendPendingAccessibilityEvents();
590 } 590 }
(...skipping 30 matching lines...) Expand all
621 render_view()->GetWebView()->clearFocusedNode(); 621 render_view()->GetWebView()->clearFocusedNode();
622 else 622 else
623 obj.setFocused(true); 623 obj.setFocused(true);
624 } 624 }
625 625
626 void RendererAccessibilityComplete::OnFatalError() { 626 void RendererAccessibilityComplete::OnFatalError() {
627 CHECK(false) << "Invalid accessibility tree."; 627 CHECK(false) << "Invalid accessibility tree.";
628 } 628 }
629 629
630 } // namespace content 630 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698