Chromium Code Reviews| 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 TreeCache* previous_cache = cache; | |
|
aboxhall
2017/05/26 01:04:59
Where does cache get mutated?
dmazzoni
2017/05/26 06:41:33
Commented.
| |
| 131 ui::AXNode* container = | 132 ui::AXNode* container = |
| 132 cache->tree.GetFromId(node->data().offset_container_id); | 133 cache->tree.GetFromId(node->data().offset_container_id); |
| 133 if (!container) { | 134 if (!container) { |
| 134 if (node == cache->tree.root()) { | 135 if (node == cache->tree.root()) { |
| 135 container = cache->owner->GetParent(node, &cache); | 136 container = cache->owner->GetParent(node, &cache); |
| 136 } else { | 137 } else { |
| 137 container = cache->tree.root(); | 138 container = cache->tree.root(); |
| 138 } | 139 } |
| 139 } | 140 } |
| 140 | 141 |
| 141 if (!container || container == node) | 142 if (!container || container == node) |
| 142 break; | 143 break; |
| 143 | 144 |
| 145 // All trees other than the desktop tree are scaled by the device | |
| 146 // scale factor. When crossing out of another tree into the desktop | |
| 147 // tree, unscale the bounds by the device scale factor. | |
| 148 if (previous_cache->tree_id != api::automation::kDesktopTreeID && | |
| 149 cache->tree_id == api::automation::kDesktopTreeID) { | |
| 150 float scale_factor = cache->owner->GetDeviceScaleFactor(); | |
| 151 if (scale_factor > 0) | |
| 152 bounds.Scale(1.0 / scale_factor); | |
| 153 } | |
| 154 | |
| 144 gfx::RectF container_bounds = container->data().location; | 155 gfx::RectF container_bounds = container->data().location; |
| 145 bounds.Offset(container_bounds.x(), container_bounds.y()); | 156 bounds.Offset(container_bounds.x(), container_bounds.y()); |
| 146 | 157 |
| 147 int scroll_x = 0; | 158 int scroll_x = 0; |
| 148 int scroll_y = 0; | 159 int scroll_y = 0; |
| 149 if (container->data().GetIntAttribute(ui::AX_ATTR_SCROLL_X, &scroll_x) && | 160 if (container->data().GetIntAttribute(ui::AX_ATTR_SCROLL_X, &scroll_x) && |
| 150 container->data().GetIntAttribute(ui::AX_ATTR_SCROLL_Y, &scroll_y)) { | 161 container->data().GetIntAttribute(ui::AX_ATTR_SCROLL_Y, &scroll_y)) { |
| 151 bounds.Offset(-scroll_x, -scroll_y); | 162 bounds.Offset(-scroll_x, -scroll_y); |
| 152 } | 163 } |
| 153 | 164 |
| 154 node = container; | 165 node = container; |
| 155 } | 166 } |
| 156 | 167 |
| 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); | 168 return gfx::ToEnclosingRect(bounds); |
| 169 } | 169 } |
| 170 | 170 |
| 171 ui::AXNode* FindNodeWithChildTreeId(ui::AXNode* node, int child_tree_id) { | 171 ui::AXNode* FindNodeWithChildTreeId(ui::AXNode* node, int child_tree_id) { |
| 172 if (child_tree_id == node->data().GetIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)) | 172 if (child_tree_id == node->data().GetIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)) |
| 173 return node; | 173 return node; |
| 174 | 174 |
| 175 for (int i = 0; i < node->child_count(); ++i) { | 175 for (int i = 0; i < node->child_count(); ++i) { |
| 176 ui::AXNode* result = | 176 ui::AXNode* result = |
| 177 FindNodeWithChildTreeId(node->ChildAtIndex(i), child_tree_id); | 177 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); | 1086 (*in_out_cache)->tree_id); |
| 1087 if (parent) { | 1087 if (parent) { |
| 1088 (*in_out_cache)->parent_node_id_from_parent_tree = parent->id(); | 1088 (*in_out_cache)->parent_node_id_from_parent_tree = parent->id(); |
| 1089 *in_out_cache = parent_cache; | 1089 *in_out_cache = parent_cache; |
| 1090 return parent; | 1090 return parent; |
| 1091 } | 1091 } |
| 1092 | 1092 |
| 1093 return nullptr; | 1093 return nullptr; |
| 1094 } | 1094 } |
| 1095 | 1095 |
| 1096 float AutomationInternalCustomBindings::GetDeviceScaleFactor() const { | |
| 1097 return context()->GetRenderFrame()->GetRenderView()->GetDeviceScaleFactor(); | |
| 1098 } | |
| 1099 | |
| 1096 void AutomationInternalCustomBindings::RouteTreeIDFunction( | 1100 void AutomationInternalCustomBindings::RouteTreeIDFunction( |
| 1097 const std::string& name, | 1101 const std::string& name, |
| 1098 TreeIDFunction callback) { | 1102 TreeIDFunction callback) { |
| 1099 scoped_refptr<TreeIDWrapper> wrapper = new TreeIDWrapper(this, callback); | 1103 scoped_refptr<TreeIDWrapper> wrapper = new TreeIDWrapper(this, callback); |
| 1100 RouteFunction(name, base::Bind(&TreeIDWrapper::Run, wrapper)); | 1104 RouteFunction(name, base::Bind(&TreeIDWrapper::Run, wrapper)); |
| 1101 } | 1105 } |
| 1102 | 1106 |
| 1103 void AutomationInternalCustomBindings::RouteNodeIDFunction( | 1107 void AutomationInternalCustomBindings::RouteNodeIDFunction( |
| 1104 const std::string& name, | 1108 const std::string& name, |
| 1105 NodeIDFunction callback) { | 1109 NodeIDFunction callback) { |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1429 for (auto id : ids) | 1433 for (auto id : ids) |
| 1430 nodes->AppendInteger(id); | 1434 nodes->AppendInteger(id); |
| 1431 args.Append(std::move(nodes)); | 1435 args.Append(std::move(nodes)); |
| 1432 } | 1436 } |
| 1433 | 1437 |
| 1434 bindings_system_->DispatchEventInContext("automationInternal.onNodesRemoved", | 1438 bindings_system_->DispatchEventInContext("automationInternal.onNodesRemoved", |
| 1435 &args, nullptr, context()); | 1439 &args, nullptr, context()); |
| 1436 } | 1440 } |
| 1437 | 1441 |
| 1438 } // namespace extensions | 1442 } // namespace extensions |
| OLD | NEW |