WebCore:
authorjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 25 Sep 2007 08:57:03 +0000 (08:57 +0000)
committerjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 25 Sep 2007 08:57:03 +0000 (08:57 +0000)
        Reviewed by Darin.

        <rdar://problem/5483567>
        REGRESSION (Tiger only, workaround in AppKit on Leopard): Pasting words copied from TextEdit in Mail adds extra newline

        * editing/ReplaceSelectionCommand.cpp:
        (WebCore::ReplaceSelectionCommand::removeUnrenderedNodes): Added.
        (WebCore::ReplaceSelectionCommand::doApply): Call removeUnrenderedNodes
        to prevent unrendered spaces from interfering with paragraph merging.
        * editing/ReplaceSelectionCommand.h:

LayoutTests:

        Reviewed by Darin.

        <rdar://problem/5483567>
        REGRESSION (Tiger only, workaround in AppKit on Leopard): Pasting words copied from TextEdit in Mail adds extra newline

        Demonstrate fix:
        * editing/pasteboard/5483567.html: Added.
        * platform/mac/editing/pasteboard/5483567-expected.checksum: Added.
        * platform/mac/editing/pasteboard/5483567-expected.png: Added.
        * platform/mac/editing/pasteboard/5483567-expected.txt: Added.

        Unrendered nodes removed:
        * editing/pasteboard/nested-blocks-with-text-area-expected.txt:
        * editing/pasteboard/nested-blocks-with-text-field-expected.txt:
        * editing/pasteboard/paste-RTFD-expected.txt:

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

12 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/5483567.html [new file with mode: 0644]
LayoutTests/editing/pasteboard/nested-blocks-with-text-area-expected.txt
LayoutTests/editing/pasteboard/nested-blocks-with-text-field-expected.txt
LayoutTests/editing/pasteboard/paste-RTFD-expected.txt
LayoutTests/platform/mac/editing/pasteboard/5483567-expected.checksum [new file with mode: 0644]
LayoutTests/platform/mac/editing/pasteboard/5483567-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/editing/pasteboard/5483567-expected.txt [new file with mode: 0644]
WebCore/ChangeLog
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/editing/ReplaceSelectionCommand.cpp
WebCore/editing/ReplaceSelectionCommand.h

index 9cb51871f966d5dc49da1807709b4a2029a781de..d9455d42c777182f9270c20fa134ba8398d3f1f5 100644 (file)
@@ -1,3 +1,21 @@
+2007-09-25  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by Darin.
+        
+        <rdar://problem/5483567> 
+        REGRESSION (Tiger only, workaround in AppKit on Leopard): Pasting words copied from TextEdit in Mail adds extra newline
+        
+        Demonstrate fix:
+        * editing/pasteboard/5483567.html: Added.
+        * platform/mac/editing/pasteboard/5483567-expected.checksum: Added.
+        * platform/mac/editing/pasteboard/5483567-expected.png: Added.
+        * platform/mac/editing/pasteboard/5483567-expected.txt: Added.
+        
+        Unrendered nodes removed:
+        * editing/pasteboard/nested-blocks-with-text-area-expected.txt:
+        * editing/pasteboard/nested-blocks-with-text-field-expected.txt:
+        * editing/pasteboard/paste-RTFD-expected.txt:
+
 2007-09-24  Sam Weinig  <sam@webkit.org>
 
         Reviewed by Adam Roben.
diff --git a/LayoutTests/editing/pasteboard/5483567.html b/LayoutTests/editing/pasteboard/5483567.html
new file mode 100644 (file)
index 0000000..09fa00e
--- /dev/null
@@ -0,0 +1,7 @@
+<div id="div" contenteditable="true">xx</div>
+
+<script>
+text = document.getElementById("div").firstChild;
+window.getSelection().setPosition(text, 1);
+document.execCommand("InsertHTML", false, " <div>foo</div> ");
+</script>
\ No newline at end of file
index 6c4426db7cd274518a2fbc16db1759c95c093644..0edf7293fa7ce2341f95a9f4023658c6bf5c2f3c 100644 (file)
@@ -33,6 +33,4 @@ layer at (0,0) size 800x600
       RenderBlock (anonymous) at (0,90) size 784x0
 layer at (313,65) size 161x26
   RenderBlock {DIV} at (1,1) size 161x26
