Title: [109272] branches/chromium/1025
Revision
109272
Author
rn...@webkit.org
Date
2012-02-29 15:08:25 -0800 (Wed, 29 Feb 2012)

Log Message

Merge 108668 - REGRESSION(r99076): WebKit pastes the trailing newline into a single-line text field
https://bugs.webkit.org/show_bug.cgi?id=79305

Reviewed by Tony Chang.

Source/WebCore: 

The bug was caused by ReplacementFragment::m_hasInterchangeNewlineAtEnd not reset even when
text field's beforeTextInserted event handler removed interchange new lines at the end.
Because the event handler is responsible for trimming new lines, we need to recompute the values
for m_hasInterchangeNewlineAt* after the event dispatch.

Test: editing/input/paste-text-ending-with-interchange-newline.html

* editing/ReplaceSelectionCommand.cpp:
(WebCore::ReplacementFragment::ReplacementFragment):

LayoutTests: 

Add a regression test. Also make Markup.dump() dump the shadow DOM of the specififed node.

* editing/input/paste-text-ending-with-interchange-newline-expected.txt: Added.
* editing/input/paste-text-ending-with-interchange-newline.html: Added.
* resources/dump-as-markup.js:
(Markup._get):
(Markup._getShadowHostIfPossible):
Review URL: https://chromiumcodereview.appspot.com/9555006

Modified Paths

Added Paths

Diff

Copied: branches/chromium/1025/LayoutTests/editing/input/paste-text-ending-with-interchange-newline-expected.txt (from rev 108668, trunk/LayoutTests/editing/input/paste-text-ending-with-interchange-newline-expected.txt) (0 => 109272)


--- branches/chromium/1025/LayoutTests/editing/input/paste-text-ending-with-interchange-newline-expected.txt	                        (rev 0)
+++ branches/chromium/1025/LayoutTests/editing/input/paste-text-ending-with-interchange-newline-expected.txt	2012-02-29 23:08:25 UTC (rev 109272)
@@ -0,0 +1,4 @@
+This tests pasting a text with an interchange new line at the end. WebKit shouldn't insert a new line.
+|   <shadow:root>
+|     <div>
+|       "abc def "

Copied: branches/chromium/1025/LayoutTests/editing/input/paste-text-ending-with-interchange-newline.html (from rev 108668, trunk/LayoutTests/editing/input/paste-text-ending-with-interchange-newline.html) (0 => 109272)


--- branches/chromium/1025/LayoutTests/editing/input/paste-text-ending-with-interchange-newline.html	                        (rev 0)
+++ branches/chromium/1025/LayoutTests/editing/input/paste-text-ending-with-interchange-newline.html	2012-02-29 23:08:25 UTC (rev 109272)
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<html>
+<body>
+<textarea>abc
+def
+</textarea>
+<input type="text">
+<script src=""
+<script>
+
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+document.querySelector('textarea').focus();
+document.execCommand('SelectAll', false, null);
+document.execCommand('Copy', false, null);
+
+var input = document.querySelector('input');
+input.focus();
+document.execCommand('Paste', false, null);
+
+Markup.description("This tests pasting a text with an interchange new line at the end. WebKit shouldn't insert a new line.");
+Markup.dump(input);
+
+</script>
+</body>
+</html>

Modified: branches/chromium/1025/LayoutTests/resources/dump-as-markup.js (109271 => 109272)


--- branches/chromium/1025/LayoutTests/resources/dump-as-markup.js	2012-02-29 23:03:19 UTC (rev 109271)
+++ branches/chromium/1025/LayoutTests/resources/dump-as-markup.js	2012-02-29 23:08:25 UTC (rev 109272)
@@ -126,14 +126,16 @@
 
 Markup.get = function(node)
 {
+    var markup = Markup._getShadowHostIfPossible(node, 0);
+    if (markup)
+        return markup.substring(1);
+
     if (!node.firstChild)
         return '| ';
 
     // Don't print any markup for the root node.
-    var markup = '';
-    for (var i = 0, len = node.childNodes.length; i < len; i++) {
+    for (var i = 0, len = node.childNodes.length; i < len; i++)
         markup += Markup._get(node.childNodes[i], 0);
-    }
     return markup.substring(1);
 }
 
@@ -227,11 +229,7 @@
         str += Markup._get(node.childNodes[i], depth + 1);
     }
 
-    if (!Markup._useHTML5libOutputFormat && node.nodeType == Node.ELEMENT_NODE && window.internals) {
-        var root = window.internals.shadowRoot(node);
-        if (root)
-            str += Markup._get(root, depth + 1);
-    }
+    str += Markup._getShadowHostIfPossible(node, depth);
     
     var selection = Markup._getSelectionMarker(node, i);
     if (selection)
@@ -240,6 +238,16 @@
     return str;
 }
 
+Markup._getShadowHostIfPossible = function (node, depth)
+{
+    if (!Markup._useHTML5libOutputFormat && node.nodeType == Node.ELEMENT_NODE && window.internals) {
+        var root = window.internals.shadowRoot(node);
+        if (root)
+            return Markup._get(root, depth + 1);
+    }
+    return '';
+}
+
 Markup._namespace = function(node)
 {
     if (Markup._NAMESPACE_URI_MAP[node.namespaceURI])

Modified: branches/chromium/1025/Source/WebCore/editing/ReplaceSelectionCommand.cpp (109271 => 109272)


--- branches/chromium/1025/Source/WebCore/editing/ReplaceSelectionCommand.cpp	2012-02-29 23:03:19 UTC (rev 109271)
+++ branches/chromium/1025/Source/WebCore/editing/ReplaceSelectionCommand.cpp	2012-02-29 23:08:25 UTC (rev 109272)
@@ -293,6 +293,9 @@
 
 void ReplacementFragment::removeInterchangeNodes(Node* container)
 {
+    m_hasInterchangeNewlineAtStart = false;
+    m_hasInterchangeNewlineAtEnd = false;
+
     // Interchange newlines at the "start" of the incoming fragment must be
     // either the first node in the fragment or the first leaf in the fragment.
     Node* node = container->firstChild();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to