| 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/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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 // Make a copy of the events, because it's possible that | 170 // Make a copy of the events, because it's possible that |
| 171 // actions inside this loop will cause more events to be | 171 // actions inside this loop will cause more events to be |
| 172 // queued up. | 172 // queued up. |
| 173 std::vector<AccessibilityHostMsg_EventParams> src_events = | 173 std::vector<AccessibilityHostMsg_EventParams> src_events = |
| 174 pending_events_; | 174 pending_events_; |
| 175 pending_events_.clear(); | 175 pending_events_.clear(); |
| 176 | 176 |
| 177 // Generate an event message from each Blink event. | 177 // Generate an event message from each Blink event. |
| 178 std::vector<AccessibilityHostMsg_EventParams> event_msgs; | 178 std::vector<AccessibilityHostMsg_EventParams> event_msgs; |
| 179 | 179 |
| 180 // If there's a layout complete message, we need to send location changes. |
| 181 bool had_layout_complete_messages = false; |
| 182 |
| 180 // Loop over each event and generate an updated event message. | 183 // Loop over each event and generate an updated event message. |
| 181 for (size_t i = 0; i < src_events.size(); ++i) { | 184 for (size_t i = 0; i < src_events.size(); ++i) { |
| 182 AccessibilityHostMsg_EventParams& event = | 185 AccessibilityHostMsg_EventParams& event = src_events[i]; |
| 183 src_events[i]; | 186 if (event.event_type == ui::AX_EVENT_LAYOUT_COMPLETE) |
| 187 had_layout_complete_messages = true; |
| 184 | 188 |
| 185 WebAXObject obj = document.accessibilityObjectFromID( | 189 WebAXObject obj = document.accessibilityObjectFromID(event.id); |
| 186 event.id); | 190 |
| 187 // Make sure the object still exists. | 191 // Make sure the object still exists. |
| 188 if (!obj.updateBackingStoreAndCheckValidity()) | 192 if (!obj.updateBackingStoreAndCheckValidity()) |
| 189 continue; | 193 continue; |
| 194 |
| 190 // Make sure it's a descendant of our root node - exceptions include the | 195 // Make sure it's a descendant of our root node - exceptions include the |
| 191 // scroll area that's the parent of the main document (we ignore it), and | 196 // scroll area that's the parent of the main document (we ignore it), and |
| 192 // possibly nodes attached to a different document. | 197 // possibly nodes attached to a different document. |
| 193 if (!tree_source_.IsInTree(obj)) | 198 if (!tree_source_.IsInTree(obj)) |
| 194 continue; | 199 continue; |
| 195 | 200 |
| 196 // When we get a "selected children changed" event, Blink | 201 // When we get a "selected children changed" event, Blink |
| 197 // doesn't also send us events for each child that changed | 202 // doesn't also send us events for each child that changed |
| 198 // selection state, so make sure we re-send that whole subtree. | 203 // selection state, so make sure we re-send that whole subtree. |
| 199 if (event.event_type == | 204 if (event.event_type == |
| 200 ui::AX_EVENT_SELECTED_CHILDREN_CHANGED) { | 205 ui::AX_EVENT_SELECTED_CHILDREN_CHANGED) { |
| 201 serializer_.DeleteClientSubtree(obj); | 206 serializer_.DeleteClientSubtree(obj); |
| 202 } | 207 } |
| 203 | 208 |
| 204 AccessibilityHostMsg_EventParams event_msg; | 209 AccessibilityHostMsg_EventParams event_msg; |
| 205 event_msg.event_type = event.event_type; | 210 event_msg.event_type = event.event_type; |
| 206 event_msg.id = event.id; | 211 event_msg.id = event.id; |
| 207 serializer_.SerializeChanges(obj, &event_msg.update); | 212 serializer_.SerializeChanges(obj, &event_msg.update); |
| 208 event_msgs.push_back(event_msg); | 213 event_msgs.push_back(event_msg); |
| 209 | 214 |
| 215 // For each node in the update, set the location in our map from |
| 216 // ids to locations. |
| 217 for (size_t i = 0; i < event_msg.update.nodes.size(); ++i) { |
| 218 locations_[event_msg.update.nodes[i].id] = |
| 219 event_msg.update.nodes[i].location; |
| 220 } |
| 221 |
| 210 VLOG(0) << "Accessibility event: " << ui::ToString(event.event_type) | 222 VLOG(0) << "Accessibility event: " << ui::ToString(event.event_type) |
| 211 << " on node id " << event_msg.id | 223 << " on node id " << event_msg.id |
| 212 << "\n" << event_msg.update.ToString(); | 224 << "\n" << event_msg.update.ToString(); |
| 213 } | 225 } |
| 214 | 226 |
| 215 Send(new AccessibilityHostMsg_Events(routing_id(), event_msgs)); | 227 Send(new AccessibilityHostMsg_Events(routing_id(), event_msgs)); |
| 216 | 228 |
| 217 SendLocationChanges(); | 229 if (had_layout_complete_messages) |
| 230 SendLocationChanges(); |
| 218 } | 231 } |
| 219 | 232 |
| 220 void RendererAccessibilityComplete::SendLocationChanges() { | 233 void RendererAccessibilityComplete::SendLocationChanges() { |
| 221 std::vector<AccessibilityHostMsg_LocationChangeParams> messages; | 234 std::vector<AccessibilityHostMsg_LocationChangeParams> messages; |
| 222 | 235 |
| 223 // Do a breadth-first explore of the whole blink AX tree. | 236 // Do a breadth-first explore of the whole blink AX tree. |
| 224 base::hash_map<int, gfx::Rect> new_locations; | 237 base::hash_map<int, gfx::Rect> new_locations; |
| 225 std::queue<WebAXObject> objs_to_explore; | 238 std::queue<WebAXObject> objs_to_explore; |
| 226 objs_to_explore.push(tree_source_.GetRoot()); | 239 objs_to_explore.push(tree_source_.GetRoot()); |
| 227 while (objs_to_explore.size()) { | 240 while (objs_to_explore.size()) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 239 gfx::Rect new_location = obj.boundingBoxRect(); | 252 gfx::Rect new_location = obj.boundingBoxRect(); |
| 240 if (iter != locations_.end() && iter->second != new_location) { | 253 if (iter != locations_.end() && iter->second != new_location) { |
| 241 AccessibilityHostMsg_LocationChangeParams message; | 254 AccessibilityHostMsg_LocationChangeParams message; |
| 242 message.id = id; | 255 message.id = id; |
| 243 message.new_location = new_location; | 256 message.new_location = new_location; |
| 244 messages.push_back(message); | 257 messages.push_back(message); |
| 245 } | 258 } |
| 246 | 259 |
| 247 // Save the new location. | 260 // Save the new location. |
| 248 new_locations[id] = new_location; | 261 new_locations[id] = new_location; |
| 262 |
| 263 // Explore children of this object. |
| 264 std::vector<blink::WebAXObject> children; |
| 265 tree_source_.GetChildren(obj, &children); |
| 266 for (size_t i = 0; i < children.size(); ++i) |
| 267 objs_to_explore.push(children[i]); |
| 249 } | 268 } |
| 250 locations_.swap(new_locations); | 269 locations_.swap(new_locations); |
| 251 | 270 |
| 252 Send(new AccessibilityHostMsg_LocationChanges(routing_id(), messages)); | 271 Send(new AccessibilityHostMsg_LocationChanges(routing_id(), messages)); |
| 253 } | 272 } |
| 254 | 273 |
| 255 void RendererAccessibilityComplete::OnDoDefaultAction(int acc_obj_id) { | 274 void RendererAccessibilityComplete::OnDoDefaultAction(int acc_obj_id) { |
| 256 const WebDocument& document = GetMainDocument(); | 275 const WebDocument& document = GetMainDocument(); |
| 257 if (document.isNull()) | 276 if (document.isNull()) |
| 258 return; | 277 return; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 render_view()->GetWebView()->clearFocusedElement(); | 409 render_view()->GetWebView()->clearFocusedElement(); |
| 391 else | 410 else |
| 392 obj.setFocused(true); | 411 obj.setFocused(true); |
| 393 } | 412 } |
| 394 | 413 |
| 395 void RendererAccessibilityComplete::OnFatalError() { | 414 void RendererAccessibilityComplete::OnFatalError() { |
| 396 CHECK(false) << "Invalid accessibility tree."; | 415 CHECK(false) << "Invalid accessibility tree."; |
| 397 } | 416 } |
| 398 | 417 |
| 399 } // namespace content | 418 } // namespace content |
| OLD | NEW |