LayoutTests:
authorjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 Jan 2007 01:30:50 +0000 (01:30 +0000)
committerjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 Jan 2007 01:30:50 +0000 (01:30 +0000)
        Reviewed by darin

        <rdar://problem/4944770>
        editing/pasteboard/4641033 layout test is broken (12328)

        The fixes not only make this test pass, but also fix a bug that
        was reflected in the results checked in for this test.  The caret
        was in the wrong position:
        * editing/pasteboard/4641033-expected.checksum:
        * editing/pasteboard/4641033-expected.png:
        * editing/pasteboard/4641033-expected.txt:
        Added:
        * editing/pasteboard/4944770-1-expected.checksum: Added.
        * editing/pasteboard/4944770-1-expected.png: Added.
        * editing/pasteboard/4944770-1-expected.txt: Added.
        * editing/pasteboard/4944770-1.html: Added.
        * editing/pasteboard/4944770-2-expected.checksum: Added.
        * editing/pasteboard/4944770-2-expected.png: Added.
        * editing/pasteboard/4944770-2-expected.txt: Added.
        * editing/pasteboard/4944770-2.html: Added.
        * editing/pasteboard/4944770-expected.checksum: Added.
        * editing/pasteboard/4944770-expected.png: Added.
        * editing/pasteboard/4944770-expected.txt: Added.
        Equivalent render trees:
        * editing/execCommand/format-block-from-range-selection-expected.txt:
        * editing/pasteboard/drag-drop-modifies-page-expected.txt:
        Fixed:
        * editing/pasteboard/nested-blocks-with-text-area-expected.checksum:
        * editing/pasteboard/nested-blocks-with-text-area-expected.png:
        * editing/pasteboard/nested-blocks-with-text-area-expected.txt:
        * editing/pasteboard/nested-blocks-with-text-field-expected.checksum:
        * editing/pasteboard/nested-blocks-with-text-field-expected.png:
        * editing/pasteboard/nested-blocks-with-text-field-expected.txt:

WebCore:

        Reviewed by darin

        <rdar://problem/4944770>
        editing/pasteboard/4641033 layout test is broken (12328)

        This layout test failure demonstrates three bugs:
        Smart replace shouldn't be turned on, but is because a word
        selection granularity from the previous test isn't cleared.
        Smart replace shouldn't add any spaces because the paste is performed
        in an empty paragraph.
        Smart replace spaces are added to the text of options inside
        the select element instead of before/after the select element.

        This patch fixes the second two problems.  During a
        ReplaceSelectionCommand, the VisiblePosition for the end of
        the inserted content is the last position in the last leaf
        inserted.  This is a problem when the last leaf is inside a
        select element, since VP creation is inconsistent there.
        Second, smart spaces were inserted inside the last leaf, not
        at the endOfInsertedContent.

        * editing/ReplaceSelectionCommand.cpp:
        (WebCore::ReplaceSelectionCommand::shouldMergeStart): Renamed
        m_lastNodeInserted to m_lastLeafInserted.  Use the
        start/endOfInsertedContent getters.
        (WebCore::ReplaceSelectionCommand::shouldMergeEnd): Ditto.
        (WebCore::ReplaceSelectionCommand::removeNodePreservingChildren): Ditto.
        (WebCore::ReplaceSelectionCommand::removeRedundantStyles): Ditto.
        (WebCore::ReplaceSelectionCommand::positionAtEndOfInsertedContent): Added.
        Special case for when the last leaf inserted is inside a select
        element: return the VisiblePosition after the select element.
        (WebCore::ReplaceSelectionCommand::positionAtStartOfInsertedContent): Added.
        (WebCore::ReplaceSelectionCommand::doApply): Did renaming.  Used
        the start/endOfInsertedContent getters.  Insert smart replace spaces
        into the right nodes.
        (WebCore::ReplaceSelectionCommand::shouldRemoveEndBR): Renaming.
        (WebCore::ReplaceSelectionCommand::completeHTMLReplacement): Ditto.
        (WebCore::ReplaceSelectionCommand::updateNodesInserted): Ditto.
        * editing/ReplaceSelectionCommand.h:

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

26 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/execCommand/format-block-from-range-selection-expected.txt
LayoutTests/editing/pasteboard/4641033-expected.checksum
LayoutTests/editing/pasteboard/4641033-expected.png
LayoutTests/editing/pasteboard/4641033-expected.txt
LayoutTests/editing/pasteboard/4944770-1-expected.checksum [new file with mode: 0644]
LayoutTests/editing/pasteboard/4944770-1-expected.png [new file with mode: 0644]
LayoutTests/editing/pasteboard/4944770-1-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/4944770-1.html [new file with mode: 0644]
LayoutTests/editing/pasteboard/4944770-2-expected.checksum [new file with mode: 0644]
LayoutTests/editing/pasteboard/4944770-2-expected.png [new file with mode: 0644]
LayoutTests/editing/pasteboard/4944770-2-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/4944770-2.html [new file with mode: 0644]
LayoutTests/editing/pasteboard/4944770-expected.checksum [new file with mode: 0644]
LayoutTests/editing/pasteboard/4944770-expected.png [new file with mode: 0644]
LayoutTests/editing/pasteboard/4944770-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/drag-drop-modifies-page-expected.txt
LayoutTests/editing/pasteboard/nested-blocks-with-text-area-expected.checksum
LayoutTests/editing/pasteboard/nested-blocks-with-text-area-expected.png
LayoutTests/editing/pasteboard/nested-blocks-with-text-area-expected.txt
LayoutTests/editing/pasteboard/nested-blocks-with-text-field-expected.checksum
LayoutTests/editing/pasteboard/nested-blocks-with-text-field-expected.png
LayoutTests/editing/pasteboard/nested-blocks-with-text-field-expected.txt
WebCore/ChangeLog
WebCore/editing/ReplaceSelectionCommand.cpp
WebCore/editing/ReplaceSelectionCommand.h

