OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/accessibility/browser_accessibility.h" | 5 #include "content/browser/accessibility/browser_accessibility.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "content/browser/accessibility/browser_accessibility_manager.h" | 15 #include "content/browser/accessibility/browser_accessibility_manager.h" |
16 #include "content/common/accessibility_messages.h" | 16 #include "content/common/accessibility_messages.h" |
17 #include "ui/accessibility/ax_text_utils.h" | 17 #include "ui/accessibility/ax_text_utils.h" |
18 #include "ui/accessibility/platform/ax_platform_node.h" | 18 #include "ui/accessibility/platform/ax_platform_node.h" |
| 19 #include "ui/gfx/geometry/rect_f.h" |
19 | 20 |
20 namespace content { | 21 namespace content { |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 // Map from unique_id to BrowserAccessibility | 25 // Map from unique_id to BrowserAccessibility |
25 using UniqueIDMap = base::hash_map<int32_t, BrowserAccessibility*>; | 26 using UniqueIDMap = base::hash_map<int32_t, BrowserAccessibility*>; |
26 base::LazyInstance<UniqueIDMap> g_unique_id_map = LAZY_INSTANCE_INITIALIZER; | 27 base::LazyInstance<UniqueIDMap> g_unique_id_map = LAZY_INSTANCE_INITIALIZER; |
27 | 28 |
28 } | 29 } |
(...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1005 continue; | 1006 continue; |
1006 } | 1007 } |
1007 | 1008 |
1008 // Union each additional child's bounds. | 1009 // Union each additional child's bounds. |
1009 bounds->Union(child_bounds); | 1010 bounds->Union(child_bounds); |
1010 } | 1011 } |
1011 } | 1012 } |
1012 | 1013 |
1013 gfx::Rect BrowserAccessibility::ElementBoundsToLocalBounds(gfx::Rect bounds) | 1014 gfx::Rect BrowserAccessibility::ElementBoundsToLocalBounds(gfx::Rect bounds) |
1014 const { | 1015 const { |
1015 // Walk up the parent chain. Every time we encounter a Web Area, offset | 1016 BrowserAccessibilityManager* manager = this->manager(); |
1016 // based on the scroll bars and then offset based on the origin of that | 1017 BrowserAccessibility* root = manager->GetRoot(); |
1017 // nested web area. | 1018 while (manager && root) { |
1018 BrowserAccessibility* parent = GetParent(); | 1019 // Apply scroll offsets. |
1019 bool need_to_offset_web_area = | 1020 if (root != this && (root->GetParent() || |
1020 (GetRole() == ui::AX_ROLE_WEB_AREA || | 1021 manager->UseRootScrollOffsetsWhenComputingBounds())) { |
1021 GetRole() == ui::AX_ROLE_ROOT_WEB_AREA); | 1022 int sx = 0; |
1022 while (parent) { | 1023 int sy = 0; |
1023 if (need_to_offset_web_area && | 1024 if (root->GetIntAttribute(ui::AX_ATTR_SCROLL_X, &sx) && |
1024 parent->GetLocation().width() > 0 && | 1025 root->GetIntAttribute(ui::AX_ATTR_SCROLL_Y, &sy)) { |
1025 parent->GetLocation().height() > 0) { | 1026 bounds.Offset(-sx, -sy); |
1026 bounds.Offset(parent->GetLocation().x(), parent->GetLocation().y()); | 1027 } |
1027 need_to_offset_web_area = false; | |
1028 } | 1028 } |
1029 | 1029 |
1030 // On some platforms, we don't want to take the root scroll offsets | 1030 // If the parent accessibility tree is in a different site instance, |
1031 // into account. | 1031 // ask the delegate to transform our coordinates into the root |
1032 if (parent->GetRole() == ui::AX_ROLE_ROOT_WEB_AREA && | 1032 // coordinate space and then we're done. |
1033 !manager()->UseRootScrollOffsetsWhenComputingBounds()) { | 1033 if (manager->delegate() && |
1034 break; | 1034 root->GetParent() && |
| 1035 root->GetParent()->manager()->delegate()) { |
| 1036 BrowserAccessibilityManager* parent_manager = |
| 1037 root->GetParent()->manager(); |
| 1038 if (manager->delegate()->AccessibilityGetSiteInstance() != |
| 1039 parent_manager->delegate()->AccessibilityGetSiteInstance()) { |
| 1040 return manager->delegate()->AccessibilityTransformToRootCoordSpace( |
| 1041 bounds); |
| 1042 } |
1035 } | 1043 } |
1036 | 1044 |
1037 if (parent->GetRole() == ui::AX_ROLE_WEB_AREA || | 1045 // Otherwise, apply the transform from this frame into the coordinate |
1038 parent->GetRole() == ui::AX_ROLE_ROOT_WEB_AREA) { | 1046 // space of its parent frame. |
1039 int sx = 0; | 1047 if (root->GetData().transform) { |
1040 int sy = 0; | 1048 gfx::RectF boundsf(bounds); |
1041 if (parent->GetIntAttribute(ui::AX_ATTR_SCROLL_X, &sx) && | 1049 root->GetData().transform->TransformRect(&boundsf); |
1042 parent->GetIntAttribute(ui::AX_ATTR_SCROLL_Y, &sy)) { | 1050 bounds = gfx::Rect(boundsf.x(), boundsf.y(), |
1043 bounds.Offset(-sx, -sy); | 1051 boundsf.width(), boundsf.height()); |
1044 } | |
1045 need_to_offset_web_area = true; | |
1046 } | 1052 } |
1047 parent = parent->GetParent(); | 1053 |
| 1054 if (!root->GetParent()) |
| 1055 break; |
| 1056 |
| 1057 manager = root->GetParent()->manager(); |
| 1058 root = manager->GetRoot(); |
1048 } | 1059 } |
1049 | 1060 |
1050 return bounds; | 1061 return bounds; |
1051 } | 1062 } |
1052 | 1063 |
1053 } // namespace content | 1064 } // namespace content |
OLD | NEW |