AX: Improve ARIA live region reliability by sending notifications when live regions...
authorcfleizach@apple.com <cfleizach@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Apr 2014 16:31:15 +0000 (16:31 +0000)
committercfleizach@apple.com <cfleizach@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Apr 2014 16:31:15 +0000 (16:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=124381

Reviewed by Mario Sanchez Prada.

Source/WebCore:

Re-organize some code so that when we detect a new node has been created, we can safely determine its live region status.
If it is a live region, we fire off a live region created notification.

Test: platform/mac/accessibility/live-region-creation-notification.html

* accessibility/AXObjectCache.cpp:
(WebCore::AXObjectCache::handleLiveRegionCreated):
(WebCore::AXObjectCache::childrenChanged):
(WebCore::AXObjectCache::handleAttributeChanged):
* accessibility/AXObjectCache.h:
(WebCore::AXObjectCache::childrenChanged):
* accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::defaultLiveRegionStatusForRole):
(WebCore::AccessibilityObject::liveRegionStatusIsEnabled):
(WebCore::AccessibilityObject::supportsARIALiveRegion):
* accessibility/AccessibilityObject.h:
(WebCore::AccessibilityObject::ariaLiveRegionStatus):
* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::ariaLiveRegionStatus):
* accessibility/AccessibilityRenderObject.h:
* accessibility/ios/AXObjectCacheIOS.mm:
(WebCore::AXObjectCache::postPlatformNotification):
* accessibility/ios/WebAccessibilityObjectWrapperIOS.h:
* accessibility/ios/WebAccessibilityObjectWrapperIOS.mm:
(-[WebAccessibilityObjectWrapper postLiveRegionCreatedNotification]):
* accessibility/mac/AXObjectCacheMac.mm:
(WebCore::AXObjectCache::postPlatformNotification):

LayoutTests:

* platform/mac/accessibility/live-region-creation-notification.html: Added.

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

13 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/mac/accessibility/live-region-creation-notification.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/accessibility/AXObjectCache.cpp
Source/WebCore/accessibility/AXObjectCache.h
Source/WebCore/accessibility/AccessibilityObject.cpp
Source/WebCore/accessibility/AccessibilityObject.h
Source/WebCore/accessibility/AccessibilityRenderObject.cpp
Source/WebCore/accessibility/AccessibilityRenderObject.h
Source/WebCore/accessibility/ios/AXObjectCacheIOS.mm
Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.h
Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm
Source/WebCore/accessibility/mac/AXObjectCacheMac.mm

index 02b555a..c45fff8 100644 (file)
@@ -1,3 +1,12 @@
+2014-04-02  Chris Fleizach  <cfleizach@apple.com>
+
+        AX: Improve ARIA live region reliability by sending notifications when live regions are created/shown and hidden/destroyed
+        https://bugs.webkit.org/show_bug.cgi?id=124381
+
+        Reviewed by Mario Sanchez Prada.
+
+        * platform/mac/accessibility/live-region-creation-notification.html: Added.
+
 2014-04-02  David Kilzer  <ddkilzer@apple.com>
 
         Add LayoutTest for crash with bidi isolates
