WebCore:
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Oct 2008 00:58:00 +0000 (00:58 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Oct 2008 00:58:00 +0000 (00:58 +0000)
2008-10-12  Glenn Wilson  <gwilson@google.com>

        Reviewed by Darin Adler.

        - https://bugs.webkit.org/show_bug.cgi?id=20461

        Added feature to allow multi-line inputs into text fields.
        HTMLInputElement would cut the set text at the first 'system' character,
        so it would truncate at the first carriage return or newline.
        This fix modifies that behavior to truncate at any non-space system character
        but changes \r, \n, and \r\n to a single space.

        Tests: editing/pasteboard/paste-multiline-text-input.html

        * html/HTMLInputElement.cpp:
        (WebCore::HTMLInputElement::constrainValue):

LayoutTests:

2008-10-12  Glenn Wilson  <gwilson@google.com>

        Reviewed by Darin Adler.

        - https://bugs.webkit.org/show_bug.cgi?id=20461

        Added new test to verify that the user can cut and paste multiple lines of text
        into a single line text field.

        * fast/forms/paste-multiline-text-input-expected.txt: Added.
        * fast/forms/paste-multiline-text-input.html: Added.
        * fast/forms/input-truncate-newline-expected.txt: Removed.
        * fast/forms/input-truncate-newline.html: Removed.

        * fast/forms/8250-expected.txt: Added.
        * fast/forms/8250.html: Updated test to be text-only and expect new results.
        * platform/mac/fast/forms/8250-expected.checksum: Removed.
        * platform/mac/fast/forms/8250-expected.png: Removed.
        * platform/mac/fast/forms/8250-expected.txt: Removed.
        * platform/qt/fast/forms/8250-expected.txt: Removed.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@37539 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/forms/8250-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/8250.html
LayoutTests/fast/forms/input-truncate-newline-expected.txt [deleted file]
LayoutTests/fast/forms/input-truncate-newline.html [deleted file]
LayoutTests/fast/forms/paste-multiline-text-input-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/paste-multiline-text-input.html [new file with mode: 0644]
LayoutTests/platform/mac/fast/forms/8250-expected.checksum [deleted file]
LayoutTests/platform/mac/fast/forms/8250-expected.png [deleted file]
LayoutTests/platform/mac/fast/forms/8250-expected.txt [deleted file]
LayoutTests/platform/qt/fast/forms/8250-expected.txt [deleted file]
WebCore/ChangeLog
WebCore/html/HTMLInputElement.cpp

index 1fb3696..04fdf61 100644 (file)
@@ -1,3 +1,24 @@
+2008-10-12  Glenn Wilson  <gwilson@google.com>
+
+        Reviewed by Darin Adler.
+
+        - https://bugs.webkit.org/show_bug.cgi?id=20461
+
+        Added new test to verify that the user can cut and paste multiple lines of text
+        into a single line text field.
+
+        * fast/forms/paste-multiline-text-input-expected.txt: Added.
+        * fast/forms/paste-multiline-text-input.html: Added.
+        * fast/forms/input-truncate-newline-expected.txt: Removed.
+        * fast/forms/input-truncate-newline.html: Removed.
+
+        * fast/forms/8250-expected.txt: Added.
+        * fast/forms/8250.html: Updated test to be text-only and expect new results.
+        * platform/mac/fast/forms/8250-expected.checksum: Removed.
+        * platform/mac/fast/forms/8250-expected.png: Removed.
+        * platform/mac/fast/forms/8250-expected.txt: Removed.
+        * platform/qt/fast/forms/8250-expected.txt: Removed.
+
 2008-10-12  Dirk Schulze  <vbs85@gmx.de>
 
         Reviewed by Eric Seidel.
diff --git a/LayoutTests/fast/forms/8250-expected.txt b/LayoutTests/fast/forms/8250-expected.txt
new file mode 100644 (file)
index 0000000..b4af35d
--- /dev/null
@@ -0,0 +1,5 @@
+This is a test for bug 8250. The 'before text inserted' event handler wasn't being told about 'interchange newlines'. The text field should have a space in it, followed by the word 'foo'.
+
+TEST PASSED
+
+
index fc80bd3..db5acdc 100644 (file)
@@ -1,10 +1,25 @@
-<p>This is a test for 8250.  The khtmlBeforeTextInserted event handler wasn't being told about interchange newlines.  You shouldn't see anything in the text field.</p>
+<p>This is a test for <a href="https://bugs.webkit.org/show_bug.cgi?id=8250">bug 8250</a>.
+The 'before text inserted' event handler wasn't being told about 'interchange newlines'.
+The text field should have a space in it, followed by the word 'foo'.</p>
+
+<p id="test result">TEST DID NOT RUN</p>
+
 <input id="test" type="text">
 
 <script>
+
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
 var e = document.getElementById("test");
 e.focus();
 e.setSelectionRange(0, 0);
 
 document.execCommand("InsertHTML", false, "<br class='Apple-interchange-newline'>foo");
-</script>
\ No newline at end of file
+
+if (e.value === " foo")
+    document.getElementById("test result").innerText = "TEST PASSED";
+else
+    document.getElementById("test result").innerText = "TEST FAILED";
+
+</script>
diff --git a/LayoutTests/fast/forms/input-truncate-newline-expected.txt b/LayoutTests/fast/forms/input-truncate-newline-expected.txt
deleted file mode 100644 (file)
index 89407c4..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-This tests that when newlines are pasted into text fields, the text gets truncated properly. 
-
-
-Passed.
diff --git a/LayoutTests/fast/forms/input-truncate-newline.html b/LayoutTests/fast/forms/input-truncate-newline.html
deleted file mode 100644 (file)
index db13840..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-<html>
-<head>
-<script src=../../editing/editing.js language="JavaScript" type="text/JavaScript" ></script>
-<script>
-
-function test()
-{ 
-    var res = "";
-    if (window.layoutTestController) {
-        layoutTestController.dumpAsText();
-        layoutTestController.waitUntilDone();
-    }
-    
-    document.getElementById('dv').focus();
-    copyCommand();
-    document.getElementById('tf').focus();
-    pasteCommand();
-    
-    if (document.getElementById('tf').value == "Test") {
-        res+= "Passed.\n";
-    }
-    document.getElementById('dv').innerHTML = "";
-    document.getElementById('result').innerHTML = res;
-    if (window.layoutTestController) {
-        layoutTestController.notifyDone();
-    }
-}
-
-</script>
-</head>
-<body onload="test()">
-This tests that when newlines are pasted into text fields, the text gets truncated properly.
-<br><br>
-<input type="text" id="tf"></input>
-<div contenteditable id="dv">Test<br>Failed</div>
-<div id="result">
-</div>
-</body>
-</html>
diff --git a/LayoutTests/fast/forms/paste-multiline-text-input-expected.txt b/LayoutTests/fast/forms/paste-multiline-text-input-expected.txt
new file mode 100644 (file)
index 0000000..5d520b4
--- /dev/null
@@ -0,0 +1,8 @@
+Test: This test verifies that text inputs will accept multiple lines of pasted text. You should see two tests "PASS" below.
+
+
+Multi-line test:
+PASS
+Null char test:
+PASS
+
diff --git a/LayoutTests/fast/forms/paste-multiline-text-input.html b/LayoutTests/fast/forms/paste-multiline-text-input.html
new file mode 100644 (file)
index 0000000..283846b
--- /dev/null
@@ -0,0 +1,76 @@
+<html> 
+  <head> 
+    <script> 
+        if (window.layoutTestController)
+            window.layoutTestController.dumpAsText();
+
+        function getInput()
+        {
+            return document.getElementById('inputId');
+        }
+
+        var DEFAULT_LINE_1 = "line\t(1 of 2)\r\nline\t(2 of 2)";
+        var EXPECTED_LINE_1 = "line\t(1 of 2) line\t(2 of 2)";
+
+        var DEFAULT_LINE_2 = "null\0char";
+        var EXPECTED_LINE_2 = "null";
+
+        var TEST_NAME_1 = "Multi-line test";
+        var TEST_NAME_2 = "Null char test";
+
+        function testMultiline()
+        {
+          log(TEST_NAME_1 + ":");
+          testInputField(DEFAULT_LINE_1, EXPECTED_LINE_1);
+
+          log(TEST_NAME_2 + ":");
+          testInputField(DEFAULT_LINE_2, EXPECTED_LINE_2);
+        }
+        function testInputField(input_value, expected)
+        {
+            getInput().value = input_value;
+            var str = jsEscape(getInput().value);
+            if (str == jsEscape(expected))
+                log("PASS");
+            else
+                log("FAIL: " + str);
+        }
+
+        function log(str) {
+            var valueField = document.getElementById('console');
+            valueField.appendChild(document.createTextNode(str));
+            valueField.appendChild(document.createElement("br"));
+        }
+
+        function jsEscape(s)
+        {
+            // Partial
+            var replacements = [
+                ["\r", "\\r"],
+                ["\n", "\\n"],
+                ["\t", "\\t"],
+                ["\f", "\\f"],
+                ["\t", "\\t"],
+                ["\0", "\\0"]
+            ];
+            for (var i = 0; i < replacements.length; ++i) {
+                var r = replacements[i];
+                s = s.replace(r[0], r[1]);
+            }
+            return s;
+        }
+    </script>
+    <style>
+        .pass { color: green; } 
+        .fail { color: red; }
+        .code { font-family: monospace; }
+    </style> 
+  </head> 
+  <body onload="testMultiline()"> 
+    <h2>Test: This test verifies that text inputs will accept multiple lines of pasted text.  You should see two tests "PASS" below.</h2> 
+    <input id=inputId style="visibility: hidden;" size=60 /><br>
+    <span class=code id=console></span>
+  </body> 
+</html> 
diff --git a/LayoutTests/platform/mac/fast/forms/8250-expected.checksum b/LayoutTests/platform/mac/fast/forms/8250-expected.checksum
deleted file mode 100644 (file)
index f41281b..0000000
+++ /dev/null
@@ -1 +0,0 @@
-a8db36e2e478eb97154d4c28bbc66304
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/fast/forms/8250-expected.png b/LayoutTests/platform/mac/fast/forms/8250-expected.png
deleted file mode 100644 (file)
index 27e4ed7..0000000
Binary files a/LayoutTests/platform/mac/fast/forms/8250-expected.png and /dev/null differ
diff --git a/LayoutTests/platform/mac/fast/forms/8250-expected.txt b/LayoutTests/platform/mac/fast/forms/8250-expected.txt
deleted file mode 100644 (file)
index 3a63438..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-layer at (0,0) size 800x600
-  RenderView at (0,0) size 800x600
-layer at (0,0) size 800x600
-  RenderBlock {HTML} at (0,0) size 800x600
-    RenderBody {BODY} at (8,8) size 784x584
-      RenderBlock {P} at (0,0) size 784x36
-        RenderText {#text} at (0,0) size 743x36
-          text run at (0,0) width 144: "This is a test for 8250. "
-          text run at (144,0) width 571: "The khtmlBeforeTextInserted event handler wasn't being told about interchange newlines. "
-          text run at (715,0) width 28: "You"
-          text run at (0,18) width 242: "shouldn't see anything in the text field."
-      RenderBlock (anonymous) at (0,52) size 784x23
-        RenderTextControl {INPUT} at (2,2) size 148x19 [bgcolor=#FFFFFF] [border: (2px inset #000000)]
-        RenderText {#text} at (0,0) size 0x0
-layer at (13,65) size 142x13
-  RenderBlock {DIV} at (3,3) size 142x13
-caret: position 0 of child 0 {DIV} of child 2 {INPUT} of child 0 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/platform/qt/fast/forms/8250-expected.txt b/LayoutTests/platform/qt/fast/forms/8250-expected.txt
deleted file mode 100644 (file)
index 55d6e3c..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-layer at (0,0) size 800x600
-  RenderView at (0,0) size 800x600
-layer at (0,0) size 800x600
-  RenderBlock {HTML} at (0,0) size 800x600
-    RenderBody {BODY} at (8,8) size 784x584
-      RenderBlock {P} at (0,0) size 784x38
-        RenderText {#text} at (0,0) size 742x38
-          text run at (0,0) width 145: "This is a test for 8250. "
-          text run at (145,0) width 572: "The khtmlBeforeTextInserted event handler wasn't being told about interchange newlines. "
-          text run at (717,0) width 25: "You"
-          text run at (0,19) width 242: "shouldn't see anything in the text field."
-      RenderBlock (anonymous) at (0,52) size 784x29
-        RenderTextControl {INPUT} at (2,2) size 168x25 [border: (2px inset #000000)]
-        RenderText {#text} at (0,0) size 0x0
-layer at (13,65) size 162x19
-  RenderBlock {DIV} at (3,3) size 162x19
-caret: position 0 of child 0 {DIV} of child 2 {INPUT} of child 0 {BODY} of child 0 {HTML} of document
index dce9729..a6d5999 100644 (file)
@@ -1,3 +1,20 @@
+2008-10-12  Glenn Wilson  <gwilson@google.com>
+
+        Reviewed by Darin Adler.
+
+        - https://bugs.webkit.org/show_bug.cgi?id=20461
+
+        Added feature to allow multi-line inputs into text fields.
+        HTMLInputElement would cut the set text at the first 'system' character,
+        so it would truncate at the first carriage return or newline.
+        This fix modifies that behavior to truncate at any non-space system character
+        but changes \r, \n, and \r\n to a single space.
+
+        Tests: editing/pasteboard/paste-multiline-text-input.html
+               
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::constrainValue):
+
 2008-10-12  Dirk Schulze  <vbs85@gmx.de>
 
         Reviewed by Eric Seidel.
index 7a1bd6a..4963b83 100644 (file)
@@ -1576,8 +1576,12 @@ void HTMLInputElement::updatePlaceholderVisibility(bool placeholderValueChanged)
 
 String HTMLInputElement::constrainValue(const String& proposedValue, int maxLen) const
 {
+    String string = proposedValue;
     if (isTextField()) {
-        StringImpl* s = proposedValue.impl();
+        string.replace("\r\n", " ");
+        string.replace('\r', ' ');
+        string.replace('\n', ' ');
+        StringImpl* s = string.impl();
         int newLen = numCharactersInGraphemeClusters(s, maxLen);
         for (int i = 0; i < newLen; ++i) {
             const UChar current = (*s)[i];
@@ -1586,10 +1590,10 @@ String HTMLInputElement::constrainValue(const String& proposedValue, int maxLen)
                 break;
             }
         }
-        if (newLen < static_cast<int>(proposedValue.length()))
-            return proposedValue.substring(0, newLen);
+        if (newLen < static_cast<int>(string.length()))
+            return string.substring(0, newLen);
     }
-    return proposedValue;
+    return string;
 }
 
 void HTMLInputElement::addSearchResult()