<!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>[164047] 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/164047">164047</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2014-02-13 12:45:35 -0800 (Thu, 13 Feb 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Copying (createMarkup) wrapping text results in space between wrapped lines stripped.
https://bugs.webkit.org/show_bug.cgi?id=63233

Source/WebCore:

The problem is StyledMarkupAccumulator uses renderedText and the space at
the end of the text has been stripped when the tag after the text was wrapped.

Patch by Chang Shu &lt;cshu@webkit.org&gt; on 2014-02-13
Reviewed by Ryosuke Niwa.

Test: editing/pasteboard/copy-text-with-wrapped-tag.html

* editing/TextIterator.cpp:
(WebCore::TextIterator::TextIterator):
(WebCore::TextIterator::handleTextBox):
* editing/TextIterator.h:
Check the special case when the iterator runs over a range that is followed by a non-text box.
In this case, the possible last space has been collapsed and needs to be restored.
* editing/markup.cpp:
(WebCore::StyledMarkupAccumulator::renderedText):
Check if the range is followed by more nodes and pass this information to the constructed TextIterator.

LayoutTests:

Patch by Chang Shu &lt;cshu@webkit.org&gt; on 2014-02-13
Reviewed by Ryosuke Niwa.

The problem is StyledMarkupAccumulator uses renderedText and the space at
the end of the text has been stripped when the tag after the text was wrapped.

