LayoutTests:
authorjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Apr 2006 20:11:45 +0000 (20:11 +0000)
committerjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Apr 2006 20:11:45 +0000 (20:11 +0000)
        Reviewed by darin

        <http://bugzilla.opendarwin.org/show_bug.cgi?id=8624>
        Placeholders aren't always removed during paste
        <rdar://problem/4059807>
        Seed: Mail: pasting quoted content sometimes adds a phantom newline

        If a webkit-block-placeholder has been introduced by a bug in deletion,
        we shouldn't remove it during paste if it is now acting as a linebreak.
        * editing/pasteboard/bad-placeholder-expected.checksum: Added.
        * editing/pasteboard/bad-placeholder-expected.png: Added.
        * editing/pasteboard/bad-placeholder-expected.txt: Added.
        * editing/pasteboard/bad-placeholder.html: Added.
        Generic placeholder brs should be removed if they are displaced by pasted content.
        * editing/pasteboard/displaced-generic-placeholder-expected.checksum: Added.
        * editing/pasteboard/displaced-generic-placeholder-expected.png: Added.
        * editing/pasteboard/displaced-generic-placeholder-expected.txt: Added.
        * editing/pasteboard/displaced-generic-placeholder.html: Added.
        So should placeholder brs with our special class on them.
        * editing/pasteboard/displaced-placeholder-expected.checksum: Added.
        * editing/pasteboard/displaced-placeholder-expected.png: Added.
        * editing/pasteboard/displaced-placeholder-expected.txt: Added.
        * editing/pasteboard/displaced-placeholder.html: Added.
        Removed an unnecessary collapsed br.
        * editing/pasteboard/paste-text-010-expected.txt:
        Two fixes, an extra line was present after pasting with an interchange newline.
        * editing/pasteboard/paste-text-016-expected.checksum: Added.
        * editing/pasteboard/paste-text-016-expected.png: Added.
        * editing/pasteboard/paste-text-016-expected.txt: Added.
        * editing/pasteboard/paste-text-017-expected.checksum: Added.
        * editing/pasteboard/paste-text-017-expected.png: Added.
        * editing/pasteboard/paste-text-017-expected.txt: Added.
        The code that interprets the incoming br as a br in strict mode had a bug.
        * editing/pasteboard/quirks-mode-br-1-expected.checksum: Added.
        * editing/pasteboard/quirks-mode-br-1-expected.png: Added.
        * editing/pasteboard/quirks-mode-br-1-expected.txt: Added.
        * editing/pasteboard/quirks-mode-br-1.html: Added.
        The linePlaceholder removal was negating the work to interpret the last
        incoming br as a br in strict mode.
        * editing/pasteboard/quirks-mode-br-2-expected.checksum: Added.
        * editing/pasteboard/quirks-mode-br-2-expected.png: Added.
        * editing/pasteboard/quirks-mode-br-2-expected.txt: Added.
        * editing/pasteboard/quirks-mode-br-2.html: Added.
        Don't let collapsed brs become rendered as a result of the paste operation.
        * editing/pasteboard/unrendered-br-expected.checksum: Added.
        * editing/pasteboard/unrendered-br-expected.png: Added.
        * editing/pasteboard/unrendered-br-expected.txt: Added.
        * editing/pasteboard/unrendered-br.html: Added.

WebCore:

        Reviewed by darin

        <http://bugzilla.opendarwin.org/show_bug.cgi?id=8624>
        Placeholders aren't always removed during paste
        <rdar://problem/4059807>
        Seed: Mail: pasting quoted content sometimes adds a phantom newline

        * editing/CompositeEditCommand.cpp: Added a FIXME.
        * editing/ReplaceSelectionCommand.cpp:
        (WebCore::ReplaceSelectionCommand::doApply):
        Removed two no-op setEndingSelection calls.
        Store away a br at the position where we'll start inserting content in case the
        br a) is made unnecessary by the insertion (it's collapsed away) b) was acting
        as a placeholder and should therefore be displaced by inserted content or c) was
        acting as a line break and, as a result of the insertion, is now acting as a
        placeholder.
        Don't only store away brs that have the webkit-block-placeholder class on them.
        Any br that does any of the three things just mentioned should be removed.
        The linePlaceholder removal was run after the code that makes sure to interpret
        incoming brs strictly, and was negating that work in certain cases.

        (WebCore::ReplaceSelectionCommand::removeEndBRIfNeeded): Described above.
        * editing/ReplaceSelectionCommand.h:
        * editing/VisiblePosition.cpp:
        (WebCore::isEqualIgnoringAffinity):
        Added a workaround for 8622.  We want this function to return true even if one of
        the two visible positions has been incorrectly canonicalized.

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

