| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_android.h" | 5 #include "content/browser/accessibility/browser_accessibility_android.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "content/browser/accessibility/browser_accessibility_manager_android.h" | 8 #include "content/browser/accessibility/browser_accessibility_manager_android.h" |
| 9 #include "content/common/accessibility_messages.h" | 9 #include "content/common/accessibility_messages.h" |
| 10 #include "content/common/accessibility_node_data.h" | |
| 11 | 10 |
| 12 namespace { | 11 namespace { |
| 13 | 12 |
| 14 // These are enums from android.text.InputType in Java: | 13 // These are enums from android.text.InputType in Java: |
| 15 enum { | 14 enum { |
| 16 ANDROID_TEXT_INPUTTYPE_TYPE_NULL = 0, | 15 ANDROID_TEXT_INPUTTYPE_TYPE_NULL = 0, |
| 17 ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME = 0x4, | 16 ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME = 0x4, |
| 18 ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME_DATE = 0x14, | 17 ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME_DATE = 0x14, |
| 19 ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME_TIME = 0x24, | 18 ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME_TIME = 0x24, |
| 20 ANDROID_TEXT_INPUTTYPE_TYPE_NUMBER = 0x2, | 19 ANDROID_TEXT_INPUTTYPE_TYPE_NUMBER = 0x2, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 bool BrowserAccessibilityAndroid::IsNative() const { | 54 bool BrowserAccessibilityAndroid::IsNative() const { |
| 56 return true; | 55 return true; |
| 57 } | 56 } |
| 58 | 57 |
| 59 bool BrowserAccessibilityAndroid::PlatformIsLeaf() const { | 58 bool BrowserAccessibilityAndroid::PlatformIsLeaf() const { |
| 60 if (child_count() == 0) | 59 if (child_count() == 0) |
| 61 return true; | 60 return true; |
| 62 | 61 |
| 63 // Iframes are always allowed to contain children. | 62 // Iframes are always allowed to contain children. |
| 64 if (IsIframe() || | 63 if (IsIframe() || |
| 65 role() == blink::WebAXRoleRootWebArea || | 64 role() == ui::AX_ROLE_ROOT_WEB_AREA || |
| 66 role() == blink::WebAXRoleWebArea) { | 65 role() == ui::AX_ROLE_WEB_AREA) { |
| 67 return false; | 66 return false; |
| 68 } | 67 } |
| 69 | 68 |
| 70 // If it has a focusable child, we definitely can't leave out children. | 69 // If it has a focusable child, we definitely can't leave out children. |
| 71 if (HasFocusableChild()) | 70 if (HasFocusableChild()) |
| 72 return false; | 71 return false; |
| 73 | 72 |
| 74 // Headings with text can drop their children. | 73 // Headings with text can drop their children. |
| 75 base::string16 name = GetText(); | 74 base::string16 name = GetText(); |
| 76 if (role() == blink::WebAXRoleHeading && !name.empty()) | 75 if (role() == ui::AX_ROLE_HEADING && !name.empty()) |
| 77 return true; | 76 return true; |
| 78 | 77 |
| 79 // Focusable nodes with text can drop their children. | 78 // Focusable nodes with text can drop their children. |
| 80 if (HasState(blink::WebAXStateFocusable) && !name.empty()) | 79 if (HasState(ui::AX_STATE_FOCUSABLE) && !name.empty()) |
| 81 return true; | 80 return true; |
| 82 | 81 |
| 83 // Nodes with only static text as children can drop their children. | 82 // Nodes with only static text as children can drop their children. |
| 84 if (HasOnlyStaticTextChildren()) | 83 if (HasOnlyStaticTextChildren()) |
| 85 return true; | 84 return true; |
| 86 | 85 |
| 87 return BrowserAccessibility::PlatformIsLeaf(); | 86 return BrowserAccessibility::PlatformIsLeaf(); |
| 88 } | 87 } |
| 89 | 88 |
| 90 bool BrowserAccessibilityAndroid::IsCheckable() const { | 89 bool BrowserAccessibilityAndroid::IsCheckable() const { |
| 91 bool checkable = false; | 90 bool checkable = false; |
| 92 bool is_aria_pressed_defined; | 91 bool is_aria_pressed_defined; |
| 93 bool is_mixed; | 92 bool is_mixed; |
| 94 GetAriaTristate("aria-pressed", &is_aria_pressed_defined, &is_mixed); | 93 GetAriaTristate("aria-pressed", &is_aria_pressed_defined, &is_mixed); |
| 95 if (role() == blink::WebAXRoleCheckBox || | 94 if (role() == ui::AX_ROLE_CHECK_BOX || |
| 96 role() == blink::WebAXRoleRadioButton || | 95 role() == ui::AX_ROLE_RADIO_BUTTON || |
| 97 is_aria_pressed_defined) { | 96 is_aria_pressed_defined) { |
| 98 checkable = true; | 97 checkable = true; |
| 99 } | 98 } |
| 100 if (HasState(blink::WebAXStateChecked)) | 99 if (HasState(ui::AX_STATE_CHECKED)) |
| 101 checkable = true; | 100 checkable = true; |
| 102 return checkable; | 101 return checkable; |
| 103 } | 102 } |
| 104 | 103 |
| 105 bool BrowserAccessibilityAndroid::IsChecked() const { | 104 bool BrowserAccessibilityAndroid::IsChecked() const { |
| 106 return HasState(blink::WebAXStateChecked); | 105 return HasState(ui::AX_STATE_CHECKED); |
| 107 } | 106 } |
| 108 | 107 |
| 109 bool BrowserAccessibilityAndroid::IsClickable() const { | 108 bool BrowserAccessibilityAndroid::IsClickable() const { |
| 110 return (PlatformIsLeaf() && !GetText().empty()); | 109 return (PlatformIsLeaf() && !GetText().empty()); |
| 111 } | 110 } |
| 112 | 111 |
| 113 bool BrowserAccessibilityAndroid::IsCollection() const { | 112 bool BrowserAccessibilityAndroid::IsCollection() const { |
| 114 return (role() == blink::WebAXRoleGrid || | 113 return (role() == ui::AX_ROLE_GRID || |
| 115 role() == blink::WebAXRoleList || | 114 role() == ui::AX_ROLE_LIST || |
| 116 role() == blink::WebAXRoleListBox || | 115 role() == ui::AX_ROLE_LIST_BOX || |
| 117 role() == blink::WebAXRoleTable || | 116 role() == ui::AX_ROLE_TABLE || |
| 118 role() == blink::WebAXRoleTree); | 117 role() == ui::AX_ROLE_TREE); |
| 119 } | 118 } |
| 120 | 119 |
| 121 bool BrowserAccessibilityAndroid::IsCollectionItem() const { | 120 bool BrowserAccessibilityAndroid::IsCollectionItem() const { |
| 122 return (role() == blink::WebAXRoleCell || | 121 return (role() == ui::AX_ROLE_CELL || |
| 123 role() == blink::WebAXRoleColumnHeader || | 122 role() == ui::AX_ROLE_COLUMN_HEADER || |
| 124 role() == blink::WebAXRoleDescriptionListTerm || | 123 role() == ui::AX_ROLE_DESCRIPTION_LIST_TERM || |
| 125 role() == blink::WebAXRoleListBoxOption || | 124 role() == ui::AX_ROLE_LIST_BOX_OPTION || |
| 126 role() == blink::WebAXRoleListItem || | 125 role() == ui::AX_ROLE_LIST_ITEM || |
| 127 role() == blink::WebAXRoleRowHeader || | 126 role() == ui::AX_ROLE_ROW_HEADER || |
| 128 role() == blink::WebAXRoleTreeItem); | 127 role() == ui::AX_ROLE_TREE_ITEM); |
| 129 } | 128 } |
| 130 | 129 |
| 131 bool BrowserAccessibilityAndroid::IsContentInvalid() const { | 130 bool BrowserAccessibilityAndroid::IsContentInvalid() const { |
| 132 std::string invalid; | 131 std::string invalid; |
| 133 return GetHtmlAttribute("aria-invalid", &invalid); | 132 return GetHtmlAttribute("aria-invalid", &invalid); |
| 134 } | 133 } |
| 135 | 134 |
| 136 bool BrowserAccessibilityAndroid::IsDismissable() const { | 135 bool BrowserAccessibilityAndroid::IsDismissable() const { |
| 137 return false; // No concept of "dismissable" on the web currently. | 136 return false; // No concept of "dismissable" on the web currently. |
| 138 } | 137 } |
| 139 | 138 |
| 140 bool BrowserAccessibilityAndroid::IsEnabled() const { | 139 bool BrowserAccessibilityAndroid::IsEnabled() const { |
| 141 return HasState(blink::WebAXStateEnabled); | 140 return HasState(ui::AX_STATE_ENABLED); |
| 142 } | 141 } |
| 143 | 142 |
| 144 bool BrowserAccessibilityAndroid::IsFocusable() const { | 143 bool BrowserAccessibilityAndroid::IsFocusable() const { |
| 145 bool focusable = HasState(blink::WebAXStateFocusable); | 144 bool focusable = HasState(ui::AX_STATE_FOCUSABLE); |
| 146 if (IsIframe() || | 145 if (IsIframe() || |
| 147 role() == blink::WebAXRoleWebArea) { | 146 role() == ui::AX_ROLE_WEB_AREA) { |
| 148 focusable = false; | 147 focusable = false; |
| 149 } | 148 } |
| 150 return focusable; | 149 return focusable; |
| 151 } | 150 } |
| 152 | 151 |
| 153 bool BrowserAccessibilityAndroid::IsFocused() const { | 152 bool BrowserAccessibilityAndroid::IsFocused() const { |
| 154 return manager()->GetFocus(manager()->GetRoot()) == this; | 153 return manager()->GetFocus(manager()->GetRoot()) == this; |
| 155 } | 154 } |
| 156 | 155 |
| 157 bool BrowserAccessibilityAndroid::IsHeading() const { | 156 bool BrowserAccessibilityAndroid::IsHeading() const { |
| 158 return (role() == blink::WebAXRoleColumnHeader || | 157 return (role() == ui::AX_ROLE_COLUMN_HEADER || |
| 159 role() == blink::WebAXRoleHeading || | 158 role() == ui::AX_ROLE_HEADING || |
| 160 role() == blink::WebAXRoleRowHeader); | 159 role() == ui::AX_ROLE_ROW_HEADER); |
| 161 } | 160 } |
| 162 | 161 |
| 163 bool BrowserAccessibilityAndroid::IsHierarchical() const { | 162 bool BrowserAccessibilityAndroid::IsHierarchical() const { |
| 164 return (role() == blink::WebAXRoleList || | 163 return (role() == ui::AX_ROLE_LIST || |
| 165 role() == blink::WebAXRoleTree); | 164 role() == ui::AX_ROLE_TREE); |
| 166 } | 165 } |
| 167 | 166 |
| 168 bool BrowserAccessibilityAndroid::IsMultiLine() const { | 167 bool BrowserAccessibilityAndroid::IsMultiLine() const { |
| 169 return role() == blink::WebAXRoleTextArea; | 168 return role() == ui::AX_ROLE_TEXT_AREA; |
| 170 } | 169 } |
| 171 | 170 |
| 172 bool BrowserAccessibilityAndroid::IsPassword() const { | 171 bool BrowserAccessibilityAndroid::IsPassword() const { |
| 173 return HasState(blink::WebAXStateProtected); | 172 return HasState(ui::AX_STATE_PROTECTED); |
| 174 } | 173 } |
| 175 | 174 |
| 176 bool BrowserAccessibilityAndroid::IsRangeType() const { | 175 bool BrowserAccessibilityAndroid::IsRangeType() const { |
| 177 return (role() == blink::WebAXRoleProgressIndicator || | 176 return (role() == ui::AX_ROLE_PROGRESS_INDICATOR || |
| 178 role() == blink::WebAXRoleScrollBar || | 177 role() == ui::AX_ROLE_SCROLL_BAR || |
| 179 role() == blink::WebAXRoleSlider); | 178 role() == ui::AX_ROLE_SLIDER); |
| 180 } | 179 } |
| 181 | 180 |
| 182 bool BrowserAccessibilityAndroid::IsScrollable() const { | 181 bool BrowserAccessibilityAndroid::IsScrollable() const { |
| 183 int dummy; | 182 int dummy; |
| 184 return GetIntAttribute(AccessibilityNodeData::ATTR_SCROLL_X_MAX, &dummy); | 183 return GetIntAttribute(ui::AX_ATTR_SCROLL_X_MAX, &dummy); |
| 185 } | 184 } |
| 186 | 185 |
| 187 bool BrowserAccessibilityAndroid::IsSelected() const { | 186 bool BrowserAccessibilityAndroid::IsSelected() const { |
| 188 return HasState(blink::WebAXStateSelected); | 187 return HasState(ui::AX_STATE_SELECTED); |
| 189 } | 188 } |
| 190 | 189 |
| 191 bool BrowserAccessibilityAndroid::IsVisibleToUser() const { | 190 bool BrowserAccessibilityAndroid::IsVisibleToUser() const { |
| 192 return !HasState(blink::WebAXStateInvisible); | 191 return !HasState(ui::AX_STATE_INVISIBLE); |
| 193 } | 192 } |
| 194 | 193 |
| 195 bool BrowserAccessibilityAndroid::CanOpenPopup() const { | 194 bool BrowserAccessibilityAndroid::CanOpenPopup() const { |
| 196 return HasState(blink::WebAXStateHaspopup); | 195 return HasState(ui::AX_STATE_HASPOPUP); |
| 197 } | 196 } |
| 198 | 197 |
| 199 const char* BrowserAccessibilityAndroid::GetClassName() const { | 198 const char* BrowserAccessibilityAndroid::GetClassName() const { |
| 200 const char* class_name = NULL; | 199 const char* class_name = NULL; |
| 201 | 200 |
| 202 switch(role()) { | 201 switch(role()) { |
| 203 case blink::WebAXRoleEditableText: | 202 case ui::AX_ROLE_EDITABLE_TEXT: |
| 204 case blink::WebAXRoleSpinButton: | 203 case ui::AX_ROLE_SPIN_BUTTON: |
| 205 case blink::WebAXRoleTextArea: | 204 case ui::AX_ROLE_TEXT_AREA: |
| 206 case blink::WebAXRoleTextField: | 205 case ui::AX_ROLE_TEXT_FIELD: |
| 207 class_name = "android.widget.EditText"; | 206 class_name = "android.widget.EditText"; |
| 208 break; | 207 break; |
| 209 case blink::WebAXRoleSlider: | 208 case ui::AX_ROLE_SLIDER: |
| 210 class_name = "android.widget.SeekBar"; | 209 class_name = "android.widget.SeekBar"; |
| 211 break; | 210 break; |
| 212 case blink::WebAXRoleComboBox: | 211 case ui::AX_ROLE_COMBO_BOX: |
| 213 class_name = "android.widget.Spinner"; | 212 class_name = "android.widget.Spinner"; |
| 214 break; | 213 break; |
| 215 case blink::WebAXRoleButton: | 214 case ui::AX_ROLE_BUTTON: |
| 216 case blink::WebAXRoleMenuButton: | 215 case ui::AX_ROLE_MENU_BUTTON: |
| 217 case blink::WebAXRolePopUpButton: | 216 case ui::AX_ROLE_POP_UP_BUTTON: |
| 218 class_name = "android.widget.Button"; | 217 class_name = "android.widget.Button"; |
| 219 break; | 218 break; |
| 220 case blink::WebAXRoleCheckBox: | 219 case ui::AX_ROLE_CHECK_BOX: |
| 221 class_name = "android.widget.CheckBox"; | 220 class_name = "android.widget.CheckBox"; |
| 222 break; | 221 break; |
| 223 case blink::WebAXRoleRadioButton: | 222 case ui::AX_ROLE_RADIO_BUTTON: |
| 224 class_name = "android.widget.RadioButton"; | 223 class_name = "android.widget.RadioButton"; |
| 225 break; | 224 break; |
| 226 case blink::WebAXRoleToggleButton: | 225 case ui::AX_ROLE_TOGGLE_BUTTON: |
| 227 class_name = "android.widget.ToggleButton"; | 226 class_name = "android.widget.ToggleButton"; |
| 228 break; | 227 break; |
| 229 case blink::WebAXRoleCanvas: | 228 case ui::AX_ROLE_CANVAS: |
| 230 case blink::WebAXRoleImage: | 229 case ui::AX_ROLE_IMAGE: |
| 231 class_name = "android.widget.Image"; | 230 class_name = "android.widget.Image"; |
| 232 break; | 231 break; |
| 233 case blink::WebAXRoleProgressIndicator: | 232 case ui::AX_ROLE_PROGRESS_INDICATOR: |
| 234 class_name = "android.widget.ProgressBar"; | 233 class_name = "android.widget.ProgressBar"; |
| 235 break; | 234 break; |
| 236 case blink::WebAXRoleTabList: | 235 case ui::AX_ROLE_TAB_LIST: |
| 237 class_name = "android.widget.TabWidget"; | 236 class_name = "android.widget.TabWidget"; |
| 238 break; | 237 break; |
| 239 case blink::WebAXRoleGrid: | 238 case ui::AX_ROLE_GRID: |
| 240 case blink::WebAXRoleTable: | 239 case ui::AX_ROLE_TABLE: |
| 241 class_name = "android.widget.GridView"; | 240 class_name = "android.widget.GridView"; |
| 242 break; | 241 break; |
| 243 case blink::WebAXRoleList: | 242 case ui::AX_ROLE_LIST: |
| 244 case blink::WebAXRoleListBox: | 243 case ui::AX_ROLE_LIST_BOX: |
| 245 class_name = "android.widget.ListView"; | 244 class_name = "android.widget.ListView"; |
| 246 break; | 245 break; |
| 247 case blink::WebAXRoleDialog: | 246 case ui::AX_ROLE_DIALOG: |
| 248 class_name = "android.app.Dialog"; | 247 class_name = "android.app.Dialog"; |
| 249 break; | 248 break; |
| 250 default: | 249 default: |
| 251 class_name = "android.view.View"; | 250 class_name = "android.view.View"; |
| 252 break; | 251 break; |
| 253 } | 252 } |
| 254 | 253 |
| 255 return class_name; | 254 return class_name; |
| 256 } | 255 } |
| 257 | 256 |
| 258 base::string16 BrowserAccessibilityAndroid::GetText() const { | 257 base::string16 BrowserAccessibilityAndroid::GetText() const { |
| 259 if (IsIframe() || | 258 if (IsIframe() || |
| 260 role() == blink::WebAXRoleWebArea) { | 259 role() == ui::AX_ROLE_WEB_AREA) { |
| 261 return base::string16(); | 260 return base::string16(); |
| 262 } | 261 } |
| 263 | 262 |
| 264 base::string16 description = GetString16Attribute( | 263 base::string16 description = GetString16Attribute( |
| 265 AccessibilityNodeData::ATTR_DESCRIPTION); | 264 ui::AX_ATTR_DESCRIPTION); |
| 266 base::string16 text; | 265 base::string16 text; |
| 267 if (!name().empty()) | 266 if (!name().empty()) |
| 268 text = base::UTF8ToUTF16(name()); | 267 text = base::UTF8ToUTF16(name()); |
| 269 else if (!description.empty()) | 268 else if (!description.empty()) |
| 270 text = description; | 269 text = description; |
| 271 else if (!value().empty()) | 270 else if (!value().empty()) |
| 272 text = base::UTF8ToUTF16(value()); | 271 text = base::UTF8ToUTF16(value()); |
| 273 | 272 |
| 274 // This is called from PlatformIsLeaf, so don't call PlatformChildCount | 273 // This is called from PlatformIsLeaf, so don't call PlatformChildCount |
| 275 // from within this! | 274 // from within this! |
| 276 if (text.empty() && HasOnlyStaticTextChildren()) { | 275 if (text.empty() && HasOnlyStaticTextChildren()) { |
| 277 for (uint32 i = 0; i < child_count(); i++) { | 276 for (uint32 i = 0; i < child_count(); i++) { |
| 278 BrowserAccessibility* child = children()[i]; | 277 BrowserAccessibility* child = children()[i]; |
| 279 text += static_cast<BrowserAccessibilityAndroid*>(child)->GetText(); | 278 text += static_cast<BrowserAccessibilityAndroid*>(child)->GetText(); |
| 280 } | 279 } |
| 281 } | 280 } |
| 282 | 281 |
| 283 switch(role()) { | 282 switch(role()) { |
| 284 case blink::WebAXRoleImageMapLink: | 283 case ui::AX_ROLE_IMAGE_MAP_LINK: |
| 285 case blink::WebAXRoleLink: | 284 case ui::AX_ROLE_LINK: |
| 286 if (!text.empty()) | 285 if (!text.empty()) |
| 287 text += base::ASCIIToUTF16(" "); | 286 text += base::ASCIIToUTF16(" "); |
| 288 text += base::ASCIIToUTF16("Link"); | 287 text += base::ASCIIToUTF16("Link"); |
| 289 break; | 288 break; |
| 290 case blink::WebAXRoleHeading: | 289 case ui::AX_ROLE_HEADING: |
| 291 // Only append "heading" if this node already has text. | 290 // Only append "heading" if this node already has text. |
| 292 if (!text.empty()) | 291 if (!text.empty()) |
| 293 text += base::ASCIIToUTF16(" Heading"); | 292 text += base::ASCIIToUTF16(" Heading"); |
| 294 break; | 293 break; |
| 295 } | 294 } |
| 296 | 295 |
| 297 return text; | 296 return text; |
| 298 } | 297 } |
| 299 | 298 |
| 300 int BrowserAccessibilityAndroid::GetItemIndex() const { | 299 int BrowserAccessibilityAndroid::GetItemIndex() const { |
| 301 int index = 0; | 300 int index = 0; |
| 302 switch(role()) { | 301 switch(role()) { |
| 303 case blink::WebAXRoleListItem: | 302 case ui::AX_ROLE_LIST_ITEM: |
| 304 case blink::WebAXRoleListBoxOption: | 303 case ui::AX_ROLE_LIST_BOX_OPTION: |
| 305 case blink::WebAXRoleTreeItem: | 304 case ui::AX_ROLE_TREE_ITEM: |
| 306 index = index_in_parent(); | 305 index = index_in_parent(); |
| 307 break; | 306 break; |
| 308 case blink::WebAXRoleSlider: | 307 case ui::AX_ROLE_SLIDER: |
| 309 case blink::WebAXRoleProgressIndicator: { | 308 case ui::AX_ROLE_PROGRESS_INDICATOR: { |
| 310 float value_for_range; | 309 float value_for_range; |
| 311 if (GetFloatAttribute( | 310 if (GetFloatAttribute( |
| 312 AccessibilityNodeData::ATTR_VALUE_FOR_RANGE, &value_for_range)) { | 311 ui::AX_ATTR_VALUE_FOR_RANGE, &value_for_range)) { |
| 313 index = static_cast<int>(value_for_range); | 312 index = static_cast<int>(value_for_range); |
| 314 } | 313 } |
| 315 break; | 314 break; |
| 316 } | 315 } |
| 317 } | 316 } |
| 318 return index; | 317 return index; |
| 319 } | 318 } |
| 320 | 319 |
| 321 int BrowserAccessibilityAndroid::GetItemCount() const { | 320 int BrowserAccessibilityAndroid::GetItemCount() const { |
| 322 int count = 0; | 321 int count = 0; |
| 323 switch(role()) { | 322 switch(role()) { |
| 324 case blink::WebAXRoleList: | 323 case ui::AX_ROLE_LIST: |
| 325 case blink::WebAXRoleListBox: | 324 case ui::AX_ROLE_LIST_BOX: |
| 326 count = PlatformChildCount(); | 325 count = PlatformChildCount(); |
| 327 break; | 326 break; |
| 328 case blink::WebAXRoleSlider: | 327 case ui::AX_ROLE_SLIDER: |
| 329 case blink::WebAXRoleProgressIndicator: { | 328 case ui::AX_ROLE_PROGRESS_INDICATOR: { |
| 330 float max_value_for_range; | 329 float max_value_for_range; |
| 331 if (GetFloatAttribute(AccessibilityNodeData::ATTR_MAX_VALUE_FOR_RANGE, | 330 if (GetFloatAttribute(ui::AX_ATTR_MAX_VALUE_FOR_RANGE, |
| 332 &max_value_for_range)) { | 331 &max_value_for_range)) { |
| 333 count = static_cast<int>(max_value_for_range); | 332 count = static_cast<int>(max_value_for_range); |
| 334 } | 333 } |
| 335 break; | 334 break; |
| 336 } | 335 } |
| 337 } | 336 } |
| 338 return count; | 337 return count; |
| 339 } | 338 } |
| 340 | 339 |
| 341 int BrowserAccessibilityAndroid::GetScrollX() const { | 340 int BrowserAccessibilityAndroid::GetScrollX() const { |
| 342 int value = 0; | 341 int value = 0; |
| 343 GetIntAttribute(AccessibilityNodeData::ATTR_SCROLL_X, &value); | 342 GetIntAttribute(ui::AX_ATTR_SCROLL_X, &value); |
| 344 return value; | 343 return value; |
| 345 } | 344 } |
| 346 | 345 |
| 347 int BrowserAccessibilityAndroid::GetScrollY() const { | 346 int BrowserAccessibilityAndroid::GetScrollY() const { |
| 348 int value = 0; | 347 int value = 0; |
| 349 GetIntAttribute(AccessibilityNodeData::ATTR_SCROLL_Y, &value); | 348 GetIntAttribute(ui::AX_ATTR_SCROLL_Y, &value); |
| 350 return value; | 349 return value; |
| 351 } | 350 } |
| 352 | 351 |
| 353 int BrowserAccessibilityAndroid::GetMaxScrollX() const { | 352 int BrowserAccessibilityAndroid::GetMaxScrollX() const { |
| 354 int value = 0; | 353 int value = 0; |
| 355 GetIntAttribute(AccessibilityNodeData::ATTR_SCROLL_X_MAX, &value); | 354 GetIntAttribute(ui::AX_ATTR_SCROLL_X_MAX, &value); |
| 356 return value; | 355 return value; |
| 357 } | 356 } |
| 358 | 357 |
| 359 int BrowserAccessibilityAndroid::GetMaxScrollY() const { | 358 int BrowserAccessibilityAndroid::GetMaxScrollY() const { |
| 360 int value = 0; | 359 int value = 0; |
| 361 GetIntAttribute(AccessibilityNodeData::ATTR_SCROLL_Y_MAX, &value); | 360 GetIntAttribute(ui::AX_ATTR_SCROLL_Y_MAX, &value); |
| 362 return value; | 361 return value; |
| 363 } | 362 } |
| 364 | 363 |
| 365 int BrowserAccessibilityAndroid::GetTextChangeFromIndex() const { | 364 int BrowserAccessibilityAndroid::GetTextChangeFromIndex() const { |
| 366 size_t index = 0; | 365 size_t index = 0; |
| 367 while (index < old_value_.length() && | 366 while (index < old_value_.length() && |
| 368 index < new_value_.length() && | 367 index < new_value_.length() && |
| 369 old_value_[index] == new_value_[index]) { | 368 old_value_[index] == new_value_[index]) { |
| 370 index++; | 369 index++; |
| 371 } | 370 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 } | 406 } |
| 408 return (old_len - left - right); | 407 return (old_len - left - right); |
| 409 } | 408 } |
| 410 | 409 |
| 411 base::string16 BrowserAccessibilityAndroid::GetTextChangeBeforeText() const { | 410 base::string16 BrowserAccessibilityAndroid::GetTextChangeBeforeText() const { |
| 412 return old_value_; | 411 return old_value_; |
| 413 } | 412 } |
| 414 | 413 |
| 415 int BrowserAccessibilityAndroid::GetSelectionStart() const { | 414 int BrowserAccessibilityAndroid::GetSelectionStart() const { |
| 416 int sel_start = 0; | 415 int sel_start = 0; |
| 417 GetIntAttribute(AccessibilityNodeData::ATTR_TEXT_SEL_START, &sel_start); | 416 GetIntAttribute(ui::AX_ATTR_TEXT_SEL_START, &sel_start); |
| 418 return sel_start; | 417 return sel_start; |
| 419 } | 418 } |
| 420 | 419 |
| 421 int BrowserAccessibilityAndroid::GetSelectionEnd() const { | 420 int BrowserAccessibilityAndroid::GetSelectionEnd() const { |
| 422 int sel_end = 0; | 421 int sel_end = 0; |
| 423 GetIntAttribute(AccessibilityNodeData::ATTR_TEXT_SEL_END, &sel_end); | 422 GetIntAttribute(ui::AX_ATTR_TEXT_SEL_END, &sel_end); |
| 424 return sel_end; | 423 return sel_end; |
| 425 } | 424 } |
| 426 | 425 |
| 427 int BrowserAccessibilityAndroid::GetEditableTextLength() const { | 426 int BrowserAccessibilityAndroid::GetEditableTextLength() const { |
| 428 return value().length(); | 427 return value().length(); |
| 429 } | 428 } |
| 430 | 429 |
| 431 int BrowserAccessibilityAndroid::AndroidInputType() const { | 430 int BrowserAccessibilityAndroid::AndroidInputType() const { |
| 432 std::string html_tag = GetStringAttribute( | 431 std::string html_tag = GetStringAttribute( |
| 433 AccessibilityNodeData::ATTR_HTML_TAG); | 432 ui::AX_ATTR_HTML_TAG); |
| 434 if (html_tag != "input") | 433 if (html_tag != "input") |
| 435 return ANDROID_TEXT_INPUTTYPE_TYPE_NULL; | 434 return ANDROID_TEXT_INPUTTYPE_TYPE_NULL; |
| 436 | 435 |
| 437 std::string type; | 436 std::string type; |
| 438 if (!GetHtmlAttribute("type", &type)) | 437 if (!GetHtmlAttribute("type", &type)) |
| 439 return ANDROID_TEXT_INPUTTYPE_TYPE_TEXT; | 438 return ANDROID_TEXT_INPUTTYPE_TYPE_TEXT; |
| 440 | 439 |
| 441 if (type == "" || type == "text" || type == "search") | 440 if (type == "" || type == "text" || type == "search") |
| 442 return ANDROID_TEXT_INPUTTYPE_TYPE_TEXT; | 441 return ANDROID_TEXT_INPUTTYPE_TYPE_TEXT; |
| 443 else if (type == "date") | 442 else if (type == "date") |
| (...skipping 15 matching lines...) Expand all Loading... |
| 459 else if (type == "url") | 458 else if (type == "url") |
| 460 return ANDROID_TEXT_INPUTTYPE_TYPE_TEXT_URI; | 459 return ANDROID_TEXT_INPUTTYPE_TYPE_TEXT_URI; |
| 461 else if (type == "week") | 460 else if (type == "week") |
| 462 return ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME; | 461 return ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME; |
| 463 | 462 |
| 464 return ANDROID_TEXT_INPUTTYPE_TYPE_NULL; | 463 return ANDROID_TEXT_INPUTTYPE_TYPE_NULL; |
| 465 } | 464 } |
| 466 | 465 |
| 467 int BrowserAccessibilityAndroid::AndroidLiveRegionType() const { | 466 int BrowserAccessibilityAndroid::AndroidLiveRegionType() const { |
| 468 std::string live = GetStringAttribute( | 467 std::string live = GetStringAttribute( |
| 469 AccessibilityNodeData::ATTR_LIVE_STATUS); | 468 ui::AX_ATTR_LIVE_STATUS); |
| 470 if (live == "polite") | 469 if (live == "polite") |
| 471 return ANDROID_VIEW_VIEW_ACCESSIBILITY_LIVE_REGION_POLITE; | 470 return ANDROID_VIEW_VIEW_ACCESSIBILITY_LIVE_REGION_POLITE; |
| 472 else if (live == "assertive") | 471 else if (live == "assertive") |
| 473 return ANDROID_VIEW_VIEW_ACCESSIBILITY_LIVE_REGION_ASSERTIVE; | 472 return ANDROID_VIEW_VIEW_ACCESSIBILITY_LIVE_REGION_ASSERTIVE; |
| 474 return ANDROID_VIEW_VIEW_ACCESSIBILITY_LIVE_REGION_NONE; | 473 return ANDROID_VIEW_VIEW_ACCESSIBILITY_LIVE_REGION_NONE; |
| 475 } | 474 } |
| 476 | 475 |
| 477 int BrowserAccessibilityAndroid::AndroidRangeType() const { | 476 int BrowserAccessibilityAndroid::AndroidRangeType() const { |
| 478 return ANDROID_VIEW_ACCESSIBILITY_RANGE_TYPE_FLOAT; | 477 return ANDROID_VIEW_ACCESSIBILITY_RANGE_TYPE_FLOAT; |
| 479 } | 478 } |
| 480 | 479 |
| 481 int BrowserAccessibilityAndroid::RowCount() const { | 480 int BrowserAccessibilityAndroid::RowCount() const { |
| 482 if (role() == blink::WebAXRoleGrid || | 481 if (role() == ui::AX_ROLE_GRID || |
| 483 role() == blink::WebAXRoleTable) { | 482 role() == ui::AX_ROLE_TABLE) { |
| 484 return CountChildrenWithRole(blink::WebAXRoleRow); | 483 return CountChildrenWithRole(ui::AX_ROLE_ROW); |
| 485 } | 484 } |
| 486 | 485 |
| 487 if (role() == blink::WebAXRoleList || | 486 if (role() == ui::AX_ROLE_LIST || |
| 488 role() == blink::WebAXRoleListBox || | 487 role() == ui::AX_ROLE_LIST_BOX || |
| 489 role() == blink::WebAXRoleTree) { | 488 role() == ui::AX_ROLE_TREE) { |
| 490 return PlatformChildCount(); | 489 return PlatformChildCount(); |
| 491 } | 490 } |
| 492 | 491 |
| 493 return 0; | 492 return 0; |
| 494 } | 493 } |
| 495 | 494 |
| 496 int BrowserAccessibilityAndroid::ColumnCount() const { | 495 int BrowserAccessibilityAndroid::ColumnCount() const { |
| 497 if (role() == blink::WebAXRoleGrid || | 496 if (role() == ui::AX_ROLE_GRID || |
| 498 role() == blink::WebAXRoleTable) { | 497 role() == ui::AX_ROLE_TABLE) { |
| 499 return CountChildrenWithRole(blink::WebAXRoleColumn); | 498 return CountChildrenWithRole(ui::AX_ROLE_COLUMN); |
| 500 } | 499 } |
| 501 return 0; | 500 return 0; |
| 502 } | 501 } |
| 503 | 502 |
| 504 int BrowserAccessibilityAndroid::RowIndex() const { | 503 int BrowserAccessibilityAndroid::RowIndex() const { |
| 505 if (role() == blink::WebAXRoleListItem || | 504 if (role() == ui::AX_ROLE_LIST_ITEM || |
| 506 role() == blink::WebAXRoleListBoxOption || | 505 role() == ui::AX_ROLE_LIST_BOX_OPTION || |
| 507 role() == blink::WebAXRoleTreeItem) { | 506 role() == ui::AX_ROLE_TREE_ITEM) { |
| 508 return index_in_parent(); | 507 return index_in_parent(); |
| 509 } | 508 } |
| 510 | 509 |
| 511 return GetIntAttribute(AccessibilityNodeData::ATTR_TABLE_CELL_ROW_INDEX); | 510 return GetIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_INDEX); |
| 512 } | 511 } |
| 513 | 512 |
| 514 int BrowserAccessibilityAndroid::RowSpan() const { | 513 int BrowserAccessibilityAndroid::RowSpan() const { |
| 515 return GetIntAttribute(AccessibilityNodeData::ATTR_TABLE_CELL_ROW_SPAN); | 514 return GetIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_SPAN); |
| 516 } | 515 } |
| 517 | 516 |
| 518 int BrowserAccessibilityAndroid::ColumnIndex() const { | 517 int BrowserAccessibilityAndroid::ColumnIndex() const { |
| 519 return GetIntAttribute(AccessibilityNodeData::ATTR_TABLE_CELL_COLUMN_INDEX); | 518 return GetIntAttribute(ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX); |
| 520 } | 519 } |
| 521 | 520 |
| 522 int BrowserAccessibilityAndroid::ColumnSpan() const { | 521 int BrowserAccessibilityAndroid::ColumnSpan() const { |
| 523 return GetIntAttribute(AccessibilityNodeData::ATTR_TABLE_CELL_COLUMN_SPAN); | 522 return GetIntAttribute(ui::AX_ATTR_TABLE_CELL_COLUMN_SPAN); |
| 524 } | 523 } |
| 525 | 524 |
| 526 float BrowserAccessibilityAndroid::RangeMin() const { | 525 float BrowserAccessibilityAndroid::RangeMin() const { |
| 527 return GetFloatAttribute(AccessibilityNodeData::ATTR_MIN_VALUE_FOR_RANGE); | 526 return GetFloatAttribute(ui::AX_ATTR_MIN_VALUE_FOR_RANGE); |
| 528 } | 527 } |
| 529 | 528 |
| 530 float BrowserAccessibilityAndroid::RangeMax() const { | 529 float BrowserAccessibilityAndroid::RangeMax() const { |
| 531 return GetFloatAttribute(AccessibilityNodeData::ATTR_MAX_VALUE_FOR_RANGE); | 530 return GetFloatAttribute(ui::AX_ATTR_MAX_VALUE_FOR_RANGE); |
| 532 } | 531 } |
| 533 | 532 |
| 534 float BrowserAccessibilityAndroid::RangeCurrentValue() const { | 533 float BrowserAccessibilityAndroid::RangeCurrentValue() const { |
| 535 return GetFloatAttribute(AccessibilityNodeData::ATTR_VALUE_FOR_RANGE); | 534 return GetFloatAttribute(ui::AX_ATTR_VALUE_FOR_RANGE); |
| 536 } | 535 } |
| 537 | 536 |
| 538 bool BrowserAccessibilityAndroid::HasFocusableChild() const { | 537 bool BrowserAccessibilityAndroid::HasFocusableChild() const { |
| 539 // This is called from PlatformIsLeaf, so don't call PlatformChildCount | 538 // This is called from PlatformIsLeaf, so don't call PlatformChildCount |
| 540 // from within this! | 539 // from within this! |
| 541 for (uint32 i = 0; i < child_count(); i++) { | 540 for (uint32 i = 0; i < child_count(); i++) { |
| 542 BrowserAccessibility* child = children()[i]; | 541 BrowserAccessibility* child = children()[i]; |
| 543 if (child->HasState(blink::WebAXStateFocusable)) | 542 if (child->HasState(ui::AX_STATE_FOCUSABLE)) |
| 544 return true; | 543 return true; |
| 545 if (static_cast<BrowserAccessibilityAndroid*>(child)->HasFocusableChild()) | 544 if (static_cast<BrowserAccessibilityAndroid*>(child)->HasFocusableChild()) |
| 546 return true; | 545 return true; |
| 547 } | 546 } |
| 548 return false; | 547 return false; |
| 549 } | 548 } |
| 550 | 549 |
| 551 bool BrowserAccessibilityAndroid::HasOnlyStaticTextChildren() const { | 550 bool BrowserAccessibilityAndroid::HasOnlyStaticTextChildren() const { |
| 552 // This is called from PlatformIsLeaf, so don't call PlatformChildCount | 551 // This is called from PlatformIsLeaf, so don't call PlatformChildCount |
| 553 // from within this! | 552 // from within this! |
| 554 for (uint32 i = 0; i < child_count(); i++) { | 553 for (uint32 i = 0; i < child_count(); i++) { |
| 555 BrowserAccessibility* child = children()[i]; | 554 BrowserAccessibility* child = children()[i]; |
| 556 if (child->role() != blink::WebAXRoleStaticText) | 555 if (child->role() != ui::AX_ROLE_STATIC_TEXT) |
| 557 return false; | 556 return false; |
| 558 } | 557 } |
| 559 return true; | 558 return true; |
| 560 } | 559 } |
| 561 | 560 |
| 562 bool BrowserAccessibilityAndroid::IsIframe() const { | 561 bool BrowserAccessibilityAndroid::IsIframe() const { |
| 563 base::string16 html_tag = GetString16Attribute( | 562 base::string16 html_tag = GetString16Attribute( |
| 564 AccessibilityNodeData::ATTR_HTML_TAG); | 563 ui::AX_ATTR_HTML_TAG); |
| 565 return html_tag == base::ASCIIToUTF16("iframe"); | 564 return html_tag == base::ASCIIToUTF16("iframe"); |
| 566 } | 565 } |
| 567 | 566 |
| 568 void BrowserAccessibilityAndroid::PostInitialize() { | 567 void BrowserAccessibilityAndroid::PostInitialize() { |
| 569 BrowserAccessibility::PostInitialize(); | 568 BrowserAccessibility::PostInitialize(); |
| 570 | 569 |
| 571 if (IsEditableText()) { | 570 if (IsEditableText()) { |
| 572 if (base::UTF8ToUTF16(value()) != new_value_) { | 571 if (base::UTF8ToUTF16(value()) != new_value_) { |
| 573 old_value_ = new_value_; | 572 old_value_ = new_value_; |
| 574 new_value_ = base::UTF8ToUTF16(value()); | 573 new_value_ = base::UTF8ToUTF16(value()); |
| 575 } | 574 } |
| 576 } | 575 } |
| 577 | 576 |
| 578 if (role() == blink::WebAXRoleAlert && first_time_) | 577 if (role() == ui::AX_ROLE_ALERT && first_time_) |
| 579 manager()->NotifyAccessibilityEvent(blink::WebAXEventAlert, this); | 578 manager()->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, this); |
| 580 | 579 |
| 581 base::string16 live; | 580 base::string16 live; |
| 582 if (GetString16Attribute( | 581 if (GetString16Attribute( |
| 583 AccessibilityNodeData::ATTR_CONTAINER_LIVE_STATUS, &live)) { | 582 ui::AX_ATTR_CONTAINER_LIVE_STATUS, &live)) { |
| 584 NotifyLiveRegionUpdate(live); | 583 NotifyLiveRegionUpdate(live); |
| 585 } | 584 } |
| 586 | 585 |
| 587 first_time_ = false; | 586 first_time_ = false; |
| 588 } | 587 } |
| 589 | 588 |
| 590 void BrowserAccessibilityAndroid::NotifyLiveRegionUpdate( | 589 void BrowserAccessibilityAndroid::NotifyLiveRegionUpdate( |
| 591 base::string16& aria_live) { | 590 base::string16& aria_live) { |
| 592 if (!EqualsASCII(aria_live, aria_strings::kAriaLivePolite) && | 591 if (!EqualsASCII(aria_live, aria_strings::kAriaLivePolite) && |
| 593 !EqualsASCII(aria_live, aria_strings::kAriaLiveAssertive)) | 592 !EqualsASCII(aria_live, aria_strings::kAriaLiveAssertive)) |
| 594 return; | 593 return; |
| 595 | 594 |
| 596 base::string16 text = GetText(); | 595 base::string16 text = GetText(); |
| 597 if (cached_text_ != text) { | 596 if (cached_text_ != text) { |
| 598 if (!text.empty()) { | 597 if (!text.empty()) { |
| 599 manager()->NotifyAccessibilityEvent(blink::WebAXEventShow, | 598 manager()->NotifyAccessibilityEvent(ui::AX_EVENT_SHOW, |
| 600 this); | 599 this); |
| 601 } | 600 } |
| 602 cached_text_ = text; | 601 cached_text_ = text; |
| 603 } | 602 } |
| 604 } | 603 } |
| 605 | 604 |
| 606 int BrowserAccessibilityAndroid::CountChildrenWithRole( | 605 int BrowserAccessibilityAndroid::CountChildrenWithRole(ui::AXRole role) const { |
| 607 blink::WebAXRole role) const { | |
| 608 int count = 0; | 606 int count = 0; |
| 609 for (uint32 i = 0; i < PlatformChildCount(); i++) { | 607 for (uint32 i = 0; i < PlatformChildCount(); i++) { |
| 610 if (PlatformGetChild(i)->role() == role) | 608 if (PlatformGetChild(i)->role() == role) |
| 611 count++; | 609 count++; |
| 612 } | 610 } |
| 613 return count; | 611 return count; |
| 614 } | 612 } |
| 615 | 613 |
| 616 } // namespace content | 614 } // namespace content |
| OLD | NEW |