-    RenderText {#text} at (3,0) size 3x13
-      text run at (3,0) width 3: " "
-caret: position 1 of child 0 {#text} of child 3 {SPAN} of child 1 {DIV} of child 4 {DIV} of child 1 {BODY} of child 0 {HTML} of document
+caret: position 1 of child 0 {#text} of child 2 {SPAN} of child 0 {DIV} of child 3 {DIV} of child 1 {BODY} of child 0 {HTML} of document
index 90fe6384cd45c37ad9c45dd1b15bf0cf298e13bc..8f717575ba991f3cf77fa8bb864c4daa4ccc2b87 100644 (file)
@@ -33,4 +33,4 @@ layer at (0,0) size 800x600
       RenderBlock (anonymous) at (0,77) size 784x0
 layer at (323,67) size 142x13
   RenderBlock {DIV} at (3,3) size 142x13
-caret: position 1 of child 0 {#text} of child 3 {SPAN} of child 1 {DIV} of child 4 {DIV} of child 1 {BODY} of child 0 {HTML} of document
+caret: position 1 of child 0 {#text} of child 2 {SPAN} of child 0 {DIV} of child 3 {DIV} of child 1 {BODY} of child 0 {HTML} of document
index a0b048f57454e8441c7f47cf095b2a55e440354c..b6b043577b0d44d9f753aea64c2a2d1d4510bf7f 100644 (file)
@@ -33,4 +33,4 @@ layer at (0,0) size 800x600
             RenderBR {BR} at (0,0) size 0x14
           RenderBlock (anonymous) at (0,204) size 756x0
       RenderBlock {DIV} at (0,260) size 784x0
-caret: position 0 of child 0 {BR} of child 12 {P} of child 4 {DIV} of child 1 {DIV} of child 1 {BODY} of child 0 {HTML} of document
+caret: position 0 of child 0 {BR} of child 6 {P} of child 4 {DIV} of child 1 {DIV} of child 1 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/platform/mac/editing/pasteboard/5483567-expected.checksum b/LayoutTests/platform/mac/editing/pasteboard/5483567-expected.checksum
new file mode 100644 (file)
index 0000000..1963e0b
--- /dev/null
@@ -0,0 +1 @@
+24f895b0fdb8bbe61988189f6e6fe10b
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/editing/pasteboard/5483567-expected.png b/LayoutTests/platform/mac/editing/pasteboard/5483567-expected.png
new file mode 100644 (file)
index 0000000..d0458f5
Binary files /dev/null and b/LayoutTests/platform/mac/editing/pasteboard/5483567-expected.png differ
diff --git a/LayoutTests/platform/mac/editing/pasteboard/5483567-expected.txt b/LayoutTests/platform/mac/editing/pasteboard/5483567-expected.txt
new file mode 100644 (file)
index 0000000..bf99292
--- /dev/null
@@ -0,0 +1,13 @@
+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 8x18
+          text run at (0,0) width 8: "x"
+        RenderText {#text} at (8,0) size 21x18
+          text run at (8,0) width 21: "foo"
+        RenderText {#text} at (29,0) size 8x18
+          text run at (29,0) width 8: "x"
+caret: position 3 of child 1 {#text} of child 0 {DIV} of child 0 {BODY} of child 0 {HTML} of document
index c3514d8bd1d3d662eb121417721b1b510a86886d..54870949f8c83d0c23455a6d9af7160f6ac6f542 100644 (file)
@@ -1,3 +1,16 @@
+2007-09-25  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by Darin.
+
+        <rdar://problem/5483567> 
+        REGRESSION (Tiger only, workaround in AppKit on Leopard): Pasting words copied from TextEdit in Mail adds extra newline
+        
+        * editing/ReplaceSelectionCommand.cpp:
+        (WebCore::ReplaceSelectionCommand::removeUnrenderedNodes): Added.
+        (WebCore::ReplaceSelectionCommand::doApply): Call removeUnrenderedNodes
+        to prevent unrendered spaces from interfering with paragraph merging.
+        * editing/ReplaceSelectionCommand.h:
+
 2007-09-24  Steve Falkenburg  <sfalken@apple.com>
 
         Reviewed by Darin.
index 7b6d9c43b32cf75b6f6bc86b3c8f424e39bbdf0f..d713a993043badd00f46d33bda811d715267445b 100644 (file)
                0867D690FE84028FC02AAC07 /* Project object */ = {
                        isa = PBXProject;
                        buildConfigurationList = 149C284308902B11008A9EFC /* Build configuration list for PBXProject "WebCore" */;
-                       compatibilityVersion = "Xcode 2.4";
                        hasScannedForEncodings = 1;
                        knownRegions = (
                                English,
index e4836b87957ac8817b24f58239bf074a7a5c23f2..445ecb006501c8bc5243bd36cbcbae67c28ba47b 100644 (file)
@@ -464,6 +464,36 @@ void ReplaceSelectionCommand::removeRedundantStyles(Node* mailBlockquoteEnclosin
     }
 }
 
+// Removes unrendered nodes after insertion but before paragraph merging.  Fixed <rdar://problem/5483567>,
+// where unrendered whitespace before and after the incoming fragment would prevent paragraph merging.
+void ReplaceSelectionCommand::removeUnrenderedNodes()
+{
+    RefPtr<Node> next;
+    for (RefPtr<Node> node = m_firstNodeInserted; node; node = next) {
+        
+        next = node->traverseNextNode();
+        
+        if (node == m_lastLeafInserted)
+            next = 0;
+        
+        if (node->hasTagName(selectTag))
+            next = node->traverseNextSibling();
+        
+        if (node->renderer())
+            continue;
+            
+        RefPtr<Node> afterFirst = m_firstNodeInserted ? m_firstNodeInserted->traverseNextSibling() : 0;
+        RefPtr<Node> beforeLast = m_lastLeafInserted ? m_lastLeafInserted->traversePreviousNode() : 0;
+        
+        removeNode(node.get());
+        
+        if (m_lastLeafInserted && !m_lastLeafInserted->inDocument())
+            m_lastLeafInserted = beforeLast;
+        if (m_firstNodeInserted && !m_firstNodeInserted->inDocument())
+            m_firstNodeInserted = m_lastLeafInserted && m_lastLeafInserted->inDocument() ? afterFirst : 0;
+    }
+}
+
 void ReplaceSelectionCommand::handlePasteAsQuotationNode()
 {
     Node* node = m_firstNodeInserted.get();
@@ -638,6 +668,8 @@ void ReplaceSelectionCommand::doApply()
     
     removeRedundantStyles(mailBlockquoteEnclosingSelectionStart);
     
+    removeUnrenderedNodes();
+    
     if (!m_firstNodeInserted)
         return;
     
index 71bda9dee14f06e049686be121aa451ba9cf1025..ec0b18237cfa9dfd06a18a9c9dac1991751e4320 100644 (file)
@@ -91,6 +91,7 @@ private:
     
     void negateStyleRulesThatAffectAppearance();
     void removeRedundantStyles(Node*);
+    void removeUnrenderedNodes();
     
     void handlePasteAsQuotationNode();