AX: <details> element should allow expand/close through AX API
authorcfleizach@apple.com <cfleizach@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Jul 2015 18:38:39 +0000 (18:38 +0000)
committercfleizach@apple.com <cfleizach@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Jul 2015 18:38:39 +0000 (18:38 +0000)
https://bugs.webkit.org/show_bug.cgi?id=146549

Reviewed by Mario Sanchez Prada.

Source/WebCore:

Allow AXExpanded to be writeable for <details> element, which, when set
will toggle the opening and closing of the element.
Post a notification when that happens as well.

Modified test: platform/mac/accessibility/details-summary.html

* accessibility/AccessibilityNodeObject.cpp:
(WebCore::AccessibilityNodeObject::hierarchicalLevel):
(WebCore::AccessibilityNodeObject::setIsExpanded):
(WebCore::shouldUseAccessibilityObjectInnerText):
* accessibility/AccessibilityNodeObject.h:
* accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::supportsPressAction):
* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::canSetExpandedAttribute):
* accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
(-[WebAccessibilityObjectWrapper accessibilityIsAttributeSettable:]):
(-[WebAccessibilityObjectWrapper _accessibilitySetValue:forAttribute:]):
* html/HTMLDetailsElement.cpp:
(WebCore::HTMLDetailsElement::toggleOpen):

LayoutTests:

* platform/mac/accessibility/details-summary-expected.txt:
* platform/mac/accessibility/details-summary.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@186598 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/platform/mac/accessibility/details-summary-expected.txt
LayoutTests/platform/mac/accessibility/details-summary.html
Source/WebCore/ChangeLog
Source/WebCore/accessibility/AccessibilityNodeObject.cpp
Source/WebCore/accessibility/AccessibilityNodeObject.h
Source/WebCore/accessibility/AccessibilityObject.cpp
Source/WebCore/accessibility/AccessibilityRenderObject.cpp
Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm

index 83938a4..94c12a3 100644 (file)
@@ -1,3 +1,13 @@
+2015-07-02  Chris Fleizach  <cfleizach@apple.com>
+
+        AX: <details> element should allow expand/close through AX API
+        https://bugs.webkit.org/show_bug.cgi?id=146549
+
+        Reviewed by Mario Sanchez Prada.
+
+        * platform/mac/accessibility/details-summary-expected.txt:
+        * platform/mac/accessibility/details-summary.html:
+
 2015-07-09  Alex Christensen  <achristensen@webkit.org>
 
         [Content Extensions] Prevent crashes with plugins.
index 9af177f..7581043 100644 (file)
@@ -12,8 +12,15 @@ PASS details1.subrole is 'AXSubrole: AXDetails'
 PASS details1.isExpanded is true
 PASS details1.childAtIndex(0).role is 'AXRole: AXGroup'
 PASS details1.childAtIndex(0).subrole is 'AXSubrole: AXSummary'
+PASS details1.isAttributeSettable('AXExpanded') is true
+PASS details1.isExpanded is false
+PASS details1.isExpanded is false
+PASS details1.isExpanded is true
+PASS details1.isExpanded is true
 PASS details2.subrole is 'AXSubrole: AXDetails'
 PASS details2.isExpanded is false
+Received AXExpandedChanged notification 
+Received AXExpandedChanged notification 
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 44dd166..8170806 100644 (file)
 
     description("This tests some basic attributes about the details element.");
 
+    var callbackCount = 0;
     if (window.accessibilityController) {
+        window.jsTestIsAsync = true;
+
+        var body = accessibilityController.rootElement.childAtIndex(0);
+        body.addNotificationListener(function(notification) {
+            if (notification == "AXExpandedChanged") {
+                callbackCount++;
+                debug("Received " + notification + " notification ");
+
+                if (callbackCount == 2) {
+                   finishJSTest();
+                }
+            }
+        });
 
         var details1 = accessibilityController.accessibleElementById("details1");
         shouldBe("details1.role", "'AXRole: AXGroup'");
         shouldBeTrue("details1.isExpanded");
         shouldBe("details1.childAtIndex(0).role", "'AXRole: AXGroup'");
         shouldBe("details1.childAtIndex(0).subrole", "'AXSubrole: AXSummary'");
+        shouldBeTrue("details1.isAttributeSettable('AXExpanded')");
+
+        // Toggle the expanded state.
+        details1.setBoolAttributeValue("AXExpanded", false);
+        details1 = accessibilityController.accessibleElementById("details1");
+        shouldBeFalse("details1.isExpanded");
+
+        // Give it the same value to make sure we don't expand.
+        details1.setBoolAttributeValue("AXExpanded", false);
+        details1 = accessibilityController.accessibleElementById("details1");
+        shouldBeFalse("details1.isExpanded");
+
+        // Set to expand again.
+        details1.setBoolAttributeValue("AXExpanded", true);
+        details1 = accessibilityController.accessibleElementById("details1");
+        shouldBeTrue("details1.isExpanded");
+
+        // And duplicate the true state to make sure it doesn't toggle off.
+        details1.setBoolAttributeValue("AXExpanded", true);
+        details1 = accessibilityController.accessibleElementById("details1");
+        shouldBeTrue("details1.isExpanded");
 
         var details2 = accessibilityController.accessibleElementById("details2");
         shouldBe("details2.subrole", "'AXSubrole: AXDetails'");
index 6ec4895..312b105 100644 (file)
@@ -1,3 +1,31 @@
+2015-07-02  Chris Fleizach  <cfleizach@apple.com>
+
+        AX: <details> element should allow expand/close through AX API
+        https://bugs.webkit.org/show_bug.cgi?id=146549
+
+        Reviewed by Mario Sanchez Prada.
+
+        Allow AXExpanded to be writeable for <details> element, which, when set
+        will toggle the opening and closing of the element. 
+        Post a notification when that happens as well.
+
+        Modified test: platform/mac/accessibility/details-summary.html
+
+        * accessibility/AccessibilityNodeObject.cpp:
+        (WebCore::AccessibilityNodeObject::hierarchicalLevel):
+        (WebCore::AccessibilityNodeObject::setIsExpanded):
+        (WebCore::shouldUseAccessibilityObjectInnerText):
+        * accessibility/AccessibilityNodeObject.h:
+        * accessibility/AccessibilityObject.cpp:
+        (WebCore::AccessibilityObject::supportsPressAction):
+        * accessibility/AccessibilityRenderObject.cpp:
+        (WebCore::AccessibilityRenderObject::canSetExpandedAttribute):
+        * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
+        (-[WebAccessibilityObjectWrapper accessibilityIsAttributeSettable:]):
+        (-[WebAccessibilityObjectWrapper _accessibilitySetValue:forAttribute:]):
+        * html/HTMLDetailsElement.cpp:
+        (WebCore::HTMLDetailsElement::toggleOpen):
+
 2015-07-09  Alex Christensen  <achristensen@webkit.org>
 
         [Content Extensions] Prevent crashes with plugins.
index 58c851f..ec5ae0c 100644 (file)
@@ -44,6 +44,7 @@
 #include "FrameView.h"
 #include "HTMLAreaElement.h"
 #include "HTMLCanvasElement.h"
+#include "HTMLDetailsElement.h"
 #include "HTMLFieldSetElement.h"
 #include "HTMLFormElement.h"
 #include "HTMLFrameElementBase.h"
@@ -1608,6 +1609,15 @@ unsigned AccessibilityNodeObject::hierarchicalLevel() const
     return level;
 }
 