index ea86298..70c08ad 100644 (file)
@@ -1,3 +1,39 @@
+2007-01-22  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by darin
+
+        <rdar://problem/4944770>
+        editing/pasteboard/4641033 layout test is broken (12328)
+
+        The fixes not only make this test pass, but also fix a bug that 
+        was reflected in the results checked in for this test.  The caret
+        was in the wrong position:
+        * editing/pasteboard/4641033-expected.checksum:
+        * editing/pasteboard/4641033-expected.png:
+        * editing/pasteboard/4641033-expected.txt:
+        Added:
+        * editing/pasteboard/4944770-1-expected.checksum: Added.
+        * editing/pasteboard/4944770-1-expected.png: Added.
+        * editing/pasteboard/4944770-1-expected.txt: Added.
+        * editing/pasteboard/4944770-1.html: Added.
+        * editing/pasteboard/4944770-2-expected.checksum: Added.
+        * editing/pasteboard/4944770-2-expected.png: Added.
+        * editing/pasteboard/4944770-2-expected.txt: Added.
+        * editing/pasteboard/4944770-2.html: Added.
+        * editing/pasteboard/4944770-expected.checksum: Added.
+        * editing/pasteboard/4944770-expected.png: Added.
+        * editing/pasteboard/4944770-expected.txt: Added.
+        Equivalent render trees:
+        * editing/execCommand/format-block-from-range-selection-expected.txt:
+        * editing/pasteboard/drag-drop-modifies-page-expected.txt:
+        Fixed:
+        * editing/pasteboard/nested-blocks-with-text-area-expected.checksum:
+        * editing/pasteboard/nested-blocks-with-text-area-expected.png:
+        * editing/pasteboard/nested-blocks-with-text-area-expected.txt:
+        * editing/pasteboard/nested-blocks-with-text-field-expected.checksum:
+        * editing/pasteboard/nested-blocks-with-text-field-expected.png:
+        * editing/pasteboard/nested-blocks-with-text-field-expected.txt:
+
 2007-01-22  Beth Dakin  <bdakin@apple.com>
 
         Reviewed by Darin.
index a0321a8..f044660 100644 (file)
@@ -37,8 +37,10 @@ layer at (0,0) size 800x600
               text run at (0,0) width 19: "raz"
           RenderBlock (anonymous) at (0,102) size 782x0
         RenderBlock {DL} at (1,153) size 782x18