diff --git a/LayoutTests/platform/mac/accessibility/live-region-creation-notification.html b/LayoutTests/platform/mac/accessibility/live-region-creation-notification.html
new file mode 100644 (file)
index 0000000..fa17f4d
--- /dev/null
@@ -0,0 +1,113 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../../resources/js-test-pre.js"></script>
+</head>
+<body id="body">
+    
+<div id="content">
+<div id="first" role="log"></div>
+</div>
+
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+    
+description("This tests that the AXLiveRegionCreated notification gets fired when live regions appear.");
+var notification = 0;
+var element = 0;
+
+function startTest() {
+    
+    var HIDE = true;
+    
+    // add second live region immediately
+    appendLiveRegion('second');
+    
+    // add third live region later
+    window.setTimeout(function() { 
+        appendLiveRegion('third'); 
+        window.setTimeout(function() { 
+            appendLiveRegion('fourth', HIDE); 
+            window.setTimeout(function() { 
+                unhide('fourth'); 
+                window.setTimeout(function() { 
+                    appendDiv('fifth'); 
+                    window.setTimeout(updateAll, 1);
+                }, 1);
+            }, 1);
+        }, 1);
+    }, 1);
+}
+
+var $ = function(id) {
+    return document.getElementById(id);
+}
+
+var updateAll = function() {
+    window.setTimeout(function() { 
+        updateLiveRegion('first'); 
+        window.setTimeout(function() { 
+            updateLiveRegion('second'); 
+            window.setTimeout(function() { 
+                updateLiveRegion('third'); 
+                window.setTimeout(function() { 
+                    updateLiveRegion('fourth'); 
+                    window.setTimeout(function() { endTest(); }, 1);
+                }, 1);
+            }, 1);
+        }, 1);
+    }, 1);
+    
+}
+var updateLiveRegion = function(id) {
+    var lr = $(id);
+    lr.innerHTML = id;
+}
+var appendLiveRegion = function(id, optHide) {
+    var lr = document.createElement('div');
+    lr.id = id;
+    lr.setAttribute('role', 'log');
+    if (optHide) {
+        lr.hidden = true;
+    }
+    $("content").appendChild(lr);
+}
+var appendDiv = function(id) {
+    var lr = document.createElement('div');
+    lr.id = id;
+    lr.setAttribute('role', 'group');
+    $("content").appendChild(lr);
+}
+var unhide = function(id){
+    $(id).hidden = false;
+}
+
+function ariaCallback(element, notification) {
+    if (notification == "AXLiveRegionCreated") {
+       debug("PASS Received live region created notification: " + notification + ": " + element.stringAttributeValue('AXDOMIdentifier'));
+    }
+}
+
+function endTest() {
+   document.getElementById("content").style.display = 'none';
+   finishJSTest();
+}
+
+window.jsTestIsAsync = true;
+if (window.accessibilityController) {
+    var addedNotification = accessibilityController.addNotificationListener(ariaCallback);
+
+    // Make sure AX is enabled by accessing root element.
+    accessibilityController.rootElement;
+
+    startTest();
+}
+successfullyParsed = true;
+
+</script>
+
+<script src="../../../resources/js-test-post.js"></script>
+</body>
+</html>
index 7d3297a..745e6f2 100644 (file)
@@ -1,3 +1,38 @@
+2014-04-02  Chris Fleizach  <cfleizach@apple.com>
+
+        AX: Improve ARIA live region reliability by sending notifications when live regions are created/shown and hidden/destroyed
+        https://bugs.webkit.org/show_bug.cgi?id=124381
+
+        Reviewed by Mario Sanchez Prada.
+
+        Re-organize some code so that when we detect a new node has been created, we can safely determine its live region status.
+        If it is a live region, we fire off a live region created notification.
+
+        Test: platform/mac/accessibility/live-region-creation-notification.html
+
+        * accessibility/AXObjectCache.cpp:
+        (WebCore::AXObjectCache::handleLiveRegionCreated):
+        (WebCore::AXObjectCache::childrenChanged):
+        (WebCore::AXObjectCache::handleAttributeChanged):
+        * accessibility/AXObjectCache.h:
+        (WebCore::AXObjectCache::childrenChanged):
+        * accessibility/AccessibilityObject.cpp:
+        (WebCore::AccessibilityObject::defaultLiveRegionStatusForRole):
+        (WebCore::AccessibilityObject::liveRegionStatusIsEnabled):
+        (WebCore::AccessibilityObject::supportsARIALiveRegion):
+        * accessibility/AccessibilityObject.h:
+        (WebCore::AccessibilityObject::ariaLiveRegionStatus):
+        * accessibility/AccessibilityRenderObject.cpp:
+        (WebCore::AccessibilityRenderObject::ariaLiveRegionStatus):
+        * accessibility/AccessibilityRenderObject.h:
+        * accessibility/ios/AXObjectCacheIOS.mm:
+        (WebCore::AXObjectCache::postPlatformNotification):
+        * accessibility/ios/WebAccessibilityObjectWrapperIOS.h:
+        * accessibility/ios/WebAccessibilityObjectWrapperIOS.mm:
+        (-[WebAccessibilityObjectWrapper postLiveRegionCreatedNotification]):
+        * accessibility/mac/AXObjectCacheMac.mm:
+        (WebCore::AXObjectCache::postPlatformNotification):
+
 2014-04-02  Martin Robinson  <mrobinson@igalia.com>
 
         REGRESSION(r165704): [GTK] Inspector resources not correctly generated
