Title: [174489] trunk
Revision
174489
Author
[email protected]
Date
2014-10-08 18:14:30 -0700 (Wed, 08 Oct 2014)

Log Message

Inline ruby does not get justified correctly
https://bugs.webkit.org/show_bug.cgi?id=137421

Source/WebCore:

Patch by Myles C. Maxfield <[email protected]> on 2014-10-08
Reviewed by Dave Hyatt.

We justify text in two passes: one counts expansion opportunities within a line,
and the other doles out widths and expansion amounts to constituent inline boxes.
This patch simply modifies both passes to descend into ruby bases. Once it has
done so, we then re-layout the ruby run with the newly found width.

Tests: fast/ruby/ruby-justification-hittest.html
       fast/ruby/ruby-justification.html

* rendering/InlineBox.h:
(WebCore::InlineBox::setExpansion): updateRubyForJustifiedText() has to set the
expansion for an inline box, so make setExpansion() public.
* rendering/RenderBlockLineLayout.cpp:
(WebCore::updateRubyForJustifiedText): Given values that have already been
computed in computeInlineDirectionPositionsForSegment(), adjust the widths and
expansion values for all the various pieces of ruby.
(WebCore::computeExpansionForJustifiedText): Call updateRubyForJustifiedText() if
necessary.
(WebCore::RenderBlockFlow::computeInlineDirectionPositionsForSegment): When
counting expansion opportunities in a line, include ruby bases.
* rendering/RenderRubyRun.h: Fix grammar in comment.
* rendering/RenderText.cpp:
(WebCore::RenderText::stringView): Give default arguments to function.
* rendering/RenderText.h: Ditto.

LayoutTests:

Reviewed by Dave Hyatt.

Test that ruby gets spaces inside the ruby base, and that hit testing the
ruby base gives us correct answers.

* fast/ruby/ruby-justification-expected.html: Added.
* fast/ruby/ruby-justification-hittest-expected.txt: Added.
* fast/ruby/ruby-justification-hittest.html: Added.
* fast/ruby/ruby-justification.html: Added.
* platform/mac/fast/ruby/bopomofo-rl-expected.txt: Ruby text gets the CSS
property text-align: justify, which worked prior to this patch. However, this
patch now justifies ruby bases, so now if there is text that is both a ruby
base and ruby text (such as ruby in ruby) it correctly gets justified. This
test does such, and therefore needs to be rebaselined.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (174488 => 174489)


--- trunk/LayoutTests/ChangeLog	2014-10-09 01:05:55 UTC (rev 174488)
+++ trunk/LayoutTests/ChangeLog	2014-10-09 01:14:30 UTC (rev 174489)
@@ -1,3 +1,23 @@
+2014-10-08  Myles C. Maxfield  <[email protected]>
+
+        Inline ruby does not get justified correctly
+        https://bugs.webkit.org/show_bug.cgi?id=137421
+
+        Reviewed by Dave Hyatt.
+
+        Test that ruby gets spaces inside the ruby base, and that hit testing the
+        ruby base gives us correct answers.
+
+        * fast/ruby/ruby-justification-expected.html: Added.
+        * fast/ruby/ruby-justification-hittest-expected.txt: Added.
+        * fast/ruby/ruby-justification-hittest.html: Added.
+        * fast/ruby/ruby-justification.html: Added.
+        * platform/mac/fast/ruby/bopomofo-rl-expected.txt: Ruby text gets the CSS
+        property text-align: justify, which worked prior to this patch. However, this
+        patch now justifies ruby bases, so now if there is text that is both a ruby
+        base and ruby text (such as ruby in ruby) it correctly gets justified. This
+        test does such, and therefore needs to be rebaselined.
+
 2014-10-08  Simon Fraser  <[email protected]>
 
         New baselines for iOS compositing tests.

Added: trunk/LayoutTests/fast/ruby/ruby-justification-expected.html (0 => 174489)


