Index: third_party/WebKit/Source/modules/accessibility/AXObject.cpp |
diff --git a/third_party/WebKit/Source/modules/accessibility/AXObject.cpp b/third_party/WebKit/Source/modules/accessibility/AXObject.cpp |
index 2e9b20e6a8035cd0d300595e0428bb40c482abc3..e6e5b1c124f0ed27d4dd1098c25698722b184edf 100644 |
--- a/third_party/WebKit/Source/modules/accessibility/AXObject.cpp |
+++ b/third_party/WebKit/Source/modules/accessibility/AXObject.cpp |
@@ -38,7 +38,9 @@ |
#include "core/frame/Settings.h" |
#include "core/html/HTMLDialogElement.h" |
#include "core/html/HTMLFrameOwnerElement.h" |
+#include "core/html/HTMLInputElement.h" |
#include "core/html/parser/HTMLParserIdioms.h" |
+#include "core/InputTypeNames.h" |
#include "core/layout/LayoutBoxModelObject.h" |
#include "modules/accessibility/AXObjectCacheImpl.h" |
#include "platform/UserGestureIndicator.h" |
@@ -391,6 +393,71 @@ bool AXObject::isButton() const { |
role == ToggleButtonRole; |
} |
+bool AXObject::isCheckable() const { |
+ switch (roleValue()) { |
+ case CheckBoxRole: |
+ case MenuItemCheckBoxRole: |
+ case MenuItemRadioRole: |
+ case RadioButtonRole: |
+ case SwitchRole: |
+ return true; |
+ default: |
+ return false; |
+ } |
+} |
+ |
+bool AXObject::isChecked() const { |
+ return checkboxOrRadioState() == ButtonStateOn; |
+} |
+ |
+// Why this is here instead of AXNodeObject: |
+// Because an AXMenuListOption (<option>) can |
+// have an ARIA role of menuitemcheckbox/menuitemradio |
+// yet does not inherit from AXNodeObject |
+AccessibilityButtonState AXObject::checkboxOrRadioState() const { |
+ if (isCheckable() && hasAttribute(aria_checkedAttr)) { |
+ const AtomicString& checkedAttribute = getAttribute(aria_checkedAttr); |
+ if (equalIgnoringCase(checkedAttribute, "true")) |
+ return ButtonStateOn; |
+ |
+ if (equalIgnoringCase(checkedAttribute, "mixed")) { |
+ // Only checkboxes should support the mixed state. |
dmazzoni
2017/02/16 20:56:04
This comment disagrees with the code below
aleventhal
2017/02/24 21:44:02
Done.
|
+ const AccessibilityRole role = roleValue(); |
+ if (role == CheckBoxRole || role == MenuItemCheckBoxRole || |
dmazzoni
2017/02/16 20:56:04
Is the set of roles checked here different than th
aleventhal
2017/02/24 21:44:02
Yes, it doesn't include the Switch role.
|
+ role == RadioButtonRole || role == MenuItemRadioRole) |
+ return ButtonStateMixed; |
+ } |
+ |
+ return ButtonStateOff; |
+ } |
+ |
+ const Node* node = this->getNode(); |
+ if (!node) |
+ return ButtonStateOff; |
+ |
+ if (isNativeInputInMixedState(node)) |
+ return ButtonStateMixed; |
+ |
+ if (isHTMLInputElement(*node) && |
+ toHTMLInputElement(*node).shouldAppearChecked()) { |
+ return ButtonStateOn; |
+ } |
+ |
+ return ButtonStateOff; |
+} |
+ |
+bool AXObject::isNativeInputInMixedState(const Node* node) { |
+ if (!isHTMLInputElement(node)) |
+ return false; |
+ |
+ const HTMLInputElement* input = toHTMLInputElement(node); |
+ const auto inputType = input->type(); |
+ if (inputType != InputTypeNames::checkbox && |
+ inputType != InputTypeNames::radio) |
+ return false; |
+ return input->shouldAppearIndeterminate(); |
dmazzoni
2017/02/16 20:56:04
Is it necessary to check the type? I wonder if
sho
aleventhal
2017/02/24 21:44:01
It doesn't right now. What do you think about keep
|
+} |
+ |
bool AXObject::isLandmarkRelated() const { |
switch (roleValue()) { |
case ApplicationRole: |
@@ -937,21 +1004,6 @@ AXSupportedAction AXObject::action() const { |
} |
} |
-AccessibilityButtonState AXObject::checkboxOrRadioValue() const { |
- const AtomicString& checkedAttribute = getAttribute(aria_checkedAttr); |
- if (equalIgnoringCase(checkedAttribute, "true")) |
- return ButtonStateOn; |
- |
- if (equalIgnoringCase(checkedAttribute, "mixed")) { |
- // Only checkboxes should support the mixed state. |
- AccessibilityRole role = ariaRoleAttribute(); |
- if (role == CheckBoxRole || role == MenuItemCheckBoxRole) |
- return ButtonStateMixed; |
- } |
- |
- return ButtonStateOff; |
-} |
- |
bool AXObject::isMultiline() const { |
Node* node = this->getNode(); |
if (!node) |