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

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

Issue 2080573003: Track all changed nodes during an update (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make suggested change. 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
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>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "content/common/accessibility_messages.h" 18 #include "content/common/accessibility_messages.h"
19 #include "content/renderer/accessibility/blink_ax_enum_conversion.h" 19 #include "content/renderer/accessibility/blink_ax_enum_conversion.h"
20 #include "content/renderer/render_frame_impl.h" 20 #include "content/renderer/render_frame_impl.h"
21 #include "content/renderer/render_view_impl.h" 21 #include "content/renderer/render_view_impl.h"
22 #include "third_party/WebKit/public/platform/WebFloatRect.h" 22 #include "third_party/WebKit/public/platform/WebFloatRect.h"
23 #include "third_party/WebKit/public/web/WebAXObject.h" 23 #include "third_party/WebKit/public/web/WebAXObject.h"
24 #include "third_party/WebKit/public/web/WebDocument.h" 24 #include "third_party/WebKit/public/web/WebDocument.h"
25 #include "third_party/WebKit/public/web/WebInputElement.h" 25 #include "third_party/WebKit/public/web/WebInputElement.h"
26 #include "third_party/WebKit/public/web/WebLocalFrame.h" 26 #include "third_party/WebKit/public/web/WebLocalFrame.h"
27 #include "third_party/WebKit/public/web/WebSettings.h" 27 #include "third_party/WebKit/public/web/WebSettings.h"
28 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
28 #include "third_party/WebKit/public/web/WebView.h" 29 #include "third_party/WebKit/public/web/WebView.h"
29 #include "ui/accessibility/ax_node.h" 30 #include "ui/accessibility/ax_node.h"
30 31
31 using blink::WebAXObject; 32 using blink::WebAXObject;
32 using blink::WebDocument; 33 using blink::WebDocument;
33 using blink::WebElement; 34 using blink::WebElement;
34 using blink::WebFloatRect; 35 using blink::WebFloatRect;
35 using blink::WebLocalFrame; 36 using blink::WebLocalFrame;
36 using blink::WebNode; 37 using blink::WebNode;
37 using blink::WebPoint; 38 using blink::WebPoint;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 72
72 RenderAccessibilityImpl::RenderAccessibilityImpl(RenderFrameImpl* render_frame) 73 RenderAccessibilityImpl::RenderAccessibilityImpl(RenderFrameImpl* render_frame)
73 : RenderFrameObserver(render_frame), 74 : RenderFrameObserver(render_frame),
74 render_frame_(render_frame), 75 render_frame_(render_frame),
75 tree_source_(render_frame), 76 tree_source_(render_frame),
76 serializer_(&tree_source_), 77 serializer_(&tree_source_),
77 pdf_tree_source_(nullptr), 78 pdf_tree_source_(nullptr),
78 last_scroll_offset_(gfx::Size()), 79 last_scroll_offset_(gfx::Size()),
79 ack_pending_(false), 80 ack_pending_(false),
80 reset_token_(0), 81 reset_token_(0),
82 during_action_(false),
81 weak_factory_(this) { 83 weak_factory_(this) {
82 WebView* web_view = render_frame_->GetRenderView()->GetWebView(); 84 WebView* web_view = render_frame_->GetRenderView()->GetWebView();
83 WebSettings* settings = web_view->settings(); 85 WebSettings* settings = web_view->settings();
84 settings->setAccessibilityEnabled(true); 86 settings->setAccessibilityEnabled(true);
85 87
86 #if defined(OS_ANDROID) 88 #if defined(OS_ANDROID)
87 // Password values are only passed through on Android. 89 // Password values are only passed through on Android.
88 settings->setAccessibilityPasswordValuesEnabled(true); 90 settings->setAccessibilityPasswordValuesEnabled(true);
89 #endif 91 #endif
90 92
91 #if !defined(OS_ANDROID) 93 #if !defined(OS_ANDROID)
92 // Inline text boxes are enabled for all nodes on all except Android. 94 // Inline text boxes are enabled for all nodes on all except Android.
93 settings->setInlineTextBoxAccessibilityEnabled(true); 95 settings->setInlineTextBoxAccessibilityEnabled(true);
94 #endif 96 #endif
95 97
96 const WebDocument& document = GetMainDocument(); 98 const WebDocument& document = GetMainDocument();
97 if (!document.isNull()) { 99 if (!document.isNull()) {
98 // It's possible that the webview has already loaded a webpage without 100 // It's possible that the webview has already loaded a webpage without
99 // accessibility being enabled. Initialize the browser's cached 101 // accessibility being enabled. Initialize the browser's cached
100 // accessibility tree by sending it a notification. 102 // accessibility tree by sending it a notification.
101 HandleAXEvent(document.accessibilityObject(), ui::AX_EVENT_LAYOUT_COMPLETE); 103 HandleAXEvent(document.accessibilityObject(), ui::AX_EVENT_LAYOUT_COMPLETE);
102 } 104 }
103 } 105 }
104 106
105 RenderAccessibilityImpl::~RenderAccessibilityImpl() { 107 RenderAccessibilityImpl::~RenderAccessibilityImpl() {
106 } 108 }
107 109
108 bool RenderAccessibilityImpl::OnMessageReceived(const IPC::Message& message) { 110 bool RenderAccessibilityImpl::OnMessageReceived(const IPC::Message& message) {
109 bool handled = true; 111 bool handled = true;
112 during_action_ = true;
110 IPC_BEGIN_MESSAGE_MAP(RenderAccessibilityImpl, message) 113 IPC_BEGIN_MESSAGE_MAP(RenderAccessibilityImpl, message)
111 IPC_MESSAGE_HANDLER(AccessibilityMsg_SetFocus, OnSetFocus) 114 IPC_MESSAGE_HANDLER(AccessibilityMsg_SetFocus, OnSetFocus)
112 IPC_MESSAGE_HANDLER(AccessibilityMsg_DoDefaultAction, OnDoDefaultAction) 115 IPC_MESSAGE_HANDLER(AccessibilityMsg_DoDefaultAction, OnDoDefaultAction)
113 IPC_MESSAGE_HANDLER(AccessibilityMsg_Events_ACK, OnEventsAck) 116 IPC_MESSAGE_HANDLER(AccessibilityMsg_Events_ACK, OnEventsAck)
114 IPC_MESSAGE_HANDLER(AccessibilityMsg_ScrollToMakeVisible, 117 IPC_MESSAGE_HANDLER(AccessibilityMsg_ScrollToMakeVisible,
115 OnScrollToMakeVisible) 118 OnScrollToMakeVisible)
116 IPC_MESSAGE_HANDLER(AccessibilityMsg_ScrollToPoint, OnScrollToPoint) 119 IPC_MESSAGE_HANDLER(AccessibilityMsg_ScrollToPoint, OnScrollToPoint)
117 IPC_MESSAGE_HANDLER(AccessibilityMsg_SetScrollOffset, OnSetScrollOffset) 120 IPC_MESSAGE_HANDLER(AccessibilityMsg_SetScrollOffset, OnSetScrollOffset)
118 IPC_MESSAGE_HANDLER(AccessibilityMsg_SetSelection, OnSetSelection) 121 IPC_MESSAGE_HANDLER(AccessibilityMsg_SetSelection, OnSetSelection)
119 IPC_MESSAGE_HANDLER(AccessibilityMsg_SetValue, OnSetValue) 122 IPC_MESSAGE_HANDLER(AccessibilityMsg_SetValue, OnSetValue)
120 IPC_MESSAGE_HANDLER(AccessibilityMsg_ShowContextMenu, OnShowContextMenu) 123 IPC_MESSAGE_HANDLER(AccessibilityMsg_ShowContextMenu, OnShowContextMenu)
121 IPC_MESSAGE_HANDLER(AccessibilityMsg_HitTest, OnHitTest) 124 IPC_MESSAGE_HANDLER(AccessibilityMsg_HitTest, OnHitTest)
122 IPC_MESSAGE_HANDLER(AccessibilityMsg_SetAccessibilityFocus, 125 IPC_MESSAGE_HANDLER(AccessibilityMsg_SetAccessibilityFocus,
123 OnSetAccessibilityFocus) 126 OnSetAccessibilityFocus)
124 IPC_MESSAGE_HANDLER(AccessibilityMsg_Reset, OnReset) 127 IPC_MESSAGE_HANDLER(AccessibilityMsg_Reset, OnReset)
125 IPC_MESSAGE_HANDLER(AccessibilityMsg_FatalError, OnFatalError) 128 IPC_MESSAGE_HANDLER(AccessibilityMsg_FatalError, OnFatalError)
126 IPC_MESSAGE_UNHANDLED(handled = false) 129 IPC_MESSAGE_UNHANDLED(handled = false)
127 IPC_END_MESSAGE_MAP() 130 IPC_END_MESSAGE_MAP()
131 during_action_ = false;
128 return handled; 132 return handled;
129 } 133 }
130 134
131 void RenderAccessibilityImpl::HandleWebAccessibilityEvent( 135 void RenderAccessibilityImpl::HandleWebAccessibilityEvent(
132 const blink::WebAXObject& obj, blink::WebAXEvent event) { 136 const blink::WebAXObject& obj, blink::WebAXEvent event) {
133 HandleAXEvent(obj, AXEventFromBlink(event)); 137 HandleAXEvent(obj, AXEventFromBlink(event));
134 } 138 }
135 139
136 void RenderAccessibilityImpl::HandleAccessibilityFindInPageResult( 140 void RenderAccessibilityImpl::HandleAccessibilityFindInPageResult(
137 int identifier, 141 int identifier,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 // inline text boxes. 208 // inline text boxes.
205 if (event == ui::AX_EVENT_FOCUS) 209 if (event == ui::AX_EVENT_FOCUS)
206 serializer_.DeleteClientSubtree(obj); 210 serializer_.DeleteClientSubtree(obj);
207 #endif 211 #endif
208 212
209 // Add the accessibility object to our cache and ensure it's valid. 213 // Add the accessibility object to our cache and ensure it's valid.
210 AccessibilityHostMsg_EventParams acc_event; 214 AccessibilityHostMsg_EventParams acc_event;
211 acc_event.id = obj.axID(); 215 acc_event.id = obj.axID();
212 acc_event.event_type = event; 216 acc_event.event_type = event;
213 217
218 if (blink::WebUserGestureIndicator::isProcessingUserGesture())
219 acc_event.event_from = ui::AX_EVENT_FROM_USER;
220 else if (during_action_)
221 acc_event.event_from = ui::AX_EVENT_FROM_ACTION;
222 else
223 acc_event.event_from = ui::AX_EVENT_FROM_PAGE;
224
214 // Discard duplicate accessibility events. 225 // Discard duplicate accessibility events.
215 for (uint32_t i = 0; i < pending_events_.size(); ++i) { 226 for (uint32_t i = 0; i < pending_events_.size(); ++i) {
216 if (pending_events_[i].id == acc_event.id && 227 if (pending_events_[i].id == acc_event.id &&
217 pending_events_[i].event_type == acc_event.event_type) { 228 pending_events_[i].event_type == acc_event.event_type) {
218 return; 229 return;
219 } 230 }
220 } 231 }
221 pending_events_.push_back(acc_event); 232 pending_events_.push_back(acc_event);
222 233
223 if (!ack_pending_ && !weak_factory_.HasWeakPtrs()) { 234 if (!ack_pending_ && !weak_factory_.HasWeakPtrs()) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 328
318 // Make sure it's a descendant of our root node - exceptions include the 329 // 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 330 // scroll area that's the parent of the main document (we ignore it), and
320 // possibly nodes attached to a different document. 331 // possibly nodes attached to a different document.
321 if (!tree_source_.IsInTree(obj)) 332 if (!tree_source_.IsInTree(obj))
322 continue; 333 continue;
323 334
324 AccessibilityHostMsg_EventParams event_msg; 335 AccessibilityHostMsg_EventParams event_msg;
325 event_msg.event_type = event.event_type; 336 event_msg.event_type = event.event_type;
326 event_msg.id = event.id; 337 event_msg.id = event.id;
338 event_msg.event_from = event.event_from;
327 if (!serializer_.SerializeChanges(obj, &event_msg.update)) { 339 if (!serializer_.SerializeChanges(obj, &event_msg.update)) {
328 LOG(ERROR) << "Failed to serialize one accessibility event."; 340 LOG(ERROR) << "Failed to serialize one accessibility event.";
329 continue; 341 continue;
330 } 342 }
331 343
332 if (pdf_tree_source_) 344 if (pdf_tree_source_)
333 AddPdfTreeToUpdate(&event_msg.update); 345 AddPdfTreeToUpdate(&event_msg.update);
334 346
335 event_msgs.push_back(event_msg); 347 event_msgs.push_back(event_msg);
336 348
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 size_t new_count = pdf_update.nodes.size(); 702 size_t new_count = pdf_update.nodes.size();
691 update->nodes.resize(old_count + new_count); 703 update->nodes.resize(old_count + new_count);
692 for (size_t i = 0; i < new_count; ++i) 704 for (size_t i = 0; i < new_count; ++i)
693 update->nodes[old_count + i] = pdf_update.nodes[i]; 705 update->nodes[old_count + i] = pdf_update.nodes[i];
694 break; 706 break;
695 } 707 }
696 } 708 }
697 } 709 }
698 710
699 } // namespace content 711 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/accessibility/render_accessibility_impl.h ('k') | ui/accessibility/ax_enums.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698