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

Side by Side Diff: chrome/renderer/extensions/automation_internal_custom_bindings.cc

Issue 2867103005: Merge to M59: Revert "Fix computation of Automation API location offsets in WebViews." (Closed)
Patch Set: Created 3 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/renderer/extensions/automation_internal_custom_bindings.h" 5 #include "chrome/renderer/extensions/automation_internal_custom_bindings.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 TreeCache* cache, ui::AXNode* node) { 546 TreeCache* cache, ui::AXNode* node) {
547 std::string role_name = ui::ToString(node->data().role); 547 std::string role_name = ui::ToString(node->data().role);
548 result.Set(v8::String::NewFromUtf8(isolate, role_name.c_str())); 548 result.Set(v8::String::NewFromUtf8(isolate, role_name.c_str()));
549 }); 549 });
550 RouteNodeIDFunction( 550 RouteNodeIDFunction(
551 "GetLocation", [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result, 551 "GetLocation", [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result,
552 TreeCache* cache, ui::AXNode* node) { 552 TreeCache* cache, ui::AXNode* node) {
553 gfx::RectF local_bounds = ComputeLocalNodeBounds(cache, node); 553 gfx::RectF local_bounds = ComputeLocalNodeBounds(cache, node);
554 gfx::Rect global_bounds = 554 gfx::Rect global_bounds =
555 ComputeGlobalNodeBounds(cache, node, local_bounds); 555 ComputeGlobalNodeBounds(cache, node, local_bounds);
556 global_bounds.Offset(cache->location_offset);
556 result.Set(RectToV8Object(isolate, global_bounds)); 557 result.Set(RectToV8Object(isolate, global_bounds));
557 }); 558 });
558 RouteNodeIDFunction( 559 RouteNodeIDFunction(
559 "GetLineStartOffsets", 560 "GetLineStartOffsets",
560 [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result, 561 [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result,
561 TreeCache* cache, ui::AXNode* node) { 562 TreeCache* cache, ui::AXNode* node) {
562 const std::vector<int> line_starts = 563 const std::vector<int> line_starts =
563 node->GetOrComputeLineStartOffsets(); 564 node->GetOrComputeLineStartOffsets();
564 v8::Local<v8::Array> array_result( 565 v8::Local<v8::Array> array_result(
565 v8::Array::New(isolate, line_starts.size())); 566 v8::Array::New(isolate, line_starts.size()));
(...skipping 19 matching lines...) Expand all
585 // and return a property of the node. 586 // and return a property of the node.
586 587
587 RouteNodeIDPlusRangeFunction( 588 RouteNodeIDPlusRangeFunction(
588 "GetBoundsForRange", 589 "GetBoundsForRange",
589 [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result, 590 [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result,
590 TreeCache* cache, ui::AXNode* node, int start, int end) { 591 TreeCache* cache, ui::AXNode* node, int start, int end) {
591 gfx::RectF local_bounds = ComputeLocalNodeBounds(cache, node); 592 gfx::RectF local_bounds = ComputeLocalNodeBounds(cache, node);
592 if (node->data().role != ui::AX_ROLE_INLINE_TEXT_BOX) { 593 if (node->data().role != ui::AX_ROLE_INLINE_TEXT_BOX) {
593 gfx::Rect global_bounds = 594 gfx::Rect global_bounds =
594 ComputeGlobalNodeBounds(cache, node, local_bounds); 595 ComputeGlobalNodeBounds(cache, node, local_bounds);
596 global_bounds.Offset(cache->location_offset);
595 result.Set(RectToV8Object(isolate, global_bounds)); 597 result.Set(RectToV8Object(isolate, global_bounds));
596 } 598 }
597 599
598 // Use character offsets to compute the local bounds of this subrange. 600 // Use character offsets to compute the local bounds of this subrange.
599 std::string name = node->data().GetStringAttribute(ui::AX_ATTR_NAME); 601 std::string name = node->data().GetStringAttribute(ui::AX_ATTR_NAME);
600 std::vector<int> character_offsets = 602 std::vector<int> character_offsets =
601 node->data().GetIntListAttribute(ui::AX_ATTR_CHARACTER_OFFSETS); 603 node->data().GetIntListAttribute(ui::AX_ATTR_CHARACTER_OFFSETS);
602 int len = 604 int len =
603 static_cast<int>(std::min(name.size(), character_offsets.size())); 605 static_cast<int>(std::min(name.size(), character_offsets.size()));
604 if (start >= 0 && start <= end && end <= len) { 606 if (start >= 0 && start <= end && end <= len) {
(...skipping 21 matching lines...) Expand all
626 local_bounds.set_height(end_offset - start_offset); 628 local_bounds.set_height(end_offset - start_offset);
627 break; 629 break;
628 } 630 }
629 } 631 }
630 632
631 // Convert from local to global coordinates second, after subsetting, 633 // Convert from local to global coordinates second, after subsetting,
632 // because the local to global conversion might involve matrix 634 // because the local to global conversion might involve matrix
633 // transformations. 635 // transformations.
634 gfx::Rect global_bounds = 636 gfx::Rect global_bounds =
635 ComputeGlobalNodeBounds(cache, node, local_bounds); 637 ComputeGlobalNodeBounds(cache, node, local_bounds);
638 global_bounds.Offset(cache->location_offset);
636 result.Set(RectToV8Object(isolate, global_bounds)); 639 result.Set(RectToV8Object(isolate, global_bounds));
637 }); 640 });
638 641
639 // Bindings that take a Tree ID and Node ID and string attribute name 642 // Bindings that take a Tree ID and Node ID and string attribute name
640 // and return a property of the node. 643 // and return a property of the node.
641 644
642 RouteNodeIDPlusAttributeFunction( 645 RouteNodeIDPlusAttributeFunction(
643 "GetStringAttribute", 646 "GetStringAttribute",
644 [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result, 647 [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result,
645 ui::AXNode* node, const std::string& attribute_name) { 648 ui::AXNode* node, const std::string& attribute_name) {
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 tree_change_observer_overall_filter_ |= 1 << observer.filter; 1025 tree_change_observer_overall_filter_ |= 1 << observer.filter;
1023 } 1026 }
1024 1027
1025 ui::AXNode* AutomationInternalCustomBindings::GetParent( 1028 ui::AXNode* AutomationInternalCustomBindings::GetParent(
1026 ui::AXNode* node, 1029 ui::AXNode* node,
1027 TreeCache** in_out_cache) { 1030 TreeCache** in_out_cache) {
1028 if (node->parent()) 1031 if (node->parent())
1029 return node->parent(); 1032 return node->parent();
1030 1033
1031 int parent_tree_id = (*in_out_cache)->tree.data().parent_tree_id; 1034 int parent_tree_id = (*in_out_cache)->tree.data().parent_tree_id;
1032
1033 // Try the desktop tree if the parent is unknown. If this tree really is
1034 // a child of the desktop tree, we'll find its parent, and if not, the
1035 // search, below, will fail until the real parent tree loads.
1036 if (parent_tree_id < 0) 1035 if (parent_tree_id < 0)
1037 parent_tree_id = api::automation::kDesktopTreeID; 1036 return nullptr;
1038 1037
1039 TreeCache* parent_cache = GetTreeCacheFromTreeID(parent_tree_id); 1038 TreeCache* parent_cache = GetTreeCacheFromTreeID(parent_tree_id);
1040 if (!parent_cache) 1039 if (!parent_cache)
1041 return nullptr; 1040 return nullptr;
1042 1041
1043 // Try to use the cached parent node from the most recent time this 1042 // Try to use the cached parent node from the most recent time this
1044 // was called. 1043 // was called.
1045 if ((*in_out_cache)->parent_node_id_from_parent_tree > 0) { 1044 if (parent_cache->parent_node_id_from_parent_tree > 0) {
1046 ui::AXNode* parent = parent_cache->tree.GetFromId( 1045 ui::AXNode* parent = parent_cache->tree.GetFromId(
1047 (*in_out_cache)->parent_node_id_from_parent_tree); 1046 parent_cache->parent_node_id_from_parent_tree);
1048 if (parent) { 1047 if (parent) {
1049 int parent_child_tree_id = 1048 int parent_child_tree_id =
1050 parent->data().GetIntAttribute(ui::AX_ATTR_CHILD_TREE_ID); 1049 parent->data().GetIntAttribute(ui::AX_ATTR_CHILD_TREE_ID);
1051 if (parent_child_tree_id == (*in_out_cache)->tree_id) { 1050 if (parent_child_tree_id == (*in_out_cache)->tree_id) {
1052 *in_out_cache = parent_cache; 1051 *in_out_cache = parent_cache;
1053 return parent; 1052 return parent;
1054 } 1053 }
1055 } 1054 }
1056 } 1055 }
1057 1056
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 cache->parent_node_id_from_parent_tree = -1; 1144 cache->parent_node_id_from_parent_tree = -1;
1146 cache->tree.SetDelegate(this); 1145 cache->tree.SetDelegate(this);
1147 cache->owner = this; 1146 cache->owner = this;
1148 tree_id_to_tree_cache_map_.insert(std::make_pair(tree_id, cache)); 1147 tree_id_to_tree_cache_map_.insert(std::make_pair(tree_id, cache));
1149 axtree_to_tree_cache_map_.insert(std::make_pair(&cache->tree, cache)); 1148 axtree_to_tree_cache_map_.insert(std::make_pair(&cache->tree, cache));
1150 } else { 1149 } else {
1151 cache = iter->second; 1150 cache = iter->second;
1152 } 1151 }
1153 1152
1154 // Update the internal state whether it's the active profile or not. 1153 // Update the internal state whether it's the active profile or not.
1154 cache->location_offset = params.location_offset;
1155 deleted_node_ids_.clear(); 1155 deleted_node_ids_.clear();
1156 if (!cache->tree.Unserialize(params.update)) { 1156 if (!cache->tree.Unserialize(params.update)) {
1157 LOG(ERROR) << cache->tree.error(); 1157 LOG(ERROR) << cache->tree.error();
1158 base::ListValue args; 1158 base::ListValue args;
1159 args.AppendInteger(tree_id); 1159 args.AppendInteger(tree_id);
1160 bindings_system_->DispatchEventInContext( 1160 bindings_system_->DispatchEventInContext(
1161 "automationInternal.onAccessibilityTreeSerializationError", &args, 1161 "automationInternal.onAccessibilityTreeSerializationError", &args,
1162 nullptr, context()); 1162 nullptr, context());
1163 return; 1163 return;
1164 } 1164 }
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 for (auto id : ids) 1403 for (auto id : ids)
1404 nodes->AppendInteger(id); 1404 nodes->AppendInteger(id);
1405 args.Append(std::move(nodes)); 1405 args.Append(std::move(nodes));
1406 } 1406 }
1407 1407
1408 bindings_system_->DispatchEventInContext("automationInternal.onNodesRemoved", 1408 bindings_system_->DispatchEventInContext("automationInternal.onNodesRemoved",
1409 &args, nullptr, context()); 1409 &args, nullptr, context());
1410 } 1410 }
1411 1411
1412 } // namespace extensions 1412 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698