LayoutTests:
authorjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 5 May 2006 01:43:26 +0000 (01:43 +0000)
committerjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 5 May 2006 01:43:26 +0000 (01:43 +0000)
        Reviewed by harrison

        Pasted content would end up inside the block that contained the end of
        the selection that was pasted into and not the block that contained
        the start of the selection that was pasted into:
        * editing/pasteboard/merge-end-5-expected.checksum: Added.
        * editing/pasteboard/merge-end-5-expected.png: Added.
        * editing/pasteboard/merge-end-5-expected.txt: Added.
        * editing/pasteboard/merge-end-5.html: Added.

        Inserting a paragraph separator was splitting and cloning the body element
        if the html element was editable:
        * editing/inserting/editable-html-element-expected.checksum: Added.
        * editing/inserting/editable-html-element-expected.png: Added.
        * editing/inserting/editable-html-element-expected.txt: Added.
        * editing/inserting/editable-html-element.html: Added.

        Since we now sometimes merge backward (from content already in the
        document to just inserted content) during the end merge, the node that
        contains the old caret is removed more often during paste.  The editing
        delegate notifications in these tests reflect this:
        * editing/pasteboard/paste-line-endings-007-expected.txt:
        * editing/pasteboard/paste-line-endings-008-expected.txt:
        * editing/pasteboard/paste-line-endings-009-expected.txt:

        Now demonstrates a bug where the html element is focused, but its contents
        aren't selected:
        * editing/selection/focus_editable_html-expected.checksum:
        * editing/selection/focus_editable_html-expected.png:
        * editing/selection/focus_editable_html-expected.txt:
        * editing/selection/focus_editable_html.html:

WebCore:

        Reviewed by harrison

        * dom/Node.cpp:
        (WebCore::Node::rootEditableElement):
        Restored code to stop at the body tag.  Editing shouldn't be allowed to
        happen outside the body, so it needs to be the editable root even if the
        html element is contentEditable.
        * editing/ReplaceSelectionCommand.cpp:
        (WebCore::ReplaceSelectionCommand::shouldMergeEnd):
        Now takes in more information so it can be "the decider".
        (WebCore::ReplaceSelectionCommand::doApply):
        Merging two paragraphs will destroy the moved one's block styles. Perform
        the end merge backward (from content already in the document to just inserted
        content) if moving forward would move the paragraph that contained the start of
        the selection being pasted into, since we always want to preserve that paragraph's
        block style.
        Moving backward in this case is also helpful because otherwise it would be
        difficult to remember the position where inserted content began (since merging
        would remove m_firstNodeInserted).  That position is needed in order to select
        the replacement and to add smart replace whitespace.
        (WebCore::ReplaceSelectionCommand::removeEndBRIfNeeded):
        If [br, 0] is at the end of a block, the br is not necessarily collapsed
        in quirks mode.  [br, 0] needs to also not be at the start of a block.

        * editing/ReplaceSelectionCommand.h:

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

20 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/inserting/editable-html-element-expected.checksum [new file with mode: 0644]
LayoutTests/editing/inserting/editable-html-element-expected.png [new file with mode: 0644]
LayoutTests/editing/inserting/editable-html-element-expected.txt [new file with mode: 0644]
LayoutTests/editing/inserting/editable-html-element.html [new file with mode: 0644]
LayoutTests/editing/pasteboard/merge-end-5-expected.checksum [new file with mode: 0644]
LayoutTests/editing/pasteboard/merge-end-5-expected.png [new file with mode: 0644]
LayoutTests/editing/pasteboard/merge-end-5-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/merge-end-5.html [new file with mode: 0644]
LayoutTests/editing/pasteboard/paste-line-endings-007-expected.txt
LayoutTests/editing/pasteboard/paste-line-endings-008-expected.txt
LayoutTests/editing/pasteboard/paste-line-endings-009-expected.txt
LayoutTests/editing/selection/focus_editable_html-expected.checksum
LayoutTests/editing/selection/focus_editable_html-expected.png
LayoutTests/editing/selection/focus_editable_html-expected.txt
LayoutTests/editing/selection/focus_editable_html.html
WebCore/ChangeLog
WebCore/dom/Node.cpp
WebCore/editing/ReplaceSelectionCommand.cpp
WebCore/editing/ReplaceSelectionCommand.h

