| 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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/common/extensions/chrome_extension_messages.h" | 16 #include "chrome/common/extensions/chrome_extension_messages.h" |
| 17 #include "chrome/common/extensions/manifest_handlers/automation.h" | 17 #include "chrome/common/extensions/manifest_handlers/automation.h" |
| 18 #include "content/public/renderer/render_frame.h" | 18 #include "content/public/renderer/render_frame.h" |
| 19 #include "content/public/renderer/render_thread.h" | 19 #include "content/public/renderer/render_thread.h" |
| 20 #include "content/public/renderer/render_view.h" | 20 #include "content/public/renderer/render_view.h" |
| 21 #include "extensions/common/extension.h" | 21 #include "extensions/common/extension.h" |
| 22 #include "extensions/common/manifest.h" | 22 #include "extensions/common/manifest.h" |
| 23 #include "extensions/renderer/script_context.h" | 23 #include "extensions/renderer/script_context.h" |
| 24 #include "ipc/message_filter.h" | 24 #include "ipc/message_filter.h" |
| 25 #include "ui/accessibility/ax_enums.h" | 25 #include "ui/accessibility/ax_enums.h" |
| 26 #include "ui/accessibility/ax_node.h" | 26 #include "ui/accessibility/ax_node.h" |
| 27 #include "ui/gfx/geometry/rect_conversions.h" |
| 27 | 28 |
| 28 namespace extensions { | 29 namespace extensions { |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| 32 // Helper to convert an enum to a V8 object. | 33 // Helper to convert an enum to a V8 object. |
| 33 template <typename EnumType> | 34 template <typename EnumType> |
| 34 v8::Local<v8::Object> ToEnumObject(v8::Isolate* isolate, | 35 v8::Local<v8::Object> ToEnumObject(v8::Isolate* isolate, |
| 35 EnumType start_after, | 36 EnumType start_after, |
| 36 EnumType end_at) { | 37 EnumType end_at) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 result->Set(CreateV8String(isolate, "width"), | 79 result->Set(CreateV8String(isolate, "width"), |
| 79 v8::Integer::New(isolate, rect.width())); | 80 v8::Integer::New(isolate, rect.width())); |
| 80 result->Set(CreateV8String(isolate, "height"), | 81 result->Set(CreateV8String(isolate, "height"), |
| 81 v8::Integer::New(isolate, rect.height())); | 82 v8::Integer::New(isolate, rect.height())); |
| 82 return result; | 83 return result; |
| 83 } | 84 } |
| 84 | 85 |
| 85 // 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 |
| 86 // unioning the bounds of their children. | 87 // unioning the bounds of their children. |
| 87 static gfx::Rect ComputeLocalNodeBounds(TreeCache* cache, ui::AXNode* node) { | 88 static gfx::Rect ComputeLocalNodeBounds(TreeCache* cache, ui::AXNode* node) { |
| 88 gfx::Rect bounds = node->data().location; | 89 gfx::Rect bounds = gfx::ToEnclosingRect(node->data().location); |
| 89 if (bounds.width() > 0 && bounds.height() > 0) | 90 if (bounds.width() > 0 && bounds.height() > 0) |
| 90 return bounds; | 91 return bounds; |
| 91 | 92 |
| 92 // Compute the bounds of each child. | 93 // Compute the bounds of each child. |
| 93 for (size_t i = 0; i < node->children().size(); i++) { | 94 for (size_t i = 0; i < node->children().size(); i++) { |
| 94 ui::AXNode* child = node->children()[i]; | 95 ui::AXNode* child = node->children()[i]; |
| 95 gfx::Rect child_bounds = ComputeLocalNodeBounds(cache, child); | 96 gfx::Rect child_bounds = ComputeLocalNodeBounds(cache, child); |
| 96 | 97 |
| 97 // Ignore children that don't have valid bounds themselves. | 98 // Ignore children that don't have valid bounds themselves. |
| 98 if (child_bounds.width() == 0 || child_bounds.height() == 0) | 99 if (child_bounds.width() == 0 || child_bounds.height() == 0) |
| (...skipping 1188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1287 v8::Local<v8::Array> args(v8::Array::New(GetIsolate(), 2U)); | 1288 v8::Local<v8::Array> args(v8::Array::New(GetIsolate(), 2U)); |
| 1288 args->Set(0U, v8::Integer::New(GetIsolate(), tree_id)); | 1289 args->Set(0U, v8::Integer::New(GetIsolate(), tree_id)); |
| 1289 v8::Local<v8::Array> nodes(v8::Array::New(GetIsolate(), ids.size())); | 1290 v8::Local<v8::Array> nodes(v8::Array::New(GetIsolate(), ids.size())); |
| 1290 args->Set(1U, nodes); | 1291 args->Set(1U, nodes); |
| 1291 for (size_t i = 0; i < ids.size(); ++i) | 1292 for (size_t i = 0; i < ids.size(); ++i) |
| 1292 nodes->Set(i, v8::Integer::New(GetIsolate(), ids[i])); | 1293 nodes->Set(i, v8::Integer::New(GetIsolate(), ids[i])); |
| 1293 context()->DispatchEvent("automationInternal.onNodesRemoved", args); | 1294 context()->DispatchEvent("automationInternal.onNodesRemoved", args); |
| 1294 } | 1295 } |
| 1295 | 1296 |
| 1296 } // namespace extensions | 1297 } // namespace extensions |
| OLD | NEW |