Chromium Code Reviews| 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 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 default: | 92 default: |
| 93 return false; | 93 return false; |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 uint32_t BrowserAccessibility::PlatformChildCount() const { | 97 uint32_t BrowserAccessibility::PlatformChildCount() const { |
| 98 if (HasIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)) { | 98 if (HasIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)) { |
| 99 BrowserAccessibilityManager* child_manager = | 99 BrowserAccessibilityManager* child_manager = |
| 100 BrowserAccessibilityManager::FromID( | 100 BrowserAccessibilityManager::FromID( |
| 101 GetIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)); | 101 GetIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)); |
| 102 if (child_manager && child_manager->GetRoot()->GetParent() == this) | 102 if (child_manager && |
| 103 child_manager->GetRoot()->GetAccessibilityParent() == this) | |
| 103 return 1; | 104 return 1; |
| 104 | 105 |
| 105 return 0; | 106 return 0; |
| 106 } | 107 } |
| 107 | 108 |
| 108 return PlatformIsLeaf() ? 0 : InternalChildCount(); | 109 return PlatformIsLeaf() ? 0 : InternalChildCount(); |
| 109 } | 110 } |
| 110 | 111 |
| 111 bool BrowserAccessibility::IsNative() const { | 112 bool BrowserAccessibility::IsNative() const { |
| 112 return false; | 113 return false; |
| 113 } | 114 } |
| 114 | 115 |
| 115 bool BrowserAccessibility::IsDescendantOf( | 116 bool BrowserAccessibility::IsDescendantOf( |
| 116 const BrowserAccessibility* ancestor) const { | 117 const BrowserAccessibility* ancestor) const { |
| 117 if (!ancestor) | 118 if (!ancestor) |
| 118 return false; | 119 return false; |
| 119 | 120 |
| 120 if (this == ancestor) | 121 if (this == ancestor) |
| 121 return true; | 122 return true; |
| 122 | 123 |
| 123 if (GetParent()) | 124 if (GetAccessibilityParent()) |
| 124 return GetParent()->IsDescendantOf(ancestor); | 125 return GetAccessibilityParent()->IsDescendantOf(ancestor); |
| 125 | 126 |
| 126 return false; | 127 return false; |
| 127 } | 128 } |
| 128 | 129 |
| 129 bool BrowserAccessibility::IsTextOnlyObject() const { | 130 bool BrowserAccessibility::IsTextOnlyObject() const { |
| 130 return GetRole() == ui::AX_ROLE_STATIC_TEXT || | 131 return GetRole() == ui::AX_ROLE_STATIC_TEXT || |
| 131 GetRole() == ui::AX_ROLE_LINE_BREAK || | 132 GetRole() == ui::AX_ROLE_LINE_BREAK || |
| 132 GetRole() == ui::AX_ROLE_INLINE_TEXT_BOX; | 133 GetRole() == ui::AX_ROLE_INLINE_TEXT_BOX; |
| 133 } | 134 } |
| 134 | 135 |
| 135 bool BrowserAccessibility::IsLineBreakObject() const { | 136 bool BrowserAccessibility::IsLineBreakObject() const { |
| 136 return GetRole() == ui::AX_ROLE_LINE_BREAK || | 137 return GetRole() == ui::AX_ROLE_LINE_BREAK || |
| 137 (IsTextOnlyObject() && GetParent() && | 138 (IsTextOnlyObject() && GetAccessibilityParent() && |
| 138 GetParent()->GetRole() == ui::AX_ROLE_LINE_BREAK); | 139 GetAccessibilityParent()->GetRole() == ui::AX_ROLE_LINE_BREAK); |
| 139 } | 140 } |
| 140 | 141 |
| 141 BrowserAccessibility* BrowserAccessibility::PlatformGetChild( | 142 BrowserAccessibility* BrowserAccessibility::PlatformGetChild( |
| 142 uint32_t child_index) const { | 143 uint32_t child_index) const { |
| 143 BrowserAccessibility* result = nullptr; | 144 BrowserAccessibility* result = nullptr; |
| 144 | 145 |
| 145 if (child_index == 0 && HasIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)) { | 146 if (child_index == 0 && HasIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)) { |
| 146 BrowserAccessibilityManager* child_manager = | 147 BrowserAccessibilityManager* child_manager = |
| 147 BrowserAccessibilityManager::FromID( | 148 BrowserAccessibilityManager::FromID( |
| 148 GetIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)); | 149 GetIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)); |
| 149 if (child_manager && child_manager->GetRoot()->GetParent() == this) | 150 if (child_manager && |
| 151 child_manager->GetRoot()->GetAccessibilityParent() == this) | |
| 150 result = child_manager->GetRoot(); | 152 result = child_manager->GetRoot(); |
| 151 } else { | 153 } else { |
| 152 result = InternalGetChild(child_index); | 154 result = InternalGetChild(child_index); |
| 153 } | 155 } |
| 154 | 156 |
| 155 return result; | 157 return result; |
| 156 } | 158 } |
| 157 | 159 |
| 158 bool BrowserAccessibility::PlatformIsChildOfLeaf() const { | 160 bool BrowserAccessibility::PlatformIsChildOfLeaf() const { |
| 159 BrowserAccessibility* ancestor = InternalGetParent(); | 161 BrowserAccessibility* ancestor = InternalGetParent(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 170 BrowserAccessibility* platform_object = | 172 BrowserAccessibility* platform_object = |
| 171 const_cast<BrowserAccessibility*>(this); | 173 const_cast<BrowserAccessibility*>(this); |
| 172 while (platform_object && platform_object->PlatformIsChildOfLeaf()) | 174 while (platform_object && platform_object->PlatformIsChildOfLeaf()) |
| 173 platform_object = platform_object->InternalGetParent(); | 175 platform_object = platform_object->InternalGetParent(); |
| 174 | 176 |
| 175 DCHECK(platform_object); | 177 DCHECK(platform_object); |
| 176 return platform_object; | 178 return platform_object; |
| 177 } | 179 } |
| 178 | 180 |
| 179 BrowserAccessibility* BrowserAccessibility::GetPreviousSibling() const { | 181 BrowserAccessibility* BrowserAccessibility::GetPreviousSibling() const { |
| 180 if (GetParent() && GetIndexInParent() > 0) | 182 if (GetAccessibilityParent() && GetIndexInParent() > 0) |
|
dmazzoni
2017/03/21 16:42:20
This actually brings up an interesting question -
| |
| 181 return GetParent()->InternalGetChild(GetIndexInParent() - 1); | 183 return GetAccessibilityParent()->InternalGetChild(GetIndexInParent() - 1); |
| 182 | 184 |
| 183 return nullptr; | 185 return nullptr; |
| 184 } | 186 } |
| 185 | 187 |
| 186 BrowserAccessibility* BrowserAccessibility::GetNextSibling() const { | 188 BrowserAccessibility* BrowserAccessibility::GetNextSibling() const { |
| 187 if (GetParent() && | 189 if (GetAccessibilityParent() && GetIndexInParent() >= 0 && |
| 188 GetIndexInParent() >= 0 && | 190 GetIndexInParent() < |
| 189 GetIndexInParent() < static_cast<int>( | 191 static_cast<int>(GetAccessibilityParent()->InternalChildCount() - |
| 190 GetParent()->InternalChildCount() - 1)) { | 192 1)) { |
| 191 return GetParent()->InternalGetChild(GetIndexInParent() + 1); | 193 return GetAccessibilityParent()->InternalGetChild(GetIndexInParent() + 1); |
| 192 } | 194 } |
| 193 | 195 |
| 194 return nullptr; | 196 return nullptr; |
| 195 } | 197 } |
| 196 | 198 |
| 197 bool BrowserAccessibility::IsPreviousSiblingOnSameLine() const { | 199 bool BrowserAccessibility::IsPreviousSiblingOnSameLine() const { |
| 198 const BrowserAccessibility* previous_sibling = GetPreviousSibling(); | 200 const BrowserAccessibility* previous_sibling = GetPreviousSibling(); |
| 199 if (!previous_sibling) | 201 if (!previous_sibling) |
| 200 return false; | 202 return false; |
| 201 | 203 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 BrowserAccessibility* BrowserAccessibility::InternalGetChild( | 302 BrowserAccessibility* BrowserAccessibility::InternalGetChild( |
| 301 uint32_t child_index) const { | 303 uint32_t child_index) const { |
| 302 if (!node_ || !manager_ || child_index >= InternalChildCount()) | 304 if (!node_ || !manager_ || child_index >= InternalChildCount()) |
| 303 return nullptr; | 305 return nullptr; |
| 304 | 306 |
| 305 auto* child_node = node_->ChildAtIndex(child_index); | 307 auto* child_node = node_->ChildAtIndex(child_index); |
| 306 DCHECK(child_node); | 308 DCHECK(child_node); |
| 307 return manager_->GetFromAXNode(child_node); | 309 return manager_->GetFromAXNode(child_node); |
| 308 } | 310 } |
| 309 | 311 |
| 310 BrowserAccessibility* BrowserAccessibility::GetParent() const { | 312 BrowserAccessibility* BrowserAccessibility::GetAccessibilityParent() const { |
| 311 if (!instance_active()) | 313 if (!instance_active()) |
| 312 return nullptr; | 314 return nullptr; |
| 313 | 315 |
| 314 ui::AXNode* parent = node_->parent(); | 316 ui::AXNode* parent = node_->parent(); |
| 315 if (parent) | 317 if (parent) |
| 316 return manager_->GetFromAXNode(parent); | 318 return manager_->GetFromAXNode(parent); |
| 317 | 319 |
| 318 return manager_->GetParentNodeFromParentTree(); | 320 return manager_->GetParentNodeFromParentTree(); |
| 319 } | 321 } |
| 320 | 322 |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 821 return GetData().GetFloatAttribute(attribute, value); | 823 return GetData().GetFloatAttribute(attribute, value); |
| 822 } | 824 } |
| 823 | 825 |
| 824 bool BrowserAccessibility::HasInheritedStringAttribute( | 826 bool BrowserAccessibility::HasInheritedStringAttribute( |
| 825 ui::AXStringAttribute attribute) const { | 827 ui::AXStringAttribute attribute) const { |
| 826 if (!instance_active()) | 828 if (!instance_active()) |
| 827 return false; | 829 return false; |
| 828 | 830 |
| 829 if (GetData().HasStringAttribute(attribute)) | 831 if (GetData().HasStringAttribute(attribute)) |
| 830 return true; | 832 return true; |
| 831 return GetParent() && GetParent()->HasInheritedStringAttribute(attribute); | 833 return GetAccessibilityParent() && |
| 834 GetAccessibilityParent()->HasInheritedStringAttribute(attribute); | |
| 832 } | 835 } |
| 833 | 836 |
| 834 const std::string& BrowserAccessibility::GetInheritedStringAttribute( | 837 const std::string& BrowserAccessibility::GetInheritedStringAttribute( |
| 835 ui::AXStringAttribute attribute) const { | 838 ui::AXStringAttribute attribute) const { |
| 836 if (!instance_active()) | 839 if (!instance_active()) |
| 837 return base::EmptyString(); | 840 return base::EmptyString(); |
| 838 | 841 |
| 839 const BrowserAccessibility* current_object = this; | 842 const BrowserAccessibility* current_object = this; |
| 840 do { | 843 do { |
| 841 if (current_object->GetData().HasStringAttribute(attribute)) | 844 if (current_object->GetData().HasStringAttribute(attribute)) |
| 842 return current_object->GetData().GetStringAttribute(attribute); | 845 return current_object->GetData().GetStringAttribute(attribute); |
| 843 current_object = current_object->GetParent(); | 846 current_object = current_object->GetAccessibilityParent(); |
| 844 } while (current_object); | 847 } while (current_object); |
| 845 return base::EmptyString(); | 848 return base::EmptyString(); |
| 846 } | 849 } |
| 847 | 850 |
| 848 bool BrowserAccessibility::GetInheritedStringAttribute( | 851 bool BrowserAccessibility::GetInheritedStringAttribute( |
| 849 ui::AXStringAttribute attribute, | 852 ui::AXStringAttribute attribute, |
| 850 std::string* value) const { | 853 std::string* value) const { |
| 851 if (!instance_active()) { | 854 if (!instance_active()) { |
| 852 *value = std::string(); | 855 *value = std::string(); |
| 853 return false; | 856 return false; |
| 854 } | 857 } |
| 855 | 858 |
| 856 if (GetData().GetStringAttribute(attribute, value)) | 859 if (GetData().GetStringAttribute(attribute, value)) |
| 857 return true; | 860 return true; |
| 858 return GetParent() && | 861 return GetAccessibilityParent() && |
| 859 GetParent()->GetData().GetStringAttribute(attribute, value); | 862 GetAccessibilityParent()->GetData().GetStringAttribute(attribute, |
| 863 value); | |
| 860 } | 864 } |
| 861 | 865 |
| 862 base::string16 BrowserAccessibility::GetInheritedString16Attribute( | 866 base::string16 BrowserAccessibility::GetInheritedString16Attribute( |
| 863 ui::AXStringAttribute attribute) const { | 867 ui::AXStringAttribute attribute) const { |
| 864 if (!instance_active()) | 868 if (!instance_active()) |
| 865 return base::string16(); | 869 return base::string16(); |
| 866 | 870 |
| 867 const BrowserAccessibility* current_object = this; | 871 const BrowserAccessibility* current_object = this; |
| 868 do { | 872 do { |
| 869 if (current_object->GetData().HasStringAttribute(attribute)) | 873 if (current_object->GetData().HasStringAttribute(attribute)) |
| 870 return current_object->GetData().GetString16Attribute(attribute); | 874 return current_object->GetData().GetString16Attribute(attribute); |
| 871 current_object = current_object->GetParent(); | 875 current_object = current_object->GetAccessibilityParent(); |
| 872 } while (current_object); | 876 } while (current_object); |
| 873 return base::string16(); | 877 return base::string16(); |
| 874 } | 878 } |
| 875 | 879 |
| 876 bool BrowserAccessibility::GetInheritedString16Attribute( | 880 bool BrowserAccessibility::GetInheritedString16Attribute( |
| 877 ui::AXStringAttribute attribute, | 881 ui::AXStringAttribute attribute, |
| 878 base::string16* value) const { | 882 base::string16* value) const { |
| 879 if (!instance_active()) { | 883 if (!instance_active()) { |
| 880 *value = base::string16(); | 884 *value = base::string16(); |
| 881 return false; | 885 return false; |
| 882 } | 886 } |
| 883 | 887 |
| 884 if (GetData().GetString16Attribute(attribute, value)) | 888 if (GetData().GetString16Attribute(attribute, value)) |
| 885 return true; | 889 return true; |
| 886 return GetParent() && | 890 return GetAccessibilityParent() && |
| 887 GetParent()->GetData().GetString16Attribute(attribute, value); | 891 GetAccessibilityParent()->GetData().GetString16Attribute(attribute, |
| 892 value); | |
| 888 } | 893 } |
| 889 | 894 |
| 890 bool BrowserAccessibility::HasIntAttribute( | 895 bool BrowserAccessibility::HasIntAttribute( |
| 891 ui::AXIntAttribute attribute) const { | 896 ui::AXIntAttribute attribute) const { |
| 892 return GetData().HasIntAttribute(attribute); | 897 return GetData().HasIntAttribute(attribute); |
| 893 } | 898 } |
| 894 | 899 |
| 895 int BrowserAccessibility::GetIntAttribute(ui::AXIntAttribute attribute) const { | 900 int BrowserAccessibility::GetIntAttribute(ui::AXIntAttribute attribute) const { |
| 896 return GetData().GetIntAttribute(attribute); | 901 return GetData().GetIntAttribute(attribute); |
| 897 } | 902 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1011 | 1016 |
| 1012 return focus_object->IsDescendantOf(this); | 1017 return focus_object->IsDescendantOf(this); |
| 1013 } | 1018 } |
| 1014 | 1019 |
| 1015 bool BrowserAccessibility::IsWebAreaForPresentationalIframe() const { | 1020 bool BrowserAccessibility::IsWebAreaForPresentationalIframe() const { |
| 1016 if (GetRole() != ui::AX_ROLE_WEB_AREA && | 1021 if (GetRole() != ui::AX_ROLE_WEB_AREA && |
| 1017 GetRole() != ui::AX_ROLE_ROOT_WEB_AREA) { | 1022 GetRole() != ui::AX_ROLE_ROOT_WEB_AREA) { |
| 1018 return false; | 1023 return false; |
| 1019 } | 1024 } |
| 1020 | 1025 |
| 1021 BrowserAccessibility* parent = GetParent(); | 1026 BrowserAccessibility* parent = GetAccessibilityParent(); |
| 1022 if (!parent) | 1027 if (!parent) |
| 1023 return false; | 1028 return false; |
| 1024 | 1029 |
| 1025 return parent->GetRole() == ui::AX_ROLE_IFRAME_PRESENTATIONAL; | 1030 return parent->GetRole() == ui::AX_ROLE_IFRAME_PRESENTATIONAL; |
| 1026 } | 1031 } |
| 1027 | 1032 |
| 1028 bool BrowserAccessibility::IsClickable() const { | 1033 bool BrowserAccessibility::IsClickable() const { |
| 1029 return ui::IsRoleClickable(GetRole()); | 1034 return ui::IsRoleClickable(GetRole()); |
| 1030 } | 1035 } |
| 1031 | 1036 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1102 case ui::AX_ROLE_TEXT_FIELD: | 1107 case ui::AX_ROLE_TEXT_FIELD: |
| 1103 return !HasState(ui::AX_STATE_RICHLY_EDITABLE); | 1108 return !HasState(ui::AX_STATE_RICHLY_EDITABLE); |
| 1104 default: | 1109 default: |
| 1105 return false; | 1110 return false; |
| 1106 } | 1111 } |
| 1107 } | 1112 } |
| 1108 | 1113 |
| 1109 // Indicates if this object is at the root of a rich edit text control. | 1114 // Indicates if this object is at the root of a rich edit text control. |
| 1110 bool BrowserAccessibility::IsRichTextControl() const { | 1115 bool BrowserAccessibility::IsRichTextControl() const { |
| 1111 return HasState(ui::AX_STATE_RICHLY_EDITABLE) && | 1116 return HasState(ui::AX_STATE_RICHLY_EDITABLE) && |
| 1112 (!GetParent() || !GetParent()->HasState(ui::AX_STATE_RICHLY_EDITABLE)); | 1117 (!GetAccessibilityParent() || |
| 1118 !GetAccessibilityParent()->HasState(ui::AX_STATE_RICHLY_EDITABLE)); | |
| 1113 } | 1119 } |
| 1114 | 1120 |
| 1115 std::string BrowserAccessibility::ComputeAccessibleNameFromDescendants() { | 1121 std::string BrowserAccessibility::ComputeAccessibleNameFromDescendants() { |
| 1116 std::string name; | 1122 std::string name; |
| 1117 for (size_t i = 0; i < InternalChildCount(); ++i) { | 1123 for (size_t i = 0; i < InternalChildCount(); ++i) { |
| 1118 BrowserAccessibility* child = InternalGetChild(i); | 1124 BrowserAccessibility* child = InternalGetChild(i); |
| 1119 std::string child_name; | 1125 std::string child_name; |
| 1120 if (child->GetStringAttribute(ui::AX_ATTR_NAME, &child_name)) { | 1126 if (child->GetStringAttribute(ui::AX_ATTR_NAME, &child_name)) { |
| 1121 if (!name.empty()) | 1127 if (!name.empty()) |
| 1122 name += " "; | 1128 name += " "; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1187 bool frame_only) const { | 1193 bool frame_only) const { |
| 1188 const BrowserAccessibility* node = this; | 1194 const BrowserAccessibility* node = this; |
| 1189 while (node) { | 1195 while (node) { |
| 1190 if (node->GetData().transform) | 1196 if (node->GetData().transform) |
| 1191 node->GetData().transform->TransformRect(&bounds); | 1197 node->GetData().transform->TransformRect(&bounds); |
| 1192 | 1198 |
| 1193 const BrowserAccessibility* container = | 1199 const BrowserAccessibility* container = |
| 1194 node->manager()->GetFromID(node->GetData().offset_container_id); | 1200 node->manager()->GetFromID(node->GetData().offset_container_id); |
| 1195 if (!container) { | 1201 if (!container) { |
| 1196 if (node == node->manager()->GetRoot() && !frame_only) { | 1202 if (node == node->manager()->GetRoot() && !frame_only) { |
| 1197 container = node->GetParent(); | 1203 container = node->GetAccessibilityParent(); |
| 1198 } else { | 1204 } else { |
| 1199 container = node->manager()->GetRoot(); | 1205 container = node->manager()->GetRoot(); |
| 1200 } | 1206 } |
| 1201 } | 1207 } |
| 1202 | 1208 |
| 1203 if (!container || container == node) | 1209 if (!container || container == node) |
| 1204 break; | 1210 break; |
| 1205 | 1211 |
| 1206 gfx::RectF container_bounds = container->GetLocation(); | 1212 gfx::RectF container_bounds = container->GetLocation(); |
| 1207 bounds.Offset(container_bounds.x(), container_bounds.y()); | 1213 bounds.Offset(container_bounds.x(), container_bounds.y()); |
| 1208 | 1214 |
| 1209 if (container->manager()->UseRootScrollOffsetsWhenComputingBounds() || | 1215 if (container->manager()->UseRootScrollOffsetsWhenComputingBounds() || |
| 1210 container->GetParent()) { | 1216 container->GetAccessibilityParent()) { |
| 1211 int sx = 0; | 1217 int sx = 0; |
| 1212 int sy = 0; | 1218 int sy = 0; |
| 1213 if (container->GetIntAttribute(ui::AX_ATTR_SCROLL_X, &sx) && | 1219 if (container->GetIntAttribute(ui::AX_ATTR_SCROLL_X, &sx) && |
| 1214 container->GetIntAttribute(ui::AX_ATTR_SCROLL_Y, &sy)) { | 1220 container->GetIntAttribute(ui::AX_ATTR_SCROLL_Y, &sy)) { |
| 1215 bounds.Offset(-sx, -sy); | 1221 bounds.Offset(-sx, -sy); |
| 1216 } | 1222 } |
| 1217 } | 1223 } |
| 1218 | 1224 |
| 1219 node = container; | 1225 node = container; |
| 1220 } | 1226 } |
| 1221 | 1227 |
| 1222 return gfx::ToEnclosingRect(bounds); | 1228 return gfx::ToEnclosingRect(bounds); |
| 1223 } | 1229 } |
| 1224 | 1230 |
| 1225 } // namespace content | 1231 } // namespace content |
| OLD | NEW |