Skip to content

Commit

Permalink
[IFC][Ruby] Return correct accessibility roles
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=266468
rdar://119712254

Reviewed by Alan Baradlay.

* LayoutTests/accessibility/mac/ruby-hierarchy-roles-expected.txt:
* LayoutTests/accessibility/mac/ruby-hierarchy-roles.html:

Update the test for the new ruby hierarchy.
Blockify by setting position:absolute.

* LayoutTests/platform/mac-wk1/TestExpectations:

Disable for now in WK1 because the setting leaks accross tests.

* Source/WebCore/accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::computeAccessibilityIsIgnored const):
(WebCore::AccessibilityRenderObject::determineAccessibilityRole):

Return the roles.

* Source/WebCore/rendering/updating/RenderTreeBuilderRuby.cpp:
(WebCore::RenderTreeBuilder::Ruby::findOrCreateParentForStyleBasedRubyChild):

Return the existing anonymous ruby box for a ruby-block parent if there is one.

Canonical link: https://commits.webkit.org/272111@main
  • Loading branch information
anttijk committed Dec 15, 2023
1 parent 29cbe4a commit 1da2795
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 31 deletions.
16 changes: 6 additions & 10 deletions LayoutTests/accessibility/mac/ruby-hierarchy-roles-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,23 @@ PASS rubyElem != null is true
PASS axRuby != null is true
PASS role is expectedRubyRole
PASS subrole is expectedRubyInlineSubrole
PASS axRubyRun != null is true
PASS axRubyBase != null is true
PASS role is expectedRubyRole
PASS subrole is expectedRubyRunSubrole
PASS subrole is expectedRubyBaseSubrole
PASS axRubyText != null is true
PASS role is expectedRubyRole
PASS subrole is expectedRubyTextSubrole
PASS axRubyBase != null is true
PASS role is expectedRubyRole
PASS subrole is expectedRubyBaseSubrole
PASS axRuby != null is true
PASS role is expectedRubyRole
PASS subrole is expectedRubyBlockSubrole
PASS axRubyRun != null is true
PASS role is expectedRubyRole
PASS subrole is expectedRubyRunSubrole
PASS axRubyText != null is true
PASS role is expectedRubyRole
PASS subrole is expectedRubyTextSubrole
PASS subrole is expectedRubyInlineSubrole
PASS axRubyBase != null is true
PASS role is expectedRubyRole
PASS subrole is expectedRubyBaseSubrole
PASS axRubyText != null is true
PASS role is expectedRubyRole
PASS subrole is expectedRubyTextSubrole
PASS successfullyParsed is true

TEST COMPLETE
Expand Down
38 changes: 17 additions & 21 deletions LayoutTests/accessibility/mac/ruby-hierarchy-roles.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- webkit-test-runner [ CSSBasedRubyEnabled=true ] -->
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
Expand All @@ -21,17 +22,15 @@
var expectedRubyRole = "AXRole: AXGroup"; // all ruby containers have AXGroup role
var expectedRubyInlineSubrole = "AXSubrole: AXRubyInline";
var expectedRubyBlockSubrole = "AXSubrole: AXRubyBlock";
var expectedRubyRunSubrole = "AXSubrole: AXRubyRun";
var expectedRubyTextSubrole = "AXSubrole: AXRubyText";
var expectedRubyBaseSubrole = "AXSubrole: AXRubyBase";

// Try inline style first, block style second
var rubyElem = document.getElementById("rubyElemId");
shouldBeTrue("rubyElem != null");
rubyElem.style.display = "inline";
checkHierarchyAndRoles(rubyElem);

rubyElem.style.display = "block";
rubyElem.style.position = "absolute";
checkHierarchyAndRoles(rubyElem);

