Skip to content

Commit

Permalink
AX: CSS content property replacement text ignored when it is the empt…
Browse files Browse the repository at this point in the history
…y string

https://bugs.webkit.org/show_bug.cgi?id=270377
rdar://123919677

Reviewed by Antoine Quint.

This issue came to light as part of the <input type=checkbox switch>
demo, but is more universally applicable as shown in the tests.

While here, also cleanup some of the code as the render objects
involved cannot become null.

New web-platform-tests tests are exported:
web-platform-tests/wpt#44971

* LayoutTests/accessibility/mac/alt-for-css-content-expected.txt:
* LayoutTests/accessibility/mac/alt-for-css-content.html:
* LayoutTests/imported/w3c/web-platform-tests/accname/name/comp_name_from_content-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/accname/name/comp_name_from_content.html:
* Source/WebCore/accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::textUnderElement const):

Canonical link: https://commits.webkit.org/275872@main
  • Loading branch information
annevk committed Mar 9, 2024
1 parent 88f3f50 commit 93c3eb8
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 deletions.
12 changes: 12 additions & 0 deletions LayoutTests/accessibility/mac/alt-for-css-content-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ AXDescription:
AXTitle:
AXValue: ALTERNATIVE CONTENT TEST6

Test7 - alt on input element ::before
AXRole: AXRadioButton
AXDescription:
AXTitle: test7 before alt
AXValue: 0

Test8 - alt on input element ::before that is the empty string
AXRole: AXRadioButton
AXDescription:
AXTitle:
AXValue: 0

alt accessed through Javascript: "ALTERNATIVE CONTENT TEST2"
PASS successfullyParsed is true

Expand Down
22 changes: 22 additions & 0 deletions LayoutTests/accessibility/mac/alt-for-css-content.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@
[aria-expanded="test6"]::before {
content: "\25BC" / attr(test6);
}

#test7 {
appearance:none;
}
#test7::before {
content: "test7 before" / "test7 before alt";
}

#test8 {
appearance:none;
}
#test8::before {
content: "test8 before" / "";
}
</style>

<div id="content">
Expand All @@ -46,6 +60,8 @@
<div id="test4" aria-expanded="test4">test4</div>
<div id="test5" test5="ALTERNATIVE CONTENT TEST5" aria-expanded="test5">test5</div>
<div id="test6" test6="ALTERNATIVE CONTENT TEST6" aria-expanded="test6">test6</div>
<input id=test7 type=radio>
<input id=test8 type=radio>
</div>

<p id="description"></p>
Expand Down Expand Up @@ -90,6 +106,12 @@
debug("Test6 - alt on text content that uses the attr() function.");
outputElement(accessibilityController.accessibleElementById("test6").childAtIndex(0));

debug("Test7 - alt on input element ::before");
outputElement(accessibilityController.accessibleElementById("test7"));

debug("Test8 - alt on input element ::before that is the empty string");
outputElement(accessibilityController.accessibleElementById("test8"));

debug("alt accessed through Javascript: " + getComputedStyle(document.getElementById("test2"), ':after').content.split(" / ")[1]);

document.getElementById("content").style.visibility = "hidden";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ label

label

Empty alternative text for CSS content in pseudo-elements when applied to primitive appearance form controls





simple w/ for each child

one two three
Expand Down Expand Up @@ -191,6 +197,8 @@ PASS link name from fallback content with ::before and ::after
PASS button name from fallback content mixing attr() and strings with ::before and ::after
PASS heading name from fallback content mixing attr() and strings with ::before and ::after
PASS link name from fallback content mixing attr() and strings with ::before and ::after
PASS primitive radio input with ::before containing empty alternative text
PASS primitive radio input with ::before containing empty alternative text for an image
PASS button name from content for each child
PASS heading name from content for each child
PASS link name from content for each child
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
content: " after "; /* [sic] leading and trailing space */
content: " after " / " alt-after "; /* Override the previous line for engines that support the Alternative Text syntax. */
}
.fallback-before-empty::before {
content: "before" / "";
}
.fallback-before-image-empty::before {
content: "before " url(/images/blue.png) / "";
}
.fallback-before-mixed::before {
content: " before "; /* [sic] leading and trailing space */
content: " before " / " start " attr(data-alt-text-before) " end "; /* Override the previous line for engines that support the Alternative Text syntax. */
Expand Down Expand Up @@ -145,6 +151,10 @@ <h3 data-alt-text-before="alt-before" data-alt-text-after="alt-after" data-expec
<a href="#" data-alt-text-before="alt-before" data-alt-text-after="alt-after" data-expectedlabel="start alt-before end label start alt-after end" data-testname="link name from fallback content mixing attr() and strings with ::before and ::after" class="ex fallback-before-mixed fallback-after-mixed">label</a><br>
<br>

<h1>Empty alternative text for CSS content in pseudo-elements when applied to primitive appearance form controls</h1>
<p><input data-expectedlabel="" data-testname="primitive radio input with ::before containing empty alternative text" class="ex fallback-before-empty" type=radio style=appearance:none>
<p><input data-expectedlabel="" data-testname="primitive radio input with ::before containing empty alternative text for an image" class="ex fallback-before-image-empty" type=radio style=appearance:none>

<h1>simple w/ for each child</h1>
<button data-expectedlabel="one two three" data-testname="button name from content for each child" class="ex"><span>one</span> <span>two</span> <span>three</span></button><br>
<h3 data-expectedlabel="one two three" data-testname="heading name from content for each child" class="ex"><span>one</span> <span>two</span> <span>three</span></h3>
Expand Down
8 changes: 3 additions & 5 deletions Source/WebCore/accessibility/AccessibilityRenderObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,13 +717,11 @@ String AccessibilityRenderObject::textUnderElement(AccessibilityTextUnderElement
if (WeakPtr renderText = dynamicDowncast<RenderText>(*m_renderer)) {
if (WeakPtr renderTextFragment = dynamicDowncast<RenderTextFragment>(*renderText)) {
// The alt attribute may be set on a text fragment through CSS, which should be honored.
const auto& altText = renderTextFragment->altText();
if (!altText.isEmpty())
if (auto& altText = renderTextFragment->altText(); !altText.isNull())
return altText;
return renderTextFragment ? renderTextFragment->contentString() : String();
return renderTextFragment->contentString();
}

return renderText ? renderText->text() : String();
return renderText->text();
}
}

Expand Down

0 comments on commit 93c3eb8

Please sign in to comment.