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 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 continue; | 940 continue; |
940 } | 941 } |
941 | 942 |
942 // Union each additional child's bounds. | 943 // Union each additional child's bounds. |
943 bounds->Union(child_bounds); | 944 bounds->Union(child_bounds); |
944 } | 945 } |
945 } | 946 } |
946 | 947 |
947 gfx::Rect BrowserAccessibility::ElementBoundsToLocalBounds(gfx::Rect bounds) | 948 gfx::Rect BrowserAccessibility::ElementBoundsToLocalBounds(gfx::Rect bounds) |
948 const { | 949 const { |
949 // Walk up the parent chain. Every time we encounter a Web Area, offset | 950 BrowserAccessibilityManager* manager = this->manager(); |
950 // based on the scroll bars and then offset based on the origin of that | 951 BrowserAccessibility* root = manager->GetRoot(); |
951 // nested web area. | 952 while (manager && root && manager->delegate()) { |
952 BrowserAccessibility* parent = GetParent(); | 953 // Apply scroll offsets. |
953 bool need_to_offset_web_area = | 954 if (root != this && (root->GetParent() || |
954 (GetRole() == ui::AX_ROLE_WEB_AREA || | 955 manager->UseRootScrollOffsetsWhenComputingBounds())) { |
955 GetRole() == ui::AX_ROLE_ROOT_WEB_AREA); | 956 int sx = 0; |
956 while (parent) { | 957 int sy = 0; |
957 if (need_to_offset_web_area && | 958 if (root->GetIntAttribute(ui::AX_ATTR_SCROLL_X, &sx) && |
958 parent->GetLocation().width() > 0 && | 959 root->GetIntAttribute(ui::AX_ATTR_SCROLL_Y, &sy)) { |
959 parent->GetLocation().height() > 0) { | 960 bounds.Offset(-sx, -sy); |
960 bounds.Offset(parent->GetLocation().x(), parent->GetLocation().y()); | 961 } |
961 need_to_offset_web_area = false; | |
962 } | 962 } |
963 | 963 |
964 // On some platforms, we don't want to take the root scroll offsets | 964 // If the parent accessibility tree is in a different site instance, |
965 // into account. | 965 // ask the delegate to transform our coordinates into the root |
966 if (parent->GetRole() == ui::AX_ROLE_ROOT_WEB_AREA && | 966 // coordinate space and then we're done. |
967 !manager()->UseRootScrollOffsetsWhenComputingBounds()) { | 967 if (root->GetParent() && root->GetParent()->manager()->delegate()) { |
968 break; | 968 BrowserAccessibilityManager* parent_manager = |
| 969 root->GetParent()->manager(); |
| 970 if (manager->delegate()->AccessibilityGetSiteInstance() != |
| 971 parent_manager->delegate()->AccessibilityGetSiteInstance()) { |
| 972 return manager->delegate()->AccessibilityTransformToRootCoordSpace( |
| 973 bounds); |
| 974 } |
969 } | 975 } |
970 | 976 |
971 if (parent->GetRole() == ui::AX_ROLE_WEB_AREA || | 977 // Otherwise, apply the transform from this frame into the coordinate |
972 parent->GetRole() == ui::AX_ROLE_ROOT_WEB_AREA) { | 978 // space of its parent frame. |
973 int sx = 0; | 979 gfx::RectF boundsf(bounds); |
974 int sy = 0; | 980 root->GetData().transform->TransformRect(&boundsf); |
975 if (parent->GetIntAttribute(ui::AX_ATTR_SCROLL_X, &sx) && | 981 bounds = gfx::Rect(boundsf.x(), boundsf.y(), |
976 parent->GetIntAttribute(ui::AX_ATTR_SCROLL_Y, &sy)) { | 982 boundsf.width(), boundsf.height()); |
977 bounds.Offset(-sx, -sy); | 983 |
978 } | 984 if (!root->GetParent()) |
979 need_to_offset_web_area = true; | 985 break; |
980 } | 986 |
981 parent = parent->GetParent(); | 987 manager = root->GetParent()->manager(); |
| 988 root = manager->GetRoot(); |
982 } | 989 } |
983 | 990 |
984 return bounds; | 991 return bounds; |
985 } | 992 } |
986 | 993 |
987 } // namespace content | 994 } // namespace content |
OLD | NEW |