Commit 2da84157 authored by adele@apple.com's avatar adele@apple.com

WebCore:

2009-04-24  Adele Peterson  <adele@apple.com>

        Reviewed by Darin Adler.

        Fix for <rdar://problem/5089327> Newline gets stripped when pasting whole lines in certain markup

        Test: editing/pasteboard/paste-blockquote-after-blockquote.html

        When we have matching quote levels, its ok to merge the starts of the inserted and existing blocks more frequently.
        But we should only merge here if the selection start was inside a mail blockquote.  This prevents against removing a 
        blockquote from newly pasted quoted content that was pasted into an unquoted position.  If that unquoted position happens 
        to be right after another blockquote, we don't want to merge and risk stripping a valid block (and newline) from the pasted content.

        * editing/ReplaceSelectionCommand.cpp:
        (WebCore::ReplaceSelectionCommand::shouldMergeStart): Also added an early return to always return false when we're already moving paragraphs.
        (WebCore::ReplaceSelectionCommand::doApply): Removed redundant check for when we're moving paragraphs.
        * editing/ReplaceSelectionCommand.h:

LayoutTests:

2009-04-24  Adele Peterson  <adele@apple.com>

        Reviewed by Darin Adler.

        Test for <rdar://problem/5089327> Newline gets stripped when pasting whole lines in certain markup

        * editing/pasteboard/paste-blockquote-after-blockquote.html: Added.
        * platform/mac/editing/pasteboard/paste-blockquote-after-blockquote-expected.checksum: Added.
        * platform/mac/editing/pasteboard/paste-blockquote-after-blockquote-expected.png: Added.
        * platform/mac/editing/pasteboard/paste-blockquote-after-blockquote-expected.txt: Added.



