Title: [288117] trunk
Revision
288117
Author
[email protected]
Date
2022-01-18 08:45:07 -0800 (Tue, 18 Jan 2022)

Log Message

AX: Improve support for aria-owns in aria trees
https://bugs.webkit.org/show_bug.cgi?id=233383

Patch by Sepand Parhami <[email protected]> on 2022-01-18
Reviewed by Chris Fleizach.

Source/WebCore:

Better supports aria-owns in trees by following children specified through ownership similar
to how DOM children are handled. Previously, you could use aria-owns for only one level of
ownership. This change also fixes tree items being included twice (once as a DOM child and
another time via aria-owns) and supports using both DOM children and aria-owns on a single
element. This change only affects trees via a change to ariaTreeRows and does not change
aria-owns behavior in general.

Tests: accessibility/mac/treeitem-row-delegation.html
       accessibility/mac/treeitem-row-delegation-poorly-formed.html

* accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::ariaTreeRows):
* accessibility/AccessibilityObject.h:

LayoutTests:

Adds test cases for additional specified behavior of aria-owns in trees as well as tests to
make sure incorrect aria-owns usage does not cause crashes.

* accessibility/mac/treeitem-row-delegation-expected.txt:
* accessibility/mac/treeitem-row-delegation-poorly-formed-expected.txt: Added.
* accessibility/mac/treeitem-row-delegation-poorly-formed.html: Added.
* accessibility/mac/treeitem-row-delegation.html:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (288116 => 288117)


--- trunk/LayoutTests/ChangeLog	2022-01-18 16:16:36 UTC (rev 288116)
+++ trunk/LayoutTests/ChangeLog	2022-01-18 16:45:07 UTC (rev 288117)
@@ -1,3 +1,18 @@
+2022-01-18  Sepand Parhami  <[email protected]>
+
+        AX: Improve support for aria-owns in aria trees
+        https://bugs.webkit.org/show_bug.cgi?id=233383
+
+        Reviewed by Chris Fleizach.
+
+        Adds test cases for additional specified behavior of aria-owns in trees as well as tests to
+        make sure incorrect aria-owns usage does not cause crashes.
+
+        * accessibility/mac/treeitem-row-delegation-expected.txt:
+        * accessibility/mac/treeitem-row-delegation-poorly-formed-expected.txt: Added.
+        * accessibility/mac/treeitem-row-delegation-poorly-formed.html: Added.
+        * accessibility/mac/treeitem-row-delegation.html:
+
 2022-01-18  Arcady Goldmints-Orlov  <[email protected]>
 
         [GLIB] Update test baselines after r288070.

Modified: trunk/LayoutTests/accessibility/mac/treeitem-row-delegation-expected.txt (288116 => 288117)


--- trunk/LayoutTests/accessibility/mac/treeitem-row-delegation-expected.txt	2022-01-18 16:16:36 UTC (rev 288116)
+++ trunk/LayoutTests/accessibility/mac/treeitem-row-delegation-expected.txt	2022-01-18 16:45:07 UTC (rev 288117)
@@ -1,11 +1,23 @@
-This tests that a treeitem was a group that uses aria-owns will report its disclosed rows correctly.
+This tests that a treeitem with a group that uses aria-owns will report its disclosed rows correctly.
 
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS treeitem2.isEqual(accessibilityController.accessibleElementById('group1-item1')) is true
+PASS tree.childrenCount is 7
+PASS treeitem1.isEqual(accessibilityController.accessibleElementById('item-1')) is true
+PASS treeitem1_1.isEqual(accessibilityController.accessibleElementById('group1-item1')) is true
+PASS treeitem1_2.isEqual(accessibilityController.accessibleElementById('group1-item2')) is true
+PASS treeitem1_3.isEqual(accessibilityController.accessibleElementById('group1-item3')) is true
+PASS treeitem1_2_1.isEqual(accessibilityController.accessibleElementById('group2-item1')) is true
+PASS treeitem1_2_2.isEqual(accessibilityController.accessibleElementById('group2-item2')) is true
+PASS treeitem2.isEqual(accessibilityController.accessibleElementById('item-2')) is true
 PASS successfullyParsed is true
 
 TEST COMPLETE
+Jaguar
 Jungle Animals
-Lions
+Birds
+Reptiles
+Cats
+Lion
+Domestic Animals