* editing/pasteboard/copy-text-with-wrapped-tag-expected.txt: Added.
* editing/pasteboard/copy-text-with-wrapped-tag.html: Added.</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="#trunkSourceWebCoreeditingTextIteratorcpp">trunk/Source/WebCore/editing/TextIterator.cpp</a></li>
<li><a href="#trunkSourceWebCoreeditingTextIteratorh">trunk/Source/WebCore/editing/TextIterator.h</a></li>
<li><a href="#trunkSourceWebCoreeditingmarkupcpp">trunk/Source/WebCore/editing/markup.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestseditingpasteboardcopytextwithwrappedtagexpectedtxt">trunk/LayoutTests/editing/pasteboard/copy-text-with-wrapped-tag-expected.txt</a></li>
<li><a href="#trunkLayoutTestseditingpasteboardcopytextwithwrappedtaghtml">trunk/LayoutTests/editing/pasteboard/copy-text-with-wrapped-tag.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (164046 => 164047)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-02-13 20:31:36 UTC (rev 164046)
+++ trunk/LayoutTests/ChangeLog        2014-02-13 20:45:35 UTC (rev 164047)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2014-02-13  Chang Shu  &lt;cshu@webkit.org&gt;
+
+        Copying (createMarkup) wrapping text results in space between wrapped lines stripped.
+        https://bugs.webkit.org/show_bug.cgi?id=63233
+
+        Reviewed by Ryosuke Niwa.
+
+        The problem is StyledMarkupAccumulator uses renderedText and the space at
+        the end of the text has been stripped when the tag after the text was wrapped.
+
+        * editing/pasteboard/copy-text-with-wrapped-tag-expected.txt: Added.
+        * editing/pasteboard/copy-text-with-wrapped-tag.html: Added.
+
</ins><span class="cx"> 2014-02-13  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Gaps for text-decoration-skip: ink are calculated assuming the glyph orientation is the same as the run orientation
</span></span></pre></div>
<a id="trunkLayoutTestseditingpasteboardcopytextwithwrappedtagexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/editing/pasteboard/copy-text-with-wrapped-tag-expected.txt (0 => 164047)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/pasteboard/copy-text-with-wrapped-tag-expected.txt                                (rev 0)
+++ trunk/LayoutTests/editing/pasteboard/copy-text-with-wrapped-tag-expected.txt        2014-02-13 20:45:35 UTC (rev 164047)
</span><span class="lines">@@ -0,0 +1,13 @@
</span><ins>+This tests to make sure that copying and pasting a text followed by an anchor tag wrapped into 2nd line do not lose the space between text and tag in the destination.
+
+Original:
+| &quot;Copy this text &quot;
+| &lt;a&gt;
+|   href=&quot;http://www.google.com&quot;
+|   &quot;AVeryLongWordThatWillWrap&quot;
+
+Pasted:
+| &quot;Copy this text &quot;
+| &lt;a&gt;
+|   href=&quot;http://www.google.com&quot;
+|   &quot;AVeryLongWordThatWillWrap&lt;#selection-caret&gt;&quot;
</ins></span></pre></div>
<a id="trunkLayoutTestseditingpasteboardcopytextwithwrappedtaghtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/editing/pasteboard/copy-text-with-wrapped-tag.html (0 => 164047)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/pasteboard/copy-text-with-wrapped-tag.html                                (rev 0)
+++ trunk/LayoutTests/editing/pasteboard/copy-text-with-wrapped-tag.html        2014-02-13 20:45:35 UTC (rev 164047)
</span><span class="lines">@@ -0,0 +1,28 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;body&gt;
+&lt;div id=&quot;description&quot;&gt;This tests to make sure that copying and pasting a text followed by an anchor tag wrapped into 2nd line do not lose the space between text and tag in the destination.&lt;/div&gt;
+&lt;div id=&quot;copy&quot; style=&quot;width: 10em; border: thin solid green;&quot;&gt;Copy this text &lt;a href=&quot;http://www.google.com&quot;&gt;AVeryLongWordThatWillWrap&lt;/a&gt;&lt;/div&gt;
+&lt;div id=&quot;paste&quot; contentEditable=&quot;true&quot; style=&quot;border: thin solid blue;&quot;&gt;&lt;/div&gt;
+
+&lt;script src=&quot;../../resources/dump-as-markup.js&quot;&gt;&lt;/script&gt;
+&lt;script&gt;
+
+Markup.description(document.getElementById('description').textContent);
+Markup.dump('copy', 'Original');
+
+copy = document.getElementById(&quot;copy&quot;);
+window.getSelection().setBaseAndExtent(copy, 0, copy, copy.childNodes.length);
+document.execCommand(&quot;Copy&quot;);
+
+if (window.testRunner) {
+    paste = document.getElementById(&quot;paste&quot;);
+    window.getSelection().setPosition(paste, 0);
+    document.execCommand(&quot;Paste&quot;);
+
+    Markup.dump('paste', 'Pasted');
+}
+
+&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (164046 => 164047)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-02-13 20:31:36 UTC (rev 164046)
+++ trunk/Source/WebCore/ChangeLog        2014-02-13 20:45:35 UTC (rev 164047)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2014-02-13  Chang Shu  &lt;cshu@webkit.org&gt;
+
+        Copying (createMarkup) wrapping text results in space between wrapped lines stripped.
+        https://bugs.webkit.org/show_bug.cgi?id=63233
+
+        The problem is StyledMarkupAccumulator uses renderedText and the space at
+        the end of the text has been stripped when the tag after the text was wrapped.
+
+        Reviewed by Ryosuke Niwa.
+
+        Test: editing/pasteboard/copy-text-with-wrapped-tag.html
+
+        * editing/TextIterator.cpp:
+        (WebCore::TextIterator::TextIterator):
+        (WebCore::TextIterator::handleTextBox):
+        * editing/TextIterator.h:
+        Check the special case when the iterator runs over a range that is followed by a non-text box.
+        In this case, the possible last space has been collapsed and needs to be restored.
+        * editing/markup.cpp:
+        (WebCore::StyledMarkupAccumulator::renderedText):
+        Check if the range is followed by more nodes and pass this information to the constructed TextIterator.
+
</ins><span class="cx"> 2014-02-13  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Gaps for text-decoration-skip: ink are calculated assuming the glyph orientation is the same as the run orientation
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingTextIteratorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/TextIterator.cpp (164046 => 164047)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/TextIterator.cpp        2014-02-13 20:31:36 UTC (rev 164046)
+++ trunk/Source/WebCore/editing/TextIterator.cpp        2014-02-13 20:45:35 UTC (rev 164047)
</span><span class="lines">@@ -302,6 +302,7 @@
</span><span class="cx">     , m_stopsOnFormControls(behavior &amp; TextIteratorStopsOnFormControls)
</span><span class="cx">     , m_shouldStop(false)
</span><span class="cx">     , m_emitsImageAltText(behavior &amp; TextIteratorEmitsImageAltText)
</span><ins>+    , m_hasNodesFollowing(behavior &amp; TextIteratorBehavesAsIfNodesFollowing)
</ins><span class="cx"> {
</span><span class="cx">     if (!r)
</span><span class="cx">         return;
</span><span class="lines">@@ -644,9 +645,12 @@
</span><span class="cx">                 m_offset = runStart + 1;
</span><span class="cx">             } else {
</span><span class="cx">                 size_t subrunEnd = str.find('\n', runStart);
</span><del>-                if (subrunEnd == notFound || subrunEnd &gt; runEnd)
</del><ins>+                if (subrunEnd == notFound || subrunEnd &gt; runEnd) {
</ins><span class="cx">                     subrunEnd = runEnd;
</span><del>-    
</del><ins>+                    bool lastSpaceCollapsedByNextNonTextBox = !nextTextBox &amp;&amp; m_hasNodesFollowing &amp;&amp; (str.length() == runEnd + 1);
+                    if (lastSpaceCollapsedByNextNonTextBox)
+                        subrunEnd++; // runEnd stopped before last space. Increment by one to restore the space.
+                }
</ins><span class="cx">                 m_offset = subrunEnd;
</span><span class="cx">                 emitText(m_node, renderer, runStart, subrunEnd);
</span><span class="cx">             }
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingTextIteratorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/TextIterator.h (164046 => 164047)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/TextIterator.h        2014-02-13 20:31:36 UTC (rev 164046)
+++ trunk/Source/WebCore/editing/TextIterator.h        2014-02-13 20:45:35 UTC (rev 164047)
</span><span class="lines">@@ -47,6 +47,7 @@
</span><span class="cx">     TextIteratorEmitsOriginalText = 1 &lt;&lt; 5,
</span><span class="cx">     TextIteratorStopsOnFormControls = 1 &lt;&lt; 6,
</span><span class="cx">     TextIteratorEmitsImageAltText = 1 &lt;&lt; 7,
</span><ins>+    TextIteratorBehavesAsIfNodesFollowing = 1 &lt;&lt; 8,
</ins><span class="cx"> };
</span><span class="cx">     
</span><span class="cx"> // FIXME: Can't really answer this question correctly without knowing the white-space mode.
</span><span class="lines">@@ -198,6 +199,7 @@
</span><span class="cx">     bool m_shouldStop;
</span><span class="cx"> 
</span><span class="cx">     bool m_emitsImageAltText;
</span><ins>+    bool m_hasNodesFollowing;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> // Iterates through the DOM range, returning all the text, and 0-length boundaries
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingmarkupcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/markup.cpp (164046 => 164047)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/markup.cpp        2014-02-13 20:31:36 UTC (rev 164046)
+++ trunk/Source/WebCore/editing/markup.cpp        2014-02-13 20:45:35 UTC (rev 164047)
</span><span class="lines">@@ -266,14 +266,17 @@
</span><span class="cx">     unsigned startOffset = 0;
</span><span class="cx">     unsigned endOffset = textNode.length();
</span><span class="cx"> 
</span><ins>+    TextIteratorBehavior behavior = TextIteratorDefaultBehavior;
</ins><span class="cx">     if (range &amp;&amp; &amp;node == range-&gt;startContainer())
</span><span class="cx">         startOffset = range-&gt;startOffset();
</span><span class="cx">     if (range &amp;&amp; &amp;node == range-&gt;endContainer())
</span><span class="cx">         endOffset = range-&gt;endOffset();
</span><ins>+    else if (range)
+        behavior = TextIteratorBehavesAsIfNodesFollowing;
</ins><span class="cx"> 
</span><span class="cx">     Position start = createLegacyEditingPosition(const_cast&lt;Node*&gt;(&amp;node), startOffset);
</span><span class="cx">     Position end = createLegacyEditingPosition(const_cast&lt;Node*&gt;(&amp;node), endOffset);
</span><del>-    return plainText(Range::create(node.document(), start, end).get());
</del><ins>+    return plainText(Range::create(node.document(), start, end).get(), behavior);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> String StyledMarkupAccumulator::stringValueForRange(const Node&amp; node, const Range* range)
</span></span></pre>
</div>
</div>

</body>
</html>