Skip to content

Commit

Permalink
[IFC][Ruby] Support annotation without base
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=265245

Reviewed by Alan Baradlay.

<ruby<rt>foo</rt></ruby>

* Source/WebCore/layout/formattingContexts/inline/InlineLine.cpp:
(WebCore::Layout::Line::Run::isContentfulOrHasDecoration):

Make empty ruby bases contentful.

* Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayContentBuilder.cpp:
(WebCore::Layout::InlineDisplayContentBuilder::handleInlineBoxEnd):
* Source/WebCore/rendering/updating/RenderTreeBuilder.cpp:
(WebCore::RenderTreeBuilder::attachInternal):
* Source/WebCore/rendering/updating/RenderTreeBuilderRuby.cpp:
(WebCore::RenderTreeBuilder::Ruby::attachForStyleBasedRuby):

Construct an anonymous base if there is no existing base.

* Source/WebCore/rendering/updating/RenderTreeBuilderRuby.h:

Canonical link: https://commits.webkit.org/271056@main
  • Loading branch information
anttijk committed Nov 22, 2023
1 parent 5f79b64 commit f73bd3f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,8 @@ bool Line::Run::isContentfulOrHasDecoration(const Run& run, const InlineFormatti
if (run.isInlineBox()) {
if (run.logicalWidth())
return true;
if (run.layoutBox().isRenderRubyBase())
return true;
// Even negative horizontal margin makes the line "contentful".
auto& inlineBoxGeometry = formattingContext.geometryForBox(run.layoutBox());
if (run.isInlineBoxStart())
Expand Down
7 changes: 6 additions & 1 deletion Source/WebCore/rendering/updating/RenderTreeBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,12 @@ void RenderTreeBuilder::attachInternal(RenderElement& parent, RenderPtr<RenderOb
}

if (parent.style().display() == DisplayType::Ruby || parent.style().display() == DisplayType::RubyBlock) {
insertRecursiveIfNeeded(rubyBuilder().findOrCreateParentForStyleBasedRubyChild(parent, *child, beforeChild));
auto& parentCandidate = rubyBuilder().findOrCreateParentForStyleBasedRubyChild(parent, *child, beforeChild);
if (&parentCandidate == &parent) {
rubyBuilder().attachForStyleBasedRuby(parentCandidate, WTFMove(child), beforeChild);
return;
}
insertRecursiveIfNeeded(parentCandidate);
return;
}

Expand Down
25 changes: 25 additions & 0 deletions Source/WebCore/rendering/updating/RenderTreeBuilderRuby.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,31 @@ RenderElement& RenderTreeBuilder::Ruby::findOrCreateParentForStyleBasedRubyChild
return *newParent;
}

void RenderTreeBuilder::Ruby::attachForStyleBasedRuby(RenderElement& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild)
{
if (parent.style().display() == DisplayType::RubyBlock) {
ASSERT(child->style().display() == DisplayType::Ruby);
m_builder.attachToRenderElementInternal(parent, WTFMove(child), beforeChild);
return;
}
ASSERT(parent.style().display() == DisplayType::Ruby);
ASSERT(child->style().display() == DisplayType::RubyBase || child->style().display() == DisplayType::RubyAnnotation);

while (beforeChild && beforeChild->parent() && beforeChild->parent() != &parent)
beforeChild = beforeChild->parent();

if (child->style().display() == DisplayType::RubyAnnotation) {
// Create an empty anonymous base if it is missing.
WeakPtr previous = beforeChild ? beforeChild->previousSibling() : parent.lastChild();
if (!previous || previous->style().display() != DisplayType::RubyBase) {
auto rubyBase = createRenderer<RenderInline>(RenderObject::Type::Inline, parent.document(), RenderStyle::createAnonymousStyleWithDisplay(parent.style(), DisplayType::RubyBase));
rubyBase->initializeStyle();
m_builder.attachToRenderElementInternal(parent, WTFMove(rubyBase), beforeChild);
}
}
m_builder.attachToRenderElementInternal(parent, WTFMove(child), beforeChild);
}

RenderRubyBase& RenderTreeBuilder::Ruby::rubyBaseSafe(RenderRubyRun& rubyRun)
{
auto* base = rubyRun.rubyBase();
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/rendering/updating/RenderTreeBuilderRuby.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ class RenderTreeBuilder::Ruby {

RenderElement& findOrCreateParentForChild(RenderRubyAsBlock& parent, const RenderObject& child, RenderObject*& beforeChild);
RenderElement& findOrCreateParentForChild(RenderRubyAsInline& parent, const RenderObject& child, RenderObject*& beforeChild);

RenderElement& findOrCreateParentForStyleBasedRubyChild(RenderElement& parent, const RenderObject& child, RenderObject*& beforeChild);
void attachForStyleBasedRuby(RenderElement& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild);

private:
void moveInlineChildren(RenderRubyBase& from, RenderRubyBase& to, RenderObject* beforeChild);
Expand Down

0 comments on commit f73bd3f

Please sign in to comment.