+void AccessibilityNodeObject::setIsExpanded(bool expand)
+{
+    if (is<HTMLDetailsElement>(node())) {
+        HTMLDetailsElement* details = downcast<HTMLDetailsElement>(node());
+        if ((expand && !details->isOpen()) || (!expand && details->isOpen()))
+            details->toggleOpen();
+    }
+}
+    
 // When building the textUnderElement for an object, determine whether or not
 // we should include the inner text of this given descendant object or skip it.
 static bool shouldUseAccessibilityObjectInnerText(AccessibilityObject* obj, AccessibilityTextUnderElementMode mode)
index a82bd81..7aee742 100644 (file)
@@ -130,6 +130,7 @@ public:
     virtual void colorValue(int& r, int& g, int& b) const override;
     virtual String ariaLabeledByAttribute() const override;
     virtual bool hasAttributesRequiredForInclusion() const override final;
+    virtual void setIsExpanded(bool) override;
 
     virtual Element* actionElement() const override;
     Element* mouseButtonListener(MouseButtonListenerResultFilter = ExcludeBodyElement) const;
index e7c6fcb..c422bad 100644 (file)
@@ -2041,6 +2041,8 @@ bool AccessibilityObject::supportsPressAction() const
 {
     if (isButton())
         return true;
+    if (roleValue() == DetailsRole)
+        return true;
     
     Element* actionElement = this->actionElement();
     if (!actionElement)
index 0cdef4d..31fadbc 100644 (file)
@@ -2800,6 +2800,9 @@ bool AccessibilityRenderObject::ariaRoleHasPresentationalChildren() const
 
 bool AccessibilityRenderObject::canSetExpandedAttribute() const
 {
+    if (roleValue() == DetailsRole)
+        return true;
+    
     // An object can be expanded if it aria-expanded is true or false.
     const AtomicString& ariaExpanded = getAttribute(aria_expandedAttr);
     return equalIgnoringCase(ariaExpanded, "true") || equalIgnoringCase(ariaExpanded, "false");
index 8ae0036..47c29f2 100644 (file)
@@ -3096,7 +3096,8 @@ static NSString* roleValueToNSString(AccessibilityRole value)
     if ([attributeName isEqualToString: NSAccessibilitySelectedChildrenAttribute])
         return m_object->canSetSelectedChildrenAttribute();
     
-    if ([attributeName isEqualToString:NSAccessibilityDisclosingAttribute])
+    if ([attributeName isEqualToString:NSAccessibilityDisclosingAttribute]
+        || [attributeName isEqualToString:NSAccessibilityExpandedAttribute])
         return m_object->canSetExpandedAttribute();
     
     if ([attributeName isEqualToString:NSAccessibilitySelectedRowsAttribute])
@@ -3423,7 +3424,7 @@ static NSString* roleValueToNSString(AccessibilityRole value)
         } else if ([attributeName isEqualToString: NSAccessibilityVisibleCharacterRangeAttribute]) {
             m_object->makeRangeVisible(PlainTextRange(range.location, range.length));
         }
-    } else if ([attributeName isEqualToString:NSAccessibilityDisclosingAttribute])
+    } else if ([attributeName isEqualToString:NSAccessibilityDisclosingAttribute] || [attributeName isEqualToString:NSAccessibilityExpandedAttribute])
         m_object->setIsExpanded([number boolValue]);
     else if ([attributeName isEqualToString:NSAccessibilitySelectedRowsAttribute]) {
         AccessibilityObject::AccessibilityChildrenVector selectedRows;