Title: [164047] trunk
Revision
164047
Author
[email protected]
Date
2014-02-13 12:45:35 -0800 (Thu, 13 Feb 2014)

Log Message

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 <[email protected]> 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 <[email protected]> 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.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (164046 => 164047)


--- trunk/LayoutTests/ChangeLog	2014-02-13 20:31:36 UTC (rev 164046)
+++ trunk/LayoutTests/ChangeLog	2014-02-13 20:45:35 UTC (rev 164047)
@@ -1,3 +1,16 @@
+2014-02-13  Chang Shu  <[email protected]>
+
+        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.
+
 2014-02-13  Myles C. Maxfield  <[email protected]>
 
         Gaps for text-decoration-skip: ink are calculated assuming the glyph orientation is the same as the run orientation

Added: trunk/LayoutTests/editing/pasteboard/copy-text-with-wrapped-tag-expected.txt (0 => 164047)


--- 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)
@@ -0,0 +1,13 @@
+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:
+| "Copy this text "
+| <a>
+|   href=""
+|   "AVeryLongWordThatWillWrap"
+
+Pasted:
+| "Copy this text "
+| <a>
+|   href=""
+|   "AVeryLongWordThatWillWrap<#selection-caret>"

Added: trunk/LayoutTests/editing/pasteboard/copy-text-with-wrapped-tag.html (0 => 164047)


--- 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)
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html>
+<body>
+<div id="description">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.</div>
+<div id="copy" style="width: 10em; border: thin solid green;">Copy this text <a href=""
+<div id="paste" contentEditable="true" style="border: thin solid blue;"></div>
+
+<script src=""
+<script>
+
+Markup.description(document.getElementById('description').textContent);
+Markup.dump('copy', 'Original');
+
+copy = document.getElementById("copy");
+window.getSelection().setBaseAndExtent(copy, 0, copy, copy.childNodes.length);
+document.execCommand("Copy");
+
+if (window.testRunner) {
+    paste = document.getElementById("paste");
+    window.getSelection().setPosition(paste, 0);
+    document.execCommand("Paste");
+
+    Markup.dump('paste', 'Pasted');
+}
+
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (164046 => 164047)


--- 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)
@@ -1,3 +1,25 @@
+2014-02-13  Chang Shu  <[email protected]>
+
+        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.
+
 2014-02-13  Myles C. Maxfield  <[email protected]>
 
         Gaps for text-decoration-skip: ink are calculated assuming the glyph orientation is the same as the run orientation

Modified: trunk/Source/WebCore/editing/TextIterator.cpp (164046 => 164047)


--- 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)
@@ -302,6 +302,7 @@
     , m_stopsOnFormControls(behavior & TextIteratorStopsOnFormControls)
     , m_shouldStop(false)
     , m_emitsImageAltText(behavior & TextIteratorEmitsImageAltText)
+    , m_hasNodesFollowing(behavior & TextIteratorBehavesAsIfNodesFollowing)
 {
     if (!r)
         return;
@@ -644,9 +645,12 @@
                 m_offset = runStart + 1;
             } else {
                 size_t subrunEnd = str.find('\n', runStart);
-                if (subrunEnd == notFound || subrunEnd > runEnd)
+                if (subrunEnd == notFound || subrunEnd > runEnd) {
                     subrunEnd = runEnd;
-    
+                    bool lastSpaceCollapsedByNextNonTextBox = !nextTextBox && m_hasNodesFollowing && (str.length() == runEnd + 1);
+                    if (lastSpaceCollapsedByNextNonTextBox)
+                        subrunEnd++; // runEnd stopped before last space. Increment by one to restore the space.
+                }
                 m_offset = subrunEnd;
                 emitText(m_node, renderer, runStart, subrunEnd);
             }

Modified: trunk/Source/WebCore/editing/TextIterator.h (164046 => 164047)


--- 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)
@@ -47,6 +47,7 @@
     TextIteratorEmitsOriginalText = 1 << 5,
     TextIteratorStopsOnFormControls = 1 << 6,
     TextIteratorEmitsImageAltText = 1 << 7,
+    TextIteratorBehavesAsIfNodesFollowing = 1 << 8,
 };
     
 // FIXME: Can't really answer this question correctly without knowing the white-space mode.
@@ -198,6 +199,7 @@
     bool m_shouldStop;
 
     bool m_emitsImageAltText;
+    bool m_hasNodesFollowing;
 };
 
 // Iterates through the DOM range, returning all the text, and 0-length boundaries

Modified: trunk/Source/WebCore/editing/markup.cpp (164046 => 164047)


--- 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)
@@ -266,14 +266,17 @@
     unsigned startOffset = 0;
     unsigned endOffset = textNode.length();
 
+    TextIteratorBehavior behavior = TextIteratorDefaultBehavior;
     if (range && &node == range->startContainer())
         startOffset = range->startOffset();
     if (range && &node == range->endContainer())
         endOffset = range->endOffset();
+    else if (range)
+        behavior = TextIteratorBehavesAsIfNodesFollowing;
 
     Position start = createLegacyEditingPosition(const_cast<Node*>(&node), startOffset);
     Position end = createLegacyEditingPosition(const_cast<Node*>(&node), endOffset);
-    return plainText(Range::create(node.document(), start, end).get());
+    return plainText(Range::create(node.document(), start, end).get(), behavior);
 }
 
 String StyledMarkupAccumulator::stringValueForRange(const Node& node, const Range* range)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to