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/gfx/geometry/rect_f.h" | |
18 | 19 |
19 namespace content { | 20 namespace content { |
20 | 21 |
21 #if !defined(PLATFORM_HAS_NATIVE_ACCESSIBILITY_IMPL) | 22 #if !defined(PLATFORM_HAS_NATIVE_ACCESSIBILITY_IMPL) |
22 // static | 23 // static |
23 BrowserAccessibility* BrowserAccessibility::Create() { | 24 BrowserAccessibility* BrowserAccessibility::Create() { |
24 return new BrowserAccessibility(); | 25 return new BrowserAccessibility(); |
25 } | 26 } |
26 #endif | 27 #endif |
27 | 28 |
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
870 continue; | 871 continue; |
871 } | 872 } |
872 | 873 |
873 // Union each additional child's bounds. | 874 // Union each additional child's bounds. |
874 bounds->Union(child_bounds); | 875 bounds->Union(child_bounds); |
875 } | 876 } |
876 } | 877 } |
877 | 878 |
878 gfx::Rect BrowserAccessibility::ElementBoundsToLocalBounds(gfx::Rect bounds) | 879 gfx::Rect BrowserAccessibility::ElementBoundsToLocalBounds(gfx::Rect bounds) |
879 const { | 880 const { |
881 // If this element has a transform, apply it and we're done. | |
aboxhall
2016/02/24 19:38:21
Why is this true in the case where, e.g., the pare
| |
882 if (GetRole() == ui::AX_ROLE_ROOT_WEB_AREA && | |
883 GetParent() && | |
884 GetParent()->manager() != manager() && | |
885 manager()->delegate()) { | |
aboxhall
2016/02/24 18:46:07
When would this be false?
dmazzoni
2016/02/24 18:53:26
Only in unit tests
| |
886 manager()->delegate()->AccessibilityTransformToRootCoordSpace(&bounds); | |
887 return bounds; | |
888 } else if (!GetData().transform.IsIdentity()) { | |
889 gfx::RectF boundsf(bounds); | |
890 GetData().transform.TransformRect(&boundsf); | |
891 return gfx::Rect(boundsf.x(), boundsf.y(), | |
892 boundsf.width(), boundsf.height()); | |
893 } | |
894 | |
880 // Walk up the parent chain. Every time we encounter a Web Area, offset | 895 // Walk up the parent chain. Every time we encounter a Web Area, offset |
881 // based on the scroll bars and then offset based on the origin of that | 896 // based on the scroll bars and then offset based on the origin of that |
882 // nested web area. | 897 // nested web area. |
883 BrowserAccessibility* parent = GetParent(); | 898 BrowserAccessibility* parent = GetParent(); |
884 bool need_to_offset_web_area = | 899 bool need_to_offset_web_area = |
885 (GetRole() == ui::AX_ROLE_WEB_AREA || | 900 (GetRole() == ui::AX_ROLE_WEB_AREA || |
886 GetRole() == ui::AX_ROLE_ROOT_WEB_AREA); | 901 GetRole() == ui::AX_ROLE_ROOT_WEB_AREA); |
887 while (parent) { | 902 while (parent) { |
903 bool parent_is_in_different_tree = parent->manager() != manager(); | |
904 | |
888 if (need_to_offset_web_area && | 905 if (need_to_offset_web_area && |
889 parent->GetLocation().width() > 0 && | 906 parent->GetLocation().width() > 0 && |
890 parent->GetLocation().height() > 0) { | 907 parent->GetLocation().height() > 0 && |
908 parent->GetData().transform.IsIdentity() && | |
909 !parent_is_in_different_tree) { | |
891 bounds.Offset(parent->GetLocation().x(), parent->GetLocation().y()); | 910 bounds.Offset(parent->GetLocation().x(), parent->GetLocation().y()); |
892 need_to_offset_web_area = false; | 911 need_to_offset_web_area = false; |
893 } | 912 } |
894 | 913 |
895 // On some platforms, we don't want to take the root scroll offsets | 914 // On some platforms, we don't want to take the root scroll offsets |
896 // into account. | 915 // into account. |
897 if (parent->GetRole() == ui::AX_ROLE_ROOT_WEB_AREA && | 916 if (parent->GetRole() == ui::AX_ROLE_ROOT_WEB_AREA && |
898 !manager()->UseRootScrollOffsetsWhenComputingBounds()) { | 917 !manager()->UseRootScrollOffsetsWhenComputingBounds()) { |
899 break; | 918 break; |
900 } | 919 } |
901 | 920 |
902 if (parent->GetRole() == ui::AX_ROLE_WEB_AREA || | 921 if (parent->GetRole() == ui::AX_ROLE_WEB_AREA || |
903 parent->GetRole() == ui::AX_ROLE_ROOT_WEB_AREA) { | 922 parent->GetRole() == ui::AX_ROLE_ROOT_WEB_AREA) { |
904 int sx = 0; | 923 int sx = 0; |
905 int sy = 0; | 924 int sy = 0; |
906 if (parent->GetIntAttribute(ui::AX_ATTR_SCROLL_X, &sx) && | 925 if (parent->GetIntAttribute(ui::AX_ATTR_SCROLL_X, &sx) && |
907 parent->GetIntAttribute(ui::AX_ATTR_SCROLL_Y, &sy)) { | 926 parent->GetIntAttribute(ui::AX_ATTR_SCROLL_Y, &sy)) { |
908 bounds.Offset(-sx, -sy); | 927 bounds.Offset(-sx, -sy); |
909 } | 928 } |
910 need_to_offset_web_area = true; | 929 need_to_offset_web_area = true; |
930 | |
931 if (parent_is_in_different_tree && manager()->delegate()) { | |
932 manager()->delegate()->AccessibilityTransformToRootCoordSpace(&bounds); | |
933 break; | |
934 } else if (!parent->GetData().transform.IsIdentity()) { | |
935 gfx::RectF boundsf(bounds); | |
936 parent->GetData().transform.TransformRect(&boundsf); | |
937 bounds = gfx::Rect(boundsf.x(), boundsf.y(), | |
938 boundsf.width(), boundsf.height()); | |
939 need_to_offset_web_area = false; | |
940 } | |
911 } | 941 } |
942 | |
912 parent = parent->GetParent(); | 943 parent = parent->GetParent(); |
913 } | 944 } |
914 | 945 |
915 return bounds; | 946 return bounds; |
916 } | 947 } |
917 | 948 |
918 } // namespace content | 949 } // namespace content |
OLD | NEW |