Added: trunk/LayoutTests/accessibility/mac/treeitem-row-delegation-poorly-formed-expected.txt (0 => 288117)


--- trunk/LayoutTests/accessibility/mac/treeitem-row-delegation-poorly-formed-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/accessibility/mac/treeitem-row-delegation-poorly-formed-expected.txt	2022-01-18 16:45:07 UTC (rev 288117)
@@ -0,0 +1,16 @@
+This tests that a treeitem with a group that uses aria-owns does not cause problems when poorly formed.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS tree.childrenCount is 7
+PASS successfullyParsed is true
+
+TEST COMPLETE
+Jungle Animals
+Cats
+Lions
+Domestic Animals
+Arctic Animals
+Sea Animals
+Orca

Added: trunk/LayoutTests/accessibility/mac/treeitem-row-delegation-poorly-formed.html (0 => 288117)


--- trunk/LayoutTests/accessibility/mac/treeitem-row-delegation-poorly-formed.html	                        (rev 0)
+++ trunk/LayoutTests/accessibility/mac/treeitem-row-delegation-poorly-formed.html	2022-01-18 16:45:07 UTC (rev 288117)
@@ -0,0 +1,48 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+
+<body id="body">
+
+<div id="tree" role="tree">
+    <!-- Reference by a grandchild through a tree item -->
+    <div id="circular-ref-1" role="treeitem" aria-level="1" aria-expanded="true" tabindex="0">Jungle Animals
+        <div role="group" aria-owns="group1-item2"></div>
+    </div>
+    <div id="group1-item2" role="treeitem" aria-level="2" aria-expanded="true" aria-setsize="1" aria-posinset="2" aria-current="page">Cats
+        <div role="group" aria-owns="group2-item1"></div>
+    </div>
+    <div id="group2-item1" role="treeitem" aria-level="3" aria-posinset="1" aria-setsize="2" aria-current="page">Lions
+        <div role="group" aria-owns="circular-ref-1"></div>
+    </div>
+
+    <!-- Reference loop with a plain div -->
+    <div role="treeitem" aria-level="1" aria-expanded="false" tabindex="-1">Domestic Animals
+	<div id="circular-ref-2" role="group" aria-owns="plain-div"></div>
+        <div id="plain-div" aria-owns="circular-ref-2"></div>
+    </div>
+
+    <!-- Multiple aria-owning elements --> 
+    <div role="treeitem" aria-level="1" aria-expanded="false" tabindex="-1">Arctic Animals
+        <div role="group" aria-owns="doubly-referenced"></div>
+    </div>
+    <div role="treeitem" aria-level="1" aria-expanded="false" tabindex="-1">Sea Animals
+        <div role="group" aria-owns="doubly-referenced"></div>
+    </div>
+    <div id="doubly-referenced" role="treeitem" aria-level="2" tabindex="-1">Orca</div>
+</div>
+
+<script>
+    description("This tests that a treeitem with a group that uses aria-owns does not cause problems when poorly formed.");
+
+    if (window.accessibilityController) {
+       var tree = accessibilityController.accessibleElementById("tree");
+       shouldBe("tree.childrenCount", "7");
+    }
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/LayoutTests/accessibility/mac/treeitem-row-delegation.html (288116 => 288117)


--- trunk/LayoutTests/accessibility/mac/treeitem-row-delegation.html	2022-01-18 16:16:36 UTC (rev 288116)
+++ trunk/LayoutTests/accessibility/mac/treeitem-row-delegation.html	2022-01-18 16:45:07 UTC (rev 288117)
@@ -8,19 +8,40 @@
 <body id="body">
 
 <div id="tree" role="tree">
+    <div id="group2-item2" role="treeitem" aria-level="3" aria-setsize="2" aria-posinset="2" aria-current="page">Jaguar</div>
     <div id="item-1" role="treeitem" aria-level="1" aria-expanded="true" tabindex="0">Jungle Animals
-        <div role="group" aria-owns="group1-item1 group1-item2 group1-item3"></div>
+        <div role="group" aria-owns="group1-item2 group1-item3 non-existent-item1">
+          <div id="group1-item3" role="treeitem" aria-level="2" aria-setsize="3" aria-posinset="3" aria-current="page">Birds</div>
+          <div id="group1-item1" role="treeitem" aria-level="2" aria-setsize="3" aria-posinset="1" aria-current="page">Reptiles</div>
+        </div>
     </div>