git-svn-id: svn://svn.chromium.org/blink/trunk@42821 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 270fc232
2009-04-24 Adele Peterson <adele@apple.com>
Reviewed by Darin Adler.
Test for <rdar://problem/5089327> Newline gets stripped when pasting whole lines in certain markup
* editing/pasteboard/paste-blockquote-after-blockquote.html: Added.
* platform/mac/editing/pasteboard/paste-blockquote-after-blockquote-expected.checksum: Added.
* platform/mac/editing/pasteboard/paste-blockquote-after-blockquote-expected.png: Added.
* platform/mac/editing/pasteboard/paste-blockquote-after-blockquote-expected.txt: Added.
2009-04-24 Ariya Hidayat <ariya.hidayat@nokia.com> 2009-04-24 Ariya Hidayat <ariya.hidayat@nokia.com>
Reviewed by Simon Hausmann. Reviewed by Simon Hausmann.
......
<style>
blockquote {
color: blue;
border-left: 2px solid blue;
margin: 0px;
padding: 0 0 0 20px;
}
</style>
<p>This tests pasting a blockquote after another blockquote.</p>
<div id="div" contenteditable="true"><blockquote type='cite'>Line 1</blockquote><br></div>
<script>
var sel = window.getSelection();
var div = document.getElementById("div");
sel.setPosition(div, 1);
document.execCommand("InsertHTML", false, "<blockquote type='cite'>Line 2</blockquote>");
</script>
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 784x18
RenderText {#text} at (0,0) size 354x18
text run at (0,0) width 354: "This tests pasting a blockquote after another blockquote."
RenderBlock {DIV} at (0,34) size 784x36
RenderBlock {BLOCKQUOTE} at (0,0) size 784x18 [color=#0000FF] [border: (2px solid #0000FF)]
RenderText {#text} at (22,0) size 41x18
text run at (22,0) width 41: "Line 1"
RenderBlock {BLOCKQUOTE} at (0,18) size 784x18 [color=#0000FF] [border: (2px solid #0000FF)]
RenderText {#text} at (22,0) size 41x18
text run at (22,0) width 41: "Line 2"
RenderBlock (anonymous) at (0,36) size 784x0
caret: position 6 of child 0 {#text} of child 1 {BLOCKQUOTE} of child 2 {DIV} of child 1 {BODY} of child 0 {HTML} of document
2009-04-24 Adele Peterson <adele@apple.com>
Reviewed by Darin Adler.
Fix for <rdar://problem/5089327> Newline gets stripped when pasting whole lines in certain markup
Test: editing/pasteboard/paste-blockquote-after-blockquote.html
When we have matching quote levels, its ok to merge the starts of the inserted and existing blocks more frequently.
But we should only merge here if the selection start was inside a mail blockquote. This prevents against removing a
blockquote from newly pasted quoted content that was pasted into an unquoted position. If that unquoted position happens
to be right after another blockquote, we don't want to merge and risk stripping a valid block (and newline) from the pasted content.
* editing/ReplaceSelectionCommand.cpp:
(WebCore::ReplaceSelectionCommand::shouldMergeStart): Also added an early return to always return false when we're already moving paragraphs.
(WebCore::ReplaceSelectionCommand::doApply): Removed redundant check for when we're moving paragraphs.
* editing/ReplaceSelectionCommand.h:
2009-04-23 Francisco Tolmasky <francisco@280north.com> 2009-04-23 Francisco Tolmasky <francisco@280north.com>
BUG 24604: WebKit profiler reports incorrect total times BUG 24604: WebKit profiler reports incorrect total times
...@@ -343,14 +343,22 @@ static bool hasMatchingQuoteLevel(VisiblePosition endOfExistingContent, VisibleP ...@@ -343,14 +343,22 @@ static bool hasMatchingQuoteLevel(VisiblePosition endOfExistingContent, VisibleP
return isInsideMailBlockquote && (numEnclosingMailBlockquotes(existing) == numEnclosingMailBlockquotes(inserted)); return isInsideMailBlockquote && (numEnclosingMailBlockquotes(existing) == numEnclosingMailBlockquotes(inserted));
} }
bool ReplaceSelectionCommand::shouldMergeStart(bool selectionStartWasStartOfParagraph, bool fragmentHasInterchangeNewlineAtStart) bool ReplaceSelectionCommand::shouldMergeStart(bool selectionStartWasStartOfParagraph, bool fragmentHasInterchangeNewlineAtStart, bool selectionStartWasInsideMailBlockquote)
{ {
if (m_movingParagraph)
return false;
VisiblePosition startOfInsertedContent(positionAtStartOfInsertedContent()); VisiblePosition startOfInsertedContent(positionAtStartOfInsertedContent());
VisiblePosition prev = startOfInsertedContent.previous(true); VisiblePosition prev = startOfInsertedContent.previous(true);
if (prev.isNull()) if (prev.isNull())
return false; return false;
if (!m_movingParagraph && isStartOfParagraph(startOfInsertedContent) && hasMatchingQuoteLevel(prev, positionAtEndOfInsertedContent())) // When we have matching quote levels, its ok to merge more frequently.
// For a successful merge, we still need to make sure that the inserted content starts with the beginning of a paragraph.
// And we should only merge here if the selection start was inside a mail blockquote. This prevents against removing a
// blockquote from newly pasted quoted content that was pasted into an unquoted position. If that unquoted position happens
// to be right after another blockquote, we don't want to merge and risk stripping a valid block (and newline) from the pasted content.
if (isStartOfParagraph(startOfInsertedContent) && selectionStartWasInsideMailBlockquote && hasMatchingQuoteLevel(prev, positionAtEndOfInsertedContent()))
return true; return true;
return !selectionStartWasStartOfParagraph && return !selectionStartWasStartOfParagraph &&
...@@ -898,13 +906,7 @@ void ReplaceSelectionCommand::doApply() ...@@ -898,13 +906,7 @@ void ReplaceSelectionCommand::doApply()
// the start merge so that the start merge doesn't effect our decision. // the start merge so that the start merge doesn't effect our decision.
m_shouldMergeEnd = shouldMergeEnd(selectionEndWasEndOfParagraph); m_shouldMergeEnd = shouldMergeEnd(selectionEndWasEndOfParagraph);
if (shouldMergeStart(selectionStartWasStartOfParagraph, fragment.hasInterchangeNewlineAtStart())) { if (shouldMergeStart(selectionStartWasStartOfParagraph, fragment.hasInterchangeNewlineAtStart(), startIsInsideMailBlockquote)) {
// Bail to avoid infinite recursion.
if (m_movingParagraph) {
// setting display:inline does not work for td elements in quirks mode
ASSERT(m_firstNodeInserted->hasTagName(tdTag));
return;
}
VisiblePosition destination = startOfInsertedContent.previous(); VisiblePosition destination = startOfInsertedContent.previous();
VisiblePosition startOfParagraphToMove = startOfInsertedContent; VisiblePosition startOfParagraphToMove = startOfInsertedContent;
......
...@@ -58,7 +58,7 @@ private: ...@@ -58,7 +58,7 @@ private:
void updateNodesInserted(Node*); void updateNodesInserted(Node*);
bool shouldRemoveEndBR(Node*, const VisiblePosition&); bool shouldRemoveEndBR(Node*, const VisiblePosition&);
bool shouldMergeStart(bool, bool); bool shouldMergeStart(bool, bool, bool);
bool shouldMergeEnd(bool selectEndWasEndOfParagraph); bool shouldMergeEnd(bool selectEndWasEndOfParagraph);
bool shouldMerge(const VisiblePosition&, const VisiblePosition&); bool shouldMerge(const VisiblePosition&, const VisiblePosition&);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment