Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
AX: Accessible name computed incorrectly for display:contents element…
…s that rely on labels or captions ("title UI elements")

https://bugs.webkit.org/show_bug.cgi?id=255910
rdar://problem/108492642

Reviewed by Chris Fleizach.

Move non-renderer-specific behavior from AccessibilityRenderObject to
AccessibilityNodeObject.

* Source/WebCore/accessibility/AccessibilityNodeObject.cpp:
* Source/WebCore/accessibility/AccessibilityNodeObject.h:
* Source/WebCore/accessibility/AccessibilityRenderObject.cpp:
* LayoutTests/accessibility/mac/figure-element-expected.txt:
* LayoutTests/accessibility/mac/figure-element.html:

Canonical link: https://commits.webkit.org/263379@main
  • Loading branch information
twilco committed Apr 25, 2023
1 parent 3161dda commit 2670ad1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 19 deletions.
7 changes: 7 additions & 0 deletions LayoutTests/accessibility/mac/figure-element-expected.txt
Expand Up @@ -38,6 +38,13 @@ figure5 description: AXDescription: Figcaption element
figure5 helpText: AXHelp: title attribute
PASS (isIgnored(titleUIElement) && isIgnored(figureCaption)) || titleUIElement.isEqual(figureCaption) is true

Test display:contents figure with figcaption element.
figure6 role: AXRole: AXGroup
figure6 roleDescription: AXRoleDescription: figure
figure6 description: AXDescription: Figcaption element (display:contents)
figure6 helpText: AXHelp:
PASS (isIgnored(titleUIElement) && isIgnored(figureCaption)) || titleUIElement.isEqual(figureCaption) is true

PASS successfullyParsed is true

TEST COMPLETE
Expand Down
8 changes: 7 additions & 1 deletion LayoutTests/accessibility/mac/figure-element.html
Expand Up @@ -35,6 +35,12 @@
<figcaption id="figCaption5">Figcaption element</figcaption>
</figure>

<p id="p6">Test display:contents figure with figcaption element.</p>
<figure id="figure6" style="display:contents">
<img src="" alt="image alt" width="20" height="20"/>
<figcaption id="figCaption6">Figcaption element (display:contents)</figcaption>
</figure>

</div>

<p id="description"></p>
Expand All @@ -50,7 +56,7 @@

if (window.accessibilityController) {

for (var k = 1; k <= 5; k++) {
for (var k = 1; k <= 6; k++) {
var figure = accessibilityController.accessibleElementById("figure" + k);
var p = document.getElementById("p" + k);
debug(p.innerText);
Expand Down
13 changes: 12 additions & 1 deletion Source/WebCore/accessibility/AccessibilityNodeObject.cpp
Expand Up @@ -1426,7 +1426,7 @@ AccessibilityObject* AccessibilityNodeObject::correspondingLabelForControlElemen

HTMLLabelElement* AccessibilityNodeObject::labelForElement(Element* element) const
{
if (!is<HTMLElement>(*element) || !downcast<HTMLElement>(*element).isLabelable())
if (!is<HTMLElement>(element) || !downcast<HTMLElement>(element)->isLabelable())
return nullptr;

const AtomString& id = element->getIdAttribute();
Expand Down Expand Up @@ -1603,6 +1603,17 @@ void AccessibilityNodeObject::titleElementText(Vector<AccessibilityText>& textOr
textOrder.append(AccessibilityText(String(), AccessibilityTextSource::LabelByElement));
}

AccessibilityObject* AccessibilityNodeObject::titleUIElement() const
{
if (!exposesTitleUIElement())
return nullptr;

if (isFigureElement())
return captionForFigure();

return axObjectCache()->getOrCreate(labelForElement(dynamicDowncast<Element>(node())));
}

bool AccessibilityNodeObject::exposesTitleUIElement() const
{
if (!isControl() && !isFigureElement())
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/accessibility/AccessibilityNodeObject.h
Expand Up @@ -197,6 +197,7 @@ class AccessibilityNodeObject : public AccessibilityObject {
AccessibilityObject* menuButtonForMenu() const;
AccessibilityObject* captionForFigure() const;
virtual void titleElementText(Vector<AccessibilityText>&) const;
AccessibilityObject* titleUIElement() const override;
bool exposesTitleUIElement() const override;

private:
Expand Down
20 changes: 3 additions & 17 deletions Source/WebCore/accessibility/AccessibilityRenderObject.cpp
Expand Up @@ -1089,24 +1089,10 @@ void AccessibilityRenderObject::titleElementText(Vector<AccessibilityText>& text

AccessibilityObject* AccessibilityRenderObject::titleUIElement() const
{
if (!m_renderer || !exposesTitleUIElement())
return nullptr;

// if isFieldset is true, the renderer is guaranteed to be a RenderFieldset
if (isFieldset())
return axObjectCache()->getOrCreate(downcast<RenderBlock>(*m_renderer).findFieldsetLegend(RenderBlock::FieldsetIncludeFloatingOrOutOfFlow));

if (isFigureElement())
return captionForFigure();

Node* node = m_renderer->node();
if (!is<Element>(node))
return nullptr;
HTMLLabelElement* label = labelForElement(downcast<Element>(node));
if (label && label->renderer())
return axObjectCache()->getOrCreate(label);
if (m_renderer && isFieldset() && exposesTitleUIElement())
return axObjectCache()->getOrCreate(dynamicDowncast<RenderBlock>(m_renderer.get())->findFieldsetLegend(RenderBlock::FieldsetIncludeFloatingOrOutOfFlow));

return nullptr;
return AccessibilityNodeObject::titleUIElement();
}

bool AccessibilityRenderObject::isAllowedChildOfTree() const
Expand Down

0 comments on commit 2670ad1

Please sign in to comment.