WebCore:
authorjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Oct 2007 23:38:41 +0000 (23:38 +0000)
committerjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Oct 2007 23:38:41 +0000 (23:38 +0000)
        Reviewed by Harrison.

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

        * editing/ReplaceSelectionCommand.cpp:
        (WebCore::ReplaceSelectionCommand::removeUnrenderedTextNodesAtEnds): Added.
        We would like to insert the fragment as-is if possible, but AppKit on Tiger
        creates fragments from RTF data that have carriage returns and spaces at the
        beginning and end, and those need to be removed since they'll interfere with
        paragraph merging.
        (WebCore::ReplaceSelectionCommand::doApply):
        * editing/ReplaceSelectionCommand.h:

LayoutTests:

        Reviewed by Harrison.

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

        Re-enabling this test:
        * editing/pasteboard/5483567.html: Added.
        * editing/pasteboard/5483567.html-disabled: Removed.
        Also demonstrates fix:
        * platform/mac/editing/pasteboard/paste-RTFD-expected.checksum:
        * platform/mac/editing/pasteboard/paste-RTFD-expected.png:
        * platform/mac/editing/pasteboard/paste-RTFD-expected.txt:

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

LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/5483567.html [new file with mode: 0644]
LayoutTests/platform/mac/editing/pasteboard/paste-RTFD-expected.checksum
LayoutTests/platform/mac/editing/pasteboard/paste-RTFD-expected.png
LayoutTests/platform/mac/editing/pasteboard/paste-RTFD-expected.txt
WebCore/ChangeLog
WebCore/editing/ReplaceSelectionCommand.cpp
WebCore/editing/ReplaceSelectionCommand.h

index 51dc2be..dffa35f 100644 (file)
@@ -1,5 +1,19 @@
 2007-10-11  Justin Garcia  <justin.garcia@apple.com>
 
+        Reviewed by Harrison.
+        
+        <rdar://problem/5483567> REGRESSION (Tiger only): Pasting words copied from TextEdit in Mail adds extra newline
+
+        Re-enabling this test:
+        * editing/pasteboard/5483567.html: Added.
+        * editing/pasteboard/5483567.html-disabled: Removed.
+        Also demonstrates fix:
+        * platform/mac/editing/pasteboard/paste-RTFD-expected.checksum:
+        * platform/mac/editing/pasteboard/paste-RTFD-expected.png:
+        * platform/mac/editing/pasteboard/paste-RTFD-expected.txt:
+
+2007-10-11  Justin Garcia  <justin.garcia@apple.com>
+
         Reviewed by Maciej.
         
         <rdar://problem/5521237> Pasting a word copied from TextEdit after a regular, breaking space, adds a leading newline
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 c427af3..3a66e19 100644 (file)
Binary files a/LayoutTests/platform/mac/editing/pasteboard/paste-RTFD-expected.png and b/LayoutTests/platform/mac/editing/pasteboard/paste-RTFD-expected.png differ
index a0b048f..b76a07e 100644 (file)
@@ -2,7 +2,7 @@ EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV > BODY > HTML
 EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: shouldInsertNode:#document-fragment replacingDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document givenAction:WebViewInsertActionPasted
-EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document toDOMRange:range from 0 of P > DIV > DIV > BODY > HTML > #document to 0 of P > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document toDOMRange:range from 0 of P > DIV > BODY > HTML > #document to 0 of P > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 layer at (0,0) size 800x600
@@ -10,27 +10,23 @@ layer 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 784x260 [border: (2px solid #FF0000)]
-        RenderBlock {DIV} at (14,14) size 756x0
-        RenderBlock {DIV} at (14,14) size 756x28
-          RenderBR {BR} at (0,0) size 0x28
-        RenderBlock {DIV} at (14,42) size 756x204
-          RenderBlock {P} at (0,0) size 756x14
-            RenderBR {BR} at (0,0) size 0x14
-          RenderBlock {P} at (0,14) size 756x14
-            RenderText {#text} at (0,0) size 86x14
-              text run at (0,0) width 86: "this is some text"
-          RenderBlock {P} at (0,28) size 756x14
-            RenderBR {BR} at (0,0) size 0x14
-          RenderBlock {P} at (0,42) size 756x120
-            RenderImage {IMG} at (0,0) size 180x120
-          RenderBlock {P} at (0,162) size 756x14
-            RenderBR {BR} at (0,0) size 0x14
-          RenderBlock {P} at (0,176) size 756x14
-            RenderText {#text} at (0,0) size 117x14
-              text run at (0,0) width 117: "this is some more text"
-          RenderBlock {P} at (0,190) size 756x14
-            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
+      RenderBlock {DIV} at (0,0) size 784x232 [border: (2px solid #FF0000)]
+        RenderBlock {P} at (14,14) size 756x14
+          RenderBR {BR} at (0,0) size 0x14
+        RenderBlock {P} at (14,28) size 756x14
+          RenderText {#text} at (0,0) size 86x14
+            text run at (0,0) width 86: "this is some text"
+        RenderBlock {P} at (14,42) size 756x14
+          RenderBR {BR} at (0,0) size 0x14
+        RenderBlock {P} at (14,56) size 756x120
+          RenderImage {IMG} at (0,0) size 180x120
+        RenderBlock {P} at (14,176) size 756x14
+          RenderBR {BR} at (0,0) size 0x14
+        RenderBlock {P} at (14,190) size 756x14
+          RenderText {#text} at (0,0) size 117x14
+            text run at (0,0) width 117: "this is some more text"
+        RenderBlock {P} at (14,204) size 756x14
+          RenderBR {BR} at (0,0) size 0x14
+        RenderBlock {DIV} at (14,218) size 756x0
+      RenderBlock {DIV} at (0,232) size 784x0
+caret: position 0 of child 0 {BR} of child 12 {P} of child 1 {DIV} of child 1 {BODY} of child 0 {HTML} of document
index dd22ea3..6474266 100644 (file)
@@ -1,3 +1,18 @@
+2007-10-11  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by Harrison.
+
+        <rdar://problem/5483567> REGRESSION (Tiger only): Pasting words copied from TextEdit in Mail adds extra newline
+        
+        * editing/ReplaceSelectionCommand.cpp:
+        (WebCore::ReplaceSelectionCommand::removeUnrenderedTextNodesAtEnds): Added.
+        We would like to insert the fragment as-is if possible, but AppKit on Tiger
+        creates fragments from RTF data that have carriage returns and spaces at the
+        beginning and end, and those need to be removed since they'll interfere with 
+        paragraph merging.
+        (WebCore::ReplaceSelectionCommand::doApply):
+        * editing/ReplaceSelectionCommand.h:
+
 2007-10-10  Justin Garcia  <justin.garcia@apple.com>
 
         Reviewed by Maciej.
index e4836b8..a49feef 100644 (file)
@@ -391,6 +391,28 @@ void ReplaceSelectionCommand::negateStyleRulesThatAffectAppearance()
     }
 }
 
+void ReplaceSelectionCommand::removeUnrenderedTextNodesAtEnds()
+{
+    document()->updateLayoutIgnorePendingStylesheets();
+    if (!m_lastLeafInserted->renderer() && 
+        m_lastLeafInserted->isTextNode() && 
+        !enclosingNodeWithTag(m_lastLeafInserted.get(), selectTag) && 
+        !enclosingNodeWithTag(m_lastLeafInserted.get(), scriptTag)) {
+        RefPtr<Node> previous = m_firstNodeInserted == m_lastLeafInserted ? 0 : m_lastLeafInserted->traversePreviousNode();
+        removeNode(m_lastLeafInserted.get());
+        m_lastLeafInserted = previous;
+    }
+    
+    // We don't have to make sure that m_firstNodeInserted isn't inside a select or script element, because
+    // it is a top level node in the fragment and the user can't insert into those elements.
+    if (!m_firstNodeInserted->renderer() && 
+        m_firstNodeInserted->isTextNode()) {
+        RefPtr<Node> next = m_firstNodeInserted == m_lastLeafInserted ? 0 : m_firstNodeInserted->traverseNextSibling();
+        removeNode(m_firstNodeInserted.get());
+        m_firstNodeInserted = next;
+    }
+}
+
 void ReplaceSelectionCommand::removeRedundantStyles(Node* mailBlockquoteEnclosingSelectionStart)
 {
     // There's usually a top level style span that holds the document's default style, push it down.
@@ -634,6 +656,8 @@ void ReplaceSelectionCommand::doApply()
         node = next;
     }
     
+    removeUnrenderedTextNodesAtEnds();
+    
     negateStyleRulesThatAffectAppearance();
     
     removeRedundantStyles(mailBlockquoteEnclosingSelectionStart);
index 71bda9d..679a90e 100644 (file)
@@ -89,6 +89,8 @@ private:
     bool shouldMergeEnd(bool);
     bool shouldMerge(const VisiblePosition&, const VisiblePosition&);
     
+    void removeUnrenderedTextNodesAtEnds();
+    
     void negateStyleRulesThatAffectAppearance();
     void removeRedundantStyles(Node*);