index 0afdd5d..4a49624 100644 (file)
@@ -636,8 +636,30 @@ void AXObjectCache::handleMenuOpened(Node* node)
     postNotification(getOrCreate(node), &document(), AXMenuOpened);
 }
     
-void AXObjectCache::childrenChanged(Node* node)
+void AXObjectCache::handleLiveRegionCreated(Node* node)
 {
+    if (!node || !node->renderer() || !node->isElementNode())
+        return;
+    
+    Element* element = toElement(node);
+    String liveRegionStatus = element->fastGetAttribute(aria_liveAttr);
+    if (liveRegionStatus.isEmpty()) {
+        const AtomicString& ariaRole = element->fastGetAttribute(roleAttr);
+        if (!ariaRole.isEmpty())
+            liveRegionStatus = AccessibilityObject::defaultLiveRegionStatusForRole(AccessibilityObject::ariaRoleToWebCoreRole(ariaRole));
+    }
+    
+    if (AccessibilityObject::liveRegionStatusIsEnabled(liveRegionStatus))
+        postNotification(getOrCreate(node), &document(), AXLiveRegionCreated);
+}
+    
+void AXObjectCache::childrenChanged(Node* node, Node* newChild)
+{
+    if (newChild) {
+        handleMenuOpened(newChild);
+        handleLiveRegionCreated(newChild);
+    }
+    
     childrenChanged(get(node));
 }
 
