| 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 if (HasState(ui::AX_STATE_CHECKED)) | 147 if (HasState(ui::AX_STATE_CHECKED)) |
| 148 checkable = true; | 148 checkable = true; |
| 149 return checkable; | 149 return checkable; |
| 150 } | 150 } |
| 151 | 151 |
| 152 bool BrowserAccessibilityAndroid::IsChecked() const { | 152 bool BrowserAccessibilityAndroid::IsChecked() const { |
| 153 return (HasState(ui::AX_STATE_CHECKED) || HasState(ui::AX_STATE_PRESSED)); | 153 return (HasState(ui::AX_STATE_CHECKED) || HasState(ui::AX_STATE_PRESSED)); |
| 154 } | 154 } |
| 155 | 155 |
| 156 bool BrowserAccessibilityAndroid::IsClickable() const { | 156 bool BrowserAccessibilityAndroid::IsClickable() const { |
| 157 if (!PlatformIsLeaf()) | 157 // If it has a default action, it's definitely clickable. |
| 158 if (HasStringAttribute(ui::AX_ATTR_ACTION)) |
| 159 return true; |
| 160 |
| 161 // Otherwise return true if it's focusable, but skip web areas and iframes. |
| 162 if (IsIframe() || (GetRole() == ui::AX_ROLE_ROOT_WEB_AREA)) |
| 158 return false; | 163 return false; |
| 159 | 164 return IsFocusable(); |
| 160 // We are very aggressive about returning true with IsClickable on Android | |
| 161 // because there is no way to know for sure what might have a click handler. | |
| 162 return IsFocusable() || !GetText().empty(); | |
| 163 } | 165 } |
| 164 | 166 |
| 165 bool BrowserAccessibilityAndroid::IsCollapsed() const { | 167 bool BrowserAccessibilityAndroid::IsCollapsed() const { |
| 166 return HasState(ui::AX_STATE_COLLAPSED); | 168 return HasState(ui::AX_STATE_COLLAPSED); |
| 167 } | 169 } |
| 168 | 170 |
| 169 bool BrowserAccessibilityAndroid::IsCollection() const { | 171 bool BrowserAccessibilityAndroid::IsCollection() const { |
| 170 return (GetRole() == ui::AX_ROLE_GRID || | 172 return (GetRole() == ui::AX_ROLE_GRID || |
| 171 GetRole() == ui::AX_ROLE_LIST || | 173 GetRole() == ui::AX_ROLE_LIST || |
| 172 GetRole() == ui::AX_ROLE_LIST_BOX || | 174 GetRole() == ui::AX_ROLE_LIST_BOX || |
| (...skipping 27 matching lines...) Expand all Loading... |
| 200 | 202 |
| 201 bool BrowserAccessibilityAndroid::IsEnabled() const { | 203 bool BrowserAccessibilityAndroid::IsEnabled() const { |
| 202 return !HasState(ui::AX_STATE_DISABLED); | 204 return !HasState(ui::AX_STATE_DISABLED); |
| 203 } | 205 } |
| 204 | 206 |
| 205 bool BrowserAccessibilityAndroid::IsExpanded() const { | 207 bool BrowserAccessibilityAndroid::IsExpanded() const { |
| 206 return HasState(ui::AX_STATE_EXPANDED); | 208 return HasState(ui::AX_STATE_EXPANDED); |
| 207 } | 209 } |
| 208 | 210 |
| 209 bool BrowserAccessibilityAndroid::IsFocusable() const { | 211 bool BrowserAccessibilityAndroid::IsFocusable() const { |
| 210 bool focusable = HasState(ui::AX_STATE_FOCUSABLE); | 212 // If it's an iframe element, or the root element of a child frame, |
| 211 if (IsIframe() || | 213 // only mark it as focusable if the element has an explicit name. |
| 212 GetRole() == ui::AX_ROLE_WEB_AREA) { | 214 // Otherwise mark it as not focusable to avoid the user landing on |
| 213 focusable = false; | 215 // empty container elements in the tree. |
| 214 } | 216 if (IsIframe() || (GetRole() == ui::AX_ROLE_ROOT_WEB_AREA && GetParent())) |
| 215 return focusable; | 217 return HasStringAttribute(ui::AX_ATTR_NAME); |
| 218 |
| 219 return HasState(ui::AX_STATE_FOCUSABLE); |
| 216 } | 220 } |
| 217 | 221 |
| 218 bool BrowserAccessibilityAndroid::IsFocused() const { | 222 bool BrowserAccessibilityAndroid::IsFocused() const { |
| 219 return manager()->GetFocus() == this; | 223 return manager()->GetFocus() == this; |
| 220 } | 224 } |
| 221 | 225 |
| 222 bool BrowserAccessibilityAndroid::IsHeading() const { | 226 bool BrowserAccessibilityAndroid::IsHeading() const { |
| 223 BrowserAccessibilityAndroid* parent = | 227 BrowserAccessibilityAndroid* parent = |
| 224 static_cast<BrowserAccessibilityAndroid*>(GetParent()); | 228 static_cast<BrowserAccessibilityAndroid*>(GetParent()); |
| 225 if (parent && parent->IsHeading()) | 229 if (parent && parent->IsHeading()) |
| (...skipping 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1424 int BrowserAccessibilityAndroid::CountChildrenWithRole(ui::AXRole role) const { | 1428 int BrowserAccessibilityAndroid::CountChildrenWithRole(ui::AXRole role) const { |
| 1425 int count = 0; | 1429 int count = 0; |
| 1426 for (uint32_t i = 0; i < PlatformChildCount(); i++) { | 1430 for (uint32_t i = 0; i < PlatformChildCount(); i++) { |
| 1427 if (PlatformGetChild(i)->GetRole() == role) | 1431 if (PlatformGetChild(i)->GetRole() == role) |
| 1428 count++; | 1432 count++; |
| 1429 } | 1433 } |
| 1430 return count; | 1434 return count; |
| 1431 } | 1435 } |
| 1432 | 1436 |
| 1433 } // namespace content | 1437 } // namespace content |
| OLD | NEW |