Skip to content

Commit

Permalink
[IFC][Ruby] Implement text-emphasis suppression
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=266484
rdar://119722467

Reviewed by Alan Baradlay.

for fast/text/emphasis-avoid-ruby.html

* Source/WebCore/rendering/RenderText.cpp:
(WebCore::RenderText::emphasisMarkExistsAndIsAbove):

Find the annotation and check if it is empty, same as the legacy code below.

Canonical link: https://commits.webkit.org/272127@main
  • Loading branch information
anttijk committed Dec 15, 2023
1 parent 52521e0 commit 4e68d91
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Source/WebCore/rendering/RenderText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2118,7 +2118,29 @@ std::optional<bool> RenderText::emphasisMarkExistsAndIsAbove(const RenderText& r
|| (!style.isHorizontalWritingMode() && (emphasisPosition & TextEmphasisPosition::Left)))
return isAbove; // Ruby text is always over, so it cannot suppress emphasis marks under.

auto findRubyAnnotation = [&]() -> RenderBlockFlow* {
for (auto* baseCandidate = renderer.parent(); baseCandidate; baseCandidate = baseCandidate->parent()) {
if (!baseCandidate->isInline())
return nullptr;
if (baseCandidate->style().display() == DisplayType::RubyBase) {
auto* annotationCandidate = baseCandidate->nextSibling();
if (annotationCandidate && annotationCandidate->style().display() == DisplayType::RubyAnnotation)
return dynamicDowncast<RenderBlockFlow>(annotationCandidate);
return nullptr;
}
}
return nullptr;
};

if (auto* annotation = findRubyAnnotation()) {
// The emphasis marks over are suppressed only if there is a ruby annotation box and it is not empty.
if (annotation->hasLines())
return { };
return isAbove;
}

RenderBlock* containingBlock = renderer.containingBlock();

if (!containingBlock || !containingBlock->isRenderRubyBase())
return isAbove; // This text is not inside a ruby base, so it does not have ruby text over it.

Expand Down

0 comments on commit 4e68d91

Please sign in to comment.