Skip to content

Commit

Permalink
Ruby style cleanups
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=266623
rdar://119856171

Reviewed by Tim Nguyen and Alan Baradlay.

* LayoutTests/fast/ruby/ruby-block-style-not-updated-expected.txt:
* Source/WebCore/html/RubyElement.cpp:
(WebCore::RubyElement::createElementRenderer):
* Source/WebCore/html/RubyTextElement.cpp:
(WebCore::RubyTextElement::createElementRenderer):

Ensure we can't create legacy ruby renderers with css ruby enabled.

* Source/WebCore/style/StyleAdjuster.cpp:
(WebCore::Style::forceBidiIsolationForRuby):

Rename and include all cases to switch.

(WebCore::Style::Adjuster::adjust const):

Remove some no-op code.

(WebCore::Style::adjustUnicodeBidiForRuby): Deleted.

Canonical link: https://commits.webkit.org/272267@main
  • Loading branch information
anttijk committed Dec 19, 2023
1 parent 7412c32 commit 4be388c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ layer at (0,0) size 800x600
layer at (0,0) size 800x600
RenderBlock {HTML} at (0,0) size 800x600
RenderBody {BODY} at (8,8) size 784x584
RenderRuby (block) {RUBY} at (0,0) size 784x128 [color=#0000FF]
RenderRubyRun (anonymous) at (0,0) size 512x128
RenderRubyBase (anonymous) at (0,0) size 512x128
RenderText {#text} at (0,0) size 512x128
text run at (0,0) width 512: "ABCD"
RenderBlock {RUBY} at (0,0) size 784x128 [color=#0000FF]
RenderText {#text} at (0,0) size 512x128
text run at (0,0) width 512: "ABCD"
RenderBlock {DIV} at (0,128) size 784x128 [color=#008000]
RenderText {#text} at (0,0) size 512x128
text run at (0,0) width 512: "EFGH"
11 changes: 6 additions & 5 deletions Source/WebCore/html/RubyElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ Ref<RubyElement> RubyElement::create(Document& document)

RenderPtr<RenderElement> RubyElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition& insertionPosition)
{
if (style.display() == DisplayType::Inline)
return createRenderer<RenderRubyAsInline>(*this, WTFMove(style));
if (style.display() == DisplayType::Block || style.display() == DisplayType::InlineBlock)
return createRenderer<RenderRubyAsBlock>(*this, WTFMove(style));

if (!document().settings().cssBasedRubyEnabled()) {
if (style.display() == DisplayType::Inline)
return createRenderer<RenderRubyAsInline>(*this, WTFMove(style));
if (style.display() == DisplayType::Block || style.display() == DisplayType::InlineBlock)
return createRenderer<RenderRubyAsBlock>(*this, WTFMove(style));
}
return HTMLElement::createElementRenderer(WTFMove(style), insertionPosition);
}

Expand Down
8 changes: 5 additions & 3 deletions Source/WebCore/html/RubyTextElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ Ref<RubyTextElement> RubyTextElement::create(Document& document)

RenderPtr<RenderElement> RubyTextElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition& insertionPosition)
{
// RenderRubyText requires its parent to be RenderRubyRun.
if (isRuby(insertionPosition.parent()) && style.display() == DisplayType::Block)
return createRenderer<RenderRubyText>(*this, WTFMove(style));
if (!document().settings().cssBasedRubyEnabled()) {
// RenderRubyText requires its parent to be RenderRubyRun.
if (isRuby(insertionPosition.parent()) && style.display() == DisplayType::Block)
return createRenderer<RenderRubyText>(*this, WTFMove(style));
}
return HTMLElement::createElementRenderer(WTFMove(style), insertionPosition);
}

Expand Down
15 changes: 8 additions & 7 deletions Source/WebCore/style/StyleAdjuster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,17 +379,21 @@ static bool isRubyContainerOrInternalRubyBox(const RenderStyle& style)
}

// https://drafts.csswg.org/css-ruby-1/#bidi
static UnicodeBidi adjustUnicodeBidiForRuby(UnicodeBidi unicodeBidi)
static UnicodeBidi forceBidiIsolationForRuby(UnicodeBidi unicodeBidi)
{
switch (unicodeBidi) {
case UnicodeBidi::Normal:
case UnicodeBidi::Embed:
case UnicodeBidi::Isolate:
return UnicodeBidi::Isolate;
case UnicodeBidi::Override:
case UnicodeBidi::IsolateOverride:
return UnicodeBidi::IsolateOverride;
default:
return unicodeBidi;
case UnicodeBidi::Plaintext:
return UnicodeBidi::Plaintext;
}
ASSERT_NOT_REACHED();
return UnicodeBidi::Isolate;
}

void Adjuster::adjust(RenderStyle& style, const RenderStyle* userAgentAppearanceStyle) const
Expand Down Expand Up @@ -418,9 +422,6 @@ void Adjuster::adjust(RenderStyle& style, const RenderStyle* userAgentAppearance

if (m_element->hasTagName(legendTag))
style.setEffectiveDisplay(equivalentBlockDisplay(style));

if (isRubyContainerOrInternalRubyBox(style))
style.setEffectiveDisplay(style.display());
}

// Top layer elements are always position: absolute; unless the position is set to fixed.
Expand Down Expand Up @@ -470,7 +471,7 @@ void Adjuster::adjust(RenderStyle& style, const RenderStyle* userAgentAppearance
style.setEffectiveDisplay(equivalentInlineDisplay(style));
// https://drafts.csswg.org/css-ruby-1/#bidi
if (isRubyContainerOrInternalRubyBox(style))
style.setUnicodeBidi(adjustUnicodeBidiForRuby(style.unicodeBidi()));
style.setUnicodeBidi(forceBidiIsolationForRuby(style.unicodeBidi()));
}

auto hasAutoZIndex = [](const RenderStyle& style, const RenderStyle& parentBoxStyle, const Element* element) {
Expand Down

0 comments on commit 4be388c

Please sign in to comment.