Skip to content

Commit

Permalink
[IFC][Ruby] Anonymous bases should have white-space:nowrap
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=266635
rdar://119864996

Reviewed by Alan Baradlay.

The UA stylesheet has 'white-space: nowrap' for bases https://www.w3.org/TR/css-ruby-1/#default-ua-ruby.
This should also be applied to anonymous bases. The behavior matches Firefox.

* LayoutTests/TestExpectations:
* LayoutTests/fast/ruby/floating-ruby-text-expected.txt:
* LayoutTests/fast/ruby/positioned-ruby-text-expected.txt:
* Source/WebCore/rendering/RenderElement.cpp:
(WebCore::RenderElement::propagateStyleToAnonymousChildren):

Don't reset ruby style when propagating style changes to anonymous children.

* Source/WebCore/rendering/updating/RenderTreeBuilderRuby.cpp:
(WebCore::createAnonymousStyleForRuby):

Set 'white-space: nowrap' to anonymous base style.

(WebCore::createAnonymousRendererForRuby):

Factor into functions.

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

Canonical link: https://commits.webkit.org/272285@main
  • Loading branch information
anttijk committed Dec 19, 2023
1 parent 1d60d45 commit bcdeb1a
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 39 deletions.
4 changes: 1 addition & 3 deletions LayoutTests/TestExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -7449,8 +7449,6 @@ imported/blink/fast/ruby/ruby-first-letter.html [ ImageOnlyFailure ]

# needs reasonable -expectation.html
fast/ruby/ruby-expansion-cjk-4.html [ ImageOnlyFailure ]
# Needs content adjustment
fast/ruby/ruby-punctuation-avoid-breaking.html [ ImageOnlyFailure ]

webkit.org/b/266537 [ Debug ] imported/w3c/web-platform-tests/css/css-ruby/empty-ruby-text-container-float.html [ Skip ]

Expand All @@ -7459,4 +7457,4 @@ http/wpt/opener/child-access-parent-via-windowproxy.html [ Skip ]
http/wpt/opener/iframe-access-top-via-windowproxy.html [ Skip ]
http/wpt/opener/parent-access-child-via-windowproxy.html [ Skip ]