37 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/bad-placeholder-expected.checksum [new file with mode: 0644]
LayoutTests/editing/pasteboard/bad-placeholder-expected.png [new file with mode: 0644]
LayoutTests/editing/pasteboard/bad-placeholder-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/bad-placeholder.html [new file with mode: 0644]
LayoutTests/editing/pasteboard/displaced-generic-placeholder-expected.checksum [new file with mode: 0644]
LayoutTests/editing/pasteboard/displaced-generic-placeholder-expected.png [new file with mode: 0644]
LayoutTests/editing/pasteboard/displaced-generic-placeholder-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/displaced-generic-placeholder.html [new file with mode: 0644]
LayoutTests/editing/pasteboard/displaced-placeholder-expected.checksum [new file with mode: 0644]
LayoutTests/editing/pasteboard/displaced-placeholder-expected.png [new file with mode: 0644]
LayoutTests/editing/pasteboard/displaced-placeholder-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/displaced-placeholder.html [new file with mode: 0644]
LayoutTests/editing/pasteboard/paste-text-010-expected.txt
LayoutTests/editing/pasteboard/paste-text-016-expected.checksum
LayoutTests/editing/pasteboard/paste-text-016-expected.png
LayoutTests/editing/pasteboard/paste-text-016-expected.txt
LayoutTests/editing/pasteboard/paste-text-017-expected.checksum
LayoutTests/editing/pasteboard/paste-text-017-expected.png
LayoutTests/editing/pasteboard/paste-text-017-expected.txt
LayoutTests/editing/pasteboard/quirks-mode-br-1-expected.checksum [new file with mode: 0644]
LayoutTests/editing/pasteboard/quirks-mode-br-1-expected.png [new file with mode: 0644]
LayoutTests/editing/pasteboard/quirks-mode-br-1-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/quirks-mode-br-1.html [new file with mode: 0644]
LayoutTests/editing/pasteboard/quirks-mode-br-2-expected.checksum [new file with mode: 0644]
LayoutTests/editing/pasteboard/quirks-mode-br-2-expected.png [new file with mode: 0644]
LayoutTests/editing/pasteboard/quirks-mode-br-2-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/quirks-mode-br-2.html [new file with mode: 0644]
LayoutTests/editing/pasteboard/unrendered-br-expected.checksum [new file with mode: 0644]
LayoutTests/editing/pasteboard/unrendered-br-expected.png [new file with mode: 0644]
LayoutTests/editing/pasteboard/unrendered-br-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/unrendered-br.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/editing/CompositeEditCommand.cpp
WebCore/editing/ReplaceSelectionCommand.cpp
WebCore/editing/ReplaceSelectionCommand.h
WebCore/editing/VisiblePosition.cpp

index 75ed029ce75a648572ea4aea20fb464adcc6b7ab..fce9263a956616a59d0111321a744436413d62ec 100644 (file)
@@ -1,3 +1,54 @@
+2006-04-27  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by darin
+        
+        <http://bugzilla.opendarwin.org/show_bug.cgi?id=8624>
+        Placeholders aren't always removed during paste
+        <rdar://problem/4059807>
+        Seed: Mail: pasting quoted content sometimes adds a phantom newline
+        
+        If a webkit-block-placeholder has been introduced by a bug in deletion,
+        we shouldn't remove it during paste if it is now acting as a linebreak.
+        * editing/pasteboard/bad-placeholder-expected.checksum: Added.
+        * editing/pasteboard/bad-placeholder-expected.png: Added.
+        * editing/pasteboard/bad-placeholder-expected.txt: Added.
+        * editing/pasteboard/bad-placeholder.html: Added.
+        Generic placeholder brs should be removed if they are displaced by pasted content.
+        * editing/pasteboard/displaced-generic-placeholder-expected.checksum: Added.
+        * editing/pasteboard/displaced-generic-placeholder-expected.png: Added.
+        * editing/pasteboard/displaced-generic-placeholder-expected.txt: Added.
+        * editing/pasteboard/displaced-generic-placeholder.html: Added.
+        So should placeholder brs with our special class on them.
+        * editing/pasteboard/displaced-placeholder-expected.checksum: Added.
+        * editing/pasteboard/displaced-placeholder-expected.png: Added.
+        * editing/pasteboard/displaced-placeholder-expected.txt: Added.
+        * editing/pasteboard/displaced-placeholder.html: Added.
+        Removed an unnecessary collapsed br.
+        * editing/pasteboard/paste-text-010-expected.txt:
+        Two fixes, an extra line was present after pasting with an interchange newline.
+        * editing/pasteboard/paste-text-016-expected.checksum: Added.
+        * editing/pasteboard/paste-text-016-expected.png: Added.
+        * editing/pasteboard/paste-text-016-expected.txt: Added.
+        * editing/pasteboard/paste-text-017-expected.checksum: Added.
+        * editing/pasteboard/paste-text-017-expected.png: Added.
+        * editing/pasteboard/paste-text-017-expected.txt: Added.
+        The code that interprets the incoming br as a br in strict mode had a bug. 
+        * editing/pasteboard/quirks-mode-br-1-expected.checksum: Added.
+        * editing/pasteboard/quirks-mode-br-1-expected.png: Added.
+        * editing/pasteboard/quirks-mode-br-1-expected.txt: Added.
+        * editing/pasteboard/quirks-mode-br-1.html: Added.
+        The linePlaceholder removal was negating the work to interpret the last
+        incoming br as a br in strict mode.
+        * editing/pasteboard/quirks-mode-br-2-expected.checksum: Added.
+        * editing/pasteboard/quirks-mode-br-2-expected.png: Added.
+        * editing/pasteboard/quirks-mode-br-2-expected.txt: Added.
+        * editing/pasteboard/quirks-mode-br-2.html: Added.
+        Don't let collapsed brs become rendered as a result of the paste operation.
+        * editing/pasteboard/unrendered-br-expected.checksum: Added.
+        * editing/pasteboard/unrendered-br-expected.png: Added.
+        * editing/pasteboard/unrendered-br-expected.txt: Added.
+        * editing/pasteboard/unrendered-br.html: Added.
+
 2006-04-25  Tim Omernick  <timo@apple.com>
 
         Reviewed by Hyatt.
diff --git a/LayoutTests/editing/pasteboard/bad-placeholder-expected.checksum b/LayoutTests/editing/pasteboard/bad-placeholder-expected.checksum
new file mode 100644 (file)
index 0000000..d524673
--- /dev/null
@@ -0,0 +1 @@
+e31566de3ec6ce9ebd4d50bd2949381a
\ No newline at end of file
diff --git a/LayoutTests/editing/pasteboard/bad-placeholder-expected.png b/LayoutTests/editing/pasteboard/bad-placeholder-expected.png
new file mode 100644 (file)
index 0000000..e8b0170
Binary files /dev/null and b/LayoutTests/editing/pasteboard/bad-placeholder-expected.png differ
diff --git a/LayoutTests/editing/pasteboard/bad-placeholder-expected.txt b/LayoutTests/editing/pasteboard/bad-placeholder-expected.txt
new file mode 100644 (file)
index 0000000..d5683b2
--- /dev/null
@@ -0,0 +1,30 @@
+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV > BODY > HTML > #document to 3 of DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 5 of #text > DIV > BODY > HTML > #document to 5 of #text > DIV > BODY > HTML > #document toDOMRange:range from 11 of #text > DIV > BODY > HTML > #document to 11 of #text > 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 751x36
+          text run at (0,0) width 751: "This is a test to make sure that a placeholder, even one without our special class on it, is removed only when it has been"
+          text run at (0,18) width 405: "collapsed away or when it has been displaced by pasted content."
+      RenderBlock {P} at (0,52) size 784x36
+        RenderText {#text} at (0,0) size 763x36
+          text run at (0,0) width 695: "Placeholders with our special class can, through bugs in deletion, be inserted into the document unnecessarily. "
+          text run at (695,0) width 61: "Once that"
+          text run at (0,18) width 763: "happens, we don't want to make matters worse by removing them if they are acting as line breaks instead of placeholders."
+      RenderBlock {DIV} at (0,104) size 784x36
+        RenderText {#text} at (0,0) size 28x18
+          text run at (0,0) width 28: "First"
+        RenderText {#text} at (28,0) size 71x18
+          text run at (28,0) width 71: " paragraph."
+        RenderBR {BR} at (99,14) size 0x0
+        RenderText {#text} at (0,18) size 118x18
+          text run at (0,18) width 118: "Second paragraph."
+caret: position 11 of child 1 {#text} of child 4 {DIV} of child 0 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/editing/pasteboard/bad-placeholder.html b/LayoutTests/editing/pasteboard/bad-placeholder.html
new file mode 100644 (file)
index 0000000..c4ac849
--- /dev/null
@@ -0,0 +1,12 @@
+<p>This is a test to make sure that a placeholder, even one without our special class on it, is removed only when it has been collapsed away or when it has been displaced by pasted content.</p>
+<p>Placeholders with our special class can, through bugs in deletion, be inserted into the document unnecessarily.  Once that happens, we don't want to make matters worse by removing them if they are acting as line breaks instead of placeholders.</p>
+<div id="test" contenteditable="true">First<br class='webkit-block-placeholder'>Second paragraph.</div>
+
+<script>
+var s = window.getSelection();
+var e = document.getElementById("test");
+
+s.setPosition(e, 0);
+s.modify("move", "forward", "word");
+document.execCommand("InsertHTML", false, " paragraph.");
+</script>
\ No newline at end of file
diff --git a/LayoutTests/editing/pasteboard/displaced-generic-placeholder-expected.checksum b/LayoutTests/editing/pasteboard/displaced-generic-placeholder-expected.checksum
new file mode 100644 (file)
index 0000000..2cfd071
--- /dev/null
@@ -0,0 +1 @@
+a4b9a91c162531eddfa8b0f40c113172
\ No newline at end of file
diff --git a/LayoutTests/editing/pasteboard/displaced-generic-placeholder-expected.png b/LayoutTests/editing/pasteboard/displaced-generic-placeholder-expected.png
new file mode 100644 (file)
index 0000000..53b5205
Binary files /dev/null and b/LayoutTests/editing/pasteboard/displaced-generic-placeholder-expected.png differ
diff --git a/LayoutTests/editing/pasteboard/displaced-generic-placeholder-expected.txt b/LayoutTests/editing/pasteboard/displaced-generic-placeholder-expected.txt
new file mode 100644 (file)
index 0000000..bbb007e
--- /dev/null
@@ -0,0 +1,24 @@
+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV > BODY > HTML > #document to 1 of DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 17 of #text > DIV > DIV > BODY > HTML > #document to 17 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 731x36
+          text run at (0,0) width 731: "This is a test to make sure that a placeholder, even one that doesn't have our special class on it, is removed when it is"
+          text run at (0,18) width 177: "displaced by pasted content."
+      RenderBlock {DIV} at (0,52) size 784x36
+        RenderBlock (anonymous) at (0,0) size 784x18
+          RenderText {#text} at (0,0) size 99x18
+            text run at (0,0) width 99: "First paragraph."
+        RenderBlock {DIV} at (0,18) size 784x18
+          RenderText {#text} at (0,0) size 118x18
+            text run at (0,0) width 118: "Second paragraph."
+        RenderBlock (anonymous) at (0,36) size 784x0
+caret: position 17 of child 0 {#text} of child 1 {DIV} of child 2 {DIV} of child 0 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/editing/pasteboard/displaced-generic-placeholder.html b/LayoutTests/editing/pasteboard/displaced-generic-placeholder.html
new file mode 100644 (file)
index 0000000..1c5f00a
--- /dev/null
@@ -0,0 +1,10 @@
+<p>This is a test to make sure that a placeholder, even one that doesn't have our special class on it, is removed when it is displaced by pasted content.</p>
+<div id="test" contenteditable="true"><br></div>
+
+<script>
+var s = window.getSelection();
+var e = document.getElementById("test");
+
+s.setPosition(e, 0);
+document.execCommand("InsertHTML", false, "First paragraph.<div>Second paragraph.</div>");
+</script>
\ No newline at end of file
diff --git a/LayoutTests/editing/pasteboard/displaced-placeholder-expected.checksum b/LayoutTests/editing/pasteboard/displaced-placeholder-expected.checksum
new file mode 100644 (file)
index 0000000..525d7d7
--- /dev/null
@@ -0,0 +1 @@
+51acfd7a90e22216ba736daa0539c16a
\ No newline at end of file
diff --git a/LayoutTests/editing/pasteboard/displaced-placeholder-expected.png b/LayoutTests/editing/pasteboard/displaced-placeholder-expected.png
new file mode 100644 (file)
index 0000000..6fe1eeb
Binary files /dev/null and b/LayoutTests/editing/pasteboard/displaced-placeholder-expected.png differ
diff --git a/LayoutTests/editing/pasteboard/displaced-placeholder-expected.txt b/LayoutTests/editing/pasteboard/displaced-placeholder-expected.txt
new file mode 100644 (file)
index 0000000..cbf12fd
--- /dev/null
@@ -0,0 +1,23 @@
+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV > BODY > HTML > #document to 1 of DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 17 of #text > DIV > DIV > BODY > HTML > #document to 17 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 784x18
+        RenderText {#text} at (0,0) size 596x18
+          text run at (0,0) width 596: "This is a test to make sure that a placeholder is removed when it is displaced by pasted content."
+      RenderBlock {DIV} at (0,34) size 784x36
+        RenderBlock (anonymous) at (0,0) size 784x18
+          RenderText {#text} at (0,0) size 99x18
+            text run at (0,0) width 99: "First paragraph."
+        RenderBlock {DIV} at (0,18) size 784x18
+          RenderText {#text} at (0,0) size 118x18
+            text run at (0,0) width 118: "Second paragraph."
+        RenderBlock (anonymous) at (0,36) size 784x0
+caret: position 17 of child 0 {#text} of child 1 {DIV} of child 2 {DIV} of child 0 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/editing/pasteboard/displaced-placeholder.html b/LayoutTests/editing/pasteboard/displaced-placeholder.html
new file mode 100644 (file)
index 0000000..8752d11
--- /dev/null
@@ -0,0 +1,10 @@
+<p>This is a test to make sure that a placeholder is removed when it is displaced by pasted content.</p>
+<div id="test" contenteditable="true"><br class='webkit-block-placeholder'></div>
+
+<script>
+var s = window.getSelection();
+var e = document.getElementById("test");
+
+s.setPosition(e, 0);
+document.execCommand("InsertHTML", false, "First paragraph.<div>Second paragraph.</div>");
+</script>
\ No newline at end of file
index cc8820dc305f0bca654ff483b2f08ec32391f7de..de55c9d7a89708faec8c911ef41461d1d95fa551 100644 (file)
@@ -46,7 +46,7 @@ EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 3 of DIV > BODY > HTML > #document to 3 of DIV > BODY > HTML > #document toDOMRange:range from 3 of DIV > BODY > HTML > #document to 3 of DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 EDITING DELEGATE: shouldInsertNode:#document-fragment replacingDOMRange:range from 3 of DIV > BODY > HTML > #document to 3 of DIV > BODY > HTML > #document givenAction:WebViewInsertActionPasted
-EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 7 of #text > DIV > BODY > HTML > #document to 7 of #text > DIV > BODY > HTML > #document toDOMRange:range from 7 of #text > DIV > BODY > HTML > #document to 7 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 7 of #text > DIV > BODY > HTML > #document to 7 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 EDITING DELEGATE: shouldInsertNode:#document-fragment replacingDOMRange:range from 7 of #text > DIV > BODY > HTML > #document to 7 of #text > DIV > BODY > HTML > #document givenAction:WebViewInsertActionPasted
@@ -67,5 +67,4 @@ layer at (0,0) size 800x600
           text run at (14,70) width 74: "of men."
         RenderText {#text} at (88,70) size 74x28
           text run at (88,70) width 74: "of men."
-        RenderBR {BR} at (162,92) size 0x0
 caret: position 7 of child 4 {#text} of child 1 {DIV} of child 1 {BODY} of child 0 {HTML} of document
index 4fb8efd2eb8637ef47b62249bd1635a8dad60f68..f067bae3ef73668af32d213b0a71aa960ef7e1fb 100644 (file)
@@ -1 +1 @@
-7d233a099920f1881928deadf93f1504
\ No newline at end of file
+b0627a2c344122f441226913df740d4a
\ No newline at end of file
index 14c58400f32db3b169ae59dc718a5b0f074f0f13..4011b2940c6f560d17f47d40827fd4b8d7b9b38e 100644 (file)
Binary files a/LayoutTests/editing/pasteboard/paste-text-016-expected.png and b/LayoutTests/editing/pasteboard/paste-text-016-expected.png differ
index 9258e4bd67df7de1572c81dfcb9d346f51352f01..539afb8c67f3e4efa3e8178dbb073739d76895a6 100644 (file)
@@ -18,7 +18,8 @@ EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotificatio
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: shouldInsertNode:#document-fragment replacingDOMRange:range from 2 of P > DIV > DIV > BODY > HTML > #document to 2 of P > DIV > DIV > BODY > HTML > #document givenAction:WebViewInsertActionPasted
-EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 3 of P > DIV > DIV > BODY > HTML > #document to 3 of P > DIV > DIV > BODY > HTML > #document toDOMRange:range from 3 of P > DIV > DIV > BODY > HTML > #document to 3 of P > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of #text > P > DIV > DIV > BODY > HTML > #document to 0 of #text > P > 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
@@ -37,9 +38,9 @@ layer at (0,0) size 800x600
         RenderText {#text} at (0,18) size 378x18
           text run at (0,18) width 378: "***TEST*** line should be second, following the first line."
       RenderBlock {DIV} at (0,36) size 784x12
-      RenderBlock {DIV} at (0,48) size 784x224
-        RenderBlock {DIV} at (0,0) size 784x224 [border: (2px solid #FF0000)]
-          RenderBlock {P} at (14,14) size 756x112
+      RenderBlock {DIV} at (0,48) size 784x196
+        RenderBlock {DIV} at (0,0) size 784x196 [border: (2px solid #FF0000)]
+          RenderBlock {P} at (14,14) size 756x84
             RenderBlock (anonymous) at (0,0) size 756x28
               RenderText {#text} at (0,0) size 319x28
                 text run at (0,0) width 319: "Should be first line of document."
@@ -47,18 +48,17 @@ layer at (0,0) size 800x600
             RenderBlock {P} at (0,28) size 756x28
               RenderText {#text} at (0,0) size 130x28
                 text run at (0,0) width 130: "***TEST***"
-            RenderBlock (anonymous) at (0,56) size 756x56
-              RenderBR {BR} at (0,0) size 0x28
-              RenderText {#text} at (0,28) size 128x28
-                text run at (0,28) width 128: "Another line."
-          RenderBlock {P} at (14,126) size 756x0
-          RenderBlock (anonymous) at (14,126) size 756x28
+            RenderBlock (anonymous) at (0,56) size 756x28
+              RenderText {#text} at (0,0) size 128x28
+                text run at (0,0) width 128: "Another line."
+          RenderBlock {P} at (14,98) size 756x0
+          RenderBlock (anonymous) at (14,98) size 756x28
             RenderText {#text} at (0,0) size 6x28
               text run at (0,0) width 6: " "
-          RenderBlock {P} at (14,154) size 756x0
-          RenderBlock (anonymous) at (14,154) size 756x28
+          RenderBlock {P} at (14,126) size 756x0
+          RenderBlock (anonymous) at (14,126) size 756x28
             RenderText {#text} at (0,0) size 6x28
               text run at (0,0) width 6: " "
-          RenderBlock {P} at (14,182) size 756x28
+          RenderBlock {P} at (14,154) size 756x28
             RenderBR {BR} at (0,0) size 0x28
-caret: position 0 of child 3 {BR} of child 0 {P} of child 1 {DIV} of child 7 {DIV} of child 1 {BODY} of child 0 {HTML} of document
+caret: position 0 of child 3 {#text} of child 0 {P} of child 1 {DIV} of child 7 {DIV} of child 1 {BODY} of child 0 {HTML} of document
index 5ab139235f52c208e60a7c6d6e36a43dd234b46d..975a166cd8d731bd32a0583a941694f31e9f11b6 100644 (file)
@@ -1 +1 @@
-2136d853988645543964c905ec7d2b08
\ No newline at end of file
+1e05ffac22396c85428d0466c50757de
\ No newline at end of file
index 53ed18832cbb9d455268fb771032ef92a1d20a62..1523d3e59ea390585b1ac6fadd5376d1332d7e21 100644 (file)
Binary files a/LayoutTests/editing/pasteboard/paste-text-017-expected.png and b/LayoutTests/editing/pasteboard/paste-text-017-expected.png differ
index a0f84340bc67d4e3f0db68ab0cdca7cc1a9f186b..f2c75d3ec58866cf2966028a72ecdb267bde4553 100644 (file)
@@ -32,8 +32,8 @@ layer at (0,0) size 800x600
           RenderBR {BR} at (189,22) size 0x0
           RenderText {#text} at (0,28) size 490x28
             text run at (0,28) width 490: "Should see a blank line between \"two\" and \"three\""
-      RenderBlock {DIV} at (0,236) size 784x144
-        RenderBlock {DIV} at (0,0) size 784x144 [border: (2px solid #FF0000)]
+      RenderBlock {DIV} at (0,236) size 784x116
+        RenderBlock {DIV} at (0,0) size 784x116 [border: (2px solid #FF0000)]
           RenderBlock {DIV} at (2,2) size 780x28
             RenderText {#text} at (0,0) size 35x28
               text run at (0,0) width 35: "one"
@@ -43,8 +43,6 @@ layer at (0,0) size 800x600
             RenderText {#text} at (0,0) size 36x28
               text run at (0,0) width 36: "two"
           RenderBlock {DIV} at (2,86) size 780x28
-            RenderBR {BR} at (0,0) size 0x28
-          RenderBlock {DIV} at (2,114) size 780x28
             RenderText {#text} at (0,0) size 49x28
               text run at (0,0) width 49: "three"
-caret: position 0 of child 0 {BR} of child 6 {DIV} of child 1 {DIV} of child 3 {DIV} of child 1 {BODY} of child 0 {HTML} of document
+caret: position 5 of child 0 {#text} of child 7 {DIV} of child 1 {DIV} of child 3 {DIV} of child 1 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/editing/pasteboard/quirks-mode-br-1-expected.checksum b/LayoutTests/editing/pasteboard/quirks-mode-br-1-expected.checksum
new file mode 100644 (file)
index 0000000..4664690
--- /dev/null
@@ -0,0 +1 @@
+e26e2f1a0df6f08405c4a702e1f1b123
\ No newline at end of file
diff --git a/LayoutTests/editing/pasteboard/quirks-mode-br-1-expected.png b/LayoutTests/editing/pasteboard/quirks-mode-br-1-expected.png
new file mode 100644 (file)
index 0000000..85cbfaf
Binary files /dev/null and b/LayoutTests/editing/pasteboard/quirks-mode-br-1-expected.png differ
diff --git a/LayoutTests/editing/pasteboard/quirks-mode-br-1-expected.txt b/LayoutTests/editing/pasteboard/quirks-mode-br-1-expected.txt
new file mode 100644 (file)
index 0000000..86722a7
--- /dev/null
@@ -0,0 +1,25 @@
+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV > BODY > HTML > #document to 1 of DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 61 of #text > DIV > DIV > BODY > HTML > #document to 61 of #text > DIV > DIV > BODY > HTML > #document toDOMRange:range from 2 of DIV > DIV > BODY > HTML > #document to 2 of 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: "This is a test to make sure that the final <br> in an incoming fragment is interpretted strictly in quirks mode (where brs at the"
+          text run at (0,18) width 184: "end of blocks are collapsed). "
+          text run at (184,18) width 509: "This test used to fail because of unrendered content to the left of the collapsed br."
+      RenderBlock {DIV} at (0,52) size 784x36
+        RenderBlock {DIV} at (0,0) size 784x36
+          RenderText {#text} at (0,0) size 370x18
+            text run at (0,0) width 370: "The test should add a single blank line after this paragraph."
+          RenderBR {BR} at (370,14) size 0x0
+          RenderBR {BR} at (0,18) size 0x18
+          RenderInline {SPAN} at (0,0) size 0x0
+caret: position 0 of child 2 {BR} of child 0 {DIV} of child 2 {DIV} of child 0 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/editing/pasteboard/quirks-mode-br-1.html b/LayoutTests/editing/pasteboard/quirks-mode-br-1.html
new file mode 100644 (file)
index 0000000..0c1b540
--- /dev/null
@@ -0,0 +1,11 @@
+<p>This is a test to make sure that the final &lt;br&gt; in an incoming fragment is interpretted strictly in quirks mode (where brs at the end of blocks are collapsed).  This test used to fail because of unrendered content to the left of the collapsed br.</p>
+<div id="test" contenteditable="true"><div>The test should add a single blank line after this paragraph.<span></span><br></div></div>
+
+<script>
+var s = window.getSelection();
+var e = document.getElementById("test");
+
+s.setPosition(e, 0);
+s.modify("move", "forward", "line");
+document.execCommand("InsertHTML", false, "<br>");
+</script>
\ No newline at end of file
diff --git a/LayoutTests/editing/pasteboard/quirks-mode-br-2-expected.checksum b/LayoutTests/editing/pasteboard/quirks-mode-br-2-expected.checksum
new file mode 100644 (file)
index 0000000..a293f84
--- /dev/null
@@ -0,0 +1 @@
+a5ff25b444cb1aafda24a30211af0150
\ No newline at end of file
diff --git a/LayoutTests/editing/pasteboard/quirks-mode-br-2-expected.png b/LayoutTests/editing/pasteboard/quirks-mode-br-2-expected.png
new file mode 100644 (file)
index 0000000..e40824f
Binary files /dev/null and b/LayoutTests/editing/pasteboard/quirks-mode-br-2-expected.png differ
diff --git a/LayoutTests/editing/pasteboard/quirks-mode-br-2-expected.txt b/LayoutTests/editing/pasteboard/quirks-mode-br-2-expected.txt
new file mode 100644 (file)
index 0000000..4141405
--- /dev/null
@@ -0,0 +1,24 @@
+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV > BODY > HTML > #document to 1 of DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 1 of DIV > BODY > HTML > #document to 1 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 {P} at (0,0) size 784x54
+        RenderText {#text} at (0,0) size 779x54
+          text run at (0,0) width 779: "This is a test to make sure that the final <br> in an incoming fragment is interpretted strictly in quirks mode (where brs at the"
+          text run at (0,18) width 184: "end of blocks are collapsed). "
+          text run at (184,18) width 545: "This test used to fail because placeholders where the paste occured were removed after"
+          text run at (0,36) width 175: "incoming brs were handled."
+      RenderBlock {P} at (0,70) size 784x18
+        RenderText {#text} at (0,0) size 385x18
+          text run at (0,0) width 385: "There should be two blank lines in the editable region below."
+      RenderBlock {DIV} at (0,104) size 784x36
+        RenderBR {BR} at (0,0) size 0x18
+        RenderBR {BR} at (0,18) size 0x18
+caret: position 0 of child 1 {BR} of child 4 {DIV} of child 0 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/editing/pasteboard/quirks-mode-br-2.html b/LayoutTests/editing/pasteboard/quirks-mode-br-2.html
new file mode 100644 (file)
index 0000000..9f7b1d5
--- /dev/null
@@ -0,0 +1,12 @@
+<p>This is a test to make sure that the final &lt;br&gt; in an incoming fragment is interpretted strictly in quirks mode (where brs at the end of blocks are collapsed).  This test used to fail because placeholders where the paste occured were removed after incoming brs were handled.</p>
+
+<p>There should be two blank lines in the editable region below.</p>
+<div id="test" contenteditable="true"><br class="webkit-block-placeholder"></div>
+
+<script>
+var s = window.getSelection();
+var e = document.getElementById("test");
+
+s.setPosition(e, 0);
+document.execCommand("InsertHTML", false, "<br>");
+</script>
\ No newline at end of file
diff --git a/LayoutTests/editing/pasteboard/unrendered-br-expected.checksum b/LayoutTests/editing/pasteboard/unrendered-br-expected.checksum
new file mode 100644 (file)
index 0000000..9f3be23
--- /dev/null
@@ -0,0 +1 @@
+e2ad9a5f99bc12d94d8ce8d2625e7bf8
\ No newline at end of file
diff --git a/LayoutTests/editing/pasteboard/unrendered-br-expected.png b/LayoutTests/editing/pasteboard/unrendered-br-expected.png
new file mode 100644 (file)
index 0000000..72e74d3
Binary files /dev/null and b/LayoutTests/editing/pasteboard/unrendered-br-expected.png differ
diff --git a/LayoutTests/editing/pasteboard/unrendered-br-expected.txt b/LayoutTests/editing/pasteboard/unrendered-br-expected.txt
new file mode 100644 (file)
index 0000000..38646ee
--- /dev/null
@@ -0,0 +1,27 @@
+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: shouldChangeSelectedDOMRange:range from 6 of #text > DIV > BODY > HTML > #document to 6 of #text > DIV > BODY > HTML > #document toDOMRange:range from 17 of #text > DIV > DIV > BODY > HTML > #document to 17 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 763x36
+          text run at (0,0) width 763: "This is a test to make sure that an unrendered br at the end of the selection being pasted into doesn't become rendered as a"
+          text run at (0,18) width 114: "result of the paste."
+      RenderBlock {DIV} at (0,52) size 784x36
+        RenderBlock (anonymous) at (0,0) size 784x18
+          RenderText {#text} at (0,0) size 32x18
+            text run at (0,0) width 32: "First "
+          RenderText {#text} at (32,0) size 67x18
+            text run at (32,0) width 67: "paragraph."
+        RenderBlock {DIV} at (0,18) size 784x18
+          RenderText {#text} at (0,0) size 118x18
+            text run at (0,0) width 118: "Second paragraph."
+        RenderBlock (anonymous) at (0,36) size 784x0
+caret: position 17 of child 0 {#text} of child 2 {DIV} of child 2 {DIV} of child 0 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/editing/pasteboard/unrendered-br.html b/LayoutTests/editing/pasteboard/unrendered-br.html
new file mode 100644 (file)
index 0000000..10f8b0a
--- /dev/null
@@ -0,0 +1,11 @@
+<p>This is a test to make sure that an unrendered br at the end of the selection being pasted into doesn't become rendered as a result of the paste.</p>
+<div id="test" contenteditable="true">First&nbsp;<br></div>
+
+<script>
+var s = window.getSelection();
+var e = document.getElementById("test");
+
+s.setPosition(e, 0);
+s.modify("move", "forward", "line");
+document.execCommand("InsertHTML", false, "paragraph.<div>Second paragraph.</div>");
+</script>
\ No newline at end of file
index 95a1c5aa0db6dc115958bdffab56448bf42817ab..27597ec267ada48a67389340ce2c29451b3f8254 100644 (file)
@@ -1,3 +1,33 @@
+2006-04-27  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by darin
+        
+        <http://bugzilla.opendarwin.org/show_bug.cgi?id=8624>
+        Placeholders aren't always removed during paste
+        <rdar://problem/4059807>
+        Seed: Mail: pasting quoted content sometimes adds a phantom newline
+
+        * editing/CompositeEditCommand.cpp: Added a FIXME.
+        * editing/ReplaceSelectionCommand.cpp:
+        (WebCore::ReplaceSelectionCommand::doApply):
+        Removed two no-op setEndingSelection calls.
+        Store away a br at the position where we'll start inserting content in case the 
+        br a) is made unnecessary by the insertion (it's collapsed away) b) was acting 
+        as a placeholder and should therefore be displaced by inserted content or c) was
+        acting as a line break and, as a result of the insertion, is now acting as a 
+        placeholder.  
+        Don't only store away brs that have the webkit-block-placeholder class on them.
+        Any br that does any of the three things just mentioned should be removed.
+        The linePlaceholder removal was run after the code that makes sure to interpret 
+        incoming brs strictly, and was negating that work in certain cases.
+        
+        (WebCore::ReplaceSelectionCommand::removeEndBRIfNeeded): Described above.
+        * editing/ReplaceSelectionCommand.h:
+        * editing/VisiblePosition.cpp:
+        (WebCore::isEqualIgnoringAffinity): 
+        Added a workaround for 8622.  We want this function to return true even if one of 
+        the two visible positions has been incorrectly canonicalized.
+
 2006-04-26  Tim Omernick  <timo@apple.com>
 
         Reviewed by Hyatt.
index 109b4c9f22d8e344322a01230b6bfabe045b1e82..5b6315a243851e3756acb16fa91897165a384b5a 100644 (file)
@@ -554,6 +554,11 @@ bool CompositeEditCommand::removeBlockPlaceholder(Node *node)
     return false;
 }
 
+// FIXME: This function should never be used.  If we're in a state where a webkit-block-placeholder
+// isn't the only thing in a block (there are bugs that can make this happen), this function will 
+// return a placeholder that might be far away from where the editing operation that's using it intends 
+// to operate.  Also a br is a placeholder if its acting like a placeholder, i.e. <div><br></div>, and 
+// this function only returs brs with our special class on them.
 Node *CompositeEditCommand::findBlockPlaceholder(Node *node)
 {
     if (!node)
index 2fc9989774a3f842b04c6f49b5139617c23b7868..efc71792fc98377754d06e2256d8842b9b31bc19 100644 (file)
@@ -542,10 +542,8 @@ void ReplaceSelectionCommand::doApply()
             if (isEndOfParagraph(visibleStart) && !isStartOfParagraph(visibleStart)) {
                 if (!isEndOfDocument(visibleStart))
                     setEndingSelection(visibleStart.next());
-            } else {
+            } else
                 insertParagraphSeparator();
-                setEndingSelection(VisiblePosition(endingSelection().start(), VP_DEFAULT_AFFINITY));
-            }
         }
         startPos = endingSelection().start();
     } 
@@ -555,10 +553,8 @@ void ReplaceSelectionCommand::doApply()
             if (isEndOfParagraph(visibleStart) && !isStartOfParagraph(visibleStart)) {
                 if (!isEndOfDocument(visibleStart))
                     setEndingSelection(visibleStart.next());
-            } else {
+            } else 
                 insertParagraphSeparator();
-                setEndingSelection(VisiblePosition(endingSelection().start(), VP_DEFAULT_AFFINITY));
-            }
         }
         // We split the current paragraph in two to avoid nesting the blocks from the fragment inside the current block.
         // For example paste <div>foo</div><div>bar</div><div>baz</div> into <div>x^x</div>, where ^ is the caret.  
@@ -574,6 +570,11 @@ void ReplaceSelectionCommand::doApply()
         startPos = endingSelection().start();
     }
     
+    // NOTE: This would be an incorrect usage of downstream() if downstream() were changed to mean the last position after 
+    // p that maps to the same visible position as p (since in the case where a br is at the end of a block and collapsed 
+    // away, there are positions after the br which map to the same visible position as [br, 0]).  
+    Node* endBR = startPos.downstream().node()->hasTagName(brTag) ? startPos.downstream().node() : 0;
+    
     if (startAtStartOfBlock && startBlock->inDocument())
         startPos = Position(startBlock, 0);
 
@@ -594,21 +595,6 @@ void ReplaceSelectionCommand::doApply()
     if (!fragment.firstChild())
         return;
     
-    // check for a line placeholder, and store it away for possible removal later.
-    Node *block = startPos.node()->enclosingBlockFlowElement();
-    Node *linePlaceholder = findBlockPlaceholder(block);
-    if (!linePlaceholder) {
-        Position downstream = startPos.downstream();
-        // NOTE: the check for brTag offset 0 could be false negative after
-        // positionAvoidingSpecialElementBoundary() because "downstream" is
-        // now a "second deepest position"
-        downstream = positionAvoidingSpecialElementBoundary(downstream);
-        if (downstream.node()->hasTagName(brTag) && downstream.offset() == 0 && 
-            fragment.hasInterchangeNewlineAtEnd() &&
-            isStartOfParagraph(VisiblePosition(downstream, VP_DEFAULT_AFFINITY)))
-            linePlaceholder = downstream.node();
-    }
-    
     // check whether to "smart replace" needs to add leading and/or trailing space
     bool addLeadingSpace = false;
     bool addTrailingSpace = false;
@@ -752,10 +738,11 @@ void ReplaceSelectionCommand::doApply()
     }
     
     Position lastPositionToSelect;
+    
+    removeEndBRIfNeeded(endBR);
 
     // step 4 : handle trailing newline
     if (fragment.hasInterchangeNewlineAtEnd()) {
-        removeLinePlaceholderIfNeeded(linePlaceholder);
 
         if (!m_lastNodeInserted) {
             lastPositionToSelect = endingSelection().end().downstream();
@@ -779,23 +766,22 @@ void ReplaceSelectionCommand::doApply()
             }
         }
     } else {
-        if (m_lastNodeInserted && m_lastNodeInserted->hasTagName(brTag) && !document()->inStrictMode()) {
-            updateLayout();
-            VisiblePosition pos(Position(m_lastNodeInserted.get(), 1), DOWNSTREAM);
-            if (isEndOfBlock(pos)) {
-                Node *next = m_lastNodeInserted->traverseNextNode();
-                bool hasTrailingBR = next && next->hasTagName(brTag) && m_lastNodeInserted->enclosingBlockFlowElement() == next->enclosingBlockFlowElement();
-                if (!hasTrailingBR) {
-                    // Insert an "extra" BR at the end of the block. 
-                    insertNodeBefore(createBreakElement(document()).get(), m_lastNodeInserted.get());
-                }
-            }
+        // We want to honor the last incoming line break, so, if it will collapse away because of quirks mode, 
+        // add an extra one.
+        // FIXME: If <div><br></div> is pasted, the br will be expanded.  That's fine, if this code is about 
+        // interpreting incoming brs strictly, but if that's true then we should expand all incoming brs, not 
+        // just the last one. 
+        if (m_lastNodeInserted && m_lastNodeInserted->hasTagName(brTag) && 
+            !document()->inStrictMode() && isEndOfBlock(VisiblePosition(Position(m_lastNodeInserted.get(), 0)))) { 
+            insertNodeBeforeAndUpdateNodesInserted(createBreakElement(document()).get(), m_lastNodeInserted.get());
         }
     }
     
     if (!m_matchStyle)
         fixupNodeStyles(fragment.nodes(), fragment.renderingInfo());
     
+    // 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.
     if (mergeEnd) {
         VisiblePosition afterInsertedContent(positionAfterNode(m_lastNodeInserted.get()));
         if (isEndOfParagraph(afterInsertedContent)) {
@@ -806,25 +792,21 @@ void ReplaceSelectionCommand::doApply()
     }
     
     completeHTMLReplacement(lastPositionToSelect);
-    
-    // step 5 : mop up
-    removeLinePlaceholderIfNeeded(linePlaceholder);
 }
 
-void ReplaceSelectionCommand::removeLinePlaceholderIfNeeded(Node *linePlaceholder)
+void ReplaceSelectionCommand::removeEndBRIfNeeded(Node* endBR)
 {
-    if (!linePlaceholder)
+    if (!endBR || !endBR->inDocument())
         return;
         
-    updateLayout();
-    if (linePlaceholder->inDocument()) {
-        VisiblePosition placeholderPos(linePlaceholder, linePlaceholder->renderer()->caretMinOffset(), DOWNSTREAM);
-        if (placeholderPos.next().isNull() ||
-            !(isStartOfParagraph(placeholderPos) && isEndOfParagraph(placeholderPos))) {
-            
-            removeNodeAndPruneAncestors(linePlaceholder);
-        }
-    }
+    VisiblePosition visiblePos(Position(endBR, 0));
+    
+    if (// The br is collapsed away and so is unnecessary.
+        !document()->inStrictMode() && isEndOfBlock(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))
+        removeNodeAndPruneAncestors(endBR);
 }
 
 void ReplaceSelectionCommand::completeHTMLReplacement(const Position &lastPositionToSelect)
index e5729ad86cda72293fc82280ac271aa1bc6d97b5..bf5cf10ed80ed19088b9ab2737c589a7504b1d99 100644 (file)
@@ -128,7 +128,7 @@ private:
 
     void updateNodesInserted(Node *);
     void fixupNodeStyles(const NodeVector&, const RenderingInfoMap&);
-    void removeLinePlaceholderIfNeeded(Node *);
+    void removeEndBRIfNeeded(Node*);
     
     bool shouldMergeStart(const ReplacementFragment&, const Selection&);
     bool shouldMergeEnd(const ReplacementFragment&, const Selection&);
index a286d34cf948f76c23afc8301c59f5526a5bae7a..4fe05a6ea25e0df7a56a5f5cd74368b299c8860f 100644 (file)
@@ -230,7 +230,9 @@ QChar VisiblePosition::character() const
 
 bool isEqualIgnoringAffinity(const VisiblePosition &a, const VisiblePosition &b)
 {
-    bool result = a.deepEquivalent() == b.deepEquivalent();
+    bool result = a.deepEquivalent() == b.deepEquivalent() || 
+                  // FIXME (8622): This is a slow but temporary workaround. 
+                  a.deepEquivalent().downstream() == b.deepEquivalent().downstream();
     if (result) {
         // We want to catch cases where positions are equal, but affinities are not, since
         // this is very likely a bug, given the places where this call is used. The difference