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

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

Issue 401643003: Correctly update the bounds of objects in the accessibility tree. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update win and android expectations Created 6 years, 5 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 | 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"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 // Make a copy of the events, because it's possible that 164 // Make a copy of the events, because it's possible that
165 // actions inside this loop will cause more events to be 165 // actions inside this loop will cause more events to be
166 // queued up. 166 // queued up.
167 std::vector<AccessibilityHostMsg_EventParams> src_events = 167 std::vector<AccessibilityHostMsg_EventParams> src_events =
168 pending_events_; 168 pending_events_;
169 pending_events_.clear(); 169 pending_events_.clear();
170 170
171 // Generate an event message from each Blink event. 171 // Generate an event message from each Blink event.
172 std::vector<AccessibilityHostMsg_EventParams> event_msgs; 172 std::vector<AccessibilityHostMsg_EventParams> event_msgs;
173 173
174 // If there's a layout complete message, we need to send location changes.
175 bool had_layout_complete_messages = false;
aboxhall 2014/07/19 15:08:05 Why is this plural?
dmazzoni 2014/07/20 04:24:17 There could be more than one "layout complete" in
aboxhall 2014/07/21 01:33:47 Obviously not a deal-breaker, but to me had_layout
176
174 // Loop over each event and generate an updated event message. 177 // Loop over each event and generate an updated event message.
175 for (size_t i = 0; i < src_events.size(); ++i) { 178 for (size_t i = 0; i < src_events.size(); ++i) {
176 AccessibilityHostMsg_EventParams& event = 179 AccessibilityHostMsg_EventParams& event = src_events[i];
177 src_events[i]; 180 if (event.event_type == ui::AX_EVENT_LAYOUT_COMPLETE)
181 had_layout_complete_messages = true;
178 182
179 WebAXObject obj = document.accessibilityObjectFromID( 183 WebAXObject obj = document.accessibilityObjectFromID(event.id);
180 event.id); 184
181 // Make sure the object still exists. 185 // Make sure the object still exists.
182 if (!obj.updateBackingStoreAndCheckValidity()) 186 if (!obj.updateBackingStoreAndCheckValidity())
183 continue; 187 continue;
188
184 // Make sure it's a descendant of our root node - exceptions include the 189 // Make sure it's a descendant of our root node - exceptions include the
185 // scroll area that's the parent of the main document (we ignore it), and 190 // scroll area that's the parent of the main document (we ignore it), and
186 // possibly nodes attached to a different document. 191 // possibly nodes attached to a different document.
187 if (!tree_source_.IsInTree(obj)) 192 if (!tree_source_.IsInTree(obj))
188 continue; 193 continue;
189 194
190 // When we get a "selected children changed" event, Blink 195 // When we get a "selected children changed" event, Blink
191 // doesn't also send us events for each child that changed 196 // doesn't also send us events for each child that changed
192 // selection state, so make sure we re-send that whole subtree. 197 // selection state, so make sure we re-send that whole subtree.
193 if (event.event_type == 198 if (event.event_type ==
194 ui::AX_EVENT_SELECTED_CHILDREN_CHANGED) { 199 ui::AX_EVENT_SELECTED_CHILDREN_CHANGED) {
195 serializer_.DeleteClientSubtree(obj); 200 serializer_.DeleteClientSubtree(obj);
196 } 201 }
197 202
198 AccessibilityHostMsg_EventParams event_msg; 203 AccessibilityHostMsg_EventParams event_msg;
199 event_msg.event_type = event.event_type; 204 event_msg.event_type = event.event_type;
200 event_msg.id = event.id; 205 event_msg.id = event.id;
201 serializer_.SerializeChanges(obj, &event_msg.update); 206 serializer_.SerializeChanges(obj, &event_msg.update);
202 event_msgs.push_back(event_msg); 207 event_msgs.push_back(event_msg);
203 208
209 // For each node in the update, set the location in our map from
210 // ids to locations.
211 for (size_t i = 0; i < event_msg.update.nodes.size(); ++i) {
212 locations_[event_msg.update.nodes[i].id] =
213 event_msg.update.nodes[i].location;
214 }
215
204 VLOG(0) << "Accessibility event: " << ui::ToString(event.event_type) 216 VLOG(0) << "Accessibility event: " << ui::ToString(event.event_type)
205 << " on node id " << event_msg.id 217 << " on node id " << event_msg.id
206 << "\n" << event_msg.update.ToString(); 218 << "\n" << event_msg.update.ToString();
207 } 219 }
208 220
209 Send(new AccessibilityHostMsg_Events(routing_id(), event_msgs)); 221 Send(new AccessibilityHostMsg_Events(routing_id(), event_msgs));
210 222
211 SendLocationChanges(); 223 if (had_layout_complete_messages)
224 SendLocationChanges();
212 } 225 }
213 226
214 void RendererAccessibilityComplete::SendLocationChanges() { 227 void RendererAccessibilityComplete::SendLocationChanges() {
215 std::vector<AccessibilityHostMsg_LocationChangeParams> messages; 228 std::vector<AccessibilityHostMsg_LocationChangeParams> messages;
216 229
217 // Do a breadth-first explore of the whole blink AX tree. 230 // Do a breadth-first explore of the whole blink AX tree.
218 base::hash_map<int, gfx::Rect> new_locations; 231 base::hash_map<int, gfx::Rect> new_locations;
219 std::queue<WebAXObject> objs_to_explore; 232 std::queue<WebAXObject> objs_to_explore;
220 objs_to_explore.push(tree_source_.GetRoot()); 233 objs_to_explore.push(tree_source_.GetRoot());
221 while (objs_to_explore.size()) { 234 while (objs_to_explore.size()) {
(...skipping 11 matching lines...) Expand all
233 gfx::Rect new_location = obj.boundingBoxRect(); 246 gfx::Rect new_location = obj.boundingBoxRect();
234 if (iter != locations_.end() && iter->second != new_location) { 247 if (iter != locations_.end() && iter->second != new_location) {
235 AccessibilityHostMsg_LocationChangeParams message; 248 AccessibilityHostMsg_LocationChangeParams message;
236 message.id = id; 249 message.id = id;
237 message.new_location = new_location; 250 message.new_location = new_location;
238 messages.push_back(message); 251 messages.push_back(message);
239 } 252 }
240 253
241 // Save the new location. 254 // Save the new location.
242 new_locations[id] = new_location; 255 new_locations[id] = new_location;
256
257 // Explore children of this object.
aboxhall 2014/07/19 15:08:05 Oops! :)
dmazzoni 2014/07/20 04:24:17 Yup! Accidentally lost when refactoring, easy fix,
258 std::vector<blink::WebAXObject> children;
259 tree_source_.GetChildren(obj, &children);
260 for (size_t i = 0; i < children.size(); ++i)
261 objs_to_explore.push(children[i]);
243 } 262 }
244 locations_.swap(new_locations); 263 locations_.swap(new_locations);
245 264
246 Send(new AccessibilityHostMsg_LocationChanges(routing_id(), messages)); 265 Send(new AccessibilityHostMsg_LocationChanges(routing_id(), messages));
247 } 266 }
248 267
249 void RendererAccessibilityComplete::OnDoDefaultAction(int acc_obj_id) { 268 void RendererAccessibilityComplete::OnDoDefaultAction(int acc_obj_id) {
250 const WebDocument& document = GetMainDocument(); 269 const WebDocument& document = GetMainDocument();
251 if (document.isNull()) 270 if (document.isNull())
252 return; 271 return;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 render_frame_->GetRenderView()->GetWebView()->clearFocusedElement(); 403 render_frame_->GetRenderView()->GetWebView()->clearFocusedElement();
385 else 404 else
386 obj.setFocused(true); 405 obj.setFocused(true);
387 } 406 }
388 407
389 void RendererAccessibilityComplete::OnFatalError() { 408 void RendererAccessibilityComplete::OnFatalError() {
390 CHECK(false) << "Invalid accessibility tree."; 409 CHECK(false) << "Invalid accessibility tree.";
391 } 410 }
392 411
393 } // namespace content 412 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698