WebCore:
authorjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Nov 2007 01:13:47 +0000 (01:13 +0000)
committerjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Nov 2007 01:13:47 +0000 (01:13 +0000)
        Reviewed by Dan Bernstein.

        <rdar://problem/5583387> ASSERTION FAILED: !refChild->hasTagName(bodyTag) when pasting newline in plain text into rich text Mail
        <rdar://problem/5583362> REGRESSION (5523.10.3-TOT): Newlines stripped when pasting plain text in Mail

        * editing/markup.cpp:
        (WebCore::createFragmentFromText): Put paragraphs of text into clones of the block
        that encloses the input context, unless that block is the body, which shouldn't
        be cloned.  In that case, use regular divs, as we did before r27369.

LayoutTests:

        Reviewed by Dan Bernstein.

        <rdar://problem/5583387> ASSERTION FAILED: !refChild->hasTagName(bodyTag) when pasting newline in plain text into rich text Mail
        <rdar://problem/5583362> REGRESSION (5523.10.3-TOT): Newlines stripped when pasting plain text in Mail

        * editing/pasteboard/5583362.html: Added.
        * editing/resources/plaintext-pasteboard-data.dat: Added.
        * platform/mac/editing/pasteboard/5583362-expected.checksum: Added.
        * platform/mac/editing/pasteboard/5583362-expected.png: Added.
        * platform/mac/editing/pasteboard/5583362-expected.txt: Added.

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

LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/5583362.html [new file with mode: 0644]
LayoutTests/editing/resources/plaintext-pasteboard-data.dat [new file with mode: 0644]
LayoutTests/platform/mac/editing/pasteboard/5583362-expected.checksum [new file with mode: 0644]
LayoutTests/platform/mac/editing/pasteboard/5583362-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/editing/pasteboard/5583362-expected.txt [new file with mode: 0644]
WebCore/ChangeLog
WebCore/editing/markup.cpp

index 1b45bc7e6f84a8d5a40d287c3ddd4400f102d288..34c91c842bb5ea1fc632e55b597fbf7fc615972c 100644 (file)
@@ -1,3 +1,16 @@
+2007-11-06  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by Dan Bernstein.
+
+        <rdar://problem/5583387> ASSERTION FAILED: !refChild->hasTagName(bodyTag) when pasting newline in plain text into rich text Mail
+        <rdar://problem/5583362> REGRESSION (5523.10.3-TOT): Newlines stripped when pasting plain text in Mail
+
+        * editing/pasteboard/5583362.html: Added.
+        * editing/resources/plaintext-pasteboard-data.dat: Added.
+        * platform/mac/editing/pasteboard/5583362-expected.checksum: Added.
+        * platform/mac/editing/pasteboard/5583362-expected.png: Added.
+        * platform/mac/editing/pasteboard/5583362-expected.txt: Added.
+
 2007-11-06  Antti Koivisto  <antti@apple.com>
 
         Correct test results.
