Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Unified Diff: Source/WebCore/editing/ReplaceSelectionCommand.cpp

Issue 13954003: Remove mail blockquote special case handling. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/WebCore/editing/ReplaceSelectionCommand.cpp
diff --git a/Source/WebCore/editing/ReplaceSelectionCommand.cpp b/Source/WebCore/editing/ReplaceSelectionCommand.cpp
index c4132fafaa375f631790ee31c05657c1a67f355f..df213ccae542ea8c64c8abbc0c3332663873e8ff 100644
--- a/Source/WebCore/editing/ReplaceSelectionCommand.cpp
+++ b/Source/WebCore/editing/ReplaceSelectionCommand.cpp
@@ -378,15 +378,7 @@ ReplaceSelectionCommand::ReplaceSelectionCommand(Document* document, PassRefPtr<
{
}
-static bool hasMatchingQuoteLevel(VisiblePosition endOfExistingContent, VisiblePosition endOfInsertedContent)
-{
- Position existing = endOfExistingContent.deepEquivalent();
- Position inserted = endOfInsertedContent.deepEquivalent();
- bool isInsideMailBlockquote = enclosingNodeOfType(inserted, isMailBlockquote, CanCrossEditingBoundary);
- return isInsideMailBlockquote && (numEnclosingMailBlockquotes(existing) == numEnclosingMailBlockquotes(inserted));
-}
-
-bool ReplaceSelectionCommand::shouldMergeStart(bool selectionStartWasStartOfParagraph, bool fragmentHasInterchangeNewlineAtStart, bool selectionStartWasInsideMailBlockquote)
+bool ReplaceSelectionCommand::shouldMergeStart(bool selectionStartWasStartOfParagraph, bool fragmentHasInterchangeNewlineAtStart)
{
if (m_movingParagraph)
return false;
@@ -395,14 +387,6 @@ bool ReplaceSelectionCommand::shouldMergeStart(bool selectionStartWasStartOfPara
VisiblePosition prev = startOfInsertedContent.previous(CannotCrossEditingBoundary);
if (prev.isNull())
return false;
-
- // 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 !selectionStartWasStartOfParagraph
&& !fragmentHasInterchangeNewlineAtStart
@@ -424,11 +408,6 @@ bool ReplaceSelectionCommand::shouldMergeEnd(bool selectionEndWasEndOfParagraph)
&& shouldMerge(endOfInsertedContent, next);
}
-static bool isMailPasteAsQuotationNode(const Node* node)
-{
- return node && node->hasTagName(blockquoteTag) && node->isElementNode() && toElement(node)->getAttribute(classAttr) == ApplePasteAsQuotation;
-}
-
static bool isHeaderElement(const Node* a)
{
if (!a)
@@ -456,8 +435,7 @@ bool ReplaceSelectionCommand::shouldMerge(const VisiblePosition& source, const V
Node* destinationNode = destination.deepEquivalent().deprecatedNode();
Node* sourceBlock = enclosingBlock(sourceNode);
Node* destinationBlock = enclosingBlock(destinationNode);
- return !enclosingNodeOfType(source.deepEquivalent(), &isMailPasteAsQuotationNode) &&
- sourceBlock && (!sourceBlock->hasTagName(blockquoteTag) || isMailBlockquote(sourceBlock)) &&
+ return sourceBlock && !sourceBlock->hasTagName(blockquoteTag) &&
enclosingListChild(sourceBlock) == enclosingListChild(destinationNode) &&
enclosingTableCell(source.deepEquivalent()) == enclosingTableCell(destination.deepEquivalent()) &&
(!isHeaderElement(sourceBlock) || haveSameTagName(sourceBlock, destinationBlock)) &&
@@ -503,12 +481,6 @@ void ReplaceSelectionCommand::removeRedundantStylesAndKeepStyleSpanInline(Insert
ContainerNode* context = element->parentNode();
- // If Mail wraps the fragment with a Paste as Quotation blockquote, or if you're pasting into a quoted region,
- // styles from blockquoteNode are allowed to override those from the source document, see <rdar://problem/4930986> and <rdar://problem/5089327>.
- Node* blockquoteNode = isMailPasteAsQuotationNode(context) ? context : enclosingNodeOfType(firstPositionInNode(context), isMailBlockquote, CanCrossEditingBoundary);
- if (blockquoteNode)
- newInlineStyle->removeStyleFromRulesAndContext(element, document()->documentElement());
-
newInlineStyle->removeStyleFromRulesAndContext(element, context);
}
@@ -720,11 +692,6 @@ static bool handleStyleSpansBeforeInsertion(ReplacementFragment& fragment, const
{
Node* topNode = fragment.firstChild();
- // Handling the case where we are doing Paste as Quotation or pasting into quoted content is more complicated (see handleStyleSpans)
- // and doesn't receive the optimization.
- if (isMailPasteAsQuotationNode(topNode) || enclosingNodeOfType(firstPositionInOrBeforeNode(topNode), isMailBlockquote, CanCrossEditingBoundary))
- return false;
-
// Either there are no style spans in the fragment or a WebKit client has added content to the fragment
// before inserting it. Look for and handle style spans after insertion.
if (!isLegacyAppleStyleSpan(topNode))
@@ -772,12 +739,6 @@ void ReplaceSelectionCommand::handleStyleSpans(InsertedNodes& insertedNodes)
RefPtr<EditingStyle> style = EditingStyle::create(wrappingStyleSpan->inlineStyle());
ContainerNode* context = wrappingStyleSpan->parentNode();
- // If Mail wraps the fragment with a Paste as Quotation blockquote, or if you're pasting into a quoted region,
- // styles from blockquoteNode are allowed to override those from the source document, see <rdar://problem/4930986> and <rdar://problem/5089327>.
- Node* blockquoteNode = isMailPasteAsQuotationNode(context) ? context : enclosingNodeOfType(firstPositionInNode(context), isMailBlockquote, CanCrossEditingBoundary);
- if (blockquoteNode)
- context = document()->documentElement();
-
// This operation requires that only editing styles to be removed from sourceDocumentStyle.
style->prepareToApplyAt(firstPositionInNode(context));
@@ -868,8 +829,7 @@ static bool isInlineNodeWithStyle(const Node* node)
const HTMLElement* element = static_cast<const HTMLElement*>(node);
const AtomicString& classAttributeValue = element->getAttribute(classAttr);
if (classAttributeValue == AppleTabSpanClass
- || classAttributeValue == AppleConvertedSpace
- || classAttributeValue == ApplePasteAsQuotation)
+ || classAttributeValue == AppleConvertedSpace)
return true;
return EditingStyle::elementIsStyledSpanOrHTMLEquivalent(element);
@@ -915,11 +875,10 @@ void ReplaceSelectionCommand::doApply()
Node* startBlock = enclosingBlock(visibleStart.deepEquivalent().deprecatedNode());
Position insertionPos = selection.start();
- bool startIsInsideMailBlockquote = enclosingNodeOfType(insertionPos, isMailBlockquote, CanCrossEditingBoundary);
bool selectionIsPlainText = !selection.isContentRichlyEditable();
Element* currentRoot = selection.rootEditableElement();
- if ((selectionStartWasStartOfParagraph && selectionEndWasEndOfParagraph && !startIsInsideMailBlockquote) ||
+ if ((selectionStartWasStartOfParagraph && selectionEndWasEndOfParagraph) ||
startBlock == currentRoot || isListItem(startBlock) || selectionIsPlainText)
m_preventNesting = false;
@@ -928,9 +887,7 @@ void ReplaceSelectionCommand::doApply()
// spans multiple blocks, not merging may leave an empty line.
// When the start of the selection being pasted into is at the start of a block, not merging
// will leave hanging block(s).
- // Merge blocks if the start of the selection was in a Mail blockquote, since we handle
- // that case specially to prevent nesting.
- bool mergeBlocksAfterDelete = startIsInsideMailBlockquote || isEndOfParagraph(visibleEnd) || isStartOfBlock(visibleStart);
+ bool mergeBlocksAfterDelete = isEndOfParagraph(visibleEnd) || isStartOfBlock(visibleStart);
// FIXME: We should only expand to include fully selected special elements if we are copying a
// selection and pasting it on top of itself.
deleteSelection(false, mergeBlocksAfterDelete, true, false);
@@ -958,27 +915,13 @@ void ReplaceSelectionCommand::doApply()
// For example paste <div>foo</div><div>bar</div><div>baz</div> into <div>x^x</div>, where ^ is the caret.
// As long as the div styles are the same, visually you'd expect: <div>xbar</div><div>bar</div><div>bazx</div>,
// not <div>xbar<div>bar</div><div>bazx</div></div>.
- // Don't do this if the selection started in a Mail blockquote.
- if (m_preventNesting && !startIsInsideMailBlockquote && !isEndOfParagraph(visibleStart) && !isStartOfParagraph(visibleStart)) {
+ if (m_preventNesting && !isEndOfParagraph(visibleStart) && !isStartOfParagraph(visibleStart)) {
insertParagraphSeparator();
setEndingSelection(endingSelection().visibleStart().previous());
}
insertionPos = endingSelection().start();
}
- // We don't want any of the pasted content to end up nested in a Mail blockquote, so first break
- // out of any surrounding Mail blockquotes. Unless we're inserting in a table, in which case
- // breaking the blockquote will prevent the content from actually being inserted in the table.
- if (startIsInsideMailBlockquote && m_preventNesting && !(enclosingNodeOfType(insertionPos, &isTableStructureNode))) {
- applyCommandToComposite(BreakBlockquoteCommand::create(document()));
- // This will leave a br between the split.
- Node* br = endingSelection().start().deprecatedNode();
- ASSERT(br->hasTagName(brTag));
- // Insert content between the two blockquotes, but remove the br (since it was just a placeholder).
- insertionPos = positionInParentBeforeNode(br);
- removeNode(br);
- }
-
// Inserting content could cause whitespace to collapse, e.g. inserting <div>foo</div> into hello^ world.
prepareWhitespaceAtPositionForSplit(insertionPos);
@@ -997,8 +940,7 @@ void ReplaceSelectionCommand::doApply()
startBlock = enclosingBlock(insertionPos.deprecatedNode());
// Adjust insertionPos to prevent nesting.
- // If the start was in a Mail blockquote, we will have already handled adjusting insertionPos above.
- if (m_preventNesting && startBlock && !isTableCell(startBlock) && !startIsInsideMailBlockquote) {
+ if (m_preventNesting && startBlock && !isTableCell(startBlock)) {
ASSERT(startBlock != currentRoot);
VisiblePosition visibleInsertionPos(insertionPos);
if (isEndOfBlock(visibleInsertionPos) && !(isStartOfBlock(visibleInsertionPos) && fragment.hasInterchangeNewlineAtEnd()))
@@ -1145,7 +1087,7 @@ void ReplaceSelectionCommand::doApply()
// the start merge so that the start merge doesn't effect our decision.
m_shouldMergeEnd = shouldMergeEnd(selectionEndWasEndOfParagraph);
- if (shouldMergeStart(selectionStartWasStartOfParagraph, fragment.hasInterchangeNewlineAtStart(), startIsInsideMailBlockquote)) {
+ if (shouldMergeStart(selectionStartWasStartOfParagraph, fragment.hasInterchangeNewlineAtStart())) {
VisiblePosition startOfParagraphToMove = positionAtStartOfInsertedContent();
VisiblePosition destination = startOfParagraphToMove.previous();
// We need to handle the case where we need to merge the end
@@ -1194,8 +1136,7 @@ void ReplaceSelectionCommand::doApply()
} else {
// Use a default paragraph element (a plain div) for the empty paragraph, using the last paragraph
// block's style seems to annoy users.
- insertParagraphSeparator(true, !startIsInsideMailBlockquote && highestEnclosingNodeOfType(endOfInsertedContent.deepEquivalent(),
- isMailBlockquote, CannotCrossEditingBoundary, insertedNodes.firstNodeInserted()->parentNode()));
+ insertParagraphSeparator(true);
}
// Select up to the paragraph separator that was added.
@@ -1210,9 +1151,6 @@ void ReplaceSelectionCommand::doApply()
} else
mergeEndIfNeeded();
- if (Node* mailBlockquote = enclosingNodeOfType(positionAtStartOfInsertedContent().deepEquivalent(), isMailPasteAsQuotationNode))
- removeNodeAttribute(toElement(mailBlockquote), classAttr);
-
if (shouldPerformSmartReplace())
addSpacesForSmartReplace();

Powered by Google App Engine
This is Rietveld 408576698