| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 v8::Integer::New(isolate, rect.y())); | 78 v8::Integer::New(isolate, rect.y())); |
| 79 result->Set(CreateV8String(isolate, "width"), | 79 result->Set(CreateV8String(isolate, "width"), |
| 80 v8::Integer::New(isolate, rect.width())); | 80 v8::Integer::New(isolate, rect.width())); |
| 81 result->Set(CreateV8String(isolate, "height"), | 81 result->Set(CreateV8String(isolate, "height"), |
| 82 v8::Integer::New(isolate, rect.height())); | 82 v8::Integer::New(isolate, rect.height())); |
| 83 return result; | 83 return result; |
| 84 } | 84 } |
| 85 | 85 |
| 86 // Compute the bounding box of a node, fixing nodes with empty bounds by | 86 // Compute the bounding box of a node, fixing nodes with empty bounds by |
| 87 // unioning the bounds of their children. | 87 // unioning the bounds of their children. |
| 88 static gfx::Rect ComputeLocalNodeBounds(TreeCache* cache, ui::AXNode* node) { | 88 static gfx::RectF ComputeLocalNodeBounds(TreeCache* cache, ui::AXNode* node) { |
| 89 gfx::Rect bounds = gfx::ToEnclosingRect(node->data().location); | 89 gfx::RectF bounds = node->data().location; |
| 90 if (bounds.width() > 0 && bounds.height() > 0) | 90 if (bounds.width() > 0 && bounds.height() > 0) |
| 91 return bounds; | 91 return bounds; |
| 92 | 92 |
| 93 // Compute the bounds of each child. | 93 // Compute the bounds of each child. |
| 94 for (size_t i = 0; i < node->children().size(); i++) { | 94 for (size_t i = 0; i < node->children().size(); i++) { |
| 95 ui::AXNode* child = node->children()[i]; | 95 ui::AXNode* child = node->children()[i]; |
| 96 gfx::Rect child_bounds = ComputeLocalNodeBounds(cache, child); | 96 gfx::RectF child_bounds = ComputeLocalNodeBounds(cache, child); |
| 97 | 97 |
| 98 // Ignore children that don't have valid bounds themselves. | 98 // Ignore children that don't have valid bounds themselves. |
| 99 if (child_bounds.width() == 0 || child_bounds.height() == 0) | 99 if (child_bounds.width() == 0 || child_bounds.height() == 0) |
| 100 continue; | 100 continue; |
| 101 | 101 |
| 102 // For the first valid child, just set the bounds to that child's bounds. | 102 // For the first valid child, just set the bounds to that child's bounds. |
| 103 if (bounds.width() == 0 || bounds.height() == 0) { | 103 if (bounds.width() == 0 || bounds.height() == 0) { |
| 104 bounds = child_bounds; | 104 bounds = child_bounds; |
| 105 continue; | 105 continue; |
| 106 } | 106 } |
| 107 | 107 |
| 108 // Union each additional child's bounds. | 108 // Union each additional child's bounds. |
| 109 bounds.Union(child_bounds); | 109 bounds.Union(child_bounds); |
| 110 } | 110 } |
| 111 | 111 |
| 112 return bounds; | 112 return bounds; |
| 113 } | 113 } |
| 114 | 114 |
| 115 // Compute the bounding box of a node in global coordinates, walking up the | 115 // Compute the bounding box of a node in global coordinates, walking up the |
| 116 // parent hierarchy to offset by frame offsets and scroll offsets. | 116 // parent hierarchy to offset by frame offsets and scroll offsets. |
| 117 static gfx::Rect ComputeGlobalNodeBounds(TreeCache* cache, ui::AXNode* node) { | 117 static gfx::Rect ComputeGlobalNodeBounds(TreeCache* cache, ui::AXNode* node) { |
| 118 gfx::Rect bounds = ComputeLocalNodeBounds(cache, node); | 118 gfx::RectF bounds = ComputeLocalNodeBounds(cache, node); |
| 119 | 119 |
| 120 ui::AXNode* root = cache->tree.root(); | 120 while (node) { |
| 121 while (root) { | 121 if (node->data().transform) |
| 122 // Apply scroll offsets. | 122 node->data().transform->TransformRect(&bounds); |
| 123 if (root != node) { | 123 |
| 124 int sx = 0; | 124 ui::AXNode* container = |
| 125 int sy = 0; | 125 cache->tree.GetFromId(node->data().offset_container_id); |
| 126 if (root->data().GetIntAttribute(ui::AX_ATTR_SCROLL_X, &sx) && | 126 if (!container) { |
| 127 root->data().GetIntAttribute(ui::AX_ATTR_SCROLL_Y, &sy)) { | 127 if (node == cache->tree.root()) { |
| 128 bounds.Offset(-sx, -sy); | 128 container = cache->owner->GetParent(node, &cache); |
| 129 } else { |
| 130 container = cache->tree.root(); |
| 129 } | 131 } |
| 130 } | 132 } |
| 131 | 133 |
| 132 if (root->data().transform) { | 134 if (!container || container == node) |
| 133 gfx::RectF boundsf(bounds); | 135 break; |
| 134 root->data().transform->TransformRect(&boundsf); | 136 |
| 135 bounds = gfx::Rect(boundsf.x(), boundsf.y(), boundsf.width(), | 137 gfx::RectF container_bounds = ComputeLocalNodeBounds(cache, container); |
| 136 boundsf.height()); | 138 bounds.Offset(container_bounds.x(), container_bounds.y()); |
| 139 |
| 140 int scroll_x = 0; |
| 141 int scroll_y = 0; |
| 142 if (container->data().GetIntAttribute(ui::AX_ATTR_SCROLL_X, &scroll_x) && |
| 143 container->data().GetIntAttribute(ui::AX_ATTR_SCROLL_Y, &scroll_y)) { |
| 144 bounds.Offset(-scroll_x, -scroll_y); |
| 137 } | 145 } |
| 138 | 146 |
| 139 ui::AXNode* parent = cache->owner->GetParent(root, &cache); | 147 node = container; |
| 140 if (!parent) | |
| 141 break; | |
| 142 | |
| 143 root = cache->tree.root(); | |
| 144 } | 148 } |
| 145 | 149 |
| 146 return bounds; | 150 return gfx::ToEnclosingRect(bounds); |
| 147 } | 151 } |
| 148 | 152 |
| 149 ui::AXNode* FindNodeWithChildTreeId(ui::AXNode* node, int child_tree_id) { | 153 ui::AXNode* FindNodeWithChildTreeId(ui::AXNode* node, int child_tree_id) { |
| 150 if (child_tree_id == node->data().GetIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)) | 154 if (child_tree_id == node->data().GetIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)) |
| 151 return node; | 155 return node; |
| 152 | 156 |
| 153 for (int i = 0; i < node->child_count(); ++i) { | 157 for (int i = 0; i < node->child_count(); ++i) { |
| 154 ui::AXNode* result = | 158 ui::AXNode* result = |
| 155 FindNodeWithChildTreeId(node->ChildAtIndex(i), child_tree_id); | 159 FindNodeWithChildTreeId(node->ChildAtIndex(i), child_tree_id); |
| 156 if (result) | 160 if (result) |
| (...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1288 v8::Local<v8::Array> args(v8::Array::New(GetIsolate(), 2U)); | 1292 v8::Local<v8::Array> args(v8::Array::New(GetIsolate(), 2U)); |
| 1289 args->Set(0U, v8::Integer::New(GetIsolate(), tree_id)); | 1293 args->Set(0U, v8::Integer::New(GetIsolate(), tree_id)); |
| 1290 v8::Local<v8::Array> nodes(v8::Array::New(GetIsolate(), ids.size())); | 1294 v8::Local<v8::Array> nodes(v8::Array::New(GetIsolate(), ids.size())); |
| 1291 args->Set(1U, nodes); | 1295 args->Set(1U, nodes); |
| 1292 for (size_t i = 0; i < ids.size(); ++i) | 1296 for (size_t i = 0; i < ids.size(); ++i) |
| 1293 nodes->Set(i, v8::Integer::New(GetIsolate(), ids[i])); | 1297 nodes->Set(i, v8::Integer::New(GetIsolate(), ids[i])); |
| 1294 context()->DispatchEvent("automationInternal.onNodesRemoved", args); | 1298 context()->DispatchEvent("automationInternal.onNodesRemoved", args); |
| 1295 } | 1299 } |
| 1296 | 1300 |
| 1297 } // namespace extensions | 1301 } // namespace extensions |
| OLD | NEW |