| OLD | NEW |
| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // walking up the parent hierarchy to offset by frame offsets and | 121 // walking up the parent hierarchy to offset by frame offsets and |
| 122 // scroll offsets. | 122 // scroll offsets. |
| 123 static gfx::Rect ComputeGlobalNodeBounds(TreeCache* cache, | 123 static gfx::Rect ComputeGlobalNodeBounds(TreeCache* cache, |
| 124 ui::AXNode* node, | 124 ui::AXNode* node, |
| 125 gfx::RectF local_bounds) { | 125 gfx::RectF local_bounds) { |
| 126 gfx::RectF bounds = local_bounds; | 126 gfx::RectF bounds = local_bounds; |
| 127 while (node) { | 127 while (node) { |
| 128 if (node->data().transform) | 128 if (node->data().transform) |
| 129 node->data().transform->TransformRect(&bounds); | 129 node->data().transform->TransformRect(&bounds); |
| 130 | 130 |
| 131 // Walk up to this node's container. This may cross a tree |
| 132 // boundary, in which case GetParent() modifies |cache|, so we |
| 133 // save the old cache temporarily. |
| 134 TreeCache* previous_cache = cache; |
| 131 ui::AXNode* container = | 135 ui::AXNode* container = |
| 132 cache->tree.GetFromId(node->data().offset_container_id); | 136 cache->tree.GetFromId(node->data().offset_container_id); |
| 133 if (!container) { | 137 if (!container) { |
| 134 if (node == cache->tree.root()) { | 138 if (node == cache->tree.root()) { |
| 135 container = cache->owner->GetParent(node, &cache); | 139 container = cache->owner->GetParent(node, &cache); |
| 136 } else { | 140 } else { |
| 137 container = cache->tree.root(); | 141 container = cache->tree.root(); |
| 138 } | 142 } |
| 139 } | 143 } |
| 140 | 144 |
| 141 if (!container || container == node) | 145 if (!container || container == node) |
| 142 break; | 146 break; |
| 143 | 147 |
| 148 // All trees other than the desktop tree are scaled by the device |
| 149 // scale factor. When crossing out of another tree into the desktop |
| 150 // tree, unscale the bounds by the device scale factor. |
| 151 if (previous_cache->tree_id != api::automation::kDesktopTreeID && |
| 152 cache->tree_id == api::automation::kDesktopTreeID) { |
| 153 float scale_factor = cache->owner->GetDeviceScaleFactor(); |
| 154 if (scale_factor > 0) |
| 155 bounds.Scale(1.0 / scale_factor); |
| 156 } |
| 157 |
| 144 gfx::RectF container_bounds = container->data().location; | 158 gfx::RectF container_bounds = container->data().location; |
| 145 bounds.Offset(container_bounds.x(), container_bounds.y()); | 159 bounds.Offset(container_bounds.x(), container_bounds.y()); |
| 146 | 160 |
| 147 int scroll_x = 0; | 161 int scroll_x = 0; |
| 148 int scroll_y = 0; | 162 int scroll_y = 0; |
| 149 if (container->data().GetIntAttribute(ui::AX_ATTR_SCROLL_X, &scroll_x) && | 163 if (container->data().GetIntAttribute(ui::AX_ATTR_SCROLL_X, &scroll_x) && |
| 150 container->data().GetIntAttribute(ui::AX_ATTR_SCROLL_Y, &scroll_y)) { | 164 container->data().GetIntAttribute(ui::AX_ATTR_SCROLL_Y, &scroll_y)) { |
| 151 bounds.Offset(-scroll_x, -scroll_y); | 165 bounds.Offset(-scroll_x, -scroll_y); |
| 152 } | 166 } |
| 153 | 167 |
| 154 node = container; | 168 node = container; |
| 155 } | 169 } |
| 156 | 170 |
| 157 // All trees other than the desktop tree are scaled by the device | |
| 158 // scale factor. Unscale them so they're all in consistent units. | |
| 159 if (cache->tree_id != api::automation::kDesktopTreeID) { | |
| 160 float scale_factor = cache->owner->context() | |
| 161 ->GetRenderFrame() | |
| 162 ->GetRenderView() | |
| 163 ->GetDeviceScaleFactor(); | |
| 164 if (scale_factor > 0) | |
| 165 bounds.Scale(1.0 / scale_factor); | |
| 166 } | |
| 167 | |
| 168 return gfx::ToEnclosingRect(bounds); | 171 return gfx::ToEnclosingRect(bounds); |
| 169 } | 172 } |
| 170 | 173 |
| 171 ui::AXNode* FindNodeWithChildTreeId(ui::AXNode* node, int child_tree_id) { | 174 ui::AXNode* FindNodeWithChildTreeId(ui::AXNode* node, int child_tree_id) { |
| 172 if (child_tree_id == node->data().GetIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)) | 175 if (child_tree_id == node->data().GetIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)) |
| 173 return node; | 176 return node; |
| 174 | 177 |
| 175 for (int i = 0; i < node->child_count(); ++i) { | 178 for (int i = 0; i < node->child_count(); ++i) { |
| 176 ui::AXNode* result = | 179 ui::AXNode* result = |
| 177 FindNodeWithChildTreeId(node->ChildAtIndex(i), child_tree_id); | 180 FindNodeWithChildTreeId(node->ChildAtIndex(i), child_tree_id); |
| (...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1086 (*in_out_cache)->tree_id); | 1089 (*in_out_cache)->tree_id); |
| 1087 if (parent) { | 1090 if (parent) { |
| 1088 (*in_out_cache)->parent_node_id_from_parent_tree = parent->id(); | 1091 (*in_out_cache)->parent_node_id_from_parent_tree = parent->id(); |
| 1089 *in_out_cache = parent_cache; | 1092 *in_out_cache = parent_cache; |
| 1090 return parent; | 1093 return parent; |
| 1091 } | 1094 } |
| 1092 | 1095 |
| 1093 return nullptr; | 1096 return nullptr; |
| 1094 } | 1097 } |
| 1095 | 1098 |
| 1099 float AutomationInternalCustomBindings::GetDeviceScaleFactor() const { |
| 1100 return context()->GetRenderFrame()->GetRenderView()->GetDeviceScaleFactor(); |
| 1101 } |
| 1102 |
| 1096 void AutomationInternalCustomBindings::RouteTreeIDFunction( | 1103 void AutomationInternalCustomBindings::RouteTreeIDFunction( |
| 1097 const std::string& name, | 1104 const std::string& name, |
| 1098 TreeIDFunction callback) { | 1105 TreeIDFunction callback) { |
| 1099 scoped_refptr<TreeIDWrapper> wrapper = new TreeIDWrapper(this, callback); | 1106 scoped_refptr<TreeIDWrapper> wrapper = new TreeIDWrapper(this, callback); |
| 1100 RouteFunction(name, base::Bind(&TreeIDWrapper::Run, wrapper)); | 1107 RouteFunction(name, base::Bind(&TreeIDWrapper::Run, wrapper)); |
| 1101 } | 1108 } |
| 1102 | 1109 |
| 1103 void AutomationInternalCustomBindings::RouteNodeIDFunction( | 1110 void AutomationInternalCustomBindings::RouteNodeIDFunction( |
| 1104 const std::string& name, | 1111 const std::string& name, |
| 1105 NodeIDFunction callback) { | 1112 NodeIDFunction callback) { |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1429 for (auto id : ids) | 1436 for (auto id : ids) |
| 1430 nodes->AppendInteger(id); | 1437 nodes->AppendInteger(id); |
| 1431 args.Append(std::move(nodes)); | 1438 args.Append(std::move(nodes)); |
| 1432 } | 1439 } |
| 1433 | 1440 |
| 1434 bindings_system_->DispatchEventInContext("automationInternal.onNodesRemoved", | 1441 bindings_system_->DispatchEventInContext("automationInternal.onNodesRemoved", |
| 1435 &args, nullptr, context()); | 1442 &args, nullptr, context()); |
| 1436 } | 1443 } |
| 1437 | 1444 |
| 1438 } // namespace extensions | 1445 } // namespace extensions |
| OLD | NEW |