function checkHierarchyAndRoles(rubyElem) {
Expand All @@ -40,36 +39,33 @@
role = axRuby.role;
subrole = axRuby.subrole;
shouldBe("role", "expectedRubyRole");
if (rubyElem.style.display == "inline") {
if (rubyElem.style.position != "absolute") {
shouldBe("subrole", "expectedRubyInlineSubrole");
}
else {
shouldBe("subrole", "expectedRubyBlockSubrole");
axRuby = axRuby.childAtIndex(0);
role = axRuby.role;
subrole = axRuby.subrole;
shouldBe("role", "expectedRubyRole");
shouldBe("subrole", "expectedRubyInlineSubrole");
}
// RubyRun
axRubyRun = axRuby.childAtIndex(0);
shouldBeTrue("axRubyRun != null");
role = axRubyRun.role;
subrole = axRubyRun.subrole;

// RubyBase
axRubyBase = axRuby.childAtIndex(0);
shouldBeTrue("axRubyBase != null");
role = axRubyBase.role;
subrole = axRubyBase.subrole;
shouldBe("role", "expectedRubyRole");
shouldBe("subrole", "expectedRubyRunSubrole");
shouldBe("subrole", "expectedRubyBaseSubrole");

// RubyText
axRubyText = axRubyRun.childAtIndex(0);
axRubyText = axRuby.childAtIndex(1);
shouldBeTrue("axRubyText != null");
role = axRubyText.role;
subrole = axRubyText.subrole;
shouldBe("role", "expectedRubyRole");
shouldBe("subrole", "expectedRubyTextSubrole");

// RubyBase
axRubyBase = axRubyRun.childAtIndex(1);
shouldBeTrue("axRubyBase != null");
role = axRubyBase.role;
subrole = axRubyBase.subrole;
shouldBe("role", "expectedRubyRole");
shouldBe("subrole", "expectedRubyBaseSubrole");
}
}
}
Expand Down
1 change: 1 addition & 0 deletions LayoutTests/platform/mac-wk1/TestExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -2725,6 +2725,7 @@ fast/css/transform-function-perspective-crash.html [ Failure ]
webkit.org/b/265535 inspector/layers/layers-for-node.html [ Pass Timeout ]

webkit.org/b/265783 fast/ruby/ruby-line-height.html [ Skip ]
webkit.org/b/265783 accessibility/mac/ruby-hierarchy-roles.html [ Skip ]

webkit.org/b/266184 compositing/images/truncated-direct-png-image.html [ ImageOnlyFailure ]

Expand Down
23 changes: 23 additions & 0 deletions Source/WebCore/accessibility/AccessibilityRenderObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,16 @@ bool AccessibilityRenderObject::computeAccessibilityIsIgnored() const
if (m_renderer->isRenderRubyRun() || m_renderer->isRenderRubyAsBlock() || m_renderer->isRenderRubyAsInline())
return false;

switch (m_renderer->style().display()) {
case DisplayType::Ruby:
case DisplayType::RubyBlock:
case DisplayType::RubyAnnotation:
case DisplayType::RubyBase:
return false;
default:
break;
}

// Find out if this element is inside of a label element.
// If so, it may be ignored because it's the label for a checkbox or radio button.
auto* controlObject = correspondingControlForLabelElement();
Expand Down Expand Up @@ -2147,6 +2157,19 @@ AccessibilityRole AccessibilityRenderObject::determineAccessibilityRole()
if (m_renderer->isRenderRubyAsInline())
return AccessibilityRole::RubyInline;

switch (m_renderer->style().display()) {
case DisplayType::Ruby:
return AccessibilityRole::RubyInline;
case DisplayType::RubyBlock:
return AccessibilityRole::RubyBlock;
case DisplayType::RubyAnnotation:
return AccessibilityRole::RubyText;
case DisplayType::RubyBase:
return AccessibilityRole::RubyBase;
default:
break;
}

if (m_renderer->isAnonymous() && (is<RenderTableCell>(m_renderer.get()) || is<RenderTableRow>(m_renderer.get()) || is<RenderTable>(m_renderer.get())))
return AccessibilityRole::Ignored;

Expand Down
6 changes: 6 additions & 0 deletions Source/WebCore/rendering/updating/RenderTreeBuilderRuby.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,12 @@ RenderElement& RenderTreeBuilder::Ruby::findOrCreateParentForStyleBasedRubyChild
if (!child.isRenderText() && child.style().display() == DisplayType::Ruby && parent.style().display() == DisplayType::RubyBlock)
return parent;

if (parent.style().display() == DisplayType::RubyBlock && parent.firstChild()) {
// See if we have an anonymous ruby box already.
ASSERT(parent.firstChild()->style().display() == DisplayType::Ruby);
return downcast<RenderElement>(*parent.firstChild());
}

if (parent.style().display() != DisplayType::Ruby) {
auto rubyContainer = createRenderer<RenderInline>(RenderObject::Type::Inline, parent.document(), RenderStyle::createAnonymousStyleWithDisplay(parent.style(), DisplayType::Ruby));
rubyContainer->initializeStyle();
Expand Down

0 comments on commit 1da2795

Please sign in to comment.