--- trunk/LayoutTests/fast/ruby/ruby-justification-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/ruby/ruby-justification-expected.html	2014-10-09 01:14:30 UTC (rev 174489)
@@ -0,0 +1,21 @@
+This test makes sure that ruby inside text-align: justify has its contents justified.
+<div style="text-align: justify; font-size: 16px;">
+<div>
+abcdefg abcdefg mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
+</div>
+<div>
+abcdefg abcdefg abcdefg mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
+</div>
+<div>
+abcdefg <ruby>abcdefg<rt><span style="color: transparent;">a</span></ruby> abcdefg mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
+</div>
+</div>
+<div style="font-family: Ahem; font-size: 16px;">
+<ruby>abcdefg&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;abcdefg<rt>a</ruby> mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
+</div>
+<div style="text-align: right;">
+a
+</div>
+<div style="text-align: justify;">
+abcdefg abcdefg mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
+</div>

Added: trunk/LayoutTests/fast/ruby/ruby-justification-hittest-expected.txt (0 => 174489)


--- trunk/LayoutTests/fast/ruby/ruby-justification-hittest-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/ruby/ruby-justification-hittest-expected.txt	2014-10-09 01:14:30 UTC (rev 174489)
@@ -0,0 +1,11 @@
+This test makes sure that hit testing works with ruby inside text-align: justify.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS right is 792
+PASS document.elementFromPoint(right - 1, bottom - 1).id is "ruby"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+abcdefg abcdefga mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm

Added: trunk/LayoutTests/fast/ruby/ruby-justification-hittest.html (0 => 174489)


--- trunk/LayoutTests/fast/ruby/ruby-justification-hittest.html	                        (rev 0)
+++ trunk/LayoutTests/fast/ruby/ruby-justification-hittest.html	2014-10-09 01:14:30 UTC (rev 174489)
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<div style="text-align: justify; font-family: Ahem;">
+<ruby id="ruby">abcdefg abcdefg<rt>a</ruby> mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
+</div>
+<script>
+description("This test makes sure that hit testing works with ruby inside text-align: justify.");
+var ruby = document.getElementById("ruby");
+var boundingRect = ruby.getBoundingClientRect();
+var right = boundingRect.right;
+var bottom = boundingRect.bottom;
+shouldBe("right", "792");
+shouldBeEqualToString("document.elementFromPoint(right - 1, bottom - 1).id", "ruby");
+</script>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/ruby/ruby-justification.html (0 => 174489)


--- trunk/LayoutTests/fast/ruby/ruby-justification.html	                        (rev 0)
+++ trunk/LayoutTests/fast/ruby/ruby-justification.html	2014-10-09 01:14:30 UTC (rev 174489)
@@ -0,0 +1,18 @@
+This test makes sure that ruby inside text-align: justify has its contents justified.
+<div style="text-align: justify; font-size: 16px;">
+<div>
+<ruby>abcdefg abcdefg<rt> </ruby> mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
+</div>
+<div>
+<ruby>abcdefg abcdefg<rt> </ruby> abcdefg mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
+</div>
+<div>
+<ruby>abcdefg abcdefg<rt><span style="color: transparent;">a</span></ruby> abcdefg mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
+</div>
+<div style="font-family: Ahem;">
+<ruby>abcdefg abcdefg<rt>a</ruby> mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
+</div>
+<div>
+<ruby>abcdefg abcdefg<rt style="text-align: right; font-size: 16px;">a</ruby> mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
+</div>
+</div>

Modified: trunk/LayoutTests/platform/mac/fast/ruby/bopomofo-rl-expected.txt (174488 => 174489)


--- trunk/LayoutTests/platform/mac/fast/ruby/bopomofo-rl-expected.txt	2014-10-09 01:05:55 UTC (rev 174488)
+++ trunk/LayoutTests/platform/mac/fast/ruby/bopomofo-rl-expected.txt	2014-10-09 01:14:30 UTC (rev 174489)
@@ -19,14 +19,14 @@
               text run at (8,0) width 32: "\x{4E16}"
         RenderRubyRun (anonymous) at (0,32) size 48x32
           RenderRubyText {RT} at (0,0) size 8x32