-    <div id="group1-item1" role="treeitem" aria-level="2" aria-setsize="3" aria-posinset="1" aria-current="page">Lions</div>
+    <div id="group1-item2" role="treeitem" aria-level="2" aria-expanded="true" aria-setsize="1" aria-posinset="2" aria-current="page">Cats
+        <div role="group" aria-owns="group2-item1 group2-item2"></div>
+    </div>
+    <div id="group2-item1" role="treeitem" aria-level="3" aria-posinset="1" aria-setsize="2" aria-current="page">Lion</div>
+    <div id="item-2" role="treeitem" aria-level="1" aria-expanded="false" tabindex="-1">Domestic Animals</div>
 </div>
 
 <script>
-    description("This tests that a treeitem was a group that uses aria-owns will report its disclosed rows correctly.");
+    description("This tests that a treeitem with a group that uses aria-owns will report its disclosed rows correctly.");
 
     if (window.accessibilityController) {
-       var treeitem = accessibilityController.accessibleElementById("item-1");
-       var treeitem2 = treeitem.disclosedRowAtIndex(0);
-       shouldBeTrue("treeitem2.isEqual(accessibilityController.accessibleElementById('group1-item1'))");
+       var tree = accessibilityController.accessibleElementById("tree");
+       var treeitem1 = tree.rowAtIndex(0);
+       var treeitem1_1 = treeitem1.disclosedRowAtIndex(0);
+       var treeitem1_2 = treeitem1.disclosedRowAtIndex(1);
+       var treeitem1_3 = treeitem1.disclosedRowAtIndex(4);
+       var treeitem1_2_1 = treeitem1_2.disclosedRowAtIndex(0);
+       var treeitem1_2_2 = treeitem1_2.disclosedRowAtIndex(1);
+       var treeitem2 = tree.rowAtIndex(6);
+       shouldBe("tree.childrenCount", "7");
+       shouldBeTrue("treeitem1.isEqual(accessibilityController.accessibleElementById('item-1'))");
+       shouldBeTrue("treeitem1_1.isEqual(accessibilityController.accessibleElementById('group1-item1'))");
+       shouldBeTrue("treeitem1_2.isEqual(accessibilityController.accessibleElementById('group1-item2'))");
+       shouldBeTrue("treeitem1_3.isEqual(accessibilityController.accessibleElementById('group1-item3'))");
+       shouldBeTrue("treeitem1_2_1.isEqual(accessibilityController.accessibleElementById('group2-item1'))");
+       shouldBeTrue("treeitem1_2_2.isEqual(accessibilityController.accessibleElementById('group2-item2'))");
+       shouldBeTrue("treeitem2.isEqual(accessibilityController.accessibleElementById('item-2'))");
     }
 </script>
 <script src=""

Modified: trunk/Source/WebCore/ChangeLog (288116 => 288117)


--- trunk/Source/WebCore/ChangeLog	2022-01-18 16:16:36 UTC (rev 288116)
+++ trunk/Source/WebCore/ChangeLog	2022-01-18 16:45:07 UTC (rev 288117)
@@ -1,3 +1,24 @@
+2022-01-18  Sepand Parhami  <[email protected]>
+
+        AX: Improve support for aria-owns in aria trees
+        https://bugs.webkit.org/show_bug.cgi?id=233383
+
+        Reviewed by Chris Fleizach.
+
+        Better supports aria-owns in trees by following children specified through ownership similar
+        to how DOM children are handled. Previously, you could use aria-owns for only one level of
+        ownership. This change also fixes tree items being included twice (once as a DOM child and
+        another time via aria-owns) and supports using both DOM children and aria-owns on a single
+        element. This change only affects trees via a change to ariaTreeRows and does not change
+        aria-owns behavior in general.
+
+        Tests: accessibility/mac/treeitem-row-delegation.html
+               accessibility/mac/treeitem-row-delegation-poorly-formed.html
+
+        * accessibility/AccessibilityObject.cpp:
+        (WebCore::AccessibilityObject::ariaTreeRows):
+        * accessibility/AccessibilityObject.h:
+
 2022-01-18  Youenn Fablet  <[email protected]>
 
         Make ServiceWorkerClient.id a UUID instead of a string derived from a ScriptExecutionContextIdentifier

