- Revision
- 292314
- Author
- [email protected]
- Date
- 2022-04-04 13:41:32 -0700 (Mon, 04 Apr 2022)
Log Message
AccessibilityNodeObject::elementRect should use children rects for display:contents AX objects
https://bugs.webkit.org/show_bug.cgi?id=238680
Reviewed by Chris Fleizach and Andres Gonzalez.
Source/WebCore:
Because display:contents AccessibilityNodeObjects can have rendered
content (unlike `hidden`, `aria-hidden="false"` node objects), we can compute
AccessibilityNodeObject::elementRect by adding up the rectangles of the object's children.
This provides a more accurate frame for these objects.
Test: accessibility/node-only-object-element-rect.html
* accessibility/AccessibilityNodeObject.cpp:
(WebCore::AccessibilityNodeObject::boundingBoxRect const):
LayoutTests:
* accessibility/node-only-object-element-rect-expected.txt: Added.
* accessibility/node-only-object-element-rect.html: Added.
* platform/glib/accessibility/node-only-object-element-rect-expected.txt: Added.
* platform/ios/TestExpectations: Enable new test.
* platform/ios/accessibility/node-only-object-element-rect-expected.txt: Added.
* platform/win/accessibility/node-only-object-element-rect-expected.txt: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (292313 => 292314)
--- trunk/LayoutTests/ChangeLog 2022-04-04 19:53:55 UTC (rev 292313)
+++ trunk/LayoutTests/ChangeLog 2022-04-04 20:41:32 UTC (rev 292314)
@@ -1,3 +1,17 @@
+2022-04-04 Tyler Wilcock <[email protected]>
+
+ AccessibilityNodeObject::elementRect should use children rects for display:contents AX objects
+ https://bugs.webkit.org/show_bug.cgi?id=238680
+
+ Reviewed by Chris Fleizach and Andres Gonzalez.
+
+ * accessibility/node-only-object-element-rect-expected.txt: Added.
+ * accessibility/node-only-object-element-rect.html: Added.
+ * platform/glib/accessibility/node-only-object-element-rect-expected.txt: Added.
+ * platform/ios/TestExpectations: Enable new test.
+ * platform/ios/accessibility/node-only-object-element-rect-expected.txt: Added.
+ * platform/win/accessibility/node-only-object-element-rect-expected.txt: Added.
+
2022-04-04 J Pascoe <[email protected]>
[ iOS 15 ] imported/w3c/web-platform-tests/WebCryptoAPI/derive_bits_keys/pbkdf2.https.any.worker.html is flaky timing out
Added: trunk/LayoutTests/accessibility/node-only-object-element-rect-expected.txt (0 => 292314)
--- trunk/LayoutTests/accessibility/node-only-object-element-rect-expected.txt (rev 0)
+++ trunk/LayoutTests/accessibility/node-only-object-element-rect-expected.txt 2022-04-04 20:41:32 UTC (rev 292314)
@@ -0,0 +1,12 @@
+This test ensures we calculate the frame correctly for objects that don't have a renderer (like display: contents elements).
+
+#toolbar: {width: 784, height: 22}
+#group: {width: 46, height: 28}
+#button: {width: 784, height: 10}
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+Foo
+Foo
+Foo
Added: trunk/LayoutTests/accessibility/node-only-object-element-rect.html (0 => 292314)
--- trunk/LayoutTests/accessibility/node-only-object-element-rect.html (rev 0)
+++ trunk/LayoutTests/accessibility/node-only-object-element-rect.html 2022-04-04 20:41:32 UTC (rev 292314)
@@ -0,0 +1,45 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+
+<div id="toolbar" role="toolbar" style="display: contents;">
+ <div>
+ <button>Foo</button>
+ </div>
+</div>
+
+<div role="toolbar">
+ <div id="group" role="group" style="display: contents;">
+ <button>Foo</button>
+ </div>
+</div>
+
+<div role="toolbar">
+ <div>
+ <button id="button" style="display: contents;">Foo</button>
+ </div>
+</div>
+
+<script>
+ var testOutput = "This test ensures we calculate the frame correctly for objects that don't have a renderer (like display: contents elements).\n\n";
+
+ function logSize(id) {
+ const axElement = accessibilityController.accessibleElementById(id);
+ testOutput += `#${id}: {width: ${axElement.width}, height: ${axElement.height}}\n`;
+ }
+
+ if (window.accessibilityController) {
+ logSize("toolbar");
+ logSize("group");
+ logSize("button");
+
+ debug(testOutput);
+ }
+</script>
+</body>
+</html>
+
Added: trunk/LayoutTests/platform/glib/accessibility/node-only-object-element-rect-expected.txt (0 => 292314)
--- trunk/LayoutTests/platform/glib/accessibility/node-only-object-element-rect-expected.txt (rev 0)
+++ trunk/LayoutTests/platform/glib/accessibility/node-only-object-element-rect-expected.txt 2022-04-04 20:41:32 UTC (rev 292314)
@@ -0,0 +1,12 @@
+This test ensures we calculate the frame correctly for objects that don't have a renderer (like display: contents elements).
+
+#toolbar: {width: 784, height: 31}
+#group: {width: 44, height: 27}
+#button: {width: 784, height: 10}
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+Foo
+Foo
+Foo
Modified: trunk/LayoutTests/platform/ios/TestExpectations (292313 => 292314)
--- trunk/LayoutTests/platform/ios/TestExpectations 2022-04-04 19:53:55 UTC (rev 292313)
+++ trunk/LayoutTests/platform/ios/TestExpectations 2022-04-04 20:41:32 UTC (rev 292314)
@@ -2095,6 +2095,7 @@
accessibility/aria-hidden-display-contents-element.html [ Pass ]
accessibility/display-contents-element-roles.html [ Pass ]
+accessibility/node-only-object-element-rect.html [ Pass ]
accessibility/video-element-url-attribute.html [ Pass ]
accessibility/visible-character-range-basic.html [ Pass ]
accessibility/visible-character-range-height-changes.html [ Pass ]
Added: trunk/LayoutTests/platform/ios/accessibility/node-only-object-element-rect-expected.txt (0 => 292314)
--- trunk/LayoutTests/platform/ios/accessibility/node-only-object-element-rect-expected.txt (rev 0)
+++ trunk/LayoutTests/platform/ios/accessibility/node-only-object-element-rect-expected.txt 2022-04-04 20:41:32 UTC (rev 292314)
@@ -0,0 +1,12 @@
+This test ensures we calculate the frame correctly for objects that don't have a renderer (like display: contents elements).
+
+#toolbar: {width: 784, height: 24}
+#group: {width: 44, height: 20}
+#button: {width: 784, height: 10}
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+Foo
+Foo
+Foo
Added: trunk/LayoutTests/platform/win/accessibility/node-only-object-element-rect-expected.txt (0 => 292314)
--- trunk/LayoutTests/platform/win/accessibility/node-only-object-element-rect-expected.txt (rev 0)
+++ trunk/LayoutTests/platform/win/accessibility/node-only-object-element-rect-expected.txt 2022-04-04 20:41:32 UTC (rev 292314)
@@ -0,0 +1,12 @@
+This test ensures we calculate the frame correctly for objects that don't have a renderer (like display: contents elements).
+
+#toolbar: {width: 784, height: 25}
+#group: {width: 38, height: 21}
+#button: {width: 784, height: 10}
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+Foo
+Foo
+Foo
Modified: trunk/Source/WebCore/ChangeLog (292313 => 292314)
--- trunk/Source/WebCore/ChangeLog 2022-04-04 19:53:55 UTC (rev 292313)
+++ trunk/Source/WebCore/ChangeLog 2022-04-04 20:41:32 UTC (rev 292314)
@@ -1,3 +1,20 @@
+2022-04-04 Tyler Wilcock <[email protected]>
+
+ AccessibilityNodeObject::elementRect should use children rects for display:contents AX objects
+ https://bugs.webkit.org/show_bug.cgi?id=238680
+
+ Reviewed by Chris Fleizach and Andres Gonzalez.
+
+ Because display:contents AccessibilityNodeObjects can have rendered
+ content (unlike `hidden`, `aria-hidden="false"` node objects), we can compute
+ AccessibilityNodeObject::elementRect by adding up the rectangles of the object's children.
+ This provides a more accurate frame for these objects.
+
+ Test: accessibility/node-only-object-element-rect.html
+
+ * accessibility/AccessibilityNodeObject.cpp:
+ (WebCore::AccessibilityNodeObject::boundingBoxRect const):
+
2022-04-04 Devin Rousso <[email protected]>
[Apple Pay] buttons should be localized based on the system if not specified by the HTML
Modified: trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp (292313 => 292314)
--- trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp 2022-04-04 19:53:55 UTC (rev 292313)
+++ trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp 2022-04-04 20:41:32 UTC (rev 292314)
@@ -205,22 +205,32 @@
LayoutRect AccessibilityNodeObject::boundingBoxRect() const
{
- // AccessibilityNodeObjects have no mechanism yet to return a size or position.
- // For now, let's return the position of the ancestor that does have a position,
- // and make it the width of that parent, and about the height of a line of text, so that it's clear the object is a child of the parent.
-
- LayoutRect boundingBox;
-
- for (AccessibilityObject* positionProvider = parentObject(); positionProvider; positionProvider = positionProvider->parentObject()) {
- if (positionProvider->isAccessibilityRenderObject()) {
- LayoutRect parentRect = positionProvider->elementRect();
- boundingBox.setSize(LayoutSize(parentRect.width(), LayoutUnit(std::min(10.0f, parentRect.height().toFloat()))));
- boundingBox.setLocation(parentRect.location());
- break;
- }
+ if (hasDisplayContents()) {
+ LayoutRect contentsRect;
+ for (const auto& child : const_cast<AccessibilityNodeObject*>(this)->children(false))
+ contentsRect.unite(child->elementRect());
+
+ if (!contentsRect.isEmpty())
+ return contentsRect;
}
-
- return boundingBox;
+
+ // Non-display:contents AccessibilityNodeObjects have no mechanism to return a size or position.
+ // Instead, let's return a box at the position of an ancestor that does have a position, make it
+ // the width of that ancestor, and about the height of a line of text, so it's clear this object is
+ // a descendant of that ancestor.
+ for (RefPtr<AccessibilityObject> ancestor = parentObject(); ancestor; ancestor = ancestor->parentObject()) {
+ if (!is<AccessibilityRenderObject>(ancestor))
+ continue;
+ auto ancestorRect = ancestor->elementRect();
+ if (ancestorRect.isEmpty())
+ continue;
+
+ return {
+ ancestorRect.location(),
+ LayoutSize(ancestorRect.width(), LayoutUnit(std::min(10.0f, ancestorRect.height().toFloat())))
+ };
+ }
+ return { };
}
void AccessibilityNodeObject::setNode(Node* node)