<!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>[181685] 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/181685">181685</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2015-03-17 23:09:56 -0700 (Tue, 17 Mar 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Unreviewed, rolling out <a href="http://trac.webkit.org/projects/webkit/changeset/181667">r181667</a>, <a href="http://trac.webkit.org/projects/webkit/changeset/181682">r181682</a>, and <a href="http://trac.webkit.org/projects/webkit/changeset/181683">r181683</a>.
https://bugs.webkit.org/show_bug.cgi?id=142812

Broke multiple tests with ASan, plus dependent commits
(Requested by ap on #webkit).

Reverted changesets:

&quot;Simple line layout: Split fragments on renderer boundary on
the fly.&quot;
https://bugs.webkit.org/show_bug.cgi?id=142579
http://trac.webkit.org/changeset/181667

&quot;Simple line layout: Change FlowContents::segmentForPosition()
to segmentForRun().&quot;
https://bugs.webkit.org/show_bug.cgi?id=142785
http://trac.webkit.org/changeset/181682

&quot;Simple line layout: Use Vector&lt;&gt;::const_iterator instead of
custom FlowContents::Iterator.&quot;
https://bugs.webkit.org/show_bug.cgi?id=142809
http://trac.webkit.org/changeset/181683</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</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="#trunkSourceWebCorerenderingSimpleLineLayoutFlowContentscpp">trunk/Source/WebCore/rendering/SimpleLineLayoutFlowContents.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingSimpleLineLayoutFlowContentsh">trunk/Source/WebCore/rendering/SimpleLineLayoutFlowContents.h</a></li>
<li><a href="#trunkSourceWebCorerenderingSimpleLineLayoutFunctionscpp">trunk/Source/WebCore/rendering/SimpleLineLayoutFunctions.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingSimpleLineLayoutResolvercpp">trunk/Source/WebCore/rendering/SimpleLineLayoutResolver.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingSimpleLineLayoutTextFragmentIteratorcpp">trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingSimpleLineLayoutTextFragmentIteratorh">trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.h</a></li>
</ul>

<h3>Removed Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfasttextsimplelinewithmultiplerenderersexpectedhtml">trunk/LayoutTests/fast/text/simple-line-with-multiple-renderers-expected.html</a></li>
<li><a href="#trunkLayoutTestsfasttextsimplelinewithmultiplerenderershtml">trunk/LayoutTests/fast/text/simple-line-with-multiple-renderers.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (181684 => 181685)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-03-18 05:38:20 UTC (rev 181684)
+++ trunk/LayoutTests/ChangeLog        2015-03-18 06:09:56 UTC (rev 181685)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2015-03-17  Commit Queue  &lt;commit-queue@webkit.org&gt;
+
+        Unreviewed, rolling out r181667, r181682, and r181683.
+        https://bugs.webkit.org/show_bug.cgi?id=142812
+
+        Broke multiple tests with ASan, plus dependent commits
+        (Requested by ap on #webkit).
+
+        Reverted changesets:
+
+        &quot;Simple line layout: Split fragments on renderer boundary on
+        the fly.&quot;
+        https://bugs.webkit.org/show_bug.cgi?id=142579
+        http://trac.webkit.org/changeset/181667
+
+        &quot;Simple line layout: Change FlowContents::segmentForPosition()
+        to segmentForRun().&quot;
+        https://bugs.webkit.org/show_bug.cgi?id=142785
+        http://trac.webkit.org/changeset/181682
+
+        &quot;Simple line layout: Use Vector&lt;&gt;::const_iterator instead of
+        custom FlowContents::Iterator.&quot;
+        https://bugs.webkit.org/show_bug.cgi?id=142809
+        http://trac.webkit.org/changeset/181683
+
</ins><span class="cx"> 2015-03-17  Alexey Proskuryakov  &lt;ap@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         fast/images/animated-png.html is crashing / failing on Yosemite
</span></span></pre></div>
<a id="trunkLayoutTestsfasttextsimplelinewithmultiplerenderersexpectedhtml"></a>
<div class="delfile"><h4>Deleted: trunk/LayoutTests/fast/text/simple-line-with-multiple-renderers-expected.html (181684 => 181685)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text/simple-line-with-multiple-renderers-expected.html        2015-03-18 05:38:20 UTC (rev 181684)
+++ trunk/LayoutTests/fast/text/simple-line-with-multiple-renderers-expected.html        2015-03-18 06:09:56 UTC (rev 181685)
</span><span class="lines">@@ -1,36 +0,0 @@
</span><del>-&lt;!DOCTYPE html&gt;
-&lt;html&gt;
-&lt;head&gt;
-&lt;title&gt;Test that segments across multiple renderers work fine with simple line layout.&lt;/title&gt;
-&lt;/head&gt;
-&lt;body&gt;
-&lt;script&gt;
-function injectTextNodes(container, style)
-{
-        container.appendChild(document.createTextNode(&quot;         &quot;));
-        container.appendChild(document.createTextNode(&quot;        &quot;));
-        container.appendChild(document.createTextNode(&quot;        This tests     &quot;));
-        container.appendChild(document.createTextNode(&quot;            &quot;));
-        container.appendChild(document.createTextNode(&quot;whitespace                 overlapping &quot;));
-        container.appendChild(document.createTextNode(&quot;        multiple     &quot;));
-        container.appendChild(document.createTextNode(&quot;                                renderers.&quot;));
-        container.appendChild(document.createTextNode(&quot;This tests when non-&quot;));
-        container.appendChild(document.createTextNode(&quot;whitespace con&quot;));
-        container.appendChild(document.createTextNode(&quot;tent o&quot;));
-        container.appendChild(document.createTextNode(&quot;verla&quot;));
-        container.appendChild(document.createTextNode(&quot;ps multiple ren&quot;));
-        container.appendChild(document.createTextNode(&quot;deres.&quot;));
-        container.style.cssText = style;
-        document.body.appendChild(container);
-}
-
-if (window.internals)
-        internals.settings.setSimpleLineLayoutEnabled(false)
-injectTextNodes(document.createElement(&quot;div&quot;));
-injectTextNodes(document.createElement(&quot;div&quot;), &quot;width: 0px&quot;);
-injectTextNodes(document.createElement(&quot;div&quot;), &quot;width: 10px&quot;);
-injectTextNodes(document.createElement(&quot;div&quot;), &quot;width: 100px&quot;);
-injectTextNodes(document.createElement(&quot;pre&quot;));
-&lt;/script&gt;
-&lt;/body&gt;
-&lt;/html&gt;
</del></span></pre></div>
<a id="trunkLayoutTestsfasttextsimplelinewithmultiplerenderershtml"></a>
<div class="delfile"><h4>Deleted: trunk/LayoutTests/fast/text/simple-line-with-multiple-renderers.html (181684 => 181685)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text/simple-line-with-multiple-renderers.html        2015-03-18 05:38:20 UTC (rev 181684)
+++ trunk/LayoutTests/fast/text/simple-line-with-multiple-renderers.html        2015-03-18 06:09:56 UTC (rev 181685)
</span><span class="lines">@@ -1,34 +0,0 @@
</span><del>-&lt;!DOCTYPE html&gt;
-&lt;html&gt;
-&lt;head&gt;
-&lt;title&gt;Test that segments across multiple renderers work fine with simple line layout.&lt;/title&gt;
-&lt;/head&gt;
-&lt;body&gt;
-&lt;script&gt;
-function injectTextNodes(container, style)
-{
-        container.appendChild(document.createTextNode(&quot;         &quot;));
-        container.appendChild(document.createTextNode(&quot;        &quot;));
-        container.appendChild(document.createTextNode(&quot;        This tests     &quot;));
-        container.appendChild(document.createTextNode(&quot;            &quot;));
-        container.appendChild(document.createTextNode(&quot;whitespace                 overlapping &quot;));
-        container.appendChild(document.createTextNode(&quot;        multiple     &quot;));
-        container.appendChild(document.createTextNode(&quot;                                renderers.&quot;));
-        container.appendChild(document.createTextNode(&quot;This tests when non-&quot;));
-        container.appendChild(document.createTextNode(&quot;whitespace con&quot;));
-        container.appendChild(document.createTextNode(&quot;tent o&quot;));
-        container.appendChild(document.createTextNode(&quot;verla&quot;));
-        container.appendChild(document.createTextNode(&quot;ps multiple ren&quot;));
-        container.appendChild(document.createTextNode(&quot;deres.&quot;));
-        container.style.cssText = style;
-        document.body.appendChild(container);
-}
-
-injectTextNodes(document.createElement(&quot;div&quot;));
-injectTextNodes(document.createElement(&quot;div&quot;), &quot;width: 0px&quot;);
-injectTextNodes(document.createElement(&quot;div&quot;), &quot;width: 10px&quot;);
-injectTextNodes(document.createElement(&quot;div&quot;), &quot;width: 100px&quot;);
-injectTextNodes(document.createElement(&quot;pre&quot;));
-&lt;/script&gt;
-&lt;/body&gt;
-&lt;/html&gt;
</del></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (181684 => 181685)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-03-18 05:38:20 UTC (rev 181684)
+++ trunk/Source/WebCore/ChangeLog        2015-03-18 06:09:56 UTC (rev 181685)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2015-03-17  Commit Queue  &lt;commit-queue@webkit.org&gt;
+
+        Unreviewed, rolling out r181667, r181682, and r181683.
+        https://bugs.webkit.org/show_bug.cgi?id=142812
+
+        Broke multiple tests with ASan, plus dependent commits
+        (Requested by ap on #webkit).
+
+        Reverted changesets:
+
+        &quot;Simple line layout: Split fragments on renderer boundary on
+        the fly.&quot;
+        https://bugs.webkit.org/show_bug.cgi?id=142579
+        http://trac.webkit.org/changeset/181667
+
+        &quot;Simple line layout: Change FlowContents::segmentForPosition()
+        to segmentForRun().&quot;
+        https://bugs.webkit.org/show_bug.cgi?id=142785
+        http://trac.webkit.org/changeset/181682
+
+        &quot;Simple line layout: Use Vector&lt;&gt;::const_iterator instead of
+        custom FlowContents::Iterator.&quot;
+        https://bugs.webkit.org/show_bug.cgi?id=142809
+        http://trac.webkit.org/changeset/181683
+
</ins><span class="cx"> 2015-03-17  Zalan Bujtas  &lt;zalan@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Simple line layout: Use Vector&lt;&gt;::const_iterator instead of custom FlowContents::Iterator.
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingSimpleLineLayoutcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/SimpleLineLayout.cpp (181684 => 181685)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/SimpleLineLayout.cpp        2015-03-18 05:38:20 UTC (rev 181684)
+++ trunk/Source/WebCore/rendering/SimpleLineLayout.cpp        2015-03-18 06:09:56 UTC (rev 181685)
</span><span class="lines">@@ -231,27 +231,9 @@
</span><span class="cx">     return 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static void revertRuns(Layout::RunVector&amp; runs, unsigned length, float width)
-{
-    ASSERT(runs.size());
-    while (length) {
-        Run&amp; lastRun = runs.last();
-        unsigned lastRunLength = lastRun.end - lastRun.start;
-        if (lastRunLength &gt; length) {
-            lastRun.logicalRight -= width;
-            lastRun.end -= length;
-            break;
-        }
-        runs.removeLast();
-        length -= lastRunLength;
-        width -= (lastRun.logicalRight - lastRun.logicalLeft);
-    }
-}
-
</del><span class="cx"> class LineState {
</span><span class="cx"> public:
</span><span class="cx">     void setAvailableWidth(float width) { m_availableWidth = width; }
</span><del>-    void setCollapedWhitespaceWidth(float width) { m_collapsedWhitespaceWidth = width; }
</del><span class="cx">     void setLogicalLeftOffset(float offset) { m_logicalLeftOffset = offset; }
</span><span class="cx">     void setOverflowedFragment(const TextFragmentIterator::TextFragment&amp; fragment) { m_overflowedFragment = fragment; }
</span><span class="cx"> 
</span><span class="lines">@@ -259,51 +241,25 @@
</span><span class="cx">     float logicalLeftOffset() const { return m_logicalLeftOffset; }
</span><span class="cx">     const TextFragmentIterator::TextFragment&amp; overflowedFragment() const { return m_overflowedFragment; }
</span><span class="cx">     bool hasTrailingWhitespace() const { return m_trailingWhitespaceLength; }
</span><del>-    TextFragmentIterator::TextFragment lastFragment() const { return m_fragments.last(); }
</del><span class="cx">     bool isWhitespaceOnly() const { return m_trailingWhitespaceWidth &amp;&amp; m_runsWidth == m_trailingWhitespaceWidth; }
</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><del>-    bool isEmpty() const
-    {
-        if (!m_fragments.size())
-            return true;
-        if (!m_lastCompleteFragment.isEmpty())
-            return false;
-        return m_fragments.last().overlapsToNextRenderer();
-    }
</del><span class="cx"> 
</span><del>-    void appendFragmentAndCreateRunIfNeeded(const TextFragmentIterator::TextFragment&amp; fragment, Layout::RunVector&amp; runs)
</del><ins>+    void appendFragment(const TextFragmentIterator::TextFragment&amp; fragment, Layout::RunVector&amp; runs)
</ins><span class="cx">     {
</span><span class="cx">         // Adjust end position while collapsing.
</span><span class="cx">         unsigned endPosition = fragment.isCollapsed() ? fragment.start() + 1 : fragment.end();
</span><del>-        // New line needs new run.
-        if (!m_runsWidth)
</del><ins>+
+        if (m_createNewRun)
</ins><span class="cx">             runs.append(Run(fragment.start(), endPosition, m_runsWidth, m_runsWidth + fragment.width(), false));
</span><span class="cx">         else {
</span><del>-            const auto&amp; lastFragment = m_fragments.last();
-            // Advance last completed fragment when the previous fragment is all set (including multiple parts across renderers)
-            if ((lastFragment.type() != fragment.type()) || !lastFragment.overlapsToNextRenderer())
-                m_lastCompleteFragment = lastFragment;
-            // Collapse neighbouring whitespace, if they are across multiple renderers and are not collapsed yet.
-            if (lastFragment.isCollapsible() &amp;&amp; fragment.isCollapsible()) {
-                ASSERT(lastFragment.isLastInRenderer());
-                if (!lastFragment.isCollapsed()) {
-                    // Line width needs to be reset so that now it takes collapsing into consideration.
-                    m_runsWidth -= (lastFragment.width() - m_collapsedWhitespaceWidth);
-                }
-                // This fragment is collapsed completely. No run is needed.
-                return;
-            }
-            if (lastFragment.isLastInRenderer() || lastFragment.isCollapsed())
-                runs.append(Run(fragment.start(), endPosition, m_runsWidth, m_runsWidth + fragment.width(), false));
-            else {
-                Run&amp; lastRun = runs.last();
-                lastRun.end = endPosition;
-                lastRun.logicalRight += fragment.width();
-            }
</del><ins>+            ASSERT(runs.size());
+            Run&amp; lastRun = runs.last();
+            lastRun.end = endPosition;
+            lastRun.logicalRight = m_runsWidth + fragment.width();
</ins><span class="cx">         }
</span><del>-        m_fragments.append(fragment);
</del><ins>+        m_createNewRun = fragment.isCollapsed();
</ins><span class="cx">         m_runsWidth += fragment.width();
</span><span class="cx"> 
</span><span class="cx">         if (fragment.type() == TextFragmentIterator::TextFragment::Whitespace) {
</span><span class="lines">@@ -318,34 +274,18 @@
</span><span class="cx">             m_firstCharacterFits = fragment.start() + 1 &gt; endPosition || m_runsWidth &lt;= m_availableWidth;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    TextFragmentIterator::TextFragment revertToLastCompleteFragment(Layout::RunVector&amp; runs)
-    {
-        ASSERT(m_fragments.size());
-        unsigned revertLength = 0;
-        float revertWidth = 0;
-        while (m_fragments.size()) {
-            const auto&amp; current = m_fragments.last();
-            if (current == m_lastCompleteFragment)
-                break;
-            revertLength += current.end() - current.start();
-            revertWidth += current.width();
-            m_fragments.removeLast();
-        }
-        m_runsWidth -= revertWidth;
-        if (revertLength)
-            revertRuns(runs, revertLength, revertWidth);
-        return m_lastCompleteFragment;
-    }
-
</del><span class="cx">     void removeTrailingWhitespace(Layout::RunVector&amp; runs)
</span><span class="cx">     {
</span><del>-        // FIXME: sync m_fragment, but it's ok for now as we don't use m_fragment anymore after removeTrailingWhitespace.
-        if (!m_trailingWhitespaceLength)
-            return;
-        revertRuns(runs, m_trailingWhitespaceLength, m_trailingWhitespaceWidth);
</del><ins>+        ASSERT(runs.size());
+        Run&amp; lastRun = runs.last();
+        lastRun.logicalRight -= m_trailingWhitespaceWidth;
+        lastRun.end -= m_trailingWhitespaceLength;
+        if (lastRun.start == lastRun.end)
+            runs.removeLast();
+
</ins><span class="cx">         m_runsWidth -= m_trailingWhitespaceWidth;
</span><del>-        m_trailingWhitespaceLength = 0;
</del><span class="cx">         m_trailingWhitespaceWidth = 0;
</span><ins>+        m_trailingWhitespaceLength = 0;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="lines">@@ -353,14 +293,12 @@
</span><span class="cx">     float m_logicalLeftOffset { 0 };
</span><span class="cx">     TextFragmentIterator::TextFragment m_overflowedFragment;
</span><span class="cx">     float m_runsWidth { 0 };
</span><del>-    TextFragmentIterator::TextFragment m_lastCompleteFragment;
</del><ins>+    bool m_createNewRun { true };
</ins><span class="cx">     float m_trailingWhitespaceWidth { 0 }; // Use this to remove trailing whitespace without re-mesuring the text.
</span><span class="cx">     unsigned m_trailingWhitespaceLength { 0 };
</span><del>-    float m_collapsedWhitespaceWidth { 0 };
</del><span class="cx">     // Having one character on the line does not necessarily mean it actually fits.
</span><span class="cx">     // First character of the first fragment might be forced on to the current line even if it does not fit.
</span><span class="cx">     bool m_firstCharacterFits { false };
</span><del>-    Vector&lt;TextFragmentIterator::TextFragment&gt; m_fragments;
</del><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> class FragmentForwardIterator : public std::iterator&lt;std::forward_iterator_tag, unsigned&gt; {
</span><span class="lines">@@ -451,36 +389,14 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // Check if we need to skip the leading whitespace.
</span><del>-    if (style.collapseWhitespace) {
-        while (firstFragment.type() == TextFragmentIterator::TextFragment::Whitespace)
-            firstFragment = textFragmentIterator.nextTextFragment();
-    }
</del><ins>+    if (style.collapseWhitespace &amp;&amp; firstFragment.type() == TextFragmentIterator::TextFragment::Whitespace)
+        firstFragment = textFragmentIterator.nextTextFragment();
</ins><span class="cx">     return firstFragment;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static void forceFragmentToLine(LineState&amp; line, TextFragmentIterator&amp; textFragmentIterator, Layout::RunVector&amp; runs, const TextFragmentIterator::TextFragment&amp; fragment)
-{
-    line.appendFragmentAndCreateRunIfNeeded(fragment, runs);
-    // Check if there are more fragments to add to the current line.
-    if (!fragment.overlapsToNextRenderer())
-        return;
-    auto nextFragment = textFragmentIterator.nextTextFragment();
-    while (true) {
-        if (nextFragment.type() != fragment.type())
-            break;
-        line.appendFragmentAndCreateRunIfNeeded(nextFragment, runs);
-        // Does it overlap to the next segment?
-        if (!nextFragment.overlapsToNextRenderer())
-            return;
-        nextFragment = textFragmentIterator.nextTextFragment();
-    }
-    line.setOverflowedFragment(nextFragment);
-}
-
</del><span class="cx"> static bool createLineRuns(LineState&amp; line, const LineState&amp; previousLine, Layout::RunVector&amp; runs, TextFragmentIterator&amp; textFragmentIterator)
</span><span class="cx"> {
</span><span class="cx">     const auto&amp; style = textFragmentIterator.style();
</span><del>-    line.setCollapedWhitespaceWidth(style.spaceWidth);
</del><span class="cx">     bool lineCanBeWrapped = style.wrapLines || style.breakWordOnOverflow;
</span><span class="cx">     auto fragment = firstFragment(textFragmentIterator, previousLine);
</span><span class="cx">     while (fragment.type() != TextFragmentIterator::TextFragment::ContentEnd) {
</span><span class="lines">@@ -488,7 +404,7 @@
</span><span class="cx">         if (fragment.type() == TextFragmentIterator::TextFragment::LineBreak) {
</span><span class="cx">             // Add the new line fragment only if there's nothing on the line. (otherwise the extra new line character would show up at the end of the content.)
</span><span class="cx">             if (!line.width())
</span><del>-                line.appendFragmentAndCreateRunIfNeeded(fragment, runs);
</del><ins>+                line.appendFragment(fragment, runs);
</ins><span class="cx">             break;
</span><span class="cx">         }
</span><span class="cx">         if (lineCanBeWrapped &amp;&amp; !line.fits(fragment.width())) {
</span><span class="lines">@@ -497,13 +413,13 @@
</span><span class="cx">             // 2. Whitespace collapse off: whitespace is wrapped.
</span><span class="cx">             // 3. First, non-whitespace fragment is either wrapped or kept on the line. (depends on overflow-wrap)
</span><span class="cx">             // 4. Non-whitespace fragment when there's already another fragment on the line gets pushed to the next line.
</span><del>-            bool emptyLine = line.isEmpty();
</del><ins>+            bool emptyLine = !line.width();
</ins><span class="cx">             // Whitespace fragment.
</span><span class="cx">             if (fragment.type() == TextFragmentIterator::TextFragment::Whitespace) {
</span><span class="cx">                 if (!style.collapseWhitespace) {
</span><span class="cx">                     // Split the fragment; (modified)fragment stays on this line, overflowedFragment is pushed to next line.
</span><span class="cx">                     line.setOverflowedFragment(splitFragmentToFitLine(fragment, line.availableWidth() - line.width(), emptyLine, textFragmentIterator));
</span><del>-                    line.appendFragmentAndCreateRunIfNeeded(fragment, runs);
</del><ins>+                    line.appendFragment(fragment, runs);
</ins><span class="cx">                 }
</span><span class="cx">                 // When whitespace collapse is on, whitespace that doesn't fit is simply skipped.
</span><span class="cx">                 break;
</span><span class="lines">@@ -512,30 +428,23 @@
</span><span class="cx">             if ((emptyLine &amp;&amp; style.breakWordOnOverflow) || !style.wrapLines) {
</span><span class="cx">                 // Split the fragment; (modified)fragment stays on this line, overflowedFragment is pushed to next line.
</span><span class="cx">                 line.setOverflowedFragment(splitFragmentToFitLine(fragment, line.availableWidth() - line.width(), emptyLine, textFragmentIterator));
</span><del>-                line.appendFragmentAndCreateRunIfNeeded(fragment, runs);
</del><ins>+                line.appendFragment(fragment, runs);
</ins><span class="cx">                 break;
</span><span class="cx">             }
</span><span class="cx">             // Non-breakable non-whitespace first fragment. Add it to the current line. -it overflows though.
</span><del>-            ASSERT(fragment.type() == TextFragmentIterator::TextFragment::NonWhitespace);
</del><span class="cx">             if (emptyLine) {
</span><del>-                forceFragmentToLine(line, textFragmentIterator, runs, fragment);
</del><ins>+                line.appendFragment(fragment, runs);
</ins><span class="cx">                 break;
</span><span class="cx">             }
</span><span class="cx">             // Non-breakable non-whitespace fragment when there's already content on the line. Push it to the next line.
</span><del>-            if (line.lastFragment().overlapsToNextRenderer()) {
-                // Check if this fragment is a continuation of a previous segment. In such cases, we need to remove them all.
-                const auto&amp; currentFragment = line.revertToLastCompleteFragment(runs);
-                textFragmentIterator.revertToFragment(currentFragment);
-                break;
-            }
</del><span class="cx">             line.setOverflowedFragment(fragment);
</span><span class="cx">             break;
</span><span class="cx">         }
</span><del>-        line.appendFragmentAndCreateRunIfNeeded(fragment, runs);
</del><ins>+        line.appendFragment(fragment, runs);
</ins><span class="cx">         // Find the next text fragment.
</span><span class="cx">         fragment = textFragmentIterator.nextTextFragment(line.width());
</span><span class="cx">     }
</span><del>-    return (fragment.type() == TextFragmentIterator::TextFragment::ContentEnd &amp;&amp; line.overflowedFragment().isEmpty()) || line.overflowedFragment().type() == TextFragmentIterator::TextFragment::ContentEnd;
</del><ins>+    return fragment.type() == TextFragmentIterator::TextFragment::ContentEnd &amp;&amp; line.overflowedFragment().isEmpty();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static void closeLineEndingAndAdjustRuns(LineState&amp; line, Layout::RunVector&amp; runs, unsigned previousRunCount, unsigned&amp; lineCount, const TextFragmentIterator&amp; textFragmentIterator)
</span><span class="lines">@@ -557,6 +466,28 @@
</span><span class="cx">     ++lineCount;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static void splitRunsAtRendererBoundary(Layout::RunVector&amp; lineRuns, const TextFragmentIterator&amp; textFragmentIterator)
+{
+    // FIXME: We should probably split during run construction instead of as a separate pass.
+    if (lineRuns.isEmpty())
+        return;
+    unsigned runIndex = 0;
+    do {
+        const Run&amp; run = lineRuns.at(runIndex);
+        ASSERT(run.start != run.end);
+        auto&amp; startSegment = textFragmentIterator.segmentForPosition(run.start);
+        if (run.end &lt;= startSegment.end)
+            continue;
+        // This run overlaps multiple renderers. Split it up.
+        // Split run at the renderer's boundary and create a new run for the left side, while use the current run as the right side.
+        float logicalRightOfLeftRun = run.logicalLeft + textFragmentIterator.textWidth(run.start, startSegment.end, run.logicalLeft);
+        lineRuns.insert(runIndex, Run(run.start, startSegment.end, run.logicalLeft, logicalRightOfLeftRun, false));
+        Run&amp; rightSideRun = lineRuns.at(runIndex + 1);
+        rightSideRun.start = startSegment.end;
+        rightSideRun.logicalLeft = logicalRightOfLeftRun;
+    } while (++runIndex &lt; lineRuns.size());
+}
+
</ins><span class="cx"> static void createTextRuns(Layout::RunVector&amp; runs, RenderBlockFlow&amp; flow, unsigned&amp; lineCount)
</span><span class="cx"> {
</span><span class="cx">     LayoutUnit borderAndPaddingBefore = flow.borderAndPaddingBefore();
</span><span class="lines">@@ -574,6 +505,9 @@
</span><span class="cx">         isEndOfContent = createLineRuns(line, previousLine, runs, textFragmentIterator);
</span><span class="cx">         closeLineEndingAndAdjustRuns(line, runs, previousRunCount, lineCount, textFragmentIterator);
</span><span class="cx">     } while (!isEndOfContent);
</span><ins>+
+    if (flow.firstChild() != flow.lastChild())
+        splitRunsAtRendererBoundary(runs, textFragmentIterator);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> std::unique_ptr&lt;Layout&gt; create(RenderBlockFlow&amp; flow)
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingSimpleLineLayoutFlowContentscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/SimpleLineLayoutFlowContents.cpp (181684 => 181685)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/SimpleLineLayoutFlowContents.cpp        2015-03-18 05:38:20 UTC (rev 181684)
+++ trunk/Source/WebCore/rendering/SimpleLineLayoutFlowContents.cpp        2015-03-18 06:09:56 UTC (rev 181685)
</span><span class="lines">@@ -51,13 +51,12 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-unsigned FlowContents::segmentIndexForRunSlow(unsigned start, unsigned end) const
</del><ins>+unsigned FlowContents::segmentIndexForPositionSlow(unsigned position) const
</ins><span class="cx"> {
</span><del>-    auto it = std::lower_bound(m_segments.begin(), m_segments.end(), start, [](const Segment&amp; segment, unsigned start) {
-        return segment.end &lt;= start;
</del><ins>+    auto it = std::lower_bound(m_segments.begin(), m_segments.end(), position, [](const Segment&amp; segment, unsigned position) {
+        return segment.end &lt;= position;
</ins><span class="cx">     });
</span><span class="cx">     ASSERT(it != m_segments.end());
</span><del>-    ASSERT_UNUSED(end, end &lt;= it-&gt;end);
</del><span class="cx">     auto index = it - m_segments.begin();
</span><span class="cx">     m_lastSegmentIndex = index;
</span><span class="cx">     return index;
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingSimpleLineLayoutFlowContentsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/SimpleLineLayoutFlowContents.h (181684 => 181685)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/SimpleLineLayoutFlowContents.h        2015-03-18 05:38:20 UTC (rev 181684)
+++ trunk/Source/WebCore/rendering/SimpleLineLayoutFlowContents.h        2015-03-18 06:09:56 UTC (rev 181685)
</span><span class="lines">@@ -43,29 +43,72 @@
</span><span class="cx">         String text;
</span><span class="cx">         const RenderObject&amp; renderer;
</span><span class="cx">     };
</span><del>-    const Segment&amp; segmentForRun(unsigned start, unsigned end) const;
</del><ins>+    const Segment&amp; segmentForPosition(unsigned) const;
</ins><span class="cx">     const Segment&amp; segmentForRenderer(const RenderObject&amp;) const;
</span><span class="cx"> 
</span><del>-    typedef Vector&lt;Segment, 8&gt;::const_iterator Iterator;
-    Iterator begin() const { return m_segments.begin(); }
-    Iterator end() const { return m_segments.end(); }
</del><ins>+    class Iterator {
+    public:
+        Iterator(const FlowContents&amp; flowContents, unsigned segmentIndex)
+            : m_flowContents(flowContents)
+            , m_segmentIndex(segmentIndex)
+        {
+        }
</ins><span class="cx"> 
</span><ins>+        Iterator&amp; operator++();
+        bool operator==(const Iterator&amp; other) const;
+        bool operator!=(const Iterator&amp; other) const;
+        const Segment&amp; operator*() const { return m_flowContents.m_segments[m_segmentIndex]; }
+
+    private:
+        const FlowContents&amp; m_flowContents;
+        unsigned m_segmentIndex;
+    };
+
+    Iterator begin() const { return Iterator(*this, 0); }
+    Iterator end() const { return Iterator(*this, m_segments.size()); }
+
+    unsigned length() const { return m_segments.last().end; };
+
+    unsigned segmentIndexForPosition(unsigned position) const;
+
</ins><span class="cx"> private:
</span><del>-    unsigned segmentIndexForRunSlow(unsigned start, unsigned end) const;
</del><ins>+    unsigned segmentIndexForPositionSlow(unsigned position) const;
+
</ins><span class="cx">     const Vector&lt;Segment, 8&gt; m_segments;
</span><ins>+
</ins><span class="cx">     mutable unsigned m_lastSegmentIndex;
</span><span class="cx"> };
</span><span class="cx"> 
</span><del>-inline const FlowContents::Segment&amp; FlowContents::segmentForRun(unsigned start, unsigned end) const
</del><ins>+inline FlowContents::Iterator&amp; FlowContents::Iterator::operator++()
</ins><span class="cx"> {
</span><del>-    ASSERT(start &lt; end);
</del><ins>+    ++m_segmentIndex;
+    return *this;
+}
+
+inline bool FlowContents::Iterator::operator==(const FlowContents::Iterator&amp; other) const
+{
+    return m_segmentIndex == other.m_segmentIndex;
+}
+
+inline bool FlowContents::Iterator::operator!=(const FlowContents::Iterator&amp; other) const
+{
+    return !(*this == other);
+}
+
+inline unsigned FlowContents::segmentIndexForPosition(unsigned position) const
+{
</ins><span class="cx">     auto&amp; lastSegment = m_segments[m_lastSegmentIndex];
</span><del>-    if (lastSegment.start &lt;= start &amp;&amp; end &lt;= lastSegment.end)
-        return m_segments[m_lastSegmentIndex];
-    return m_segments[segmentIndexForRunSlow(start, end)];
</del><ins>+    if (lastSegment.start &lt;= position &amp;&amp; position &lt; lastSegment.end)
+        return m_lastSegmentIndex;
+    return segmentIndexForPositionSlow(position);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+inline const FlowContents::Segment&amp; FlowContents::segmentForPosition(unsigned position) const
+{
+    return m_segments[segmentIndexForPosition(position)];
</ins><span class="cx"> }
</span><ins>+
</ins><span class="cx"> }
</span><ins>+}
</ins><span class="cx"> 
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingSimpleLineLayoutFunctionscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/SimpleLineLayoutFunctions.cpp (181684 => 181685)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/SimpleLineLayoutFunctions.cpp        2015-03-18 05:38:20 UTC (rev 181684)
+++ trunk/Source/WebCore/rendering/SimpleLineLayoutFunctions.cpp        2015-03-18 06:09:56 UTC (rev 181685)
</span><span class="lines">@@ -84,7 +84,6 @@
</span><span class="cx">             continue;
</span><span class="cx">         TextRun textRun(run.text());
</span><span class="cx">         textRun.setTabSize(!style.collapseWhiteSpace(), style.tabSize());
</span><del>-        textRun.setXPos(run.rect().x());
</del><span class="cx">         FloatPoint textOrigin = run.baseline() + paintOffset;
</span><span class="cx">         textOrigin.setY(roundToDevicePixel(LayoutUnit(textOrigin.y()), flow.document().deviceScaleFactor()));
</span><span class="cx">         context.drawText(font, textRun, textOrigin);
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingSimpleLineLayoutResolvercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/SimpleLineLayoutResolver.cpp (181684 => 181685)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/SimpleLineLayoutResolver.cpp        2015-03-18 05:38:20 UTC (rev 181684)
+++ trunk/Source/WebCore/rendering/SimpleLineLayoutResolver.cpp        2015-03-18 06:09:56 UTC (rev 181685)
</span><span class="lines">@@ -76,8 +76,7 @@
</span><span class="cx"> {
</span><span class="cx">     auto&amp; resolver = m_iterator.resolver();
</span><span class="cx">     auto&amp; run = m_iterator.simpleRun();
</span><del>-    ASSERT(run.start &lt; run.end);
-    auto&amp; segment = resolver.m_flowContents.segmentForRun(run.start, run.end);
</del><ins>+    auto&amp; segment = resolver.m_flowContents.segmentForPosition(run.start);
</ins><span class="cx">     // We currently split runs on segment boundaries (different RenderObject).
</span><span class="cx">     ASSERT(run.end &lt;= segment.end);
</span><span class="cx">     if (segment.text.is8Bit())
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingSimpleLineLayoutTextFragmentIteratorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.cpp (181684 => 181685)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.cpp        2015-03-18 05:38:20 UTC (rev 181684)
+++ trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.cpp        2015-03-18 06:09:56 UTC (rev 181685)
</span><span class="lines">@@ -48,8 +48,7 @@
</span><span class="cx"> 
</span><span class="cx"> TextFragmentIterator::TextFragmentIterator(const RenderBlockFlow&amp; flow)
</span><span class="cx">     : m_flowContents(flow)
</span><del>-    , m_currentSegment(m_flowContents.begin())
-    , m_lineBreakIterator(m_currentSegment-&gt;text, flow.style().locale())
</del><ins>+    , m_lineBreakIterator((*m_flowContents.begin()).text, flow.style().locale())
</ins><span class="cx">     , m_style(flow.style())
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="lines">@@ -61,135 +60,115 @@
</span><span class="cx">     // 2. whitespace (collasped, non-collapsed multi or single) or
</span><span class="cx">     // 3. non-whitespace characters.
</span><span class="cx">     // 4. empty, indicating content end.
</span><del>-    ASSERT(m_currentSegment != m_flowContents.end());
-    if (m_position == m_currentSegment-&gt;end)
-        ++m_currentSegment;
-    // Is it content end?
-    if (m_currentSegment == m_flowContents.end())
</del><ins>+    if (isEnd(m_position))
</ins><span class="cx">         return TextFragment(m_position, m_position, 0, TextFragment::ContentEnd);
</span><del>-    unsigned segmentEndPosition = m_currentSegment-&gt;end;
-    unsigned startPosition = m_position;
</del><span class="cx">     if (isLineBreak(m_position)) {
</span><del>-        unsigned endPosition = ++m_position;
-        return TextFragment(startPosition, endPosition, 0, TextFragment::LineBreak);
</del><ins>+        TextFragment fragment(m_position, m_position + 1, 0, TextFragment::LineBreak);
+        ++m_position;
+        return fragment;
</ins><span class="cx">     }
</span><del>-    float width = 0;
-    bool overlappingFragment = false;
-    unsigned endPosition = skipToNextPosition(PositionType::NonWhitespace, startPosition, width, xPosition, overlappingFragment);
</del><ins>+    unsigned startPosition = m_position;
+    unsigned endPosition = skipToNextPosition(PositionType::NonWhitespace, startPosition);
</ins><span class="cx">     ASSERT(startPosition &lt;= endPosition);
</span><del>-    if (startPosition &lt; endPosition) {
</del><ins>+    if (endPosition &gt; startPosition) {
</ins><span class="cx">         bool multipleWhitespace = startPosition + 1 &lt; endPosition;
</span><span class="cx">         bool isCollapsed = multipleWhitespace &amp;&amp; m_style.collapseWhitespace;
</span><span class="cx">         bool isBreakable = !isCollapsed &amp;&amp; multipleWhitespace;
</span><ins>+        float width = isCollapsed ? m_style.spaceWidth : textWidth(startPosition, endPosition, xPosition);
</ins><span class="cx">         m_position = endPosition;
</span><del>-        return TextFragment(startPosition, endPosition, width, TextFragment::Whitespace, endPosition == segmentEndPosition, false, isCollapsed, m_style.collapseWhitespace, isBreakable);
</del><ins>+        return TextFragment(startPosition, endPosition, width, TextFragment::Whitespace, isCollapsed, isBreakable);
</ins><span class="cx">     }
</span><del>-    endPosition = skipToNextPosition(PositionType::Breakable, startPosition, width, xPosition, overlappingFragment);
</del><ins>+    endPosition = skipToNextPosition(PositionType::Breakable, startPosition + 1);
</ins><span class="cx">     m_position = endPosition;
</span><del>-    return TextFragment(startPosition, endPosition, width, TextFragment::NonWhitespace, endPosition == segmentEndPosition, overlappingFragment, false, false, m_style.breakWordOnOverflow);
</del><ins>+    return TextFragment(startPosition, endPosition, textWidth(startPosition, endPosition, xPosition), TextFragment::NonWhitespace, false, m_style.breakWordOnOverflow);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void TextFragmentIterator::revertToFragment(const TextFragment&amp; fragment)
</del><ins>+float TextFragmentIterator::textWidth(unsigned from, unsigned to, float xPosition) const
</ins><span class="cx"> {
</span><del>-    ASSERT(m_position &gt;= fragment.end());
-    ASSERT(fragment.start() &gt;= 0);
-    // Revert segment first.
-    while (m_currentSegment-&gt;start &gt; fragment.start())
-        --m_currentSegment;
-    // TODO: It reverts to the last fragment on the same position, but that's ok for now as we don't need to
-    // differentiate multiple renderers on the same position.
-    m_position = fragment.start();
</del><ins>+    const auto&amp; fromSegment = m_flowContents.segmentForPosition(from);
+    ASSERT(is&lt;RenderText&gt;(fromSegment.renderer));
+    if ((m_style.font.isFixedPitch() &amp;&amp; fromSegment.end &gt;= to) || (from == fromSegment.start &amp;&amp; to == fromSegment.end))
+        return downcast&lt;RenderText&gt;(fromSegment.renderer).width(from - fromSegment.start, to - from, m_style.font, xPosition, nullptr, nullptr);
+
+    const auto* segment = &amp;fromSegment;
+    float textWidth = 0;
+    unsigned fragmentEnd = 0;
+    while (true) {
+        fragmentEnd = std::min(to, segment-&gt;end);
+        textWidth += segment-&gt;text.is8Bit() ? runWidth&lt;LChar&gt;(segment-&gt;text, from - segment-&gt;start, fragmentEnd - segment-&gt;start, xPosition + textWidth) :
+            runWidth&lt;UChar&gt;(segment-&gt;text, from - segment-&gt;start, fragmentEnd - segment-&gt;start, xPosition + textWidth);
+        if (fragmentEnd == to)
+            break;
+        from = fragmentEnd;
+        segment = &amp;m_flowContents.segmentForPosition(fragmentEnd);
+    };
+
+    return textWidth;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> template &lt;typename CharacterType&gt;
</span><del>-unsigned TextFragmentIterator::nextBreakablePosition(const FlowContents::Segment&amp; segment, unsigned startPosition)
</del><ins>+static unsigned nextBreakablePosition(LazyLineBreakIterator&amp; lineBreakIterator, const FlowContents::Segment&amp; segment, unsigned startPosition)
</ins><span class="cx"> {
</span><del>-    ASSERT(startPosition &lt; segment.end);
-    if (segment.text.impl() != m_lineBreakIterator.string().impl()) {
-        const String&amp; currentText = m_lineBreakIterator.string();
-        unsigned textLength = currentText.length();
-        UChar lastCharacter = textLength &gt; 0 ? currentText[textLength - 1] : 0;
-        UChar secondToLastCharacter = textLength &gt; 1 ? currentText[textLength - 2] : 0;
-        m_lineBreakIterator.setPriorContext(lastCharacter, secondToLastCharacter);
-        m_lineBreakIterator.resetStringAndReleaseIterator(segment.text, m_style.locale, LineBreakIteratorModeUAX14);
-    }
-    const auto* characters = segment.text.characters&lt;CharacterType&gt;();
-    unsigned segmentLength = segment.end - segment.start;
-    unsigned segmentPosition = startPosition - segment.start;
-    return segment.start + nextBreakablePositionNonLoosely&lt;CharacterType, NBSPBehavior::IgnoreNBSP&gt;(m_lineBreakIterator, characters, segmentLength, segmentPosition);
</del><ins>+    return nextBreakablePositionNonLoosely&lt;CharacterType, NBSPBehavior::IgnoreNBSP&gt;(lineBreakIterator, segment.text.characters&lt;CharacterType&gt;(), segment.end - segment.start, startPosition);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> template &lt;typename CharacterType&gt;
</span><del>-unsigned TextFragmentIterator::nextNonWhitespacePosition(const FlowContents::Segment&amp; segment, unsigned startPosition)
</del><ins>+static unsigned nextNonWhitespacePosition(const FlowContents::Segment&amp; segment, unsigned startPosition, const TextFragmentIterator::Style&amp; style)
</ins><span class="cx"> {
</span><del>-    ASSERT(startPosition &lt; segment.end);
</del><span class="cx">     const auto* text = segment.text.characters&lt;CharacterType&gt;();
</span><span class="cx">     unsigned position = startPosition;
</span><del>-    for (; position &lt; segment.end; ++position) {
-        auto character = text[position - segment.start];
-        bool isWhitespace = character == ' ' || character == '\t' || (!m_style.preserveNewline &amp;&amp; character == '\n');
</del><ins>+    unsigned length = segment.end - segment.start;
+    for (; position &lt; length; ++position) {
+        auto character = text[position];
+        bool isWhitespace = character == ' ' || character == '\t' || (!style.preserveNewline &amp;&amp; character == '\n');
</ins><span class="cx">         if (!isWhitespace)
</span><span class="cx">             return position;
</span><span class="cx">     }
</span><span class="cx">     return position;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-float TextFragmentIterator::textWidth(unsigned from, unsigned to, float xPosition) const
</del><ins>+unsigned TextFragmentIterator::skipToNextPosition(PositionType positionType, unsigned startPosition) const
</ins><span class="cx"> {
</span><del>-    auto&amp; segment = *m_currentSegment;
-    ASSERT(segment.start &lt;= from &amp;&amp; from &lt;= segment.end &amp;&amp; segment.start &lt;= to &amp;&amp; to &lt;= segment.end);
-    ASSERT(is&lt;RenderText&gt;(segment.renderer));
-    if (m_style.font.isFixedPitch() || (from == segment.start &amp;&amp; to == segment.end))
-        return downcast&lt;RenderText&gt;(segment.renderer).width(from - segment.start, to - from, m_style.font, xPosition, nullptr, nullptr);
-    return segment.text.is8Bit() ? runWidth&lt;LChar&gt;(segment, from, to, xPosition) : runWidth&lt;UChar&gt;(segment, from, to, xPosition);
-}
</del><ins>+    if (isEnd(startPosition))
+        return startPosition;
</ins><span class="cx"> 
</span><del>-unsigned TextFragmentIterator::skipToNextPosition(PositionType positionType, unsigned startPosition, float&amp; width, float xPosition, bool&amp; overlappingFragment)
-{
-    overlappingFragment = false;
</del><span class="cx">     unsigned currentPosition = startPosition;
</span><del>-    unsigned nextPosition = currentPosition;
-    // Collapsed whitespace has constant width. Do not measure it.
-    if (positionType == NonWhitespace)
-        nextPosition = m_currentSegment-&gt;text.is8Bit() ? nextNonWhitespacePosition&lt;LChar&gt;(*m_currentSegment, currentPosition) : nextNonWhitespacePosition&lt;UChar&gt;(*m_currentSegment, currentPosition);
-    else if (positionType == Breakable) {
-        // nextBreakablePosition returns the same position for certain characters such as hyphens. Call next again with modified position unless it's the end of the segment.
-        nextPosition = m_currentSegment-&gt;text.is8Bit() ? nextBreakablePosition&lt;LChar&gt;(*m_currentSegment, currentPosition) : nextBreakablePosition&lt;UChar&gt;(*m_currentSegment, currentPosition);
-        // We need to know whether the word actually finishes at the end of this renderer or not.
-        if (nextPosition == m_currentSegment-&gt;end) {
-            const auto nextSegment = m_currentSegment + 1;
-            if (nextSegment != m_flowContents.end())
-                overlappingFragment = nextPosition &lt; (nextSegment-&gt;text.is8Bit() ? nextBreakablePosition&lt;LChar&gt;(*nextSegment, nextPosition) : nextBreakablePosition&lt;UChar&gt;(*nextSegment, nextPosition));
-        } else if (nextPosition == currentPosition) {
-            if (++nextPosition &lt; m_currentSegment-&gt;end)
-                nextPosition = m_currentSegment-&gt;text.is8Bit() ? nextBreakablePosition&lt;LChar&gt;(*m_currentSegment, currentPosition + 1) : nextBreakablePosition&lt;UChar&gt;(*m_currentSegment, currentPosition + 1);
-        }
</del><ins>+    FlowContents::Iterator it(m_flowContents, m_flowContents.segmentIndexForPosition(currentPosition));
+    for (auto end = m_flowContents.end(); it != end; ++it) {
+        auto&amp; segment = *it;
+        unsigned currentPositonRelativeToSegment = currentPosition - segment.start;
+        unsigned nextPositionRelativeToSegment = 0;
+        if (positionType == NonWhitespace) {
+            nextPositionRelativeToSegment = segment.text.is8Bit() ? nextNonWhitespacePosition&lt;LChar&gt;(segment, currentPositonRelativeToSegment, m_style) :
+                nextNonWhitespacePosition&lt;UChar&gt;(segment, currentPositonRelativeToSegment, m_style);
+        } else if (positionType == Breakable) {
+            if (segment.text.impl() != m_lineBreakIterator.string().impl()) {
+                UChar lastCharacter = segment.start &gt; 0 ? characterAt(segment.start - 1) : 0;
+                UChar secondToLastCharacter = segment.start &gt; 1 ? characterAt(segment.start - 2) : 0;
+                m_lineBreakIterator.setPriorContext(lastCharacter, secondToLastCharacter);
+                m_lineBreakIterator.resetStringAndReleaseIterator(segment.text, m_style.locale, LineBreakIteratorModeUAX14);
+            }
+            nextPositionRelativeToSegment = segment.text.is8Bit() ? nextBreakablePosition&lt;LChar&gt;(m_lineBreakIterator, segment, currentPositonRelativeToSegment) :
+                nextBreakablePosition&lt;UChar&gt;(m_lineBreakIterator, segment, currentPositonRelativeToSegment);
+        } else
+            ASSERT_NOT_REACHED();
+        currentPosition = segment.start + nextPositionRelativeToSegment;
+        if (currentPosition &lt; segment.end)
+            break;
</ins><span class="cx">     }
</span><del>-    width = 0;
-    if (nextPosition == currentPosition)
-        return currentPosition;
-    bool measureText = positionType != NonWhitespace || !m_style.collapseWhitespace;
-    if (measureText) {
-        float textWidth = this-&gt;textWidth(currentPosition, nextPosition, xPosition);
-        xPosition += textWidth;
-        width += textWidth;
-    } else if (startPosition &lt; nextPosition)
-        width = m_style.spaceWidth;
-    return nextPosition;
</del><ins>+    return currentPosition;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> template &lt;typename CharacterType&gt;
</span><del>-float TextFragmentIterator::runWidth(const FlowContents::Segment&amp; segment, unsigned startPosition, unsigned endPosition, float xPosition) const
</del><ins>+float TextFragmentIterator::runWidth(const String&amp; text, unsigned from, unsigned to, float xPosition) const
</ins><span class="cx"> {
</span><del>-    ASSERT(startPosition &lt;= endPosition);
-    if (startPosition == endPosition)
</del><ins>+    ASSERT(from &lt;= to);
+    if (from == to)
</ins><span class="cx">         return 0;
</span><del>-    unsigned segmentFrom = startPosition - segment.start;
-    unsigned segmentTo = endPosition - segment.start;
-    bool measureWithEndSpace = m_style.collapseWhitespace &amp;&amp; segmentTo &lt; segment.text.length() &amp;&amp; segment.text[segmentTo] == ' ';
</del><ins>+    bool measureWithEndSpace = m_style.collapseWhitespace &amp;&amp; to &lt; text.length() &amp;&amp; text[to] == ' ';
</ins><span class="cx">     if (measureWithEndSpace)
</span><del>-        ++segmentTo;
-    TextRun run(segment.text.characters&lt;CharacterType&gt;() + segmentFrom, segmentTo - segmentFrom);
</del><ins>+        ++to;
+    TextRun run(text.characters&lt;CharacterType&gt;() + from, to - from);
</ins><span class="cx">     run.setXPos(xPosition);
</span><span class="cx">     run.setTabSize(!!m_style.tabWidth, m_style.tabWidth);
</span><span class="cx">     float width = m_style.font.width(run);
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingSimpleLineLayoutTextFragmentIteratorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.h (181684 => 181685)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.h        2015-03-18 05:38:20 UTC (rev 181684)
+++ trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.h        2015-03-18 06:09:56 UTC (rev 181685)
</span><span class="lines">@@ -43,15 +43,12 @@
</span><span class="cx">     public:
</span><span class="cx">         enum Type { ContentEnd, LineBreak, Whitespace, NonWhitespace };
</span><span class="cx">         TextFragment() = default;
</span><del>-        TextFragment(unsigned start, unsigned end, float width, Type type, bool isLastInRenderer = false, bool overlapsToNextRenderer = false, bool isCollapsed = false, bool isCollapsible = false, bool isBreakable = false)
</del><ins>+        TextFragment(unsigned start, unsigned end, float width, Type type, bool isCollapsed = false, bool isBreakable = false)
</ins><span class="cx">             : m_start(start)
</span><span class="cx">             , m_end(end)
</span><del>-            , m_width(width)
</del><span class="cx">             , m_type(type)
</span><del>-            , m_isLastInRenderer(isLastInRenderer)
-            , m_overlapsToNextRenderer(overlapsToNextRenderer)
</del><ins>+            , m_width(width)
</ins><span class="cx">             , m_isCollapsed(isCollapsed)
</span><del>-            , m_isCollapsible(isCollapsible)
</del><span class="cx">             , m_isBreakable(isBreakable)
</span><span class="cx">         {
</span><span class="cx">         }
</span><span class="lines">@@ -60,41 +57,22 @@
</span><span class="cx">         unsigned end() const { return m_end; }
</span><span class="cx">         float width() const { return m_width; }
</span><span class="cx">         Type type() const { return m_type; }
</span><del>-        bool isLastInRenderer() const { return m_isLastInRenderer; }
-        bool overlapsToNextRenderer() const { return m_overlapsToNextRenderer; }
</del><span class="cx">         bool isCollapsed() const { return m_isCollapsed; }
</span><del>-        bool isCollapsible() const { return m_isCollapsible; }
</del><span class="cx">         bool isBreakable() const { return m_isBreakable; }
</span><span class="cx"> 
</span><span class="cx">         bool isEmpty() const { return start() == end(); }
</span><span class="cx">         TextFragment split(unsigned splitPosition, const TextFragmentIterator&amp;);
</span><del>-        bool operator==(const TextFragment&amp; other) const
-        {
-            return m_start == other.m_start
-                &amp;&amp; m_end == other.m_end
-                &amp;&amp; m_width == other.m_width
-                &amp;&amp; m_type == other.m_type
-                &amp;&amp; m_isLastInRenderer == other.m_isLastInRenderer
-                &amp;&amp; m_overlapsToNextRenderer == other.m_overlapsToNextRenderer
-                &amp;&amp; m_isCollapsed == other.m_isCollapsed
-                &amp;&amp; m_isCollapsible == other.m_isCollapsible
-                &amp;&amp; m_isBreakable == other.m_isBreakable;
-        }
</del><span class="cx"> 
</span><span class="cx">     private:
</span><span class="cx">         unsigned m_start { 0 };
</span><span class="cx">         unsigned m_end { 0 };
</span><del>-        float m_width { 0 };
</del><span class="cx">         Type m_type { NonWhitespace };
</span><del>-        bool m_isLastInRenderer { false };
-        bool m_overlapsToNextRenderer { false };
</del><ins>+        float m_width { 0 };
</ins><span class="cx">         bool m_isCollapsed { false };
</span><del>-        bool m_isCollapsible { false };
</del><span class="cx">         bool m_isBreakable { false };
</span><span class="cx">     };
</span><span class="cx">     TextFragment nextTextFragment(float xPosition = 0);
</span><del>-    void revertToFragment(const TextFragment&amp;);
-    float textWidth(unsigned startPosition, unsigned endPosition, float xPosition) const;
</del><ins>+    float textWidth(unsigned from, unsigned to, float xPosition) const;
</ins><span class="cx"> 
</span><span class="cx">     struct Style {
</span><span class="cx">         explicit Style(const RenderStyle&amp;);
</span><span class="lines">@@ -110,18 +88,19 @@
</span><span class="cx">         AtomicString locale;
</span><span class="cx">     };
</span><span class="cx">     const Style&amp; style() const { return m_style; }
</span><ins>+    // FIXME: remove splitRunsAtRendererBoundary()
+    const FlowContents::Segment&amp; segmentForPosition(unsigned position) const { return m_flowContents.segmentForPosition(position); };
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     enum PositionType { Breakable, NonWhitespace };
</span><del>-    unsigned skipToNextPosition(PositionType, unsigned startPosition, float&amp; width, float xPosition, bool&amp; overlappingFragment);
</del><ins>+    unsigned skipToNextPosition(PositionType, unsigned startPosition) const;
+    UChar characterAt(unsigned position) const;
</ins><span class="cx">     bool isLineBreak(unsigned position) const;
</span><del>-    template &lt;typename CharacterType&gt; unsigned nextBreakablePosition(const FlowContents::Segment&amp;, unsigned startPosition);
-    template &lt;typename CharacterType&gt; unsigned nextNonWhitespacePosition(const FlowContents::Segment&amp;, unsigned startPosition);
-    template &lt;typename CharacterType&gt; float runWidth(const FlowContents::Segment&amp;, unsigned startPosition, unsigned endPosition, float xPosition) const;
</del><ins>+    bool isEnd(unsigned position) const;
+    template &lt;typename CharacterType&gt; float runWidth(const String&amp;, unsigned from, unsigned to, float xPosition) const;
</ins><span class="cx"> 
</span><span class="cx">     FlowContents m_flowContents;
</span><del>-    FlowContents::Iterator m_currentSegment;
-    LazyLineBreakIterator m_lineBreakIterator;
</del><ins>+    mutable LazyLineBreakIterator m_lineBreakIterator;
</ins><span class="cx">     const Style m_style;
</span><span class="cx">     unsigned m_position { 0 };
</span><span class="cx"> };
</span><span class="lines">@@ -148,14 +127,25 @@
</span><span class="cx">     return newFragment;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+inline UChar TextFragmentIterator::characterAt(unsigned position) const
+{
+    auto&amp; segment = m_flowContents.segmentForPosition(position);
+    return segment.text[position - segment.start];
+}
+
</ins><span class="cx"> inline bool TextFragmentIterator::isLineBreak(unsigned position) const
</span><span class="cx"> {
</span><del>-    const auto&amp; segment = *m_currentSegment;
-    ASSERT(segment.start &lt;= position &amp;&amp; position &lt; segment.end);
-    return m_style.preserveNewline &amp;&amp; segment.text[position - segment.start] == '\n';
</del><ins>+    if (isEnd(position))
+        return false;
+    return m_style.preserveNewline &amp;&amp; characterAt(position) == '\n';
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+inline bool TextFragmentIterator::isEnd(unsigned position) const
+{
+    return position &gt;= m_flowContents.length();
</ins><span class="cx"> }
</span><ins>+
</ins><span class="cx"> }
</span><ins>+}
</ins><span class="cx"> 
</span><span class="cx"> #endif
</span></span></pre>
</div>
</div>

</body>
</html>