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