Modified: trunk/Source/WebCore/accessibility/AccessibilityObject.cpp (288116 => 288117)


--- trunk/Source/WebCore/accessibility/AccessibilityObject.cpp	2022-01-18 16:16:36 UTC (rev 288116)
+++ trunk/Source/WebCore/accessibility/AccessibilityObject.cpp	2022-01-18 16:45:07 UTC (rev 288117)
@@ -1893,25 +1893,68 @@
     });
 }
 
-void AccessibilityObject::ariaTreeRows(AccessibilityChildrenVector& result)
+void AccessibilityObject::ariaTreeRows(AccessibilityChildrenVector& rows, AccessibilityChildrenVector& ancestors)
 {
-    // If the element specifies its tree rows through aria-owns, return that first.
     AccessibilityChildrenVector ariaOwns;
     ariaOwnsElements(ariaOwns);
-    if (ariaOwns.size()) {
-        result.appendVector(ariaOwns);
-        return;
-    }
     
+    ancestors.append(this);
+
+    // The ordering of rows is first DOM children *not* in aria-owns, followed by all specified
+    // in aria-owns.
     for (const auto& child : children()) {
         // Add tree items as the rows.
-        if (child->roleValue() == AccessibilityRole::TreeItem)
-            result.append(child);
+        if (child->roleValue() == AccessibilityRole::TreeItem) {
+            // Child appears both as a direct child and aria-owns, we should use the ordering as
+            // described in aria-owns for this child.
+            if (ariaOwns.contains(child))
+                continue;
+            
+            // The result set may already contain the child through aria-owns. For example,
+            // a treeitem sitting under the tree root, which is owned elsewhere in the tree.
+            if (rows.contains(child))
+                continue;
 
+            rows.append(child);
+        }
+
         // Now see if this item also has rows hiding inside of it.
-        child->ariaTreeRows(result);
+        if (is<AccessibilityObject>(*child))
+            downcast<AccessibilityObject>(*child).ariaTreeRows(rows, ancestors);
     }
+
+    // Now go through the aria-owns elements.
+    for (const auto& child : ariaOwns) {
+        // Avoid a circular reference via aria-owns by checking if our parent
+        // path includes this child. Currently, looking up the aria-owns parent
+        // path itself could be expensive, so we track it separately.
+        if (ancestors.contains(child))
+            continue;
+        
+        // Add tree items as the rows.
+        if (child->roleValue() == AccessibilityRole::TreeItem) {
+            // Hopefully a flow that does not occur often in practice, but if someone were to include
+            // the owned child ealier in the top level of the tree, then reference via aria-owns later,
+            // move it to the right place.
+            if (rows.contains(child))
+                rows.removeFirst(child);
+            
+            rows.append(child);
+        }
+
+        // Now see if this item also has rows hiding inside of it.
+        if (is<AccessibilityObject>(*child))
+            downcast<AccessibilityObject>(*child).ariaTreeRows(rows, ancestors);
+    }
+    
+    ancestors.removeLast();
 }
+
+void AccessibilityObject::ariaTreeRows(AccessibilityChildrenVector& rows    )
+{
+    AccessibilityChildrenVector ancestors;
+    ariaTreeRows(rows, ancestors);
+}
     
 void AccessibilityObject::ariaTreeItemContent(AccessibilityChildrenVector& result)
 {

Modified: trunk/Source/WebCore/accessibility/AccessibilityObject.h (288116 => 288117)


--- trunk/Source/WebCore/accessibility/AccessibilityObject.h	2022-01-18 16:16:36 UTC (rev 288116)
+++ trunk/Source/WebCore/accessibility/AccessibilityObject.h	2022-01-18 16:45:07 UTC (rev 288117)
@@ -826,6 +826,8 @@
     std::optional<SimpleRange> findTextRange(const Vector<String>& searchStrings, const SimpleRange& start, AccessibilitySearchTextDirection) const;
     std::optional<SimpleRange> visibleCharacterRange() const override;
 
+    void ariaTreeRows(AccessibilityChildrenVector& rows, AccessibilityChildrenVector& ancestors);
+    
 #if PLATFORM(COCOA) && ENABLE(MODEL_ELEMENT)
     Vector<RetainPtr<id>> modelElementChildren() override;
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to