index edd7bf3546d9be51e37a71a75a97cb651ba57fe0..08d3dea3a8d3f1b3b26cb456121104a8e60741e8 100644 (file)
@@ -1,3 +1,37 @@
+2006-05-04  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by harrison
+
+        Pasted content would end up inside the block that contained the end of 
+        the selection that was pasted into and not the block that contained 
+        the start of the selection that was pasted into:
+        * editing/pasteboard/merge-end-5-expected.checksum: Added.
+        * editing/pasteboard/merge-end-5-expected.png: Added.
+        * editing/pasteboard/merge-end-5-expected.txt: Added.
+        * editing/pasteboard/merge-end-5.html: Added.
+        
+        Inserting a paragraph separator was splitting and cloning the body element
+        if the html element was editable:
+        * editing/inserting/editable-html-element-expected.checksum: Added.
+        * editing/inserting/editable-html-element-expected.png: Added.
+        * editing/inserting/editable-html-element-expected.txt: Added.
+        * editing/inserting/editable-html-element.html: Added.
+        
+        Since we now sometimes merge backward (from content already in the 
+        document to just inserted content) during the end merge, the node that 
+        contains the old caret is removed more often during paste.  The editing 
+        delegate notifications in these tests reflect this:
+        * editing/pasteboard/paste-line-endings-007-expected.txt:
+        * editing/pasteboard/paste-line-endings-008-expected.txt:
+        * editing/pasteboard/paste-line-endings-009-expected.txt:
+        
+        Now demonstrates a bug where the html element is focused, but its contents
+        aren't selected:
+        * editing/selection/focus_editable_html-expected.checksum:
+        * editing/selection/focus_editable_html-expected.png:
+        * editing/selection/focus_editable_html-expected.txt:
+        * editing/selection/focus_editable_html.html:
+
 2006-05-04  Beth Dakin  <bdakin@apple.com>
 
         Reviewed by Hyatt.
