Index: chrome/renderer/extensions/automation_internal_custom_bindings.cc |
diff --git a/chrome/renderer/extensions/automation_internal_custom_bindings.cc b/chrome/renderer/extensions/automation_internal_custom_bindings.cc |
index 9241f859718a90edfbbbf968647db336ae95b772..89a19c6ad1a9dfdf49704029ccbc007b7d4b76c6 100644 |
--- a/chrome/renderer/extensions/automation_internal_custom_bindings.cc |
+++ b/chrome/renderer/extensions/automation_internal_custom_bindings.cc |
@@ -128,6 +128,10 @@ static gfx::Rect ComputeGlobalNodeBounds(TreeCache* cache, |
if (node->data().transform) |
node->data().transform->TransformRect(&bounds); |
+ // Walk up to this node's container. This may cross a tree |
+ // boundary, in which case GetParent() modifies |cache|, so we |
+ // save the old cache temporarily. |
+ TreeCache* previous_cache = cache; |
ui::AXNode* container = |
cache->tree.GetFromId(node->data().offset_container_id); |
if (!container) { |
@@ -141,6 +145,16 @@ static gfx::Rect ComputeGlobalNodeBounds(TreeCache* cache, |
if (!container || container == node) |
break; |
+ // All trees other than the desktop tree are scaled by the device |
+ // scale factor. When crossing out of another tree into the desktop |
+ // tree, unscale the bounds by the device scale factor. |
+ if (previous_cache->tree_id != api::automation::kDesktopTreeID && |
+ cache->tree_id == api::automation::kDesktopTreeID) { |
+ float scale_factor = cache->owner->GetDeviceScaleFactor(); |
+ if (scale_factor > 0) |
+ bounds.Scale(1.0 / scale_factor); |
+ } |
+ |
gfx::RectF container_bounds = container->data().location; |
bounds.Offset(container_bounds.x(), container_bounds.y()); |
@@ -154,17 +168,6 @@ static gfx::Rect ComputeGlobalNodeBounds(TreeCache* cache, |
node = container; |
} |
- // All trees other than the desktop tree are scaled by the device |
- // scale factor. Unscale them so they're all in consistent units. |
- if (cache->tree_id != api::automation::kDesktopTreeID) { |
- float scale_factor = cache->owner->context() |
- ->GetRenderFrame() |
- ->GetRenderView() |
- ->GetDeviceScaleFactor(); |
- if (scale_factor > 0) |
- bounds.Scale(1.0 / scale_factor); |
- } |
- |
return gfx::ToEnclosingRect(bounds); |
} |
@@ -1093,6 +1096,10 @@ ui::AXNode* AutomationInternalCustomBindings::GetParent( |
return nullptr; |
} |
+float AutomationInternalCustomBindings::GetDeviceScaleFactor() const { |
+ return context()->GetRenderFrame()->GetRenderView()->GetDeviceScaleFactor(); |
+} |
+ |
void AutomationInternalCustomBindings::RouteTreeIDFunction( |
const std::string& name, |
TreeIDFunction callback) { |