-            RenderRuby (inline) {RUBY} at (0,0) size 8x16
-              RenderRubyRun (anonymous) at (0,8) size 8x16
-                RenderRubyText {RT} at (-8,0) size 8x16
-                  RenderText {#text} at (0,4) size 8x8
-                    text run at (0,4) width 8: "\x{2CB}"
-                RenderRubyBase (anonymous) at (0,0) size 8x16
-                  RenderText {#text} at (0,0) size 8x16
-                    text run at (0,0) width 16: "\x{3115}\x{3124}"
+            RenderRuby (inline) {RUBY} at (0,0) size 8x24
+              RenderRubyRun (anonymous) at (0,4) size 8x24
+                RenderRubyText {RT} at (-8,0) size 8x24
+                  RenderText {#text} at (0,8) size 8x8
+                    text run at (0,8) width 8: "\x{2CB}"
+                RenderRubyBase (anonymous) at (0,0) size 8x24
+                  RenderText {#text} at (0,0) size 8x24
+                    text run at (0,0) width 24: "\x{3115}\x{3124}"
           RenderRubyBase (anonymous) at (0,0) size 48x32
             RenderText {#text} at (8,0) size 32x32
               text run at (8,0) width 32: "\x{4E0A}"
@@ -45,14 +45,14 @@
               text run at (8,0) width 32: "\x{7121}"
         RenderRubyRun (anonymous) at (0,96) size 48x32
           RenderRubyText {RT} at (0,0) size 8x32
-            RenderRuby (inline) {RUBY} at (0,0) size 8x16
-              RenderRubyRun (anonymous) at (0,8) size 8x16
-                RenderRubyText {RT} at (-8,0) size 8x16
-                  RenderText {#text} at (0,4) size 8x8
-                    text run at (0,4) width 8: "\x{2CA}"
-                RenderRubyBase (anonymous) at (0,0) size 8x16
-                  RenderText {#text} at (0,0) size 8x16
-                    text run at (0,0) width 16: "\x{310B}\x{3122}"
+            RenderRuby (inline) {RUBY} at (0,0) size 8x24
+              RenderRubyRun (anonymous) at (0,4) size 8x24
+                RenderRubyText {RT} at (-8,0) size 8x24
+                  RenderText {#text} at (0,8) size 8x8
+                    text run at (0,8) width 8: "\x{2CA}"
+                RenderRubyBase (anonymous) at (0,0) size 8x24
+                  RenderText {#text} at (0,0) size 8x24
+                    text run at (0,0) width 24: "\x{310B}\x{3122}"
           RenderRubyBase (anonymous) at (0,0) size 48x32
             RenderText {#text} at (8,0) size 32x32
               text run at (8,0) width 32: "\x{96E3}"
@@ -78,27 +78,27 @@
               text run at (8,0) width 32: "\x{53EA}"
         RenderRubyRun (anonymous) at (0,192) size 48x32
           RenderRubyText {RT} at (0,0) size 8x32
-            RenderRuby (inline) {RUBY} at (0,0) size 8x16
-              RenderRubyRun (anonymous) at (0,8) size 8x16
-                RenderRubyText {RT} at (-8,0) size 8x16
-                  RenderText {#text} at (0,4) size 8x8
-                    text run at (0,4) width 8: "\x{2CB}"
-                RenderRubyBase (anonymous) at (0,0) size 8x16
-                  RenderText {#text} at (0,0) size 8x16
-                    text run at (0,0) width 16: "\x{3106}\x{311A}"
+            RenderRuby (inline) {RUBY} at (0,0) size 8x24
+              RenderRubyRun (anonymous) at (0,4) size 8x24
+                RenderRubyText {RT} at (-8,0) size 8x24
+                  RenderText {#text} at (0,8) size 8x8
+                    text run at (0,8) width 8: "\x{2CB}"
+                RenderRubyBase (anonymous) at (0,0) size 8x24
+                  RenderText {#text} at (0,0) size 8x24
+                    text run at (0,0) width 24: "\x{3106}\x{311A}"
           RenderRubyBase (anonymous) at (0,0) size 48x32
             RenderText {#text} at (8,0) size 32x32
               text run at (8,0) width 32: "\x{6015}"
         RenderRubyRun (anonymous) at (0,224) size 48x32
           RenderRubyText {RT} at (0,0) size 8x32
-            RenderRuby (inline) {RUBY} at (0,0) size 8x16
-              RenderRubyRun (anonymous) at (0,8) size 8x16
-                RenderRubyText {RT} at (-8,0) size 8x16
-                  RenderText {#text} at (0,4) size 8x8
-                    text run at (0,4) width 8: "\x{2C7}"
-                RenderRubyBase (anonymous) at (0,0) size 8x16
-                  RenderText {#text} at (0,0) size 8x16
-                    text run at (0,0) width 16: "\x{3127}\x{3121}"
+            RenderRuby (inline) {RUBY} at (0,0) size 8x24
+              RenderRubyRun (anonymous) at (0,4) size 8x24
+                RenderRubyText {RT} at (-8,0) size 8x24
+                  RenderText {#text} at (0,8) size 8x8
+                    text run at (0,8) width 8: "\x{2C7}"
+                RenderRubyBase (anonymous) at (0,0) size 8x24
+                  RenderText {#text} at (0,0) size 8x24
+                    text run at (0,0) width 24: "\x{3127}\x{3121}"
           RenderRubyBase (anonymous) at (0,0) size 48x32
             RenderText {#text} at (8,0) size 32x32
               text run at (8,0) width 32: "\x{6709}"
@@ -111,14 +111,14 @@
               text run at (8,0) width 32: "\x{5FC3}"
         RenderRubyRun (anonymous) at (0,288) size 48x32
           RenderRubyText {RT} at (0,0) size 8x32
-            RenderRuby (inline) {RUBY} at (0,0) size 8x16
-              RenderRubyRun (anonymous) at (0,8) size 8x16
-                RenderRubyText {RT} at (-8,0) size 8x16
-                  RenderText {#text} at (0,4) size 8x8
-                    text run at (0,4) width 8: "\x{2CA}"
-                RenderRubyBase (anonymous) at (0,0) size 8x16
-                  RenderText {#text} at (0,0) size 8x16
-                    text run at (0,0) width 16: "\x{3116}\x{3123}"
+            RenderRuby (inline) {RUBY} at (0,0) size 8x24
+              RenderRubyRun (anonymous) at (0,4) size 8x24
+                RenderRubyText {RT} at (-8,0) size 8x24
+                  RenderText {#text} at (0,8) size 8x8
+                    text run at (0,8) width 8: "\x{2CA}"
+                RenderRubyBase (anonymous) at (0,0) size 8x24
+                  RenderText {#text} at (0,0) size 8x24
+                    text run at (0,0) width 24: "\x{3116}\x{3123}"
           RenderRubyBase (anonymous) at (0,0) size 48x32
             RenderText {#text} at (8,0) size 32x32
               text run at (8,0) width 32: "\x{4EBA}"

Modified: trunk/Source/WebCore/ChangeLog (174488 => 174489)


--- trunk/Source/WebCore/ChangeLog	2014-10-09 01:05:55 UTC (rev 174488)
+++ trunk/Source/WebCore/ChangeLog	2014-10-09 01:14:30 UTC (rev 174489)
@@ -1,3 +1,34 @@
+2014-10-08  Myles C. Maxfield  <[email protected]>
+
+        Inline ruby does not get justified correctly
+        https://bugs.webkit.org/show_bug.cgi?id=137421
+
+        Reviewed by Dave Hyatt.
+
+        We justify text in two passes: one counts expansion opportunities within a line,
+        and the other doles out widths and expansion amounts to constituent inline boxes.
+        This patch simply modifies both passes to descend into ruby bases. Once it has
+        done so, we then re-layout the ruby run with the newly found width.
+
+        Tests: fast/ruby/ruby-justification-hittest.html
+               fast/ruby/ruby-justification.html
+
+        * rendering/InlineBox.h:
+        (WebCore::InlineBox::setExpansion): updateRubyForJustifiedText() has to set the
+        expansion for an inline box, so make setExpansion() public.
+        * rendering/RenderBlockLineLayout.cpp:
+        (WebCore::updateRubyForJustifiedText): Given values that have already been
+        computed in computeInlineDirectionPositionsForSegment(), adjust the widths and
+        expansion values for all the various pieces of ruby.
+        (WebCore::computeExpansionForJustifiedText): Call updateRubyForJustifiedText() if
+        necessary.
+        (WebCore::RenderBlockFlow::computeInlineDirectionPositionsForSegment): When
+        counting expansion opportunities in a line, include ruby bases.
+        * rendering/RenderRubyRun.h: Fix grammar in comment.
+        * rendering/RenderText.cpp:
+        (WebCore::RenderText::stringView): Give default arguments to function.
+        * rendering/RenderText.h: Ditto.
+
 2014-10-08  Dean Jackson  <[email protected]>
 
         PopupMenus should indicate if they are using a custom rendering

Modified: trunk/Source/WebCore/platform/graphics/Font.h (174488 => 174489)


--- trunk/Source/WebCore/platform/graphics/Font.h	2014-10-09 01:05:55 UTC (rev 174488)
+++ trunk/Source/WebCore/platform/graphics/Font.h	2014-10-09 01:14:30 UTC (rev 174489)
@@ -201,6 +201,9 @@
     static bool isCJKIdeograph(UChar32);
     static bool isCJKIdeographOrSymbol(UChar32);
 
+    // BEWARE: If isAfterExpansion is true after this function call, then the returned value includes a trailing opportunity
+    // which may or may not actually be present. RenderBlockFlow::computeInlineDirectionPositionsForSegment() compensates
+    // for this by decrementing the returned value if isAfterExpansion is true at the end of a line.
     static unsigned expansionOpportunityCount(const StringView&, TextDirection, bool& isAfterExpansion);
 
     WEBCORE_EXPORT static void setShouldUseSmoothing(bool);

Modified: trunk/Source/WebCore/rendering/InlineBox.h (174488 => 174489)


--- trunk/Source/WebCore/rendering/InlineBox.h	2014-10-09 01:05:55 UTC (rev 174488)
+++ trunk/Source/WebCore/rendering/InlineBox.h	2014-10-09 01:14:30 UTC (rev 174489)
@@ -269,6 +269,13 @@
     bool dirOverride() const { return m_bitfields.dirOverride(); }
     void setDirOverride(bool dirOverride) { m_bitfields.setDirOverride(dirOverride); }
 
+    void setExpansion(float newExpansion)
+    {
+        m_logicalWidth -= m_expansion;
+        m_expansion = newExpansion;
+        m_logicalWidth += m_expansion;
+    }
+
 private:
     InlineBox* m_next; // The next element on the same line as us.
     InlineBox* m_prev; // The previous element on the same line as us.
@@ -400,7 +407,6 @@
     bool canHaveLeadingExpansion() const { return m_bitfields.hasSelectedChildrenOrCanHaveLeadingExpansion(); }
     void setCanHaveLeadingExpansion(bool canHaveLeadingExpansion) { m_bitfields.setHasSelectedChildrenOrCanHaveLeadingExpansion(canHaveLeadingExpansion); }
     float expansion() const { return m_expansion; }
-    void setExpansion(float expansion) { m_expansion = expansion; }
     
     // For InlineFlowBox and InlineTextBox
     bool extracted() const { return m_bitfields.extracted(); }

Modified: trunk/Source/WebCore/rendering/InlineTextBox.h (174488 => 174489)


--- trunk/Source/WebCore/rendering/InlineTextBox.h	2014-10-09 01:05:55 UTC (rev 174488)
+++ trunk/Source/WebCore/rendering/InlineTextBox.h	2014-10-09 01:14:30 UTC (rev 174489)
@@ -133,13 +133,6 @@
 public:
     virtual bool isLineBreak() const override final;
 
-    void setExpansion(float newExpansion)
-    {
-        m_logicalWidth -= expansion();
-        InlineBox::setExpansion(newExpansion);
-        m_logicalWidth += newExpansion;
-    }
-
 private:
     virtual bool isInlineTextBox() const override final { return true; }
 

Modified: trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp (174488 => 174489)


--- trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp	2014-10-09 01:05:55 UTC (rev 174488)
+++ trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp	2014-10-09 01:14:30 UTC (rev 174489)
@@ -38,6 +38,8 @@
 #include "RenderFlowThread.h"
 #include "RenderLineBreak.h"
 #include "RenderRegion.h"
+#include "RenderRubyBase.h"
+#include "RenderRubyText.h"
 #include "RenderView.h"
 #include "SVGRootInlineBox.h"
 #include "Settings.h"
@@ -544,8 +546,42 @@
     }
 }
 
-static inline void computeExpansionForJustifiedText(BidiRun* firstRun, BidiRun* trailingSpaceRun, Vector<unsigned, 16>& expansionOpportunities, unsigned expansionOpportunityCount, float& totalLogicalWidth, float availableLogicalWidth)
+static inline void updateRubyForJustifiedText(RenderRubyRun& rubyRun, BidiRun& r, const Vector<unsigned, 16>& expansionOpportunities, unsigned& expansionOpportunityCount, float& totalLogicalWidth, float availableLogicalWidth, size_t& i)
 {
+    if (!rubyRun.rubyBase() || !rubyRun.rubyBase()->firstRootBox() || rubyRun.rubyBase()->firstRootBox()->nextRootBox() || !r.renderer().style().collapseWhiteSpace())
+        return;
+
+    auto& rubyBase = *rubyRun.rubyBase();
+    auto& rootBox = *rubyBase.firstRootBox();
+
+    float totalExpansion = 0;
+    unsigned totalOpportunitiesInRun = 0;
+    for (auto* leafChild = rootBox.firstLeafChild(); leafChild; leafChild = leafChild->nextLeafChild()) {
+        if (!leafChild->isInlineTextBox())
+            continue;
+
+        unsigned opportunitiesInRun = expansionOpportunities[i++];
+        ASSERT(opportunitiesInRun <= expansionOpportunityCount);
+        auto expansion = (availableLogicalWidth - totalLogicalWidth) * opportunitiesInRun / expansionOpportunityCount;
+        totalExpansion += expansion;
+        totalOpportunitiesInRun += opportunitiesInRun;
+    }
+
+    if (totalOpportunitiesInRun) {
+        ASSERT(!rubyRun.hasOverrideWidth());
+        rubyRun.setOverrideLogicalContentWidth(rubyRun.logicalWidth() + totalExpansion);
+        rubyRun.setNeedsLayout(MarkOnlyThis);
+        rubyRun.layoutBlock(true);
+        rubyRun.clearOverrideLogicalContentWidth();
+        r.box()->setExpansion(totalExpansion);
+
+        totalLogicalWidth += totalExpansion;
+        expansionOpportunityCount -= totalOpportunitiesInRun;
+    }
+}
+
+static inline void computeExpansionForJustifiedText(BidiRun* firstRun, BidiRun* trailingSpaceRun, const Vector<unsigned, 16>& expansionOpportunities, unsigned expansionOpportunityCount, float totalLogicalWidth, float availableLogicalWidth)
+{
     if (!expansionOpportunityCount || availableLogicalWidth <= totalLogicalWidth)
         return;
 
@@ -567,9 +603,11 @@
                 totalLogicalWidth += expansion;
             }
             expansionOpportunityCount -= opportunitiesInRun;
-            if (!expansionOpportunityCount)
-                break;
-        }
+        } else if (r->renderer().isRubyRun())
+            updateRubyForJustifiedText(toRenderRubyRun(r->renderer()), *r, expansionOpportunities, expansionOpportunityCount, totalLogicalWidth, availableLogicalWidth, i);
+
+        if (!expansionOpportunityCount)
+            break;
     }
 }
 
@@ -695,7 +733,27 @@
 
             setLogicalWidthForTextRun(lineBox, r, &renderText, totalLogicalWidth, lineInfo, textBoxDataMap, verticalPositionCache, wordMeasurements);
         } else {
-            isAfterExpansion = false;
+            bool encounteredJustifiedRuby = false;
+            if (r->renderer().isRubyRun() && textAlign == JUSTIFY && r != trailingSpaceRun && toRenderRubyRun(r->renderer()).rubyBase()) {
+                auto* rubyBase = toRenderRubyRun(r->renderer()).rubyBase();
+                if (rubyBase->firstRootBox() && !rubyBase->firstRootBox()->nextRootBox() && r->renderer().style().collapseWhiteSpace()) {
+                    for (auto* leafChild = rubyBase->firstRootBox()->firstLeafChild(); leafChild; leafChild = leafChild->nextLeafChild()) {
+                        if (!leafChild->isInlineTextBox())
+                            continue;
+                        if (!isAfterExpansion)
+                            toInlineTextBox(leafChild)->setCanHaveLeadingExpansion(true);
+                        encounteredJustifiedRuby = true;
+                        auto& renderText = downcast<RenderText>(leafChild->renderer());
+                        unsigned opportunitiesInRun = Font::expansionOpportunityCount(renderText.stringView(), leafChild->direction(), isAfterExpansion);
+                        expansionOpportunities.append(opportunitiesInRun);
+                        expansionOpportunityCount += opportunitiesInRun;
+                    }
+                }
+            }
+
+            if (!encounteredJustifiedRuby)
+                isAfterExpansion = false;
+
             if (!r->renderer().isRenderInline()) {
                 RenderBox& renderBox = toRenderBox(r->renderer());
                 if (renderBox.isRubyRun())

Modified: trunk/Source/WebCore/rendering/RenderBox.cpp (174488 => 174489)


--- trunk/Source/WebCore/rendering/RenderBox.cpp	2014-10-09 01:05:55 UTC (rev 174488)
+++ trunk/Source/WebCore/rendering/RenderBox.cpp	2014-10-09 01:14:30 UTC (rev 174489)
@@ -2285,7 +2285,7 @@
     // width.  Use the width from the style context.
     // FIXME: Account for block-flow in flexible boxes.
     // https://bugs.webkit.org/show_bug.cgi?id=46418
-    if (hasOverrideWidth() && (style().borderFit() == BorderFitLines || parent()->isFlexibleBoxIncludingDeprecated())) {
+    if (hasOverrideWidth() && (isRubyRun() || style().borderFit() == BorderFitLines || parent()->isFlexibleBoxIncludingDeprecated())) {
         computedValues.m_extent = overrideLogicalContentWidth() + borderAndPaddingLogicalWidth();
         return;
     }

Modified: trunk/Source/WebCore/rendering/RenderRubyBase.cpp (174488 => 174489)


--- trunk/Source/WebCore/rendering/RenderRubyBase.cpp	2014-10-09 01:05:55 UTC (rev 174488)
+++ trunk/Source/WebCore/rendering/RenderRubyBase.cpp	2014-10-09 01:14:30 UTC (rev 174489)
@@ -143,7 +143,7 @@
 
 void RenderRubyBase::adjustInlineDirectionLineBounds(int expansionOpportunityCount, float& logicalLeft, float& logicalWidth) const
 {
-    int maxPreferredLogicalWidth = this->maxPreferredLogicalWidth();
+    LayoutUnit maxPreferredLogicalWidth = rubyRun() && rubyRun()->hasOverrideWidth() ? rubyRun()->overrideLogicalContentWidth() : this->maxPreferredLogicalWidth();
     if (maxPreferredLogicalWidth >= logicalWidth)
         return;
 

Modified: trunk/Source/WebCore/rendering/RenderRubyRun.h (174488 => 174489)


--- trunk/Source/WebCore/rendering/RenderRubyRun.h	2014-10-09 01:05:55 UTC (rev 174488)
+++ trunk/Source/WebCore/rendering/RenderRubyRun.h	2014-10-09 01:14:30 UTC (rev 174489)
@@ -38,7 +38,7 @@
 class RenderRubyBase;
 class RenderRubyText;
 
-// RenderRubyRun are 'inline-block/table' like objects,and wrap a single pairing of a ruby base with its ruby text(s).
+// RenderRubyRuns are 'inline-block/table' like objects, and wrap a single pairing of a ruby base with its ruby text(s).
 // See RenderRuby.h for further comments on the structure
 
 class RenderRubyRun final : public RenderBlockFlow {

Modified: trunk/Source/WebCore/rendering/RenderText.cpp (174488 => 174489)


--- trunk/Source/WebCore/rendering/RenderText.cpp	2014-10-09 01:05:55 UTC (rev 174488)
+++ trunk/Source/WebCore/rendering/RenderText.cpp	2014-10-09 01:14:30 UTC (rev 174489)
@@ -1529,6 +1529,8 @@
 
 StringView RenderText::stringView(int start, int stop) const
 {
+    if (stop == -1)
+        stop = textLength();
     ASSERT(static_cast<unsigned>(start) <= length());
     ASSERT(static_cast<unsigned>(stop) <= length());
     ASSERT(start <= stop);

Modified: trunk/Source/WebCore/rendering/RenderText.h (174488 => 174489)


--- trunk/Source/WebCore/rendering/RenderText.h	2014-10-09 01:05:55 UTC (rev 174488)
+++ trunk/Source/WebCore/rendering/RenderText.h	2014-10-09 01:14:30 UTC (rev 174489)
@@ -156,7 +156,7 @@
     void deleteLineBoxesBeforeSimpleLineLayout();
     const SimpleLineLayout::Layout* simpleLineLayout() const;
 
-    StringView stringView(int start, int stop) const;
+    StringView stringView(int start = 0, int stop = -1) const;
 
 protected:
     virtual void computePreferredLogicalWidths(float leadWidth);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to