diff --git a/LayoutTests/editing/inserting/editable-html-element-expected.checksum b/LayoutTests/editing/inserting/editable-html-element-expected.checksum
new file mode 100644 (file)
index 0000000..b193f53
--- /dev/null
@@ -0,0 +1 @@
+d53960e87b7f062db7c195bd7a7a7f9a
\ No newline at end of file
diff --git a/LayoutTests/editing/inserting/editable-html-element-expected.png b/LayoutTests/editing/inserting/editable-html-element-expected.png
new file mode 100644 (file)
index 0000000..33b07ec
Binary files /dev/null and b/LayoutTests/editing/inserting/editable-html-element-expected.png differ
diff --git a/LayoutTests/editing/inserting/editable-html-element-expected.txt b/LayoutTests/editing/inserting/editable-html-element-expected.txt
new file mode 100644 (file)
index 0000000..734786b
--- /dev/null
@@ -0,0 +1,27 @@
+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of HTML > #document to 2 of HTML > #document
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of BODY > HTML > #document to 0 of BODY > HTML > #document toDOMRange:range from 259 of #text > BODY > HTML > #document to 259 of #text > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 259 of #text > BODY > HTML > #document to 259 of #text > BODY > HTML > #document toDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+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 784x54
+        RenderText {#text} at (0,0) size 783x54
+          text run at (0,0) width 714: "This tests to make sure that when the enclosing block is the body element, and when the html element is editable, "
+          text run at (714,0) width 69: "inserting a "
+          text run at (0,18) width 755: "paragraph separator doesn't split the body (inserting a paragraph separator usually splits/clones the enclosing block flow "
+          text run at (0,36) width 58: "element)."
+      RenderBlock {DIV} at (0,54) size 784x18
+        RenderBR {BR} at (0,0) size 0x18
+caret: position 0 of child 0 {BR} of child 2 {DIV} of child 1 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/editing/inserting/editable-html-element.html b/LayoutTests/editing/inserting/editable-html-element.html
new file mode 100644 (file)
index 0000000..814971f
--- /dev/null
@@ -0,0 +1,17 @@
+<html contenteditable="true">
+<script>
+function runTest() {
+    var s = window.getSelection();
+    var e = document.getElementById("test");
+    
+    s.setPosition(e, 0);
+    document.execCommand("InsertText", false, "This tests to make sure that when the enclosing block is the body element, and when the html element is editable,  inserting a paragraph separator doesn't split the body (inserting a paragraph separator usually splits/clones the enclosing block flow element).");
+    s.setPosition(e, 0);
+    s.modify("move", "forward", "line");
+    s.modify("move", "forward", "line");
+    s.modify("move", "forward", "line");
+    document.execCommand("InsertParagraph"); 
+}
+</script>
+<body id="test" onLoad="runTest();"></body>
+</html>
\ No newline at end of file
diff --git a/LayoutTests/editing/pasteboard/merge-end-5-expected.checksum b/LayoutTests/editing/pasteboard/merge-end-5-expected.checksum
new file mode 100644 (file)
index 0000000..6d67c74
--- /dev/null
@@ -0,0 +1 @@
+139f3f0fa86488b5ad811ca6c2aedc1d
\ No newline at end of file
diff --git a/LayoutTests/editing/pasteboard/merge-end-5-expected.png b/LayoutTests/editing/pasteboard/merge-end-5-expected.png
new file mode 100644 (file)
index 0000000..7b022f9
Binary files /dev/null and b/LayoutTests/editing/pasteboard/merge-end-5-expected.png differ
diff --git a/LayoutTests/editing/pasteboard/merge-end-5-expected.txt b/LayoutTests/editing/pasteboard/merge-end-5-expected.txt
new file mode 100644 (file)
index 0000000..2c39de0
--- /dev/null
@@ -0,0 +1,28 @@
+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV > BODY > HTML > #document to 2 of DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 36 of #text > DIV > DIV > BODY > HTML > #document to 36 of #text > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+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 {P} at (0,0) size 784x36
+        RenderText {#text} at (0,0) size 779x36
+          text run at (0,0) width 779: "Pasting a paragraph or less into a selection that spans multiple blocks should insert content into the block containing the start"
+          text run at (0,18) width 99: "of the selection."
+      RenderBlock {DIV} at (0,52) size 784x20
+        RenderBlock {DIV} at (0,0) size 784x20 [border: (1px solid #FF0000)]
+          RenderText {#text} at (1,1) size 32x18
+            text run at (1,1) width 32: "This "
+          RenderText {#text} at (33,1) size 231x18
+            text run at (33,1) width 231: "text should have a red border around"
+          RenderText {#text} at (264,1) size 16x18
+            text run at (264,1) width 16: " it."
+caret: position 36 of child 1 {#text} of child 0 {DIV} of child 2 {DIV} of child 0 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/editing/pasteboard/merge-end-5.html b/LayoutTests/editing/pasteboard/merge-end-5.html
new file mode 100644 (file)
index 0000000..ec1522d
--- /dev/null
@@ -0,0 +1,16 @@
+<p>Pasting a paragraph or less into a selection that spans multiple blocks should insert content into the block containing the start of the selection.</p>
+<div id="test" contenteditable="true"><div style="border: 1px solid red;">This x</div><div style="border: 1px solid blue;">x it.</div></div>
+
+<script>
+var s = window.getSelection();
+var e = document.getElementById("test");
+
+s.setPosition(e, 0);
+
+s.modify("move", "forward", "word");
+s.modify("move", "forward", "character");
+s.modify("extend", "forward", "word");
+s.modify("extend", "forward", "word");
+
+document.execCommand("InsertHTML", false, "<div><div>text should have a red border around</div></div>");
+</script>
\ No newline at end of file
index 87b8e0246d5f33cbab69a380d063151ede5156b2..76d14a0ad79a9c1da0be07f86470b4bb55240a29 100644 (file)
@@ -12,7 +12,7 @@ EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotificatio
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: shouldInsertNode:#document-fragment replacingDOMRange:range from 9 of #text > DIV > DIV > BODY > HTML > #document to 1 of #text > DIV > DIV > DIV > BODY > HTML > #document givenAction:WebViewInsertActionPasted
-EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 9 of #text > DIV > DIV > BODY > HTML > #document to 1 of #text > DIV > DIV > DIV > BODY > HTML > #document toDOMRange:range from 1 of #text > DIV > DIV > DIV > BODY > HTML > #document to 1 of #text > DIV > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 1 of #text > DIV > DIV > DIV > BODY > HTML > #document to 1 of #text > DIV > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 layer at (0,0) size 800x600
index 419d2c127bb31a5f9fc8bb7bf10d74fb7a2b33a9..afbe05871408b94cff1c120d7a5f2e44fcd2f49b 100644 (file)
@@ -12,7 +12,7 @@ EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotificatio
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: shouldInsertNode:#document-fragment replacingDOMRange:range from 8 of #text > DIV > DIV > DIV > BODY > HTML > #document to 1 of #text > DIV > DIV > DIV > BODY > HTML > #document givenAction:WebViewInsertActionPasted
-EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 8 of #text > DIV > DIV > DIV > BODY > HTML > #document to 1 of #text > DIV > DIV > DIV > BODY > HTML > #document toDOMRange:range from 1 of #text > DIV > DIV > DIV > BODY > HTML > #document to 1 of #text > DIV > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 1 of #text > DIV > DIV > DIV > BODY > HTML > #document to 1 of #text > DIV > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 layer at (0,0) size 800x600
index 7dffc8739e79043369edac020f8d9e90056711b0..f746ca1eca9f02da77356ecbe1248decaa8d2298 100644 (file)
@@ -12,7 +12,7 @@ EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotificatio
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: shouldInsertNode:#document-fragment replacingDOMRange:range from 8 of #text > DIV > DIV > DIV > BODY > HTML > #document to 1 of #text > DIV > DIV > DIV > DIV > BODY > HTML > #document givenAction:WebViewInsertActionPasted
-EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 8 of #text > DIV > DIV > DIV > BODY > HTML > #document to 1 of #text > DIV > DIV > DIV > DIV > BODY > HTML > #document toDOMRange:range from 1 of #text > DIV > DIV > DIV > DIV > BODY > HTML > #document to 1 of #text > DIV > DIV > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 1 of #text > DIV > DIV > DIV > DIV > BODY > HTML > #document to 1 of #text > DIV > DIV > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 layer at (0,0) size 800x600
index b25b1dc7d3b3771786fe8b8c355dae4df88cfe73..f1f661179bae324f978c5da23d2f8d6120f61840 100644 (file)
@@ -1 +1 @@
-c3bcb36ef50d4a8e133ce53c9769bf25
\ No newline at end of file
+2b32e27839b60eda65fb9513e21e39be
\ No newline at end of file
index 8248ae241eb4759eba3a447cfa2a44541c0dbf37..b64607220ea9e97c24a645719b06ac17bea9e6cf 100644 (file)
Binary files a/LayoutTests/editing/selection/focus_editable_html-expected.png and b/LayoutTests/editing/selection/focus_editable_html-expected.png differ
index d8c2946d57e2014c6879640dedeeb35c6fdc0d4b..cbe1da4e8a2c065cdd5bd726307bef74d8e25dc5 100644 (file)
@@ -1,23 +1,26 @@
 EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of HTML > #document to 1 of HTML > #document
 EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
-EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 1 of #text > BODY > HTML > #document to 42 of #text > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of HTML > #document to 0 of HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
-layer at (0,0) size 2008x2070
+layer at (0,0) size 2008x2088
   RenderCanvas at (0,0) size 785x585
-layer at (0,0) size 2008x2070
-  RenderBlock {HTML} at (0,0) size 785x2070
-    RenderBody {BODY} at (8,8) size 769x2054
-      RenderBlock (anonymous) at (0,0) size 769x36
+layer at (0,0) size 2008x2088
+  RenderBlock {HTML} at (0,0) size 785x2088
+    RenderBody {BODY} at (8,8) size 769x2072
+      RenderBlock (anonymous) at (0,0) size 769x54
         RenderText {#text} at (0,0) size 583x18
           text run at (0,0) width 583: "This test makes sure that we don't scroll unnecessarily to reveal an editable HTML Element. "
         RenderBR {BR} at (583,14) size 0x0
         RenderText {#text} at (0,18) size 262x18
           text run at (0,18) width 262: "If the document doesn't scroll, test passes."
-      RenderBlock {DIV} at (0,36) size 2000x2000
-      RenderBlock (anonymous) at (0,2036) size 769x18
+        RenderBR {BR} at (262,32) size 0x0
+        RenderInline {B} at (0,0) size 528x18
+          RenderText {#text} at (0,36) size 528x18
+            text run at (0,36) width 528: "This demonstrates a bug: normally, focusing an element will select its contents."
+        RenderText {#text} at (0,0) size 0x0
+      RenderBlock {DIV} at (0,54) size 2000x2000
+      RenderBlock (anonymous) at (0,2054) size 769x18
         RenderText {#text} at (0,0) size 237x18
           text run at (0,0) width 237: "If the document scrolls here, test fails."
         RenderText {#text} at (0,0) size 0x0
-selection start: position 1 of child 0 {#text} of child 0 {BODY} of child 0 {HTML} of document
-selection end:   position 42 of child 4 {#text} of child 0 {BODY} of child 0 {HTML} of document
-scrolled to 0,8
+caret: position 0 of child 0 {HTML} of document
index c9cd712a74799258942166fe6b167b65cfef81cf..44c803f82b57f42142ea278622dae970c4631319 100644 (file)
@@ -1,7 +1,8 @@
 <html id="hElem" contenteditable=true>
 <body onload="document.getElementById('hElem').focus()">
 This test makes sure that we don't scroll unnecessarily to reveal an editable HTML Element.
-<br> If the document doesn't scroll, test passes.
+<br> If the document doesn't scroll, test passes.<br>
+<b>This demonstrates a bug: normally, focusing an element will select its contents.</b>
 <div style="width:2000px;height:2000px;"></div>
 If the document scrolls here, test fails.
 </body>
index 8183246bf48afeaf755e56fc40699c5fa4976947..6fd6183bb0ba25312d4cbbba4ad25d79c91bf3c2 100644 (file)
@@ -1,3 +1,31 @@
+2006-05-04  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by harrison
+
+        * dom/Node.cpp:
+        (WebCore::Node::rootEditableElement):
+        Restored code to stop at the body tag.  Editing shouldn't be allowed to 
+        happen outside the body, so it needs to be the editable root even if the 
+        html element is contentEditable.
+        * editing/ReplaceSelectionCommand.cpp:
+        (WebCore::ReplaceSelectionCommand::shouldMergeEnd):
+        Now takes in more information so it can be "the decider".
+        (WebCore::ReplaceSelectionCommand::doApply):
+        Merging two paragraphs will destroy the moved one's block styles. Perform 
+        the end merge backward (from content already in the document to just inserted
+        content) if moving forward would move the paragraph that contained the start of 
+        the selection being pasted into, since we always want to preserve that paragraph's 
+        block style.
+        Moving backward in this case is also helpful because otherwise it would be
+        difficult to remember the position where inserted content began (since merging
+        would remove m_firstNodeInserted).  That position is needed in order to select 
+        the replacement and to add smart replace whitespace.
+        (WebCore::ReplaceSelectionCommand::removeEndBRIfNeeded):
+        If [br, 0] is at the end of a block, the br is not necessarily collapsed
+        in quirks mode.  [br, 0] needs to also not be at the start of a block.
+         
+        * editing/ReplaceSelectionCommand.h:
+
 2006-05-04  Tim Omernick  <timo@apple.com>
 
         Reviewed by Darin.
index 2897a93f5d45d897a82ac4611affde69901023a1..e12660582a0efbfda81e4278eca3275863bb0c8c 100644 (file)
@@ -1044,9 +1044,12 @@ Element *Node::enclosingInlineElement() const
 Element* Node::rootEditableElement() const
 {
     Element* result = 0;
-    for (Node* n = const_cast<Node*>(this); n && n->isContentEditable(); n = n->parentNode())
+    for (Node* n = const_cast<Node*>(this); n && n->isContentEditable(); n = n->parentNode()) {
         if (n->isBlockFlow() && n->isElementNode())
             result = static_cast<Element*>(n);
+        if (n->hasTagName(bodyTag))
+            break;
+    }
     return result;
 }
 
index d0d75bcc167e7dc11bd0984df74e83cbd6f06dcc..d14644c7e1fcdd1943a3a3ebac0fd36d4b5360d4 100644 (file)
@@ -496,16 +496,17 @@ bool ReplaceSelectionCommand::shouldMergeStart(const ReplacementFragment& incomi
     return false;
 }
 
-bool ReplaceSelectionCommand::shouldMergeEnd(const ReplacementFragment& incomingFragment, const VisiblePosition& endOfInsertedContent, const VisiblePosition& destination)
+bool ReplaceSelectionCommand::shouldMergeEnd(const VisiblePosition& endOfInsertedContent, bool fragmentHadInterchangeNewlineAtEnd, bool selectionEndWasEndOfParagraph)
 {
     Node* endNode = endOfInsertedContent.deepEquivalent().node();
-    Node* destinationNode = destination.deepEquivalent().node();
+    Node* nextNode = endOfInsertedContent.next().deepEquivalent().node();
     // FIXME: Unify the naming scheme for these enclosing element getters.
-    return !incomingFragment.hasInterchangeNewlineAtEnd() && 
+    return !selectionEndWasEndOfParagraph &&
+           !fragmentHadInterchangeNewlineAtEnd && 
            isEndOfParagraph(endOfInsertedContent) && 
-           nearestMailBlockquote(endNode) == nearestMailBlockquote(destinationNode) &&
-           enclosingListChild(endNode) == enclosingListChild(destinationNode) &&
-           enclosingTableCell(endNode) == enclosingTableCell(destinationNode) &&
+           nearestMailBlockquote(endNode) == nearestMailBlockquote(nextNode) &&
+           enclosingListChild(endNode) == enclosingListChild(nextNode) &&
+           enclosingTableCell(endNode) == enclosingTableCell(nextNode) &&
            !endNode->hasTagName(hrTag);
 }
 
@@ -800,10 +801,22 @@ void ReplaceSelectionCommand::doApply()
     // Make sure that content after the end of the selection being pasted into is in the same paragraph as the 
     // last bit of content that was inserted.
     VisiblePosition endOfInsertedContent(Position(m_lastNodeInserted.get(), maxDeepOffset(m_lastNodeInserted.get())));
-    VisiblePosition destination = endOfInsertedContent.next();
-    if (!endWasEndOfParagraph && shouldMergeEnd(fragment, endOfInsertedContent, destination)) {
-        VisiblePosition startOfParagraphToMove = startOfParagraph(endOfInsertedContent);
-        moveParagraph(startOfParagraphToMove, endOfInsertedContent, destination);
+    VisiblePosition startOfInsertedContent(Position(m_firstNodeInserted.get(), 0));
+    if (shouldMergeEnd(endOfInsertedContent, fragment.hasInterchangeNewlineAtEnd(), endWasEndOfParagraph)) {
+        // Merging two paragraphs will destroy the moved one's block styles.  Always move forward to preserve
+        // the block style of the paragraph already in the document, unless the paragraph to move would include the
+        // what was the start of the selection that was pasted into.
+        bool mergeForward = !inSameParagraph(startOfInsertedContent, endOfInsertedContent);
+        
+        VisiblePosition destination = mergeForward ? endOfInsertedContent.next() : endOfInsertedContent;
+        VisiblePosition startOfParagraphToMove = mergeForward ? startOfParagraph(endOfInsertedContent) : endOfInsertedContent.next();
+
+        moveParagraph(startOfParagraphToMove, endOfParagraph(startOfParagraphToMove), destination);
+        // Merging forward will remove the last node inserted from the document.
+        // FIXME: Maintain positions for the start and end of inserted content instead of keeping nodes.  The nodes are
+        // only ever used to create positions where inserted content starts/ends.
+        if (mergeForward)
+            m_lastNodeInserted = destination.previous().deepEquivalent().node();
     }
     
     completeHTMLReplacement(lastPositionToSelect);
@@ -817,7 +830,7 @@ void ReplaceSelectionCommand::removeEndBRIfNeeded(Node* endBR)
     VisiblePosition visiblePos(Position(endBR, 0));
     
     if (// The br is collapsed away and so is unnecessary.
-        !document()->inStrictMode() && isEndOfBlock(visiblePos) ||
+        !document()->inStrictMode() && isEndOfBlock(visiblePos) && !isStartOfBlock(visiblePos) ||
         // A br that was originally holding a line open should be displaced by inserted content.
         // A br that was originally acting as a line break should still be acting as a line break, not as a placeholder.
         isStartOfParagraph(visiblePos) && isEndOfParagraph(visiblePos))
index 72966623ff245cf4ee34259ac2a5289937a1a0a0..aeb6b320819c2d7d7064b3aacd57d852d3f11792 100644 (file)
@@ -131,7 +131,7 @@ private:
     void removeEndBRIfNeeded(Node*);
     
     bool shouldMergeStart(const ReplacementFragment&, const Selection&);
-    bool shouldMergeEnd(const ReplacementFragment&, const VisiblePosition&, const VisiblePosition&);
+    bool shouldMergeEnd(const VisiblePosition&, bool, bool);
 
     RefPtr<Node> m_firstNodeInserted;
     RefPtr<Node> m_lastNodeInserted;