diff --git a/LayoutTests/editing/pasteboard/5583362.html b/LayoutTests/editing/pasteboard/5583362.html
new file mode 100644 (file)
index 0000000..b70579c
--- /dev/null
@@ -0,0 +1,28 @@
+<html>
+<head>
+<script>
+function runTest() {
+    if (!window.objCPlugin)
+        return document.write('FAIL - no objCPlugin');
+        
+    objCPlugin.removeBridgeRestrictions_(window);
+    if (!window.objc)
+        return document.write('FAIL - no window.objc');
+    
+    var myURL = document.URL;    
+    var resourceURL = myURL.replace('pasteboard/5583362.html','resources/plaintext-pasteboard-data.dat');
+    var data = objc('NSData').dataWithContentsOfURL_(objc('NSURL').URLWithString_(resourceURL));
+    
+    var pasteboard = objc('NSPasteboard').generalPasteboard();
+    var pasteboardType = 'NSStringPboardType';
+    
+    pasteboard.declareType_owner_(pasteboardType, 0);
+    pasteboard.setData_forType_(data, pasteboardType);
+    
+    document.body.focus();
+    document.execCommand("Paste");
+}
+</script>
+</head>
+<body contenteditable="true"><script>runTest();</script></body>
+</html>
diff --git a/LayoutTests/editing/resources/plaintext-pasteboard-data.dat b/LayoutTests/editing/resources/plaintext-pasteboard-data.dat
new file mode 100644 (file)
index 0000000..77c2ca5
--- /dev/null
@@ -0,0 +1,2 @@
+Hello World.
+There should be two separate paragraphs here.
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/editing/pasteboard/5583362-expected.checksum b/LayoutTests/platform/mac/editing/pasteboard/5583362-expected.checksum
new file mode 100644 (file)
index 0000000..0c9fb88
--- /dev/null
@@ -0,0 +1 @@
+0e5c32ebc7729d58a36af540e315f0a6
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/editing/pasteboard/5583362-expected.png b/LayoutTests/platform/mac/editing/pasteboard/5583362-expected.png
new file mode 100644 (file)
index 0000000..e88bccc
Binary files /dev/null and b/LayoutTests/platform/mac/editing/pasteboard/5583362-expected.png differ
diff --git a/LayoutTests/platform/mac/editing/pasteboard/5583362-expected.txt b/LayoutTests/platform/mac/editing/pasteboard/5583362-expected.txt
new file mode 100644 (file)
index 0000000..bb06c24
--- /dev/null
@@ -0,0 +1,12 @@
+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 {DIV} at (0,0) size 784x18
+        RenderText {#text} at (0,0) size 83x18
+          text run at (0,0) width 83: "Hello World."
+      RenderBlock {DIV} at (0,18) size 784x18
+        RenderText {#text} at (0,0) size 293x18
+          text run at (0,0) width 293: "There should be two separate paragraphs here."
+caret: position 45 of child 0 {#text} of child 1 {DIV} of child 1 {BODY} of child 0 {HTML} of document
index 480f5624154685592f8a3a40ab828a0990ef2d5c..d972308f9c578a9f97d3e13370f9186241325b55 100644 (file)
@@ -1,3 +1,15 @@
+2007-11-06  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by Dan Bernstein.
+        
+        <rdar://problem/5583387> ASSERTION FAILED: !refChild->hasTagName(bodyTag) when pasting newline in plain text into rich text Mail
+        <rdar://problem/5583362> REGRESSION (5523.10.3-TOT): Newlines stripped when pasting plain text in Mail
+
+        * editing/markup.cpp:
+        (WebCore::createFragmentFromText): Put paragraphs of text into clones of the block
+        that encloses the input context, unless that block is the body, which shouldn't
+        be cloned.  In that case, use regular divs, as we did before r27369.
+
 2007-11-06  Christian Dywan  <christian@twotoasts.de>
 
         Reviewed by Darin.
index 6b42bc511a276661f134df956bb844a0859e3cbe..36c0392a21e132201527bf5768f0b669298e8a5a 100644 (file)
@@ -971,8 +971,6 @@ PassRefPtr<DocumentFragment> createFragmentFromText(Range* context, const String
 {
     if (!context)
         return 0;
-        
-    Node* block = enclosingBlock(context->startNode());
 
     Node* styleNode = context->startNode();
     if (!styleNode) {
@@ -1014,6 +1012,9 @@ PassRefPtr<DocumentFragment> createFragmentFromText(Range* context, const String
     }
 
     // Break string into paragraphs. Extra line breaks turn into empty paragraphs.
+    Node* block = enclosingBlock(context->startNode());
+    bool useClonesOfEnclosingBlock = !block->hasTagName(bodyTag);
+    
     DeprecatedStringList list = DeprecatedStringList::split('\n', string, true); // true gets us empty strings in the list
     while (!list.isEmpty()) {
         DeprecatedString s = list.first();
@@ -1026,7 +1027,7 @@ PassRefPtr<DocumentFragment> createFragmentFromText(Range* context, const String
             ASSERT(ec == 0);
             element->setAttribute(classAttr, AppleInterchangeNewline);            
         } else {
-            element = static_cast<Element *>(block->cloneNode(false).get());
+            element = useClonesOfEnclosingBlock ? static_cast<Element*>(block->cloneNode(false).get()) : createDefaultParagraphElement(document);
             fillContainerFromString(element.get(), s);
         }
         fragment->appendChild(element.release(), ec);