webkit.org/b/266477 compositing/layer-creation/scale-rotation-transition-overlap.html [ Failure Timeout ]
webkit.org/b/266477 compositing/layer-creation/scale-rotation-transition-overlap.html [ Failure Timeout ]
25 changes: 12 additions & 13 deletions LayoutTests/fast/ruby/floating-ruby-text-expected.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
layer at (0,0) size 800x600
RenderView at (0,0) size 800x600
layer at (0,0) size 800x46
RenderBlock {HTML} at (0,0) size 800x46 [color=#FFFFFF]
RenderBody {BODY} at (8,8) size 784x30
RenderInline {RUBY} at (0,0) size 740x25
RenderInline (generated) at (0,0) size 740x25
RenderText {#text} at (0,5) size 740x25
text run at (0,5) width 740: "Attempt to create a floating ruby text element. Float is not supported for"
text run at (0,20) width 670: "ruby text, which should be apparent from the resulting render tree."
RenderBlock {RT} at (0,0) size 740x5
RenderText {#text} at (350,0) size 40x5
text run at (350,0) width 40: "rubytext"
layer at (0,0) size 1428x585
RenderView at (0,0) size 800x585
layer at (0,0) size 800x31
RenderBlock {HTML} at (0,0) size 800x31 [color=#FFFFFF]
RenderBody {BODY} at (8,8) size 784x15
RenderInline {RUBY} at (0,0) size 1420x10
RenderInline (generated) at (0,0) size 1420x10
RenderText {#text} at (0,5) size 1420x10
text run at (0,5) width 1420: "Attempt to create a floating ruby text element. Float is not supported for ruby text, which should be apparent from the resulting render tree."
RenderBlock {RT} at (0,0) size 1420x5
RenderText {#text} at (690,0) size 40x5
text run at (690,0) width 40: "rubytext"
RenderText {#text} at (0,0) size 0x0
26 changes: 12 additions & 14 deletions LayoutTests/fast/ruby/positioned-ruby-text-expected.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
layer at (0,0) size 800x600
RenderView at (0,0) size 800x600
layer at (0,0) size 800x61
RenderBlock {HTML} at (0,0) size 800x61
RenderBody {BODY} at (8,8) size 784x45
RenderInline {RUBY} at (0,0) size 760x40
RenderInline (generated) at (0,0) size 760x40
RenderText {#text} at (0,5) size 760x40
text run at (0,5) width 760: "Attempt to create a positioned ruby text element. Non-static position is not"
text run at (0,20) width 750: "supported for ruby text, which should be apparent from the resulting render"
text run at (0,35) width 50: "tree."
RenderBlock {RT} at (0,0) size 760x5
RenderText {#text} at (360,0) size 40x5
text run at (360,0) width 40: "rubytext"
layer at (0,0) size 1588x585
RenderView at (0,0) size 800x585
layer at (0,0) size 800x31
RenderBlock {HTML} at (0,0) size 800x31
RenderBody {BODY} at (8,8) size 784x15
RenderInline {RUBY} at (0,0) size 1580x10
RenderInline (generated) at (0,0) size 1580x10
RenderText {#text} at (0,5) size 1580x10
text run at (0,5) width 1580: "Attempt to create a positioned ruby text element. Non-static position is not supported for ruby text, which should be apparent from the resulting render tree."
RenderBlock {RT} at (0,0) size 1580x5
RenderText {#text} at (770,0) size 40x5
text run at (770,0) width 40: "rubytext"
RenderText {#text} at (0,0) size 0x0
2 changes: 2 additions & 0 deletions LayoutTests/platform/ios/TestExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -1767,6 +1767,8 @@ fast/ruby/ruby-expansion-cjk.html [ ImageOnlyFailure ]
fast/ruby/ruby-inline-style-not-updated-with-before-after-content.html [ Failure ]
fast/ruby/ruby-inline-style-not-updated.html [ Failure ]
fast/ruby/ruby-justification.html [ ImageOnlyFailure ]
fast/ruby/floating-ruby-text.html [ Failure ]
fast/ruby/positioned-ruby-text.html [ Failure ]
fast/shapes/shape-outside-floats/shape-outside-floats-shape-margin-percent.html [ ImageOnlyFailure ]
fast/spatial-navigation/snav-1st-stop.html [ Failure ]
fast/spatial-navigation/snav-clipped-overflowed-content.html [ Failure ]
Expand Down
9 changes: 8 additions & 1 deletion Source/WebCore/rendering/RenderElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
#include "RenderText.h"
#include "RenderTheme.h"
#include "RenderTreeBuilder.h"
#include "RenderTreeBuilderRuby.h"
#include "RenderView.h"
#include "ResolvedStyle.h"
#include "SVGElementTypeHelpers.h"
Expand Down Expand Up @@ -780,7 +781,13 @@ void RenderElement::propagateStyleToAnonymousChildren(StylePropagationType propa
if (is<RenderFragmentedFlow>(elementChild.get()))
continue;

auto newStyle = RenderStyle::createAnonymousStyleWithDisplay(style(), elementChild->style().display());
auto newStyle = [&] {
auto display = elementChild->style().display();
if (display == DisplayType::RubyBase || display == DisplayType::Ruby)
return createAnonymousStyleForRuby(style(), display);
return RenderStyle::createAnonymousStyleWithDisplay(style(), display);
}();

if (style().specifiesColumns()) {
if (elementChild->style().specifiesColumns())
newStyle.inheritColumnPropertiesFrom(style());
Expand Down
30 changes: 22 additions & 8 deletions Source/WebCore/rendering/updating/RenderTreeBuilderRuby.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,25 @@ RenderElement& RenderTreeBuilder::Ruby::findOrCreateParentForChild(RenderRubyAsI
return *lastRun;
}

RenderStyle createAnonymousStyleForRuby(const RenderStyle& parentStyle, DisplayType display)
{
ASSERT(display == DisplayType::Ruby || display == DisplayType::RubyBase);

auto style = RenderStyle::createAnonymousStyleWithDisplay(parentStyle, display);
style.setUnicodeBidi(UnicodeBidi::Isolate);
if (display == DisplayType::RubyBase)
style.setTextWrapMode(TextWrapMode::NoWrap);
return style;
}

static RenderPtr<RenderElement> createAnonymousRendererForRuby(RenderElement& parent, DisplayType display)
{
auto style = createAnonymousStyleForRuby(parent.style(), display);
auto ruby = createRenderer<RenderInline>(RenderObject::Type::Inline, parent.document(), WTFMove(style));
ruby->initializeStyle();
return ruby;
}

RenderElement& RenderTreeBuilder::Ruby::findOrCreateParentForStyleBasedRubyChild(RenderElement& parent, const RenderObject& child, RenderObject*& beforeChild)
{
if (!child.isRenderText() && child.style().display() == DisplayType::Ruby && parent.style().display() == DisplayType::RubyBlock)
Expand All @@ -259,8 +278,7 @@ RenderElement& RenderTreeBuilder::Ruby::findOrCreateParentForStyleBasedRubyChild
}

if (parent.style().display() != DisplayType::Ruby) {
auto rubyContainer = createRenderer<RenderInline>(RenderObject::Type::Inline, parent.document(), RenderStyle::createAnonymousStyleWithDisplay(parent.style(), DisplayType::Ruby));
rubyContainer->initializeStyle();
auto rubyContainer = createAnonymousRendererForRuby(parent, DisplayType::Ruby);
WeakPtr newParent = rubyContainer.get();
m_builder.attach(parent, WTFMove(rubyContainer), beforeChild);
beforeChild = nullptr;
Expand All @@ -279,10 +297,7 @@ RenderElement& RenderTreeBuilder::Ruby::findOrCreateParentForStyleBasedRubyChild
return downcast<RenderElement>(*previous);
}

auto baseStyle = RenderStyle::createAnonymousStyleWithDisplay(parent.style(), DisplayType::RubyBase);
baseStyle.setUnicodeBidi(UnicodeBidi::Isolate);

auto rubyBase = createRenderer<RenderInline>(RenderObject::Type::Inline, parent.document(), WTFMove(baseStyle));
auto rubyBase = createAnonymousRendererForRuby(parent, DisplayType::RubyBase);
rubyBase->initializeStyle();
WeakPtr newParent = rubyBase.get();
m_builder.inlineBuilder().attach(downcast<RenderInline>(parent), WTFMove(rubyBase), beforeChild);
Expand All @@ -307,8 +322,7 @@ void RenderTreeBuilder::Ruby::attachForStyleBasedRuby(RenderElement& parent, Ren
// 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();
auto rubyBase = createAnonymousRendererForRuby(parent, DisplayType::RubyBase);
m_builder.attachToRenderElementInternal(parent, WTFMove(rubyBase), beforeChild);
}
}
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 @@ -64,5 +64,7 @@ class RenderTreeBuilder::Ruby {
RenderTreeBuilder& m_builder;
};

RenderStyle createAnonymousStyleForRuby(const RenderStyle& parentStyle, DisplayType);

}

0 comments on commit bcdeb1a

Please sign in to comment.