Skip to content

Commit

Permalink
Cherry-pick ecb40fd. rdar://118118138
Browse files Browse the repository at this point in the history
    AX: VoiceOver does not announce button in text if button is in shadow root
    https://bugs.webkit.org/show_bug.cgi?id=264410
    rdar://118118138

    Reviewed by Tyler Wilcock.

    In shadow DOM elements, if text was within nested elements, textUnderElement would not include it.

    This patch resolves that by adding to our logic for when we decide whether or not to skip a child's
    text. Instead of just checking whether the child's parent and the current node match, we also check
    that the elements are either both in the DOM or Shadow DOM.

    * LayoutTests/accessibility/custom-elements/shadow-element-text-expected.txt: Added.
    * LayoutTests/accessibility/custom-elements/shadow-element-text.html: Added.
    * LayoutTests/platform/glib/accessibility/custom-elements/shadow-element-text-expected.txt: Added.
    * Source/WebCore/accessibility/AccessibilityNodeObject.cpp:
    (WebCore::AccessibilityNodeObject::textUnderElement const):

    Canonical link: https://commits.webkit.org/270542@main

Canonical link: https://commits.webkit.org/267815.558@safari-7617-branch
  • Loading branch information
rjepstein committed Nov 10, 2023
1 parent 58e9a1c commit 033fcc7
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This test ensures that shadow dom elements return the right text.

Button1 text: AXTitle: Button One
AXDescription:
AXHelp:
Button2 text: AXTitle: Nested Button Two
AXDescription:
AXHelp:

PASS successfullyParsed is true

TEST COMPLETE
Button One
Nested Button Two

34 changes: 34 additions & 0 deletions LayoutTests/accessibility/custom-elements/shadow-element-text.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/accessibility-helper.js"></script>
<script src="../../resources/js-test.js"></script>
</head>
<body>

<my-button id="button1">Button One</my-button>
<my-button id="button2"><div>Nested Button Two</div></my-button>

<script>
class MyButton extends HTMLElement {
constructor() {
super();
const root = this.attachShadow({ mode: 'open' });
root.innerHTML = `<button id=${this.id}><slot></slot></button>`;
}
}
customElements.define('my-button', MyButton);

let output = "This test ensures that shadow dom elements return the right text.\n\n";

if (window.accessibilityController) {
var button1 = accessibilityController.accessibleElementById("button1");
output += `Button1 text: ${platformTextAlternatives(button1)}\n`;

var button2 = accessibilityController.accessibleElementById("button2");
output += `Button2 text: ${platformTextAlternatives(button2)}\n`;
debug(output);
}
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
This test ensures that shadow dom elements return the right text.

Button1 text: AXTitle: Button One
AXDescription:
Button2 text: AXTitle: Nested Button Two
AXDescription:

PASS successfullyParsed is true

TEST COMPLETE
Button One
Nested Button Two

2 changes: 1 addition & 1 deletion Source/WebCore/accessibility/AccessibilityNodeObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2378,7 +2378,7 @@ String AccessibilityNodeObject::textUnderElement(AccessibilityTextUnderElementMo
if (node) {
auto* childParentElement = child->node() ? child->node()->parentElement() : nullptr;
// Do not take the textUnderElement for a different element (determined by child's element parent not being us). Otherwise we may doubly-expose the same text.
if (childParentElement && childParentElement != node && childParentElement->shadowHost() != node)
if (childParentElement && childParentElement != node && childParentElement->shadowHost() != node && node->isInShadowTree() == childParentElement->isInShadowTree())
continue;
}

Expand Down

0 comments on commit 033fcc7

Please sign in to comment.