Reviewed by John
authorkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Dec 2004 18:01:01 +0000 (18:01 +0000)
committerkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Dec 2004 18:01:01 +0000 (18:01 +0000)
        Fix for this bug:

        <rdar://problem/3907422> REGRESSION (Mail): Pasting quoted content can place content after body element

        * khtml/editing/htmlediting.cpp:
        (khtml::ReplaceSelectionCommand::doApply): Detect when the body element is the "reference block" used
        for determining the location for inserting content. Do not allow an insert before or after if the
        reference block is the body. Perform insertNodeAt(0) and appendNode, respectively, in the block-is-body case.
        * layout-tests/editing/inserting/insert-3907422-fix-expected.txt: Added.
        * layout-tests/editing/inserting/insert-3907422-fix.html: Added.

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

LayoutTests/editing/inserting/insert-3907422-fix-expected.txt [new file with mode: 0644]
LayoutTests/editing/inserting/insert-3907422-fix.html [new file with mode: 0644]
WebCore/ChangeLog-2005-08-23
WebCore/khtml/editing/htmlediting.cpp

diff --git a/LayoutTests/editing/inserting/insert-3907422-fix-expected.txt b/LayoutTests/editing/inserting/insert-3907422-fix-expected.txt
new file mode 100644 (file)
index 0000000..f36f88f
--- /dev/null
@@ -0,0 +1,28 @@
+layer at (0,0) size 800x600
+  RenderCanvas 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 (anonymous) at (0,0) size 784x18
+        RenderText {TEXT} at (0,0) size 21x18
+          text run at (0,0) width 21: "foo"
+      RenderBlock {BLOCKQUOTE} at (40,34) size 704x18
+        RenderText {TEXT} at (0,0) size 20x18
+          text run at (0,0) width 20: "bar"
+      RenderBlock (anonymous) at (0,68) size 784x18
+        RenderText {TEXT} at (0,0) size 22x18
+          text run at (0,0) width 22: "baz"
+        RenderText {TEXT} at (22,0) size 21x18
+          text run at (22,0) width 21: "foo"
+      RenderBlock {BLOCKQUOTE} at (40,102) size 704x18
+        RenderText {TEXT} at (0,0) size 20x18
+          text run at (0,0) width 20: "bar"
+      RenderBlock (anonymous) at (0,136) size 784x18
+        RenderText {TEXT} at (0,0) size 22x18
+          text run at (0,0) width 22: "baz"
+        RenderText {TEXT} at (0,0) size 0x0
+        RenderText {TEXT} at (0,0) size 0x0
+selection is CARET:
+start:      position 3 of child 6 {TEXT} of root {BODY}
+upstream:   position 3 of child 6 {TEXT} of root {BODY}
+downstream: position 1 of child 8 {TEXT} of root {BODY}
diff --git a/LayoutTests/editing/inserting/insert-3907422-fix.html b/LayoutTests/editing/inserting/insert-3907422-fix.html
new file mode 100644 (file)
index 0000000..94fceee
--- /dev/null
@@ -0,0 +1,36 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    word-wrap: break-word; 
+    -khtml-nbsp-mode: space; 
+    -khtml-line-break: after-white-space;
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    selectAllCommand();
+    cutCommand();
+    pasteCommand();
+    pasteCommand();
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable id="root" class="editing">
+<div>foo<blockquote>bar</blockquote>baz</div>
+
+<!-- Buggy code before fix would insert blockquote after body element in second paste -->
+
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
index 8ef4f0e..34c0b6b 100644 (file)
@@ -1,3 +1,18 @@
+2004-12-07  Ken Kocienda  <kocienda@apple.com>
+
+        Reviewed by John
+
+        Fix for this bug:
+        
+        <rdar://problem/3907422> REGRESSION (Mail): Pasting quoted content can place content after body element
+
+        * khtml/editing/htmlediting.cpp:
+        (khtml::ReplaceSelectionCommand::doApply): Detect when the body element is the "reference block" used
+        for determining the location for inserting content. Do not allow an insert before or after if the
+        reference block is the body. Perform insertNodeAt(0) and appendNode, respectively, in the block-is-body case.
+        * layout-tests/editing/inserting/insert-3907422-fix-expected.txt: Added.
+        * layout-tests/editing/inserting/insert-3907422-fix.html: Added.
+
 2004-12-07  Darin Adler  <darin@apple.com>
 
         Reviewed by Don.
index 8a32b23..153fbcf 100644 (file)
@@ -3358,11 +3358,17 @@ void ReplaceSelectionCommand::doApply()
     if (node) {
         NodeImpl *refNode = node;
         NodeImpl *node = refNode ? refNode->nextSibling() : 0;
-        if (isProbablyBlock(refNode) && (insertBlocksBefore || startAtStartOfBlock)) {
-            insertNodeBefore(refNode, refBlock);
+        if (isProbablyBlock(refNode) && (insertBlocksBefore || startAtStartOfBlock) && !mergeStart) {
+            if (refBlock->id() == ID_BODY)
+                insertNodeAt(refNode, refBlock, 0);
+            else
+                insertNodeBefore(refNode, refBlock);
         }
-        else if (isProbablyBlock(refNode) && startAtEndOfBlock) {
-            insertNodeAfter(refNode, refBlock);
+        else if (isProbablyBlock(refNode) && startAtEndOfBlock && !mergeEnd) {
+            if (refBlock->id() == ID_BODY)
+                appendNode(refNode, refBlock);
+            else
+                insertNodeAfter(refNode, refBlock);
         }
         else {
             insertNodeAt(refNode, insertionPos.node(), insertionPos.offset());