@@ -645,8 +667,11 @@ void AXObjectCache::childrenChanged(RenderObject* renderer, RenderObject* newChi
 {
     if (!renderer)
         return;
-    if (newChild)
+    
+    if (newChild) {
         handleMenuOpened(newChild->node());
+        handleLiveRegionCreated(newChild->node());
+    }
     
     childrenChanged(get(renderer));
 }
@@ -899,7 +924,7 @@ void AXObjectCache::handleAttributeChanged(const QualifiedName& attrName, Elemen
     else if (attrName == aria_expandedAttr)
         handleAriaExpandedChange(element);
     else if (attrName == aria_hiddenAttr)
-        childrenChanged(element->parentNode());
+        childrenChanged(element->parentNode(), element);
     else if (attrName == aria_invalidAttr)
         postNotification(element, AXObjectCache::AXInvalidStatusChanged);
     else
index bb7c19f..a66eef8 100644 (file)
@@ -104,7 +104,7 @@ public:
 
     void detachWrapper(AccessibilityObject*, AccessibilityDetachmentType);
     void attachWrapper(AccessibilityObject*);
-    void childrenChanged(Node*);
+    void childrenChanged(Node*, Node* newChild = nullptr);
     void childrenChanged(RenderObject*, RenderObject* newChild = nullptr);
     void childrenChanged(AccessibilityObject*);
     void checkedStateChanged(Node*);
@@ -169,6 +169,7 @@ public:
         AXSelectedTextChanged,
         AXValueChanged,
         AXScrolledToAnchor,
+        AXLiveRegionCreated,
         AXLiveRegionChanged,
         AXMenuListItemSelected,
         AXMenuListValueChanged,
@@ -243,6 +244,7 @@ private:
     Vector<std::pair<RefPtr<AccessibilityObject>, AXNotification>> m_notificationsToPost;
     void notificationPostTimerFired(Timer<AXObjectCache>&);
     void handleMenuOpened(Node*);
+    void handleLiveRegionCreated(Node*);
     void handleMenuItemSelected(Node*);
     
     static AccessibilityObject* focusedImageMapUIElement(HTMLAreaElement*);
@@ -288,7 +290,7 @@ inline const Element* AXObjectCache::rootAXEditableElement(const Node*) { return
 inline void AXObjectCache::attachWrapper(AccessibilityObject*) { }
 inline void AXObjectCache::checkedStateChanged(Node*) { }
 inline void AXObjectCache::childrenChanged(RenderObject*, RenderObject*) { }
-inline void AXObjectCache::childrenChanged(Node*) { }
+inline void AXObjectCache::childrenChanged(Node*, Node*) { }
 inline void AXObjectCache::childrenChanged(AccessibilityObject*) { }
 inline void AXObjectCache::textChanged(RenderObject*) { }
 inline void AXObjectCache::textChanged(Node*) { }
index c4c2e5d..fce4745 100644 (file)
@@ -1489,7 +1489,24 @@ void AccessibilityObject::ariaTreeItemDisclosedRows(AccessibilityChildrenVector&
             obj->ariaTreeRows(result);
     }    
 }
-
+    
+const String AccessibilityObject::defaultLiveRegionStatusForRole(AccessibilityRole role)
+{
+    switch (role) {
+    case ApplicationAlertDialogRole:
+    case ApplicationAlertRole:
+        return ASCIILiteral("assertive");
+    case ApplicationLogRole:
+    case ApplicationStatusRole:
+        return ASCIILiteral("polite");
+    case ApplicationTimerRole:
+    case ApplicationMarqueeRole:
+        return ASCIILiteral("off");
+    default:
+        return nullAtom;
+    }
+}
+    
 #if HAVE(ACCESSIBILITY)
 const String& AccessibilityObject::actionVerb() const
 {
@@ -1825,10 +1842,14 @@ bool AccessibilityObject::supportsARIAAttributes() const
         || hasAttribute(aria_relevantAttr);
 }
     
+bool AccessibilityObject::liveRegionStatusIsEnabled(const AtomicString& liveRegionStatus)
+{
+    return equalIgnoringCase(liveRegionStatus, "polite") || equalIgnoringCase(liveRegionStatus, "assertive");
+}
+    
 bool AccessibilityObject::supportsARIALiveRegion() const
 {
-    const AtomicString& liveRegion = ariaLiveRegionStatus();
-    return equalIgnoringCase(liveRegion, "polite") || equalIgnoringCase(liveRegion, "assertive");
+    return liveRegionStatusIsEnabled(ariaLiveRegionStatus());
 }
 
 AccessibilityObject* AccessibilityObject::elementAccessibilityHitTest(const IntPoint& point) const
index f8aace1..1dd2d6d 100644 (file)
@@ -837,10 +837,12 @@ public:
     // ARIA live-region features.
     bool supportsARIALiveRegion() const;
     bool isInsideARIALiveRegion() const;
-    virtual const AtomicString& ariaLiveRegionStatus() const { return nullAtom; }
+    virtual const String ariaLiveRegionStatus() const { return String(); }
     virtual const AtomicString& ariaLiveRegionRelevant() const { return nullAtom; }
     virtual bool ariaLiveRegionAtomic() const { return false; }
     virtual bool ariaLiveRegionBusy() const { return false; }
+    static const String defaultLiveRegionStatusForRole(AccessibilityRole);
+    static bool liveRegionStatusIsEnabled(const AtomicString&);
     
     bool supportsARIAAttributes() const;
     
index 82458e8..75a91c4 100644 (file)
@@ -3049,29 +3049,12 @@ bool AccessibilityRenderObject::canHaveChildren() const
     return AccessibilityNodeObject::canHaveChildren();
 }
 
-const AtomicString& AccessibilityRenderObject::ariaLiveRegionStatus() const
+const String AccessibilityRenderObject::ariaLiveRegionStatus() const
 {
-    static NeverDestroyed<const AtomicString> liveRegionStatusAssertive("assertive", AtomicString::ConstructFromLiteral);
-    static NeverDestroyed<const AtomicString> liveRegionStatusPolite("polite", AtomicString::ConstructFromLiteral);
-    static NeverDestroyed<const AtomicString> liveRegionStatusOff("off", AtomicString::ConstructFromLiteral);
-    
     const AtomicString& liveRegionStatus = getAttribute(aria_liveAttr);
     // These roles have implicit live region status.
-    if (liveRegionStatus.isEmpty()) {
-        switch (roleValue()) {
-        case ApplicationAlertDialogRole:
-        case ApplicationAlertRole:
-            return liveRegionStatusAssertive;
-        case ApplicationLogRole:
-        case ApplicationStatusRole:
-            return liveRegionStatusPolite;
-        case ApplicationTimerRole:
-        case ApplicationMarqueeRole:
-            return liveRegionStatusOff;
-        default:
-            break;
-        }
-    }
+    if (liveRegionStatus.isEmpty())
+        return defaultLiveRegionStatusForRole(roleValue());
 
     return liveRegionStatus;
 }
index da8f814..877af73 100644 (file)
@@ -278,7 +278,7 @@ private:
     
     virtual ESpeak speakProperty() const override;
     
-    virtual const AtomicString& ariaLiveRegionStatus() const override;
+    virtual const String ariaLiveRegionStatus() const override;
     virtual const AtomicString& ariaLiveRegionRelevant() const override;
     virtual bool ariaLiveRegionAtomic() const override;
     virtual bool ariaLiveRegionBusy() const override;
index 224af86..cc65bc7 100644 (file)
@@ -70,6 +70,9 @@ void AXObjectCache::postPlatformNotification(AccessibilityObject* obj, AXNotific
         case AXLiveRegionChanged:
             [obj->wrapper() postLiveRegionChangeNotification];
             break;
+        case AXLiveRegionCreated:
+            [obj->wrapper() postLiveRegionCreatedNotification];
+            break;
         case AXChildrenChanged:
             [obj->wrapper() postChildrenChangedNotification];
             break;
index fc45e53..7738525 100644 (file)
@@ -60,6 +60,7 @@
 - (void)postLoadCompleteNotification;
 - (void)postChildrenChangedNotification;
 - (void)postInvalidStatusChangedNotification;
+- (void)postLiveRegionCreatedNotification;
 
 @end
 
index 58cd3f8..6d8c0c8 100644 (file)
@@ -1367,6 +1367,11 @@ static RenderObject* rendererForView(WAKView* view)
     // The UIKit accessibility wrapper will override and post appropriate notification.    
 }
 
+- (void)postLiveRegionCreatedNotification
+{
+    // The UIKit accessibility wrapper will override and post appropriate notification.    
+}
+
 - (void)postLoadCompleteNotification
 {
     // The UIKit accessibility wrapper will override and post appropriate notification.    
index 5f248de..1506fe8 100644 (file)
 #define NSAccessibilityLiveRegionChangedNotification @"AXLiveRegionChanged"
 #endif
 
+#ifndef NSAccessibilityLiveRegionCreatedNotification 
+#define NSAccessibilityLiveRegionCreatedNotification @"AXLiveRegionCreated"
+#endif
+
 // The simple Cocoa calls in this file don't throw exceptions.
 
 namespace WebCore {
@@ -103,6 +107,9 @@ void AXObjectCache::postPlatformNotification(AccessibilityObject* obj, AXNotific
         case AXValueChanged:
             macNotification = NSAccessibilityValueChangedNotification;
             break;
+        case AXLiveRegionCreated:
+            macNotification = NSAccessibilityLiveRegionCreatedNotification;
+            break;
         case AXLiveRegionChanged:
             macNotification = NSAccessibilityLiveRegionChangedNotification;
             break;