<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[197987] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/197987">197987</a></dd>
<dt>Author</dt> <dd>zalan@apple.com</dd>
<dt>Date</dt> <dd>2016-03-10 20:03:32 -0800 (Thu, 10 Mar 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Simple line layout: Add text-align: justify support.
https://bugs.webkit.org/show_bug.cgi?id=155006

Reviewed by Antti Koivisto.

Source/WebCore:

This patch enables text-align: justify; for simple line layout (only latin text for now).
It speeds up/reduced memory consumption for justified text.

PerformanceTests/Layout/line-layout-simple.html
before text-align: justify support -&gt; mean: 86.20513022288704 runs/s
after -&gt; mean: 96.73972475626084 runs/s

Covered by existing text-align: justify tests.

* rendering/SimpleLineLayout.cpp:
(WebCore::SimpleLineLayout::canUseForFontAndText):
(WebCore::SimpleLineLayout::LineState::expansionOpportunityCount):
(WebCore::SimpleLineLayout::LineState::expansionOportunity):
(WebCore::SimpleLineLayout::expansionBehavior):
(WebCore::SimpleLineLayout::justifyRuns):
(WebCore::SimpleLineLayout::closeLineEndingAndAdjustRuns):
(WebCore::SimpleLineLayout::createTextRuns):
(WebCore::SimpleLineLayout::printReason):
(WebCore::SimpleLineLayout::canUseForStyle): Deleted.
* rendering/SimpleLineLayout.h:
* rendering/SimpleLineLayoutFunctions.cpp:
(WebCore::SimpleLineLayout::paintFlow):
* rendering/SimpleLineLayoutResolver.h:
(WebCore::SimpleLineLayout::RunResolver::Run::expansion):
(WebCore::SimpleLineLayout::RunResolver::Run::expansionBehavior):

LayoutTests:

Rebaseline based on simple line layout output.

* fast/text/whitespace/023-expected.txt:
* platform/mac/css2.1/t0905-c5525-fltwidth-00-c-g-expected.txt:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsfasttextwhitespace023expectedtxt">trunk/LayoutTests/fast/text/whitespace/023-expected.txt</a></li>
<li><a href="#trunkLayoutTestsplatformmaccss21t0905c5525fltwidth00cgexpectedtxt">trunk/LayoutTests/platform/mac/css2.1/t0905-c5525-fltwidth-00-c-g-expected.txt</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorerenderingSimpleLineLayoutcpp">trunk/Source/WebCore/rendering/SimpleLineLayout.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingSimpleLineLayouth">trunk/Source/WebCore/rendering/SimpleLineLayout.h</a></li>
<li><a href="#trunkSourceWebCorerenderingSimpleLineLayoutFunctionscpp">trunk/Source/WebCore/rendering/SimpleLineLayoutFunctions.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingSimpleLineLayoutResolverh">trunk/Source/WebCore/rendering/SimpleLineLayoutResolver.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (197986 => 197987)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-03-11 03:57:52 UTC (rev 197986)
+++ trunk/LayoutTests/ChangeLog        2016-03-11 04:03:32 UTC (rev 197987)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2016-03-10  Zalan Bujtas  &lt;zalan@apple.com&gt;
+
+        Simple line layout: Add text-align: justify support.
+        https://bugs.webkit.org/show_bug.cgi?id=155006
+
+        Reviewed by Antti Koivisto.
+
+        Rebaseline based on simple line layout output.
+
+        * fast/text/whitespace/023-expected.txt:
+        * platform/mac/css2.1/t0905-c5525-fltwidth-00-c-g-expected.txt:
+
</ins><span class="cx"> 2016-03-10  Nan Wang  &lt;n_wang@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         AX: Force allow user zoom
</span></span></pre></div>
<a id="trunkLayoutTestsfasttextwhitespace023expectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/text/whitespace/023-expected.txt (197986 => 197987)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text/whitespace/023-expected.txt        2016-03-11 03:57:52 UTC (rev 197986)
+++ trunk/LayoutTests/fast/text/whitespace/023-expected.txt        2016-03-11 04:03:32 UTC (rev 197987)
</span><span class="lines">@@ -6,6 +6,4 @@
</span><span class="cx">       RenderBlock {PRE} at (0,0) size 304x34 [border: (2px solid #008000)]
</span><span class="cx">         RenderText {#text} at (2,2) size 94x30
</span><span class="cx">           text run at (2,2) width 86: &quot;This should&quot;
</span><del>-          text run at (87,2) width 1: &quot; &quot;
</del><span class="cx">           text run at (2,17) width 94: &quot;not justify.&quot;
</span><del>-          text run at (95,17) width 1: &quot; &quot;
</del></span></pre></div>
<a id="trunkLayoutTestsplatformmaccss21t0905c5525fltwidth00cgexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/mac/css2.1/t0905-c5525-fltwidth-00-c-g-expected.txt (197986 => 197987)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac/css2.1/t0905-c5525-fltwidth-00-c-g-expected.txt        2016-03-11 03:57:52 UTC (rev 197986)
+++ trunk/LayoutTests/platform/mac/css2.1/t0905-c5525-fltwidth-00-c-g-expected.txt        2016-03-11 04:03:32 UTC (rev 197987)
</span><span class="lines">@@ -46,7 +46,7 @@
</span><span class="cx">           text run at (233,306) width 152: &quot;ignore this float text&quot;
</span><span class="cx">           text run at (0,324) width 257: &quot;ignore this float text ignore this float&quot;
</span><span class="cx">       RenderBlock {DIV} at (0,154) size 769x468 [color=#C0C0C0]
</span><del>-        RenderText {#text} at (384,0) size 770x468
</del><ins>+        RenderText {#text} at (384,0) size 769x468
</ins><span class="cx">           text run at (384,0) width 385: &quot;this is some dummy text this is some dummy text this is&quot;
</span><span class="cx">           text run at (384,18) width 98: &quot;some dummy &quot;
</span><span class="cx">           text run at (481,18) width 288: &quot;text this is some dummy text this is some&quot;
</span><span class="lines">@@ -88,7 +88,7 @@
</span><span class="cx">           text run at (569,360) width 200: &quot;some dummy text this is some&quot;
</span><span class="cx">           text run at (0,378) width 244: &quot;dummy text this is some dummy text &quot;
</span><span class="cx">           text run at (243,378) width 460: &quot;this is some dummy text this is some dummy text this is some dummy &quot;
</span><del>-          text run at (702,378) width 68: &quot;text this is&quot;
</del><ins>+          text run at (702,378) width 67: &quot;text this is&quot;
</ins><span class="cx">           text run at (0,396) width 365: &quot;some dummy text this is some dummy text this is some &quot;
</span><span class="cx">           text run at (364,396) width 405: &quot;dummy text this is some dummy text this is some dummy text&quot;
</span><span class="cx">           text run at (0,414) width 47: &quot;this is &quot;
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (197986 => 197987)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-03-11 03:57:52 UTC (rev 197986)
+++ trunk/Source/WebCore/ChangeLog        2016-03-11 04:03:32 UTC (rev 197987)
</span><span class="lines">@@ -1,3 +1,36 @@
</span><ins>+2016-03-10  Zalan Bujtas  &lt;zalan@apple.com&gt;
+
+        Simple line layout: Add text-align: justify support.
+        https://bugs.webkit.org/show_bug.cgi?id=155006
+
+        Reviewed by Antti Koivisto.
+
+        This patch enables text-align: justify; for simple line layout (only latin text for now).
+        It speeds up/reduced memory consumption for justified text.
+
+        PerformanceTests/Layout/line-layout-simple.html
+        before text-align: justify support -&gt; mean: 86.20513022288704 runs/s
+        after -&gt; mean: 96.73972475626084 runs/s
+
+        Covered by existing text-align: justify tests.
+
+        * rendering/SimpleLineLayout.cpp:
+        (WebCore::SimpleLineLayout::canUseForFontAndText):
+        (WebCore::SimpleLineLayout::LineState::expansionOpportunityCount):
+        (WebCore::SimpleLineLayout::LineState::expansionOportunity):
+        (WebCore::SimpleLineLayout::expansionBehavior):
+        (WebCore::SimpleLineLayout::justifyRuns):
+        (WebCore::SimpleLineLayout::closeLineEndingAndAdjustRuns):
+        (WebCore::SimpleLineLayout::createTextRuns):
+        (WebCore::SimpleLineLayout::printReason):
+        (WebCore::SimpleLineLayout::canUseForStyle): Deleted.
+        * rendering/SimpleLineLayout.h:
+        * rendering/SimpleLineLayoutFunctions.cpp:
+        (WebCore::SimpleLineLayout::paintFlow):
+        * rendering/SimpleLineLayoutResolver.h:
+        (WebCore::SimpleLineLayout::RunResolver::Run::expansion):
+        (WebCore::SimpleLineLayout::RunResolver::Run::expansionBehavior):
+
</ins><span class="cx"> 2016-03-10  Nan Wang  &lt;n_wang@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         AX: Force allow user zoom
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingSimpleLineLayoutcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/SimpleLineLayout.cpp (197986 => 197987)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/SimpleLineLayout.cpp        2016-03-11 03:57:52 UTC (rev 197986)
+++ trunk/Source/WebCore/rendering/SimpleLineLayout.cpp        2016-03-11 04:03:32 UTC (rev 197987)
</span><span class="lines">@@ -74,7 +74,7 @@
</span><span class="cx">     FlowHasNonSupportedChild              = 1LLU  &lt;&lt; 9,
</span><span class="cx">     FlowHasUnsupportedFloat               = 1LLU  &lt;&lt; 10,
</span><span class="cx">     FlowHasUnsupportedUnderlineDecoration = 1LLU  &lt;&lt; 11,
</span><del>-    FlowIsJustifyAligned                  = 1LLU  &lt;&lt; 12,
</del><ins>+    FlowHasJustifiedNonLatinText          = 1LLU  &lt;&lt; 12,
</ins><span class="cx">     FlowHasOverflowVisible                = 1LLU  &lt;&lt; 13,
</span><span class="cx">     FlowIsNotLTR                          = 1LLU  &lt;&lt; 14,
</span><span class="cx">     FlowHasLineBoxContainProperty         = 1LLU  &lt;&lt; 15,
</span><span class="lines">@@ -186,6 +186,8 @@
</span><span class="cx">         SET_REASON_AND_RETURN_IF_NEEDED(FlowHasSVGFont, reasons, includeReasons);
</span><span class="cx"> 
</span><span class="cx">     for (const auto&amp; textRenderer : childrenOfType&lt;RenderText&gt;(flow)) {
</span><ins>+        if (style.textAlign() == JUSTIFY &amp;&amp; !textRenderer.originalText().containsOnlyLatin1())
+            SET_REASON_AND_RETURN_IF_NEEDED(FlowHasJustifiedNonLatinText, reasons, includeReasons);
</ins><span class="cx">         if (textRenderer.isCombineText())
</span><span class="cx">             SET_REASON_AND_RETURN_IF_NEEDED(FlowTextIsCombineText, reasons, includeReasons);
</span><span class="cx">         if (textRenderer.isCounter())
</span><span class="lines">@@ -213,8 +215,6 @@
</span><span class="cx">         SET_REASON_AND_RETURN_IF_NEEDED(FlowHasTextOverflow, reasons, includeReasons);
</span><span class="cx">     if ((style.textDecorationsInEffect() &amp; TextDecorationUnderline) &amp;&amp; style.textUnderlinePosition() == TextUnderlinePositionUnder)
</span><span class="cx">         SET_REASON_AND_RETURN_IF_NEEDED(FlowHasUnsupportedUnderlineDecoration, reasons, includeReasons);
</span><del>-    if (style.textAlign() == JUSTIFY)
-        SET_REASON_AND_RETURN_IF_NEEDED(FlowIsJustifyAligned, reasons, includeReasons);
</del><span class="cx">     // Non-visible overflow should be pretty easy to support.
</span><span class="cx">     if (style.overflowX() != OVISIBLE || style.overflowY() != OVISIBLE)
</span><span class="cx">         SET_REASON_AND_RETURN_IF_NEEDED(FlowHasOverflowVisible, reasons, includeReasons);
</span><span class="lines">@@ -409,6 +409,28 @@
</span><span class="cx">     bool fits(float extra) const { return m_availableWidth &gt;= m_runsWidth + extra; }
</span><span class="cx">     bool firstCharacterFits() const { return m_firstCharacterFits; }
</span><span class="cx">     float width() const { return m_runsWidth; }
</span><ins>+    std::pair&lt;unsigned, bool&gt; expansionOpportunityCount(unsigned from, unsigned to) const
+    {
+        // linebreak runs are special.
+        if (from == to)
+            return std::make_pair(0, false);
+        unsigned expansionOpportunityCount = 0;
+        auto previousFragmentType = TextFragmentIterator::TextFragment::ContentEnd;
+        for (const auto&amp; fragment : m_fragments) {
+            if (fragment.end() &lt;= from)
+                continue;
+            auto currentFragmentType = fragment.type();
+            auto expansionOpportunity = this-&gt;expansionOpportunity(currentFragmentType, previousFragmentType);
+            if (expansionOpportunity)
+                ++expansionOpportunityCount;
+            previousFragmentType = currentFragmentType;
+            if (fragment.end() &gt;= to)
+                return std::make_pair(expansionOpportunityCount, expansionOpportunity);
+        }
+        ASSERT_NOT_REACHED();
+        return std::make_pair(expansionOpportunityCount, false);
+    }
+
</ins><span class="cx">     bool isEmpty() const
</span><span class="cx">     {
</span><span class="cx">         if (!m_fragments.size())
</span><span class="lines">@@ -508,6 +530,12 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx"> private:
</span><ins>+    bool expansionOpportunity(TextFragmentIterator::TextFragment::Type currentFragmentType, TextFragmentIterator::TextFragment::Type previousFragmentType) const
+    {
+        return (currentFragmentType == TextFragmentIterator::TextFragment::Whitespace
+            || (currentFragmentType == TextFragmentIterator::TextFragment::NonWhitespace &amp;&amp; previousFragmentType == TextFragmentIterator::TextFragment::NonWhitespace));
+    }
+
</ins><span class="cx">     float m_availableWidth { 0 };
</span><span class="cx">     float m_logicalLeftOffset { 0 };
</span><span class="cx">     TextFragmentIterator::TextFragment m_overflowedFragment;
</span><span class="lines">@@ -723,20 +751,75 @@
</span><span class="cx">     return (fragment.type() == TextFragmentIterator::TextFragment::ContentEnd &amp;&amp; line.overflowedFragment().isEmpty()) || line.overflowedFragment().type() == TextFragmentIterator::TextFragment::ContentEnd;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static void closeLineEndingAndAdjustRuns(LineState&amp; line, Layout::RunVector&amp; runs, unsigned previousRunCount, unsigned&amp; lineCount, const TextFragmentIterator&amp; textFragmentIterator)
</del><ins>+static ExpansionBehavior expansionBehavior(bool isAfterExpansion, bool lastRunOnLine)
</ins><span class="cx"> {
</span><del>-    if (previousRunCount == runs.size())
</del><ins>+    ExpansionBehavior expansionBehavior;
+    expansionBehavior = isAfterExpansion ? ForbidLeadingExpansion : AllowLeadingExpansion;
+    expansionBehavior |= lastRunOnLine ? ForbidTrailingExpansion : AllowTrailingExpansion;
+    return expansionBehavior;
+}
+
+static void justifyRuns(const LineState&amp; line, Layout::RunVector&amp; runs, Optional&lt;unsigned&gt; lastRunIndexOfPreviousLine)
+{
+    ASSERT(runs.size());
+    auto widthToDistribute = line.availableWidth() - line.width();
+    if (widthToDistribute &lt;= 0)
</ins><span class="cx">         return;
</span><del>-    ASSERT(runs.size());
</del><ins>+
+    auto firstRunIndex = lastRunIndexOfPreviousLine ? lastRunIndexOfPreviousLine.value() + 1 : 0;
+    auto lastRunIndex = runs.size() - 1;
+    ASSERT(firstRunIndex &lt;= lastRunIndex);
+    Vector&lt;std::pair&lt;unsigned, ExpansionBehavior&gt;&gt; expansionOpportunityList;
+    unsigned expansionOpportunityCountOnThisLine = 0;
+    auto isAfterExpansion = true;
+    for (auto i = firstRunIndex; i &lt;= lastRunIndex; ++i) {
+        const auto&amp; run = runs.at(i);
+        unsigned opportunityCountInRun = 0;
+        std::tie(opportunityCountInRun, isAfterExpansion) = line.expansionOpportunityCount(run.start, run.end);
+        expansionOpportunityList.append(std::make_pair(opportunityCountInRun, expansionBehavior(isAfterExpansion, i == lastRunIndex)));
+        expansionOpportunityCountOnThisLine += opportunityCountInRun;
+    }
+    if (!expansionOpportunityCountOnThisLine)
+        return;
+
+    ASSERT(expansionOpportunityList.size() == lastRunIndex - firstRunIndex + 1);
+    auto expansion = widthToDistribute / expansionOpportunityCountOnThisLine;
+    float accumulatedExpansion = 0;
+    for (auto i = firstRunIndex; i &lt;= lastRunIndex; ++i) {
+        auto&amp; run = runs.at(i);
+        unsigned opportunityCountInRun;
+        std::tie(opportunityCountInRun, run.expansionBehavior) = expansionOpportunityList.at(i - firstRunIndex);
+        run.expansion = opportunityCountInRun * expansion;
+        run.logicalLeft += accumulatedExpansion;
+        run.logicalRight += (accumulatedExpansion + run.expansion);
+        accumulatedExpansion += run.expansion;
+    }
+}
+
+static void closeLineEndingAndAdjustRuns(LineState&amp; line, Layout::RunVector&amp; runs, Optional&lt;unsigned&gt; lastRunIndexOfPreviousLine, unsigned&amp; lineCount,
+    const TextFragmentIterator&amp; textFragmentIterator, bool lastLine)
+{
+    if (!runs.size() || (lastRunIndexOfPreviousLine &amp;&amp; runs.size() - 1 == lastRunIndexOfPreviousLine.value()))
+        return;
</ins><span class="cx">     removeTrailingWhitespace(line, runs, textFragmentIterator);
</span><span class="cx">     if (!runs.size())
</span><span class="cx">         return;
</span><span class="cx">     // Adjust runs' position by taking line's alignment into account.
</span><del>-    if (float lineLogicalLeft = computeLineLeft(textFragmentIterator.style().textAlign, line.availableWidth(), line.width(), line.logicalLeftOffset())) {
-        for (unsigned i = previousRunCount; i &lt; runs.size(); ++i) {
-            runs[i].logicalLeft += lineLogicalLeft;
-            runs[i].logicalRight += lineLogicalLeft;
-        }
</del><ins>+    const auto&amp; style = textFragmentIterator.style();
+    auto textAlign = style.textAlign;
+    // Fallback to LEFT alignment both for non-collapsable content and for the last line.
+    if (textAlign == JUSTIFY &amp;&amp; (!style.collapseWhitespace || lastLine))
+        textAlign = LEFT;
+
+    auto lineLogicalLeft = line.logicalLeftOffset();
+    if (textAlign == JUSTIFY)
+        justifyRuns(line, runs, lastRunIndexOfPreviousLine);
+    else
+        lineLogicalLeft = computeLineLeft(textAlign, line.availableWidth(), line.width(), line.logicalLeftOffset());
+    auto firstRunIndex = lastRunIndexOfPreviousLine ? lastRunIndexOfPreviousLine.value() + 1 : 0;
+    for (auto i = firstRunIndex; i &lt; runs.size(); ++i) {
+        runs[i].logicalLeft += lineLogicalLeft;
+        runs[i].logicalRight += lineLogicalLeft;
</ins><span class="cx">     }
</span><span class="cx">     runs.last().isEndOfLine = true;
</span><span class="cx">     ++lineCount;
</span><span class="lines">@@ -749,14 +832,16 @@
</span><span class="cx">     LineState line;
</span><span class="cx">     bool isEndOfContent = false;
</span><span class="cx">     TextFragmentIterator textFragmentIterator = TextFragmentIterator(flow);
</span><ins>+    Optional&lt;unsigned&gt; lastRunIndexOfPreviousLine;
</ins><span class="cx">     do {
</span><span class="cx">         flow.setLogicalHeight(lineHeight * lineCount + borderAndPaddingBefore);
</span><span class="cx">         LineState previousLine = line;
</span><del>-        unsigned previousRunCount = runs.size();
</del><span class="cx">         line = LineState();
</span><span class="cx">         updateLineConstrains(flow, line, !lineCount);
</span><span class="cx">         isEndOfContent = createLineRuns(line, previousLine, runs, textFragmentIterator);
</span><del>-        closeLineEndingAndAdjustRuns(line, runs, previousRunCount, lineCount, textFragmentIterator);
</del><ins>+        closeLineEndingAndAdjustRuns(line, runs, lastRunIndexOfPreviousLine, lineCount, textFragmentIterator, isEndOfContent);
+        if (runs.size())
+            lastRunIndexOfPreviousLine = runs.size() - 1;
</ins><span class="cx">     } while (!isEndOfContent);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -829,8 +914,8 @@
</span><span class="cx">     case FlowHasUnsupportedUnderlineDecoration:
</span><span class="cx">         stream &lt;&lt; &quot;text-underline-position: under&quot;;
</span><span class="cx">         break;
</span><del>-    case FlowIsJustifyAligned:
-        stream &lt;&lt; &quot;text-align: justify&quot;;
</del><ins>+    case FlowHasJustifiedNonLatinText:
+        stream &lt;&lt; &quot;text-align: justify with non-latin text&quot;;
</ins><span class="cx">         break;
</span><span class="cx">     case FlowHasOverflowVisible:
</span><span class="cx">         stream &lt;&lt; &quot;overflow: visible&quot;;
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingSimpleLineLayouth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/SimpleLineLayout.h (197986 => 197987)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/SimpleLineLayout.h        2016-03-11 03:57:52 UTC (rev 197986)
+++ trunk/Source/WebCore/rendering/SimpleLineLayout.h        2016-03-11 04:03:32 UTC (rev 197987)
</span><span class="lines">@@ -26,6 +26,7 @@
</span><span class="cx"> #ifndef SimpleLineLayout_h
</span><span class="cx"> #define SimpleLineLayout_h
</span><span class="cx"> 
</span><ins>+#include &quot;TextFlags.h&quot;
</ins><span class="cx"> #include &lt;wtf/Vector.h&gt;
</span><span class="cx"> #include &lt;wtf/text/WTFString.h&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -59,6 +60,9 @@
</span><span class="cx">     unsigned isEndOfLine : 1;
</span><span class="cx">     float logicalLeft;
</span><span class="cx">     float logicalRight;
</span><ins>+    // TODO: Move these optional items out of SimpleLineLayout::Run to a supplementary structure.
+    float expansion { 0 };
+    ExpansionBehavior expansionBehavior { ForbidLeadingExpansion | ForbidTrailingExpansion };
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> class Layout {
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingSimpleLineLayoutFunctionscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/SimpleLineLayoutFunctions.cpp (197986 => 197987)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/SimpleLineLayoutFunctions.cpp        2016-03-11 03:57:52 UTC (rev 197986)
+++ trunk/Source/WebCore/rendering/SimpleLineLayoutFunctions.cpp        2016-03-11 04:03:32 UTC (rev 197987)
</span><span class="lines">@@ -106,10 +106,9 @@
</span><span class="cx">         if (paintRect.y() &gt; visualOverflowRect.maxY() || paintRect.maxY() &lt; visualOverflowRect.y())
</span><span class="cx">             continue;
</span><span class="cx"> 
</span><del>-        TextRun textRun(run.text());
-        textRun.setTabSize(!style.collapseWhiteSpace(), style.tabSize());
</del><span class="cx">         // x position indicates the line offset from the rootbox. It's always 0 in case of simple line layout.
</span><del>-        textRun.setXPos(0);
</del><ins>+        TextRun textRun(run.text(), 0, run.expansion(), run.expansionBehavior());
+        textRun.setTabSize(!style.collapseWhiteSpace(), style.tabSize());
</ins><span class="cx">         FloatPoint textOrigin = FloatPoint(rect.x() + paintOffset.x(), roundToDevicePixel(run.baselinePosition() + paintOffset.y(), deviceScaleFactor));
</span><span class="cx">         textPainter.paintText(textRun, textRun.length(), rect, textOrigin);
</span><span class="cx">         if (textDecorationPainter) {
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingSimpleLineLayoutResolverh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/SimpleLineLayoutResolver.h (197986 => 197987)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/SimpleLineLayoutResolver.h        2016-03-11 03:57:52 UTC (rev 197986)
+++ trunk/Source/WebCore/rendering/SimpleLineLayoutResolver.h        2016-03-11 04:03:32 UTC (rev 197987)
</span><span class="lines">@@ -62,6 +62,8 @@
</span><span class="cx">         unsigned end() const;
</span><span class="cx"> 
</span><span class="cx">         FloatRect rect() const;
</span><ins>+        float expansion() const;
+        ExpansionBehavior expansionBehavior() const;
</ins><span class="cx">         int baselinePosition() const;
</span><span class="cx">         StringView text() const;
</span><span class="cx">         bool isEndOfLine() const;
</span><span class="lines">@@ -170,6 +172,16 @@
</span><span class="cx">     return m_iterator.simpleRun().end;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+inline float RunResolver::Run::expansion() const
+{
+    return m_iterator.simpleRun().expansion;
+}
+
+inline ExpansionBehavior RunResolver::Run::expansionBehavior() const
+{
+    return m_iterator.simpleRun().expansionBehavior;
+}
+
</ins><span class="cx"> inline int RunResolver::Run::baselinePosition() const
</span><span class="cx"> {
</span><span class="cx">     return roundToInt(computeBaselinePosition());
</span></span></pre>
</div>
</div>

</body>
</html>