| 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/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/web/WebAXObject.h" | 23 #include "third_party/WebKit/public/web/WebAXObject.h" |
| 23 #include "third_party/WebKit/public/web/WebDocument.h" | 24 #include "third_party/WebKit/public/web/WebDocument.h" |
| 24 #include "third_party/WebKit/public/web/WebInputElement.h" | 25 #include "third_party/WebKit/public/web/WebInputElement.h" |
| 25 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 26 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 26 #include "third_party/WebKit/public/web/WebSettings.h" | 27 #include "third_party/WebKit/public/web/WebSettings.h" |
| 27 #include "third_party/WebKit/public/web/WebView.h" | 28 #include "third_party/WebKit/public/web/WebView.h" |
| 28 #include "ui/accessibility/ax_node.h" | 29 #include "ui/accessibility/ax_node.h" |
| 29 | 30 |
| 30 using blink::WebAXObject; | 31 using blink::WebAXObject; |
| 31 using blink::WebDocument; | 32 using blink::WebDocument; |
| 32 using blink::WebElement; | 33 using blink::WebElement; |
| 34 using blink::WebFloatRect; |
| 33 using blink::WebLocalFrame; | 35 using blink::WebLocalFrame; |
| 34 using blink::WebNode; | 36 using blink::WebNode; |
| 35 using blink::WebPoint; | 37 using blink::WebPoint; |
| 36 using blink::WebRect; | 38 using blink::WebRect; |
| 37 using blink::WebScopedAXContext; | 39 using blink::WebScopedAXContext; |
| 38 using blink::WebSettings; | 40 using blink::WebSettings; |
| 39 using blink::WebView; | 41 using blink::WebView; |
| 40 | 42 |
| 41 namespace content { | 43 namespace content { |
| 42 | 44 |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 } | 332 } |
| 331 | 333 |
| 332 if (pdf_tree_source_) | 334 if (pdf_tree_source_) |
| 333 AddPdfTreeToUpdate(&event_msg.update); | 335 AddPdfTreeToUpdate(&event_msg.update); |
| 334 | 336 |
| 335 event_msgs.push_back(event_msg); | 337 event_msgs.push_back(event_msg); |
| 336 | 338 |
| 337 // For each node in the update, set the location in our map from | 339 // For each node in the update, set the location in our map from |
| 338 // ids to locations. | 340 // ids to locations. |
| 339 for (size_t i = 0; i < event_msg.update.nodes.size(); ++i) { | 341 for (size_t i = 0; i < event_msg.update.nodes.size(); ++i) { |
| 340 locations_[event_msg.update.nodes[i].id] = | 342 ui::AXNodeData& src = event_msg.update.nodes[i]; |
| 341 event_msg.update.nodes[i].location; | 343 ui::AXRelativeBounds& dst = locations_[event_msg.update.nodes[i].id]; |
| 344 dst.offset_container_id = src.offset_container_id; |
| 345 dst.bounds = src.location; |
| 346 dst.transform.reset(nullptr); |
| 347 if (src.transform) |
| 348 dst.transform.reset(new gfx::Transform(*src.transform)); |
| 342 } | 349 } |
| 343 | 350 |
| 344 DVLOG(0) << "Accessibility event: " << ui::ToString(event.event_type) | 351 DVLOG(0) << "Accessibility event: " << ui::ToString(event.event_type) |
| 345 << " on node id " << event_msg.id | 352 << " on node id " << event_msg.id |
| 346 << "\n" << event_msg.update.ToString(); | 353 << "\n" << event_msg.update.ToString(); |
| 347 } | 354 } |
| 348 | 355 |
| 349 Send(new AccessibilityHostMsg_Events(routing_id(), event_msgs, reset_token_)); | 356 Send(new AccessibilityHostMsg_Events(routing_id(), event_msgs, reset_token_)); |
| 350 reset_token_ = 0; | 357 reset_token_ = 0; |
| 351 | 358 |
| 352 if (had_layout_complete_messages) | 359 if (had_layout_complete_messages) |
| 353 SendLocationChanges(); | 360 SendLocationChanges(); |
| 354 } | 361 } |
| 355 | 362 |
| 356 void RenderAccessibilityImpl::SendLocationChanges() { | 363 void RenderAccessibilityImpl::SendLocationChanges() { |
| 357 std::vector<AccessibilityHostMsg_LocationChangeParams> messages; | 364 std::vector<AccessibilityHostMsg_LocationChangeParams> messages; |
| 358 | 365 |
| 359 // Update layout on the root of the tree. | 366 // Update layout on the root of the tree. |
| 360 WebAXObject root = tree_source_.GetRoot(); | 367 WebAXObject root = tree_source_.GetRoot(); |
| 361 if (!root.updateLayoutAndCheckValidity()) | 368 if (!root.updateLayoutAndCheckValidity()) |
| 362 return; | 369 return; |
| 363 | 370 |
| 364 // Do a breadth-first explore of the whole blink AX tree. | 371 // Do a breadth-first explore of the whole blink AX tree. |
| 365 base::hash_map<int, gfx::RectF> new_locations; | 372 base::hash_map<int, ui::AXRelativeBounds> new_locations; |
| 366 std::queue<WebAXObject> objs_to_explore; | 373 std::queue<WebAXObject> objs_to_explore; |
| 367 objs_to_explore.push(root); | 374 objs_to_explore.push(root); |
| 368 while (objs_to_explore.size()) { | 375 while (objs_to_explore.size()) { |
| 369 WebAXObject obj = objs_to_explore.front(); | 376 WebAXObject obj = objs_to_explore.front(); |
| 370 objs_to_explore.pop(); | 377 objs_to_explore.pop(); |
| 371 | 378 |
| 372 // See if we had a previous location. If not, this whole subtree must | 379 // See if we had a previous location. If not, this whole subtree must |
| 373 // be new, so don't continue to explore this branch. | 380 // be new, so don't continue to explore this branch. |
| 374 int id = obj.axID(); | 381 int id = obj.axID(); |
| 375 base::hash_map<int, gfx::RectF>::iterator iter = locations_.find(id); | 382 auto iter = locations_.find(id); |
| 376 if (iter == locations_.end()) | 383 if (iter == locations_.end()) |
| 377 continue; | 384 continue; |
| 378 | 385 |
| 379 // If the location has changed, append it to the IPC message. | 386 // If the location has changed, append it to the IPC message. |
| 380 gfx::RectF new_location = gfx::RectF(obj.boundingBoxRect()); | 387 WebAXObject offset_container; |
| 388 WebFloatRect bounds_in_container; |
| 389 SkMatrix44 container_transform; |
| 390 obj.getRelativeBounds( |
| 391 offset_container, bounds_in_container, container_transform); |
| 392 ui::AXRelativeBounds new_location; |
| 393 new_location.offset_container_id = offset_container.axID(); |
| 394 new_location.bounds = bounds_in_container; |
| 395 if (!container_transform.isIdentity()) |
| 396 new_location.transform = base::WrapUnique( |
| 397 new gfx::Transform(container_transform)); |
| 381 if (iter != locations_.end() && iter->second != new_location) { | 398 if (iter != locations_.end() && iter->second != new_location) { |
| 382 AccessibilityHostMsg_LocationChangeParams message; | 399 AccessibilityHostMsg_LocationChangeParams message; |
| 383 message.id = id; | 400 message.id = id; |
| 384 message.new_location = new_location; | 401 message.new_location = new_location; |
| 385 messages.push_back(message); | 402 messages.push_back(message); |
| 386 } | 403 } |
| 387 | 404 |
| 388 // Save the new location. | 405 // Save the new location. |
| 389 new_locations[id] = new_location; | 406 new_locations[id] = new_location; |
| 390 | 407 |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 size_t new_count = pdf_update.nodes.size(); | 689 size_t new_count = pdf_update.nodes.size(); |
| 673 update->nodes.resize(old_count + new_count); | 690 update->nodes.resize(old_count + new_count); |
| 674 for (size_t i = 0; i < new_count; ++i) | 691 for (size_t i = 0; i < new_count; ++i) |
| 675 update->nodes[old_count + i] = pdf_update.nodes[i]; | 692 update->nodes[old_count + i] = pdf_update.nodes[i]; |
| 676 break; | 693 break; |
| 677 } | 694 } |
| 678 } | 695 } |
| 679 } | 696 } |
| 680 | 697 |
| 681 } // namespace content | 698 } // namespace content |
| OLD | NEW |