-          RenderText {#text} at (0,0) size 24x18
-            text run at (0,0) width 24: "dar "
+          RenderText {#text} at (0,0) size 20x18
+            text run at (0,0) width 20: "dar"
+          RenderText {#text} at (20,0) size 4x18
+            text run at (20,0) width 4: " "
         RenderBlock (anonymous) at (1,187) size 782x0
         RenderBlock {DL} at (1,187) size 782x18
           RenderText {#text} at (0,0) size 20x18
index c304c8a..2cab8fa 100644 (file)
@@ -1 +1 @@
-0b5df9dee82211eee3dc09b171ac8e1e
\ No newline at end of file
+5675296d472f20e3cd206c66257490d1
\ No newline at end of file
index eab2153..f848d7d 100644 (file)
Binary files a/LayoutTests/editing/pasteboard/4641033-expected.png and b/LayoutTests/editing/pasteboard/4641033-expected.png differ
index 824d450..d73847a 100644 (file)
@@ -3,7 +3,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 1 of #text > DIV > BODY > HTML > #document to 1 of #text > 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 1 of SELECT > DIV > BODY > HTML > #document to 1 of SELECT > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 layer at (0,0) size 800x600
@@ -34,4 +34,4 @@ layer at (0,0) size 800x600
               text run at (0,0) width 7: "1"
         RenderText {#text} at (0,0) size 0x0
         RenderText {#text} at (0,0) size 0x0
-caret: position 1 of child 1 {#text} of child 2 {DIV} of child 1 {BODY} of child 0 {HTML} of document
+caret: position 1 of child 2 {SELECT} of child 2 {DIV} of child 1 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/editing/pasteboard/4944770-1-expected.checksum b/LayoutTests/editing/pasteboard/4944770-1-expected.checksum
new file mode 100644 (file)
index 0000000..735fe61
--- /dev/null
@@ -0,0 +1 @@
+6188a9d324b4ac253ba9888011184529
\ No newline at end of file
diff --git a/LayoutTests/editing/pasteboard/4944770-1-expected.png b/LayoutTests/editing/pasteboard/4944770-1-expected.png
new file mode 100644 (file)
index 0000000..4c9393d
Binary files /dev/null and b/LayoutTests/editing/pasteboard/4944770-1-expected.png differ
diff --git a/LayoutTests/editing/pasteboard/4944770-1-expected.txt b/LayoutTests/editing/pasteboard/4944770-1-expected.txt
new file mode 100644 (file)
index 0000000..c1521c5
--- /dev/null
@@ -0,0 +1,25 @@
+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 {P} at (0,0) size 784x36
+        RenderText {#text} at (0,0) size 744x36
+          text run at (0,0) width 408: "This tests smart paste of a fragment that ends in a select element. "
+          text run at (408,0) width 336: "There should be no spaces added because the paste is"
+          text run at (0,18) width 214: "performed in an empty paragraph."
+      RenderBlock {DIV} at (0,52) size 784x22
+        RenderText {#text} at (0,1) size 21x18
+          text run at (0,1) width 21: "foo"
+        RenderMenuList {SELECT} at (23,2) size 38x18 [bgcolor=#FFFFFF]
+          RenderBlock (anonymous) at (8,2) size 7x13
+            RenderText at (0,0) size 7x13
+              text run at (0,0) width 7: "1"
+      RenderBlock {DIV} at (0,74) size 784x22
+        RenderText {#text} at (0,1) size 21x18
+          text run at (0,1) width 21: "foo"
+        RenderMenuList {SELECT} at (23,2) size 38x18 [bgcolor=#FFFFFF]
+          RenderBlock (anonymous) at (8,2) size 7x13
+            RenderText at (0,0) size 7x13
+              text run at (0,0) width 7: "1"
+caret: position 3 of child 1 {SELECT} of child 4 {DIV} of child 0 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/editing/pasteboard/4944770-1.html b/LayoutTests/editing/pasteboard/4944770-1.html
new file mode 100644 (file)
index 0000000..ec711ea
--- /dev/null
@@ -0,0 +1,17 @@
+<p>This tests smart paste of a fragment that ends in a select element.  There should be no spaces added because the paste is performed in an empty paragraph.</p>
+<div contenteditable="true" id="copy">foo<select><option>1</option><option>2</option><option>3</option></select></div>
+<div contenteditable="true" id="paste"></div>
+
+<script>
+var copy = document.getElementById("copy");
+var paste = document.getElementById("paste");
+var sel = window.getSelection();
+
+sel.setPosition(copy, 0);
+sel.modify("extend", "forward", "word");
+sel.modify("extend", "forward", "word");
+document.execCommand("Copy");
+
+sel.setPosition(paste, 0);
+document.execCommand("Paste");
+</script>
diff --git a/LayoutTests/editing/pasteboard/4944770-2-expected.checksum b/LayoutTests/editing/pasteboard/4944770-2-expected.checksum
new file mode 100644 (file)
index 0000000..7089321
--- /dev/null
@@ -0,0 +1 @@
+cf71ee7b0fa4efc17ef98b8abd8c8336
\ No newline at end of file
diff --git a/LayoutTests/editing/pasteboard/4944770-2-expected.png b/LayoutTests/editing/pasteboard/4944770-2-expected.png
new file mode 100644 (file)
index 0000000..ce177a6
Binary files /dev/null and b/LayoutTests/editing/pasteboard/4944770-2-expected.png differ
diff --git a/LayoutTests/editing/pasteboard/4944770-2-expected.txt b/LayoutTests/editing/pasteboard/4944770-2-expected.txt
new file mode 100644 (file)
index 0000000..eb3efe8
--- /dev/null
@@ -0,0 +1,29 @@
+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 {P} at (0,0) size 784x36
+        RenderText {#text} at (0,0) size 776x36
+          text run at (0,0) width 408: "This tests smart paste of a fragment that ends in a select element. "
+          text run at (408,0) width 368: "There should be spaces added before and after the inserted"
+          text run at (0,18) width 50: "content."
+      RenderBlock {DIV} at (0,52) size 784x22
+        RenderMenuList {SELECT} at (2,2) size 38x18 [bgcolor=#FFFFFF]
+          RenderBlock (anonymous) at (8,2) size 7x13
+            RenderText at (0,0) size 7x13
+              text run at (0,0) width 7: "1"
+      RenderBlock {DIV} at (0,74) size 784x22
+        RenderText {#text} at (0,1) size 8x18
+          text run at (0,1) width 8: "x"
+        RenderText {#text} at (8,1) size 4x18
+          text run at (8,1) width 4: " "
+        RenderMenuList {SELECT} at (14,2) size 38x18 [bgcolor=#FFFFFF]
+          RenderBlock (anonymous) at (8,2) size 7x13
+            RenderText at (0,0) size 7x13
+              text run at (0,0) width 7: "1"
+        RenderText {#text} at (54,1) size 4x18
+          text run at (54,1) width 4: " "
+        RenderText {#text} at (58,1) size 8x18
+          text run at (58,1) width 8: "x"
+caret: position 1 of child 3 {#text} of child 4 {DIV} of child 0 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/editing/pasteboard/4944770-2.html b/LayoutTests/editing/pasteboard/4944770-2.html
new file mode 100644 (file)
index 0000000..bbb3ca2
--- /dev/null
@@ -0,0 +1,17 @@
+<p>This tests smart paste of a fragment that ends in a select element.  There should be spaces added before and after the inserted content.</p>
+<div contenteditable="true" id="copy"><select><option>1</option><option>2</option><option>3</option></select></div>
+<div contenteditable="true" id="paste">xx</div>
+
+<script>
+var copy = document.getElementById("copy");
+var paste = document.getElementById("paste");
+var sel = window.getSelection();
+
+sel.setPosition(copy, 0);
+sel.modify("extend", "forward", "word");
+document.execCommand("Copy");
+
+sel.setPosition(paste, 0);
+sel.modify("move", "forward", "character");
+document.execCommand("Paste");
+</script>
diff --git a/LayoutTests/editing/pasteboard/4944770-expected.checksum b/LayoutTests/editing/pasteboard/4944770-expected.checksum
new file mode 100644 (file)
index 0000000..6d837a4
--- /dev/null
@@ -0,0 +1 @@
+fb5e24646c6ac02f77f8dbfaf8d9e0cc
\ No newline at end of file
diff --git a/LayoutTests/editing/pasteboard/4944770-expected.png b/LayoutTests/editing/pasteboard/4944770-expected.png
new file mode 100644 (file)
index 0000000..cfdedf3
Binary files /dev/null and b/LayoutTests/editing/pasteboard/4944770-expected.png differ
diff --git a/LayoutTests/editing/pasteboard/4944770-expected.txt b/LayoutTests/editing/pasteboard/4944770-expected.txt
new file mode 100644 (file)
index 0000000..85b018f
--- /dev/null
@@ -0,0 +1,28 @@
+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 784x576
+      RenderBlock {P} at (0,0) size 784x36
+        RenderText {#text} at (0,0) size 769x36
+          text run at (0,0) width 741: "This tests dropping content into the unwanted space above a list items content when the content is wrapped in a span. "
+          text run at (741,0) width 28: "You"
+          text run at (0,18) width 234: "should see 'DragMe DropAboveMe'."
+      RenderBlock {DIV} at (0,52) size 784x58
+        RenderListItem {LI} at (0,0) size 784x40 [border: (1px solid #000000)]
+          RenderBlock (anonymous) at (1,1) size 782x18
+            RenderListMarker at (-1,0) size 7x18: bullet
+            RenderInline {SPAN} at (0,0) size 0x18
+          RenderBlock (anonymous) at (1,19) size 782x20
+            RenderBlock {DIV} at (0,0) size 782x20 [border: (1px solid #FF0000)]
+              RenderInline {SPAN} at (0,0) size 57x18
+                RenderInline {SPAN} at (0,0) size 57x18
+                  RenderText {#text} at (1,1) size 57x18
+                    text run at (1,1) width 57: "DragMe "
+              RenderText {#text} at (58,1) size 97x18
+                text run at (58,1) width 97: "DropAboveMe"
+          RenderBlock (anonymous) at (1,39) size 782x0
+            RenderInline {SPAN} at (0,0) size 0x0
+        RenderBlock {DIV} at (0,40) size 784x18
+          RenderBR {BR} at (0,0) size 0x18
+      RenderBlock {UL} at (0,126) size 784x0
index 55c0786..21be70a 100644 (file)
@@ -4,7 +4,7 @@ EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotificatio
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: shouldInsertNode:#document-fragment replacingDOMRange:range from 6 of #text > DIV > BODY > HTML > #document to 6 of #text > DIV > BODY > HTML > #document givenAction:WebViewInsertActionDropped
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
-EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of #text > DIV > BODY > HTML > #document to 5 of #text > SPAN > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of #text > SPAN > DIV > BODY > HTML > #document to 6 of #text > SPAN > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 layer at (0,0) size 800x600
@@ -18,10 +18,8 @@ layer at (0,0) size 800x600
       RenderBlock {DIV} at (0,34) size 784x18
         RenderText {#text} at (0,0) size 37x18
           text run at (0,0) width 37: "world"
-        RenderText {#text} at (37,0) size 4x18
-          text run at (37,0) width 4: " "
-        RenderInline {SPAN} at (0,0) size 31x18
-          RenderText {#text} at (41,0) size 31x18
-            text run at (41,0) width 31: "hello"
-selection start: position 0 of child 1 {#text} of child 3 {DIV} of child 1 {BODY} of child 0 {HTML} of document
-selection end:   position 5 of child 0 {#text} of child 2 {SPAN} of child 3 {DIV} of child 1 {BODY} of child 0 {HTML} of document
+        RenderInline {SPAN} at (0,0) size 35x18
+          RenderText {#text} at (37,0) size 35x18
+            text run at (37,0) width 35: " hello"
+selection start: position 0 of child 0 {#text} of child 1 {SPAN} of child 3 {DIV} of child 1 {BODY} of child 0 {HTML} of document
+selection end:   position 6 of child 0 {#text} of child 1 {SPAN} of child 3 {DIV} of child 1 {BODY} of child 0 {HTML} of document
index 4f14906..21f32e9 100644 (file)
Binary files a/LayoutTests/editing/pasteboard/nested-blocks-with-text-area-expected.png and b/LayoutTests/editing/pasteboard/nested-blocks-with-text-area-expected.png differ
index 8492c6e..6c4426d 100644 (file)
@@ -5,7 +5,7 @@ EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of BODY > HTML > #do
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
-EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 1 of #text > DIV > BODY > HTML > #document to 1 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 1 of #text > SPAN > DIV > DIV > BODY > HTML > #document to 1 of #text > SPAN > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 layer at (0,0) size 800x600
@@ -21,7 +21,7 @@ layer at (0,0) size 800x600
         RenderText {#text} at (29,0) size 725x36
           text run at (29,0) width 725: "This test checks that pasing in a combination of nested blocks where one starts with a text field doesn't crash or fail "
           text run at (359,18) width 65: "assertions."
-      RenderBlock {DIV} at (0,54) size 784x54
+      RenderBlock {DIV} at (0,54) size 784x36
         RenderBlock {DIV} at (0,0) size 784x36
           RenderTextControl {TEXTAREA} at (304,2) size 163x28 [bgcolor=#FFFFFF] [border: (1px solid #000000)]
           RenderText {#text} at (469,18) size 4x18
@@ -30,12 +30,9 @@ layer at (0,0) size 800x600
             RenderText {#text} at (473,18) size 8x18
               text run at (473,18) width 8: "x"
           RenderText {#text} at (0,0) size 0x0
-        RenderBlock (anonymous) at (0,36) size 784x18
-          RenderText {#text} at (390,0) size 4x18
-            text run at (390,0) width 4: " "
-      RenderBlock (anonymous) at (0,108) size 784x0
+      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 2 {#text} of child 4 {DIV} of child 1 {BODY} of child 0 {HTML} of document
+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
index 5bfe023..91755a8 100644 (file)
Binary files a/LayoutTests/editing/pasteboard/nested-blocks-with-text-field-expected.png and b/LayoutTests/editing/pasteboard/nested-blocks-with-text-field-expected.png differ
index 78b616a..90fe638 100644 (file)
@@ -5,7 +5,7 @@ EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of BODY > HTML > #do
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
-EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 1 of #text > DIV > BODY > HTML > #document to 1 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 1 of #text > SPAN > DIV > DIV > BODY > HTML > #document to 1 of #text > SPAN > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 layer at (0,0) size 800x600
@@ -21,7 +21,7 @@ layer at (0,0) size 800x600
         RenderText {#text} at (29,0) size 725x36
           text run at (29,0) width 725: "This test checks that pasing in a combination of nested blocks where one starts with a text field doesn't crash or fail "
           text run at (359,18) width 65: "assertions."
-      RenderBlock {DIV} at (0,54) size 784x41
+      RenderBlock {DIV} at (0,54) size 784x23
         RenderBlock {DIV} at (0,0) size 784x23
           RenderTextControl {INPUT} at (312,2) size 148x19 [bgcolor=#FFFFFF] [border: (2px inset #000000)]
           RenderText {#text} at (462,2) size 4x18
@@ -30,10 +30,7 @@ layer at (0,0) size 800x600
             RenderText {#text} at (466,2) size 8x18
               text run at (466,2) width 8: "x"
           RenderText {#text} at (0,0) size 0x0
-        RenderBlock (anonymous) at (0,23) size 784x18
-          RenderText {#text} at (390,0) size 4x18
-            text run at (390,0) width 4: " "
-      RenderBlock (anonymous) at (0,95) size 784x0
+      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 2 {#text} of child 4 {DIV} of child 1 {BODY} of child 0 {HTML} of document
+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
index 30d6c65..66f2a07 100644 (file)
@@ -1,3 +1,45 @@
+2007-01-22  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by darin
+        
+        <rdar://problem/4944770>
+        editing/pasteboard/4641033 layout test is broken (12328)
+        
+        This layout test failure demonstrates three bugs:
+        Smart replace shouldn't be turned on, but is because a word
+        selection granularity from the previous test isn't cleared.
+        Smart replace shouldn't add any spaces because the paste is performed
+        in an empty paragraph.
+        Smart replace spaces are added to the text of options inside
+        the select element instead of before/after the select element.
+        
+        This patch fixes the second two problems.  During a 
+        ReplaceSelectionCommand, the VisiblePosition for the end of 
+        the inserted content is the last position in the last leaf 
+        inserted.  This is a problem when the last leaf is inside a 
+        select element, since VP creation is inconsistent there.  
+        Second, smart spaces were inserted inside the last leaf, not
+        at the endOfInsertedContent.
+
+        * editing/ReplaceSelectionCommand.cpp:
+        (WebCore::ReplaceSelectionCommand::shouldMergeStart): Renamed 
+        m_lastNodeInserted to m_lastLeafInserted.  Use the 
+        start/endOfInsertedContent getters.
+        (WebCore::ReplaceSelectionCommand::shouldMergeEnd): Ditto.
+        (WebCore::ReplaceSelectionCommand::removeNodePreservingChildren): Ditto.
+        (WebCore::ReplaceSelectionCommand::removeRedundantStyles): Ditto.
+        (WebCore::ReplaceSelectionCommand::positionAtEndOfInsertedContent): Added.
+        Special case for when the last leaf inserted is inside a select 
+        element: return the VisiblePosition after the select element.
+        (WebCore::ReplaceSelectionCommand::positionAtStartOfInsertedContent): Added.
+        (WebCore::ReplaceSelectionCommand::doApply): Did renaming.  Used
+        the start/endOfInsertedContent getters.  Insert smart replace spaces
+        into the right nodes.
+        (WebCore::ReplaceSelectionCommand::shouldRemoveEndBR): Renaming.
+        (WebCore::ReplaceSelectionCommand::completeHTMLReplacement): Ditto.
+        (WebCore::ReplaceSelectionCommand::updateNodesInserted): Ditto.
+        * editing/ReplaceSelectionCommand.h:
+
 2007-01-22  Darin Adler  <darin@apple.com>
 
         Reviewed by Adam.
index 906083b..c1a2281 100644 (file)
@@ -287,7 +287,7 @@ ReplaceSelectionCommand::ReplaceSelectionCommand(Document* document, PassRefPtr<
 
 bool ReplaceSelectionCommand::shouldMergeStart(bool selectionStartWasStartOfParagraph, bool fragmentHasInterchangeNewlineAtStart)
 {
-    VisiblePosition startOfInsertedContent(Position(m_firstNodeInserted.get(), 0));
+    VisiblePosition startOfInsertedContent(positionAtStartOfInsertedContent());
     VisiblePosition prev = startOfInsertedContent.previous(true);
     if (prev.isNull())
         return false;
@@ -301,7 +301,7 @@ bool ReplaceSelectionCommand::shouldMergeStart(bool selectionStartWasStartOfPara
 
 bool ReplaceSelectionCommand::shouldMergeEnd(bool selectionEndWasEndOfParagraph)
 {
-    VisiblePosition endOfInsertedContent(Position(m_lastNodeInserted.get(), maxDeepOffset(m_lastNodeInserted.get())));
+    VisiblePosition endOfInsertedContent(positionAtEndOfInsertedContent());
     VisiblePosition next = endOfInsertedContent.next(true);
     if (next.isNull())
         return false;
@@ -322,8 +322,8 @@ void ReplaceSelectionCommand::removeNodePreservingChildren(Node* node)
 {
     if (m_firstNodeInserted == node)
         m_firstNodeInserted = node->traverseNextNode();
-    if (m_lastNodeInserted == node)
-        m_lastNodeInserted = node->lastChild() ? node->lastChild() : node->traverseNextSibling();
+    if (m_lastLeafInserted == node)
+        m_lastLeafInserted = node->lastChild() ? node->lastChild() : node->traverseNextSibling();
     CompositeEditCommand::removeNodePreservingChildren(node);
 }
 
@@ -400,7 +400,7 @@ void ReplaceSelectionCommand::removeRedundantStyles(Node* mailBlockquoteEnclosin
             parentStyle->diff(style.get());
             styles.append(style.release());
         }
-        if (node == m_lastNodeInserted)
+        if (node == m_lastLeafInserted)
             break;
     }
     
@@ -450,6 +450,20 @@ void ReplaceSelectionCommand::handlePasteAsQuotationNode()
         static_cast<Element*>(node)->setAttribute(classAttr, "");
 }
 
+VisiblePosition ReplaceSelectionCommand::positionAtEndOfInsertedContent()
+{
+    Node* lastNode = m_lastLeafInserted.get();
+    Node* enclosingSelect = enclosingNodeWithTag(lastNode, selectTag);
+    if (enclosingSelect)
+        lastNode = enclosingSelect;
+    return VisiblePosition(Position(lastNode, maxDeepOffset(lastNode)));
+}
+
+VisiblePosition ReplaceSelectionCommand::positionAtStartOfInsertedContent()
+{
+    return VisiblePosition(Position(m_firstNodeInserted.get(), 0));
+}
+
 void ReplaceSelectionCommand::doApply()
 {
     Selection selection = endingSelection();
@@ -589,8 +603,8 @@ void ReplaceSelectionCommand::doApply()
     
     removeRedundantStyles(mailBlockquoteEnclosingSelectionStart);
     
-    endOfInsertedContent = VisiblePosition(Position(m_lastNodeInserted.get(), maxDeepOffset(m_lastNodeInserted.get())));
-    startOfInsertedContent = VisiblePosition(Position(m_firstNodeInserted.get(), 0));
+    endOfInsertedContent = positionAtEndOfInsertedContent();
+    startOfInsertedContent = positionAtStartOfInsertedContent();
     
     // We inserted before the startBlock to prevent nesting, and the content before the startBlock wasn't in its own block and
     // didn't have a br after it, so the inserted content ended up in the same paragraph.
@@ -604,8 +618,8 @@ void ReplaceSelectionCommand::doApply()
     if (shouldRemoveEndBR(endBR)) {
         if (interchangeNewlineAtEnd) {
             interchangeNewlineAtEnd = false;
-            m_lastNodeInserted = endBR;
-            lastPositionToSelect = VisiblePosition(Position(m_lastNodeInserted.get(), 0)).deepEquivalent();
+            m_lastLeafInserted = endBR;
+            lastPositionToSelect = VisiblePosition(Position(m_lastLeafInserted.get(), 0)).deepEquivalent();
         } else
             removeNodeAndPruneAncestors(endBR);
     }
@@ -618,12 +632,12 @@ void ReplaceSelectionCommand::doApply()
         // only ever used to create positions where inserted content starts/ends.
         moveParagraph(startOfParagraphToMove, endOfParagraph(startOfParagraphToMove), destination);
         m_firstNodeInserted = endingSelection().visibleStart().deepEquivalent().downstream().node();
-        if (!m_lastNodeInserted->inDocument())
-            m_lastNodeInserted = endingSelection().visibleEnd().deepEquivalent().upstream().node();
+        if (!m_lastLeafInserted->inDocument())
+            m_lastLeafInserted = endingSelection().visibleEnd().deepEquivalent().upstream().node();
     }
             
-    endOfInsertedContent = VisiblePosition(Position(m_lastNodeInserted.get(), maxDeepOffset(m_lastNodeInserted.get())));
-    startOfInsertedContent = VisiblePosition(Position(m_firstNodeInserted.get(), 0));
+    endOfInsertedContent = positionAtEndOfInsertedContent();
+    startOfInsertedContent = positionAtStartOfInsertedContent();
     
     if (interchangeNewlineAtEnd) {
         VisiblePosition next = endOfInsertedContent.next(true);
@@ -642,13 +656,13 @@ void ReplaceSelectionCommand::doApply()
             lastPositionToSelect = next.deepEquivalent().downstream();
         }
 
-    } else if (m_lastNodeInserted->hasTagName(brTag)) {
+    } else if (m_lastLeafInserted->hasTagName(brTag)) {
         // We want to honor the last incoming line break, so, if it will collapse away because of quirks mode, 
         // add an extra one.
         // FIXME: This will expand a br inside a block: <div><br></div>
         // FIXME: Should we expand all incoming brs that collapse because of quirks mode?
         if (!document()->inStrictMode() && isEndOfBlock(endOfInsertedContent) && !isStartOfParagraph(endOfInsertedContent))
-            insertNodeBeforeAndUpdateNodesInserted(createBreakElement(document()).get(), m_lastNodeInserted.get());
+            insertNodeBeforeAndUpdateNodesInserted(createBreakElement(document()).get(), m_lastLeafInserted.get());
             
     } else if (shouldMergeEnd(selectionEndWasEndOfParagraph)) {
     
@@ -661,11 +675,11 @@ void ReplaceSelectionCommand::doApply()
         VisiblePosition startOfParagraphToMove = mergeForward ? startOfParagraph(endOfInsertedContent) : endOfInsertedContent.next();
 
         moveParagraph(startOfParagraphToMove, endOfParagraph(startOfParagraphToMove), destination);
-        // Merging forward will remove m_lastNodeInserted from the document.
+        // Merging forward will remove m_lastLeafInserted 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();
+            m_lastLeafInserted = destination.previous().deepEquivalent().node();
             if (!m_firstNodeInserted->inDocument())
                 m_firstNodeInserted = endingSelection().visibleStart().deepEquivalent().node();
         }
@@ -673,8 +687,8 @@ void ReplaceSelectionCommand::doApply()
     
     handlePasteAsQuotationNode();
     
-    endOfInsertedContent = VisiblePosition(Position(m_lastNodeInserted.get(), maxDeepOffset(m_lastNodeInserted.get())));
-    startOfInsertedContent = VisiblePosition(Position(m_firstNodeInserted.get(), 0));    
+    endOfInsertedContent = positionAtEndOfInsertedContent();
+    startOfInsertedContent = positionAtStartOfInsertedContent();
     
     // Add spaces for smart replace.
     if (m_smartReplace && currentRoot) {
@@ -687,30 +701,32 @@ void ReplaceSelectionCommand::doApply()
         bool needsTrailingSpace = !isEndOfParagraph(endOfInsertedContent) &&
                                   !frame->isCharacterSmartReplaceExempt(endOfInsertedContent.characterAfter(), false);
         if (needsTrailingSpace) {
-            RenderObject* renderer = m_lastNodeInserted->renderer();
+            RenderObject* renderer = m_lastLeafInserted->renderer();
             bool collapseWhiteSpace = !renderer || renderer->style()->collapseWhiteSpace();
-            if (m_lastNodeInserted->isTextNode()) {
-                Text* text = static_cast<Text*>(m_lastNodeInserted.get());
+            Node* endNode = positionAtEndOfInsertedContent().deepEquivalent().upstream().node();
+            if (endNode->isTextNode()) {
+                Text* text = static_cast<Text*>(endNode);
                 insertTextIntoNode(text, text->length(), collapseWhiteSpace ? nonBreakingSpaceString() : " ");
             } else {
                 RefPtr<Node> node = document()->createEditingTextNode(collapseWhiteSpace ? nonBreakingSpaceString() : " ");
-                insertNodeAfterAndUpdateNodesInserted(node.get(), m_lastNodeInserted.get());
+                insertNodeAfterAndUpdateNodesInserted(node.get(), endNode);
             }
         }
     
         bool needsLeadingSpace = !isStartOfParagraph(startOfInsertedContent) &&
                                  !frame->isCharacterSmartReplaceExempt(startOfInsertedContent.previous().characterAfter(), true);
         if (needsLeadingSpace) {
-            RenderObject* renderer = m_lastNodeInserted->renderer();
+            RenderObject* renderer = m_lastLeafInserted->renderer();
             bool collapseWhiteSpace = !renderer || renderer->style()->collapseWhiteSpace();
-            if (m_firstNodeInserted->isTextNode()) {
-                Text* text = static_cast<Text*>(m_firstNodeInserted.get());
+            Node* startNode = positionAtStartOfInsertedContent().deepEquivalent().downstream().node();
+            if (startNode->isTextNode()) {
+                Text* text = static_cast<Text*>(startNode);
                 insertTextIntoNode(text, 0, collapseWhiteSpace ? nonBreakingSpaceString() : " ");
             } else {
                 RefPtr<Node> node = document()->createEditingTextNode(collapseWhiteSpace ? nonBreakingSpaceString() : " ");
-                // Don't updateNodesInserted.  Doing so would set m_lastNodeInserted to be the node containing the 
-                // leading space, but m_lastNodeInserted is supposed to mark the end of pasted content.
-                insertNodeBefore(node.get(), m_firstNodeInserted.get());
+                // Don't updateNodesInserted.  Doing so would set m_lastLeafInserted to be the node containing the 
+                // leading space, but m_lastLeafInserted is supposed to mark the end of pasted content.
+                insertNodeBefore(node.get(), startNode);
                 // FIXME: Use positions to track the start/end of inserted content.
                 m_firstNodeInserted = node;
             }
@@ -732,7 +748,7 @@ bool ReplaceSelectionCommand::shouldRemoveEndBR(Node* endBR)
         !document()->inStrictMode() && isEndOfBlock(visiblePos) && !isStartOfParagraph(visiblePos) ||
         // A br that was originally holding a line open should be displaced by inserted content or turned into a line break.
         // 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) && !m_lastNodeInserted->hasTagName(brTag);
+        isStartOfParagraph(visiblePos) && isEndOfParagraph(visiblePos) && !m_lastLeafInserted->hasTagName(brTag);
 }
 
 void ReplaceSelectionCommand::completeHTMLReplacement(const Position &lastPositionToSelect)
@@ -740,13 +756,11 @@ void ReplaceSelectionCommand::completeHTMLReplacement(const Position &lastPositi
     Position start;
     Position end;
 
-    if (m_firstNodeInserted && m_firstNodeInserted->inDocument() && m_lastNodeInserted && m_lastNodeInserted->inDocument()) {
-        
-        Node* lastLeaf = m_lastNodeInserted->lastDescendant();
-        Node* firstLeaf = m_firstNodeInserted->firstDescendant();
+    // FIXME: This should never not be the case.
+    if (m_firstNodeInserted && m_firstNodeInserted->inDocument() && m_lastLeafInserted && m_lastLeafInserted->inDocument()) {
         
-        start = Position(firstLeaf, 0);
-        end = Position(lastLeaf, maxDeepOffset(lastLeaf));
+        start = positionAtStartOfInsertedContent().deepEquivalent();
+        end = positionAtEndOfInsertedContent().deepEquivalent();
         
         // FIXME (11475): Remove this and require that the creator of the fragment to use nbsps.
         rebalanceWhitespaceAt(start);
@@ -801,10 +815,10 @@ void ReplaceSelectionCommand::updateNodesInserted(Node *node)
     if (!m_firstNodeInserted)
         m_firstNodeInserted = node;
     
-    if (node == m_lastNodeInserted)
+    if (node == m_lastLeafInserted)
         return;
     
-    m_lastNodeInserted = node->lastDescendant();
+    m_lastLeafInserted = node->lastDescendant();
 }
 
 } // namespace WebCore
index 7313e8e..1974030 100644 (file)
@@ -94,9 +94,12 @@ private:
     void handlePasteAsQuotationNode();
     
     virtual void removeNodePreservingChildren(Node*);
+    
+    VisiblePosition positionAtStartOfInsertedContent();
+    VisiblePosition positionAtEndOfInsertedContent();
 
     RefPtr<Node> m_firstNodeInserted;
-    RefPtr<Node> m_lastNodeInserted;
+    RefPtr<Node> m_lastLeafInserted;
     RefPtr<CSSMutableStyleDeclaration> m_insertionStyle;
     bool m_selectReplacement;
     bool m_smartReplace;