Title: [108668] trunk
Revision
108668
Author
[email protected]
Date
2012-02-23 13:17:27 -0800 (Thu, 23 Feb 2012)

Log Message

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):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (108667 => 108668)


--- trunk/LayoutTests/ChangeLog	2012-02-23 21:15:16 UTC (rev 108667)
+++ trunk/LayoutTests/ChangeLog	2012-02-23 21:17:27 UTC (rev 108668)
@@ -1,3 +1,18 @@
+2012-02-22  Ryosuke Niwa  <[email protected]>
+
+        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.
+
+        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):
+
 2012-02-23  Csaba Osztrogonác  <[email protected]>
 
         [Qt] Unreviewed gardening.

Added: trunk/LayoutTests/editing/input/paste-text-ending-with-interchange-newline-expected.txt (0 => 108668)


--- trunk/LayoutTests/editing/input/paste-text-ending-with-interchange-newline-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/editing/input/paste-text-ending-with-interchange-newline-expected.txt	2012-02-23 21:17:27 UTC (rev 108668)
@@ -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 "

Added: trunk/LayoutTests/editing/input/paste-text-ending-with-interchange-newline.html (0 => 108668)


--- trunk/LayoutTests/editing/input/paste-text-ending-with-interchange-newline.html	                        (rev 0)
+++ trunk/LayoutTests/editing/input/paste-text-ending-with-interchange-newline.html	2012-02-23 21:17:27 UTC (rev 108668)
@@ -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: trunk/LayoutTests/resources/dump-as-markup.js (108667 => 108668)


--- trunk/LayoutTests/resources/dump-as-markup.js	2012-02-23 21:15:16 UTC (rev 108667)
+++ trunk/LayoutTests/resources/dump-as-markup.js	2012-02-23 21:17:27 UTC (rev 108668)
@@ -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);
 }
 
@@ -228,11 +230,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)
@@ -241,6 +239,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: trunk/Source/WebCore/ChangeLog (108667 => 108668)


--- trunk/Source/WebCore/ChangeLog	2012-02-23 21:15:16 UTC (rev 108667)
+++ trunk/Source/WebCore/ChangeLog	2012-02-23 21:17:27 UTC (rev 108668)
@@ -1,3 +1,20 @@
+2012-02-22  Ryosuke Niwa  <[email protected]>
+
+        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.
+
+        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):
+
 2012-02-23  Andreas Kling  <[email protected]>
 
         Make use of StylePropertySet::setProperty(propertyID, CSSValue).

Modified: trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp (108667 => 108668)


--- trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp	2012-02-23 21:15:16 UTC (rev 108667)
+++ trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp	2012-02-23 21:17:27 UTC (rev 108668)
@@ -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
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to