| 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/i18n/break_iterator.h" | 7 #include "base/i18n/break_iterator.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 133 |
| 134 // Nodes with only static text as children can drop their children. | 134 // Nodes with only static text as children can drop their children. |
| 135 if (HasOnlyTextChildren()) | 135 if (HasOnlyTextChildren()) |
| 136 return true; | 136 return true; |
| 137 } | 137 } |
| 138 | 138 |
| 139 return false; | 139 return false; |
| 140 } | 140 } |
| 141 | 141 |
| 142 bool BrowserAccessibilityAndroid::IsCheckable() const { | 142 bool BrowserAccessibilityAndroid::IsCheckable() const { |
| 143 bool checkable = false; | 143 return GetRole() == ui::AX_ROLE_CHECK_BOX || |
| 144 bool is_aria_pressed_defined; | 144 GetRole() == ui::AX_ROLE_RADIO_BUTTON || |
| 145 bool is_mixed; | 145 GetRole() == ui::AX_ROLE_MENU_ITEM_CHECK_BOX || |
| 146 GetAriaTristate("aria-pressed", &is_aria_pressed_defined, &is_mixed); | 146 GetRole() == ui::AX_ROLE_MENU_ITEM_RADIO || |
| 147 if (GetRole() == ui::AX_ROLE_CHECK_BOX || | 147 GetRole() == ui::AX_ROLE_TOGGLE_BUTTON || |
| 148 GetRole() == ui::AX_ROLE_RADIO_BUTTON || | 148 // TODO(aleventhal) does this ever happen when checkable is not true |
| 149 GetRole() == ui::AX_ROLE_MENU_ITEM_CHECK_BOX || | 149 // yet? |
| 150 GetRole() == ui::AX_ROLE_MENU_ITEM_RADIO || | 150 HasIntAttribute(ui::AX_ATTR_CHECKED_STATE); |
| 151 is_aria_pressed_defined) { | |
| 152 checkable = true; | |
| 153 } | |
| 154 // TODO(aleventhal) does this ever happen when checkable is not true yet? | |
| 155 if (HasIntAttribute(ui::AX_ATTR_CHECKED_STATE)) | |
| 156 checkable = true; | |
| 157 return checkable; | |
| 158 } | 151 } |
| 159 | 152 |
| 160 bool BrowserAccessibilityAndroid::IsChecked() const { | 153 bool BrowserAccessibilityAndroid::IsChecked() const { |
| 161 const auto checked_state = static_cast<ui::AXCheckedState>( | 154 const auto checked_state = static_cast<ui::AXButtonState>( |
| 162 GetIntAttribute(ui::AX_ATTR_CHECKED_STATE)); | 155 GetIntAttribute(ui::AX_ATTR_CHECKED_STATE)); |
| 163 return (checked_state == ui::AX_CHECKED_STATE_TRUE || | 156 const auto pressed_state = static_cast<ui::AXButtonState>( |
| 164 HasState(ui::AX_STATE_PRESSED)); | 157 GetIntAttribute(ui::AX_ATTR_PRESSED_STATE)); |
| 158 return (checked_state == ui::AX_BUTTON_STATE_TRUE || |
| 159 pressed_state == ui::AX_BUTTON_STATE_TRUE); |
| 165 } | 160 } |
| 166 | 161 |
| 167 bool BrowserAccessibilityAndroid::IsClickable() const { | 162 bool BrowserAccessibilityAndroid::IsClickable() const { |
| 168 // If it has a custom default action verb, it's definitely clickable. | 163 // If it has a custom default action verb, it's definitely clickable. |
| 169 if (HasIntAttribute(ui::AX_ATTR_DEFAULT_ACTION_VERB)) | 164 if (HasIntAttribute(ui::AX_ATTR_DEFAULT_ACTION_VERB)) |
| 170 return true; | 165 return true; |
| 171 | 166 |
| 172 // Otherwise return true if it's focusable, but skip web areas and iframes. | 167 // Otherwise return true if it's focusable, but skip web areas and iframes. |
| 173 if (IsIframe() || (GetRole() == ui::AX_ROLE_ROOT_WEB_AREA)) | 168 if (IsIframe() || (GetRole() == ui::AX_ROLE_ROOT_WEB_AREA)) |
| 174 return false; | 169 return false; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 190 return (GetRole() == ui::AX_ROLE_CELL || | 185 return (GetRole() == ui::AX_ROLE_CELL || |
| 191 GetRole() == ui::AX_ROLE_COLUMN_HEADER || | 186 GetRole() == ui::AX_ROLE_COLUMN_HEADER || |
| 192 GetRole() == ui::AX_ROLE_DESCRIPTION_LIST_TERM || | 187 GetRole() == ui::AX_ROLE_DESCRIPTION_LIST_TERM || |
| 193 GetRole() == ui::AX_ROLE_LIST_BOX_OPTION || | 188 GetRole() == ui::AX_ROLE_LIST_BOX_OPTION || |
| 194 GetRole() == ui::AX_ROLE_LIST_ITEM || | 189 GetRole() == ui::AX_ROLE_LIST_ITEM || |
| 195 GetRole() == ui::AX_ROLE_ROW_HEADER || | 190 GetRole() == ui::AX_ROLE_ROW_HEADER || |
| 196 GetRole() == ui::AX_ROLE_TREE_ITEM); | 191 GetRole() == ui::AX_ROLE_TREE_ITEM); |
| 197 } | 192 } |
| 198 | 193 |
| 199 bool BrowserAccessibilityAndroid::IsContentInvalid() const { | 194 bool BrowserAccessibilityAndroid::IsContentInvalid() const { |
| 200 std::string invalid; | 195 return HasIntAttribute(ui::AX_ATTR_INVALID_STATE) && |
| 201 return GetHtmlAttribute("aria-invalid", &invalid); | 196 GetIntAttribute(ui::AX_ATTR_INVALID_STATE) != ui |
| 197 : AX_ATTR_INVALID_STATE_FALSE; |
| 202 } | 198 } |
| 203 | 199 |
| 204 bool BrowserAccessibilityAndroid::IsDismissable() const { | 200 bool BrowserAccessibilityAndroid::IsDismissable() const { |
| 205 return false; // No concept of "dismissable" on the web currently. | 201 return false; // No concept of "dismissable" on the web currently. |
| 206 } | 202 } |
| 207 | 203 |
| 208 bool BrowserAccessibilityAndroid::IsEditableText() const { | 204 bool BrowserAccessibilityAndroid::IsEditableText() const { |
| 209 return GetRole() == ui::AX_ROLE_TEXT_FIELD; | 205 return GetRole() == ui::AX_ROLE_TEXT_FIELD; |
| 210 } | 206 } |
| 211 | 207 |
| (...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1104 return value.length(); | 1100 return value.length(); |
| 1105 } | 1101 } |
| 1106 | 1102 |
| 1107 int BrowserAccessibilityAndroid::AndroidInputType() const { | 1103 int BrowserAccessibilityAndroid::AndroidInputType() const { |
| 1108 std::string html_tag = GetStringAttribute( | 1104 std::string html_tag = GetStringAttribute( |
| 1109 ui::AX_ATTR_HTML_TAG); | 1105 ui::AX_ATTR_HTML_TAG); |
| 1110 if (html_tag != "input") | 1106 if (html_tag != "input") |
| 1111 return ANDROID_TEXT_INPUTTYPE_TYPE_NULL; | 1107 return ANDROID_TEXT_INPUTTYPE_TYPE_NULL; |
| 1112 | 1108 |
| 1113 std::string type; | 1109 std::string type; |
| 1114 if (!GetHtmlAttribute("type", &type)) | 1110 if (!GetData().GetHtmlAttribute("type", type)) |
| 1115 return ANDROID_TEXT_INPUTTYPE_TYPE_TEXT; | 1111 return ANDROID_TEXT_INPUTTYPE_TYPE_TEXT; |
| 1116 | 1112 |
| 1117 if (type.empty() || type == "text" || type == "search") | 1113 if (type.empty() || type == "text" || type == "search") |
| 1118 return ANDROID_TEXT_INPUTTYPE_TYPE_TEXT; | 1114 return ANDROID_TEXT_INPUTTYPE_TYPE_TEXT; |
| 1119 else if (type == "date") | 1115 else if (type == "date") |
| 1120 return ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME_DATE; | 1116 return ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME_DATE; |
| 1121 else if (type == "datetime" || type == "datetime-local") | 1117 else if (type == "datetime" || type == "datetime-local") |
| 1122 return ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME; | 1118 return ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME; |
| 1123 else if (type == "email") | 1119 else if (type == "email") |
| 1124 return ANDROID_TEXT_INPUTTYPE_TYPE_TEXT_WEB_EMAIL; | 1120 return ANDROID_TEXT_INPUTTYPE_TYPE_TEXT_WEB_EMAIL; |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1416 int BrowserAccessibilityAndroid::CountChildrenWithRole(ui::AXRole role) const { | 1412 int BrowserAccessibilityAndroid::CountChildrenWithRole(ui::AXRole role) const { |
| 1417 int count = 0; | 1413 int count = 0; |
| 1418 for (uint32_t i = 0; i < PlatformChildCount(); i++) { | 1414 for (uint32_t i = 0; i < PlatformChildCount(); i++) { |
| 1419 if (PlatformGetChild(i)->GetRole() == role) | 1415 if (PlatformGetChild(i)->GetRole() == role) |
| 1420 count++; | 1416 count++; |
| 1421 } | 1417 } |
| 1422 return count; | 1418 return count; |
| 1423 } | 1419 } |
| 1424 | 1420 |
| 1425 } // namespace content | 1421 } // namespace content |
| OLD | NEW |