Commit 908c1a14 authored by xiaochengh's avatar xiaochengh Committed by Commit bot

Prune deprecated functions from ReplaceSelectionCommand

BUG=647219,651373

Review-Url: https://codereview.chromium.org/2395393002
Cr-Commit-Position: refs/heads/master@{#423830}
parent a3e8310c
...@@ -154,8 +154,8 @@ static Position positionAvoidingPrecedingNodes(Position pos) { ...@@ -154,8 +154,8 @@ static Position positionAvoidingPrecedingNodes(Position pos) {
if (nextPosition == pos || if (nextPosition == pos ||
enclosingBlock(nextPosition.computeContainerNode()) != enclosingBlock(nextPosition.computeContainerNode()) !=
enclosingBlockElement || enclosingBlockElement ||
createVisiblePositionDeprecated(pos).deepEquivalent() != createVisiblePosition(pos).deepEquivalent() !=
createVisiblePositionDeprecated(nextPosition).deepEquivalent()) createVisiblePosition(nextPosition).deepEquivalent())
break; break;
} }
return pos; return pos;
...@@ -472,14 +472,14 @@ bool ReplaceSelectionCommand::shouldMergeStart( ...@@ -472,14 +472,14 @@ bool ReplaceSelectionCommand::shouldMergeStart(
// pasted into an unquoted position. If that unquoted position happens to be // 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 // right after another blockquote, we don't want to merge and risk stripping a
// valid block (and newline) from the pasted content. // valid block (and newline) from the pasted content.
if (isStartOfParagraphDeprecated(startOfInsertedContent) && if (isStartOfParagraph(startOfInsertedContent) &&
selectionStartWasInsideMailBlockquote && selectionStartWasInsideMailBlockquote &&
hasMatchingQuoteLevel(prev, positionAtEndOfInsertedContent())) hasMatchingQuoteLevel(prev, positionAtEndOfInsertedContent()))
return true; return true;
return !selectionStartWasStartOfParagraph && return !selectionStartWasStartOfParagraph &&
!fragmentHasInterchangeNewlineAtStart && !fragmentHasInterchangeNewlineAtStart &&
isStartOfParagraphDeprecated(startOfInsertedContent) && isStartOfParagraph(startOfInsertedContent) &&
!isHTMLBRElement( !isHTMLBRElement(
*startOfInsertedContent.deepEquivalent().anchorNode()) && *startOfInsertedContent.deepEquivalent().anchorNode()) &&
shouldMerge(startOfInsertedContent, prev); shouldMerge(startOfInsertedContent, prev);
...@@ -494,7 +494,7 @@ bool ReplaceSelectionCommand::shouldMergeEnd( ...@@ -494,7 +494,7 @@ bool ReplaceSelectionCommand::shouldMergeEnd(
return false; return false;
return !selectionEndWasEndOfParagraph && return !selectionEndWasEndOfParagraph &&
isEndOfParagraphDeprecated(endOfInsertedContent) && isEndOfParagraph(endOfInsertedContent) &&
!isHTMLBRElement( !isHTMLBRElement(
*endOfInsertedContent.deepEquivalent().anchorNode()) && *endOfInsertedContent.deepEquivalent().anchorNode()) &&
shouldMerge(endOfInsertedContent, next); shouldMerge(endOfInsertedContent, next);
...@@ -755,8 +755,9 @@ void ReplaceSelectionCommand::moveElementOutOfAncestor( ...@@ -755,8 +755,9 @@ void ReplaceSelectionCommand::moveElementOutOfAncestor(
if (!hasEditableStyle(*ancestor->parentNode())) if (!hasEditableStyle(*ancestor->parentNode()))
return; return;
document().updateStyleAndLayoutIgnorePendingStylesheets();
VisiblePosition positionAtEndOfNode = VisiblePosition positionAtEndOfNode =
createVisiblePositionDeprecated(lastPositionInOrAfterNode(element)); createVisiblePosition(lastPositionInOrAfterNode(element));
VisiblePosition lastPositionInParagraph = VisiblePosition lastPositionInParagraph =
VisiblePosition::lastPositionInNode(ancestor); VisiblePosition::lastPositionInNode(ancestor);
if (positionAtEndOfNode.deepEquivalent() == if (positionAtEndOfNode.deepEquivalent() ==
...@@ -817,24 +818,27 @@ void ReplaceSelectionCommand::removeUnrenderedTextNodesAtEnds( ...@@ -817,24 +818,27 @@ void ReplaceSelectionCommand::removeUnrenderedTextNodesAtEnds(
VisiblePosition ReplaceSelectionCommand::positionAtEndOfInsertedContent() VisiblePosition ReplaceSelectionCommand::positionAtEndOfInsertedContent()
const { const {
// TODO(xiaochengh): Hoist the call and change it into a DCHECK.
document().updateStyleAndLayoutIgnorePendingStylesheets();
// TODO(yosin): We should set |m_endOfInsertedContent| not in SELECT // TODO(yosin): We should set |m_endOfInsertedContent| not in SELECT
// element, since contents of SELECT elements, e.g. OPTION, OPTGROUP, are // element, since contents of SELECT elements, e.g. OPTION, OPTGROUP, are
// not editable, or SELECT element is an atomic on editing. // not editable, or SELECT element is an atomic on editing.
HTMLSelectElement* enclosingSelect = toHTMLSelectElement( HTMLSelectElement* enclosingSelect = toHTMLSelectElement(
enclosingElementWithTag(m_endOfInsertedContent, selectTag)); enclosingElementWithTag(m_endOfInsertedContent, selectTag));
if (enclosingSelect) if (enclosingSelect)
return createVisiblePositionDeprecated( return createVisiblePosition(lastPositionInOrAfterNode(enclosingSelect));
lastPositionInOrAfterNode(enclosingSelect));
if (m_endOfInsertedContent.isOrphan()) if (m_endOfInsertedContent.isOrphan())
return VisiblePosition(); return VisiblePosition();
return createVisiblePositionDeprecated(m_endOfInsertedContent); return createVisiblePosition(m_endOfInsertedContent);
} }
VisiblePosition ReplaceSelectionCommand::positionAtStartOfInsertedContent() VisiblePosition ReplaceSelectionCommand::positionAtStartOfInsertedContent()
const { const {
// TODO(xiaochengh): Hoist the call and change it into a DCHECK.
document().updateStyleAndLayoutIgnorePendingStylesheets();
if (m_startOfInsertedContent.isOrphan()) if (m_startOfInsertedContent.isOrphan())
return VisiblePosition(); return VisiblePosition();
return createVisiblePositionDeprecated(m_startOfInsertedContent); return createVisiblePosition(m_startOfInsertedContent);
} }
static void removeHeadContents(ReplacementFragment& fragment) { static void removeHeadContents(ReplacementFragment& fragment) {
...@@ -1005,20 +1009,21 @@ void ReplaceSelectionCommand::mergeEndIfNeeded(EditingState* editingState) { ...@@ -1005,20 +1009,21 @@ void ReplaceSelectionCommand::mergeEndIfNeeded(EditingState* editingState) {
// paragraph already in the document, unless the paragraph to move would // paragraph already in the document, unless the paragraph to move would
// include the what was the start of the selection that was pasted into, so // include the what was the start of the selection that was pasted into, so
// that we preserve that paragraph's block styles. // that we preserve that paragraph's block styles.
bool mergeForward = !( bool mergeForward =
inSameParagraphDeprecated(startOfInsertedContent, endOfInsertedContent) && !(inSameParagraph(startOfInsertedContent, endOfInsertedContent) &&
!isStartOfParagraphDeprecated(startOfInsertedContent)); !isStartOfParagraph(startOfInsertedContent));
VisiblePosition destination = mergeForward VisiblePosition destination = mergeForward
? nextPositionOf(endOfInsertedContent) ? nextPositionOf(endOfInsertedContent)
: endOfInsertedContent; : endOfInsertedContent;
// TODO(xiaochengh): Stop storing VisiblePositions through mutations.
VisiblePosition startOfParagraphToMove = VisiblePosition startOfParagraphToMove =
mergeForward ? startOfParagraphDeprecated(endOfInsertedContent) mergeForward ? startOfParagraph(endOfInsertedContent)
: nextPositionOf(endOfInsertedContent); : nextPositionOf(endOfInsertedContent);
// Merging forward could result in deleting the destination anchor node. // Merging forward could result in deleting the destination anchor node.
// To avoid this, we add a placeholder node before the start of the paragraph. // To avoid this, we add a placeholder node before the start of the paragraph.
if (endOfParagraphDeprecated(startOfParagraphToMove).deepEquivalent() == if (endOfParagraph(startOfParagraphToMove).deepEquivalent() ==
destination.deepEquivalent()) { destination.deepEquivalent()) {
HTMLBRElement* placeholder = HTMLBRElement::create(document()); HTMLBRElement* placeholder = HTMLBRElement::create(document());
insertNodeBefore(placeholder, insertNodeBefore(placeholder,
...@@ -1026,22 +1031,26 @@ void ReplaceSelectionCommand::mergeEndIfNeeded(EditingState* editingState) { ...@@ -1026,22 +1031,26 @@ void ReplaceSelectionCommand::mergeEndIfNeeded(EditingState* editingState) {
editingState); editingState);
if (editingState->isAborted()) if (editingState->isAborted())
return; return;
document().updateStyleAndLayoutIgnorePendingStylesheets();
destination = VisiblePosition::beforeNode(placeholder); destination = VisiblePosition::beforeNode(placeholder);
startOfParagraphToMove =
createVisiblePosition(startOfParagraphToMove.toPositionWithAffinity());
} }
moveParagraph(startOfParagraphToMove, moveParagraph(startOfParagraphToMove, endOfParagraph(startOfParagraphToMove),
endOfParagraphDeprecated(startOfParagraphToMove), destination, destination, editingState);
editingState);
if (editingState->isAborted()) if (editingState->isAborted())
return; return;
document().updateStyleAndLayoutIgnorePendingStylesheets();
// Merging forward will remove m_endOfInsertedContent from the document. // Merging forward will remove m_endOfInsertedContent from the document.
if (mergeForward) { if (mergeForward) {
if (m_startOfInsertedContent.isOrphan()) if (m_startOfInsertedContent.isOrphan()) {
m_startOfInsertedContent = m_startOfInsertedContent =
endingSelection().visibleStartDeprecated().deepEquivalent(); endingSelection().visibleStart().deepEquivalent();
m_endOfInsertedContent = }
endingSelection().visibleEndDeprecated().deepEquivalent(); m_endOfInsertedContent = endingSelection().visibleEnd().deepEquivalent();
// If we merged text nodes, m_endOfInsertedContent could be null. If // If we merged text nodes, m_endOfInsertedContent could be null. If
// this is the case, we use m_startOfInsertedContent. // this is the case, we use m_startOfInsertedContent.
if (m_endOfInsertedContent.isNull()) if (m_endOfInsertedContent.isNull())
...@@ -1124,6 +1133,8 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) { ...@@ -1124,6 +1133,8 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) {
if (trivialReplaceResult) if (trivialReplaceResult)
return; return;
document().updateStyleAndLayoutIgnorePendingStylesheets();
// We can skip matching the style if the selection is plain text. // We can skip matching the style if the selection is plain text.
if ((selection.start().anchorNode()->layoutObject() && if ((selection.start().anchorNode()->layoutObject() &&
selection.start().anchorNode()->layoutObject()->style()->userModify() == selection.start().anchorNode()->layoutObject()->style()->userModify() ==
...@@ -1138,13 +1149,12 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) { ...@@ -1138,13 +1149,12 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) {
m_insertionStyle->mergeTypingStyle(&document()); m_insertionStyle->mergeTypingStyle(&document());
} }
const VisiblePosition visibleStart = selection.visibleStartDeprecated(); const VisiblePosition visibleStart = selection.visibleStart();
const VisiblePosition visibleEnd = selection.visibleEndDeprecated(); const VisiblePosition visibleEnd = selection.visibleEnd();
const bool selectionEndWasEndOfParagraph = const bool selectionEndWasEndOfParagraph = isEndOfParagraph(visibleEnd);
isEndOfParagraphDeprecated(visibleEnd);
const bool selectionStartWasStartOfParagraph = const bool selectionStartWasStartOfParagraph =
isStartOfParagraphDeprecated(visibleStart); isStartOfParagraph(visibleStart);
Element* enclosingBlockOfVisibleStart = Element* enclosingBlockOfVisibleStart =
enclosingBlock(visibleStart.deepEquivalent().anchorNode()); enclosingBlock(visibleStart.deepEquivalent().anchorNode());
...@@ -1170,7 +1180,7 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) { ...@@ -1170,7 +1180,7 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) {
// Merge blocks if the start of the selection was in a Mail blockquote, // Merge blocks if the start of the selection was in a Mail blockquote,
// since we handle that case specially to prevent nesting. // since we handle that case specially to prevent nesting.
bool mergeBlocksAfterDelete = startIsInsideMailBlockquote || bool mergeBlocksAfterDelete = startIsInsideMailBlockquote ||
isEndOfParagraphDeprecated(visibleEnd) || isEndOfParagraph(visibleEnd) ||
isStartOfBlock(visibleStart); isStartOfBlock(visibleStart);
// FIXME: We should only expand to include fully selected special elements // FIXME: We should only expand to include fully selected special elements
// if we are copying a selection and pasting it on top of itself. // if we are copying a selection and pasting it on top of itself.
...@@ -1178,10 +1188,10 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) { ...@@ -1178,10 +1188,10 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) {
if (editingState->isAborted()) if (editingState->isAborted())
return; return;
if (fragment.hasInterchangeNewlineAtStart()) { if (fragment.hasInterchangeNewlineAtStart()) {
VisiblePosition startAfterDelete = document().updateStyleAndLayoutIgnorePendingStylesheets();
endingSelection().visibleStartDeprecated(); VisiblePosition startAfterDelete = endingSelection().visibleStart();
if (isEndOfParagraphDeprecated(startAfterDelete) && if (isEndOfParagraph(startAfterDelete) &&
!isStartOfParagraphDeprecated(startAfterDelete) && !isStartOfParagraph(startAfterDelete) &&
!isEndOfEditableOrNonEditableContent(startAfterDelete)) !isEndOfEditableOrNonEditableContent(startAfterDelete))
setEndingSelection(nextPositionOf(startAfterDelete)); setEndingSelection(nextPositionOf(startAfterDelete));
else else
...@@ -1194,13 +1204,15 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) { ...@@ -1194,13 +1204,15 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) {
if (fragment.hasInterchangeNewlineAtStart()) { if (fragment.hasInterchangeNewlineAtStart()) {
const VisiblePosition next = const VisiblePosition next =
nextPositionOf(visibleStart, CannotCrossEditingBoundary); nextPositionOf(visibleStart, CannotCrossEditingBoundary);
if (isEndOfParagraphDeprecated(visibleStart) && if (isEndOfParagraph(visibleStart) && !isStartOfParagraph(visibleStart) &&
!isStartOfParagraphDeprecated(visibleStart) && next.isNotNull()) next.isNotNull()) {
setEndingSelection(next); setEndingSelection(next);
else } else {
insertParagraphSeparator(editingState); insertParagraphSeparator(editingState);
if (editingState->isAborted()) if (editingState->isAborted())
return; return;
document().updateStyleAndLayoutIgnorePendingStylesheets();
}
} }
// We split the current paragraph in two to avoid nesting the blocks from // We split the current paragraph in two to avoid nesting the blocks from
// the fragment inside the current block. // the fragment inside the current block.
...@@ -1217,15 +1229,13 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) { ...@@ -1217,15 +1229,13 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) {
// <div>xbar<div>bar</div><div>bazx</div></div> // <div>xbar<div>bar</div><div>bazx</div></div>
// Don't do this if the selection started in a Mail blockquote. // Don't do this if the selection started in a Mail blockquote.
if (m_preventNesting && !startIsInsideMailBlockquote && if (m_preventNesting && !startIsInsideMailBlockquote &&
!isEndOfParagraphDeprecated( !isEndOfParagraph(endingSelection().visibleStart()) &&
endingSelection().visibleStartDeprecated()) && !isStartOfParagraph(endingSelection().visibleStart())) {
!isStartOfParagraphDeprecated(
endingSelection().visibleStartDeprecated())) {
insertParagraphSeparator(editingState); insertParagraphSeparator(editingState);
if (editingState->isAborted()) if (editingState->isAborted())
return; return;
setEndingSelection( document().updateStyleAndLayoutIgnorePendingStylesheets();
previousPositionOf(endingSelection().visibleStartDeprecated())); setEndingSelection(previousPositionOf(endingSelection().visibleStart()));
} }
} }
...@@ -1257,6 +1267,8 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) { ...@@ -1257,6 +1267,8 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) {
// <div>foo</div> into hello^ world. // <div>foo</div> into hello^ world.
prepareWhitespaceAtPositionForSplit(insertionPos); prepareWhitespaceAtPositionForSplit(insertionPos);
document().updateStyleAndLayoutIgnorePendingStylesheets();
// If the downstream node has been removed there's no point in continuing. // If the downstream node has been removed there's no point in continuing.
if (!mostForwardCaretPosition(insertionPos).anchorNode()) if (!mostForwardCaretPosition(insertionPos).anchorNode())
return; return;
...@@ -1285,8 +1297,7 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) { ...@@ -1285,8 +1297,7 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) {
enclosingBlockOfInsertionPos != currentRoot && enclosingBlockOfInsertionPos != currentRoot &&
!isTableCell(enclosingBlockOfInsertionPos) && !isTableCell(enclosingBlockOfInsertionPos) &&
!startIsInsideMailBlockquote) { !startIsInsideMailBlockquote) {
VisiblePosition visibleInsertionPos = VisiblePosition visibleInsertionPos = createVisiblePosition(insertionPos);
createVisiblePositionDeprecated(insertionPos);
if (isEndOfBlock(visibleInsertionPos) && if (isEndOfBlock(visibleInsertionPos) &&
!(isStartOfBlock(visibleInsertionPos) && !(isStartOfBlock(visibleInsertionPos) &&
fragment.hasInterchangeNewlineAtEnd())) fragment.hasInterchangeNewlineAtEnd()))
...@@ -1310,6 +1321,8 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) { ...@@ -1310,6 +1321,8 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) {
removeHeadContents(fragment); removeHeadContents(fragment);
document().updateStyleAndLayoutIgnorePendingStylesheets();
// We don't want the destination to end up inside nodes that weren't selected. // We don't want the destination to end up inside nodes that weren't selected.
// To avoid that, we move the position forward without changing the visible // To avoid that, we move the position forward without changing the visible
// position so we're still at the same visible location, but outside of // position so we're still at the same visible location, but outside of
...@@ -1430,6 +1443,8 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) { ...@@ -1430,6 +1443,8 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) {
return; return;
} }
document().updateStyleAndLayoutIgnorePendingStylesheets();
// Mutation events (bug 20161) may have already removed the inserted content // Mutation events (bug 20161) may have already removed the inserted content
if (!insertedNodes.firstNodeInserted() || if (!insertedNodes.firstNodeInserted() ||
!insertedNodes.firstNodeInserted()->isConnected()) !insertedNodes.firstNodeInserted()->isConnected())
...@@ -1442,7 +1457,7 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) { ...@@ -1442,7 +1457,7 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) {
!enclosingBlockOfInsertionPos->isConnected()) !enclosingBlockOfInsertionPos->isConnected())
enclosingBlockOfInsertionPos = nullptr; enclosingBlockOfInsertionPos = nullptr;
VisiblePosition startOfInsertedContent = createVisiblePositionDeprecated( VisiblePosition startOfInsertedContent = createVisiblePosition(
firstPositionInOrBeforeNode(insertedNodes.firstNodeInserted())); firstPositionInOrBeforeNode(insertedNodes.firstNodeInserted()));
// We inserted before the enclosingBlockOfInsertionPos to prevent nesting, and // We inserted before the enclosingBlockOfInsertionPos to prevent nesting, and
...@@ -1453,7 +1468,7 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) { ...@@ -1453,7 +1468,7 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) {
insertionPos.anchorNode() == enclosingBlockOfInsertionPos->parentNode() && insertionPos.anchorNode() == enclosingBlockOfInsertionPos->parentNode() &&
(unsigned)insertionPos.computeEditingOffset() < (unsigned)insertionPos.computeEditingOffset() <
enclosingBlockOfInsertionPos->nodeIndex() && enclosingBlockOfInsertionPos->nodeIndex() &&
!isStartOfParagraphDeprecated(startOfInsertedContent)) { !isStartOfParagraph(startOfInsertedContent)) {
insertNodeAt(HTMLBRElement::create(document()), insertNodeAt(HTMLBRElement::create(document()),
startOfInsertedContent.deepEquivalent(), editingState); startOfInsertedContent.deepEquivalent(), editingState);
if (editingState->isAborted()) if (editingState->isAborted())
...@@ -1510,6 +1525,7 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) { ...@@ -1510,6 +1525,7 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) {
if (shouldMergeStart(selectionStartWasStartOfParagraph, if (shouldMergeStart(selectionStartWasStartOfParagraph,
fragment.hasInterchangeNewlineAtStart(), fragment.hasInterchangeNewlineAtStart(),
startIsInsideMailBlockquote)) { startIsInsideMailBlockquote)) {
// TODO(xiaochengh): Stop storing VisiblePositions through mutations.
VisiblePosition startOfParagraphToMove = positionAtStartOfInsertedContent(); VisiblePosition startOfParagraphToMove = positionAtStartOfInsertedContent();
VisiblePosition destination = previousPositionOf(startOfParagraphToMove); VisiblePosition destination = previousPositionOf(startOfParagraphToMove);
// We need to handle the case where we need to merge the end // We need to handle the case where we need to merge the end
...@@ -1536,7 +1552,7 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) { ...@@ -1536,7 +1552,7 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) {
// Insert a line break just after the inserted content to separate it from // Insert a line break just after the inserted content to separate it from
// what comes after and prevent that from happening. // what comes after and prevent that from happening.
VisiblePosition endOfInsertedContent = positionAtEndOfInsertedContent(); VisiblePosition endOfInsertedContent = positionAtEndOfInsertedContent();
if (startOfParagraphDeprecated(endOfInsertedContent).deepEquivalent() == if (startOfParagraph(endOfInsertedContent).deepEquivalent() ==
startOfParagraphToMove.deepEquivalent()) { startOfParagraphToMove.deepEquivalent()) {
insertNodeAt(HTMLBRElement::create(document()), insertNodeAt(HTMLBRElement::create(document()),
endOfInsertedContent.deepEquivalent(), editingState); endOfInsertedContent.deepEquivalent(), editingState);
...@@ -1548,19 +1564,25 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) { ...@@ -1548,19 +1564,25 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) {
return; return;
} }
document().updateStyleAndLayoutIgnorePendingStylesheets();
// FIXME: Maintain positions for the start and end of inserted content // FIXME: Maintain positions for the start and end of inserted content
// instead of keeping nodes. The nodes are only ever used to create // instead of keeping nodes. The nodes are only ever used to create
// positions where inserted content starts/ends. // positions where inserted content starts/ends.
moveParagraph(startOfParagraphToMove, moveParagraph(startOfParagraphToMove,
endOfParagraphDeprecated(startOfParagraphToMove), destination, endOfParagraph(createVisiblePosition(
editingState); startOfParagraphToMove.toPositionWithAffinity())),
destination, editingState);
if (editingState->isAborted()) if (editingState->isAborted())
return; return;
document().updateStyleAndLayoutIgnorePendingStylesheets();
m_startOfInsertedContent = mostForwardCaretPosition( m_startOfInsertedContent = mostForwardCaretPosition(
endingSelection().visibleStartDeprecated().deepEquivalent()); endingSelection().visibleStart().deepEquivalent());
if (m_endOfInsertedContent.isOrphan()) if (m_endOfInsertedContent.isOrphan()) {
m_endOfInsertedContent = mostBackwardCaretPosition( m_endOfInsertedContent = mostBackwardCaretPosition(
endingSelection().visibleEndDeprecated().deepEquivalent()); endingSelection().visibleEnd().deepEquivalent());
}
} }
Position lastPositionToSelect; Position lastPositionToSelect;
...@@ -1570,7 +1592,7 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) { ...@@ -1570,7 +1592,7 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) {
nextPositionOf(endOfInsertedContent, CannotCrossEditingBoundary); nextPositionOf(endOfInsertedContent, CannotCrossEditingBoundary);
if (selectionEndWasEndOfParagraph || if (selectionEndWasEndOfParagraph ||
!isEndOfParagraphDeprecated(endOfInsertedContent) || next.isNull()) { !isEndOfParagraph(endOfInsertedContent) || next.isNull()) {
if (HTMLTextFormControlElement* textControl = if (HTMLTextFormControlElement* textControl =
enclosingTextFormControl(currentRoot)) { enclosingTextFormControl(currentRoot)) {
if (!insertedNodes.lastLeafInserted()->nextSibling()) { if (!insertedNodes.lastLeafInserted()->nextSibling()) {
...@@ -1583,8 +1605,8 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) { ...@@ -1583,8 +1605,8 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) {
VisiblePosition::afterNode(insertedNodes.lastLeafInserted())); VisiblePosition::afterNode(insertedNodes.lastLeafInserted()));
// Select up to the paragraph separator that was added. // Select up to the paragraph separator that was added.
lastPositionToSelect = lastPositionToSelect =
endingSelection().visibleStartDeprecated().deepEquivalent(); endingSelection().visibleStart().deepEquivalent();
} else if (!isStartOfParagraphDeprecated(endOfInsertedContent)) { } else if (!isStartOfParagraph(endOfInsertedContent)) {
setEndingSelection(endOfInsertedContent); setEndingSelection(endOfInsertedContent);
Element* enclosingBlockElement = Element* enclosingBlockElement =
enclosingBlock(endOfInsertedContent.deepEquivalent().anchorNode()); enclosingBlock(endOfInsertedContent.deepEquivalent().anchorNode());
...@@ -1609,9 +1631,11 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) { ...@@ -1609,9 +1631,11 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) {
return; return;
} }
document().updateStyleAndLayoutIgnorePendingStylesheets();
// Select up to the paragraph separator that was added. // Select up to the paragraph separator that was added.
lastPositionToSelect = lastPositionToSelect =
endingSelection().visibleStartDeprecated().deepEquivalent(); endingSelection().visibleStart().deepEquivalent();
updateNodesInserted(lastPositionToSelect.anchorNode()); updateNodesInserted(lastPositionToSelect.anchorNode());
} }
} else { } else {
...@@ -1658,15 +1682,14 @@ bool ReplaceSelectionCommand::shouldRemoveEndBR( ...@@ -1658,15 +1682,14 @@ bool ReplaceSelectionCommand::shouldRemoveEndBR(
// Remove the br if it is collapsed away and so is unnecessary. // Remove the br if it is collapsed away and so is unnecessary.
if (!document().inNoQuirksMode() && isEndOfBlock(visiblePos) && if (!document().inNoQuirksMode() && isEndOfBlock(visiblePos) &&
!isStartOfParagraphDeprecated(visiblePos)) !isStartOfParagraph(visiblePos))
return true; return true;
// A br that was originally holding a line open should be displaced by // A br that was originally holding a line open should be displaced by
// inserted content or turned into a line break. // inserted content or turned into a line break.
// A br that was originally acting as a line break should still be acting as a // A br that was originally acting as a line break should still be acting as a
// line break, not as a placeholder. // line break, not as a placeholder.
return isStartOfParagraphDeprecated(visiblePos) && return isStartOfParagraph(visiblePos) && isEndOfParagraph(visiblePos);
isEndOfParagraphDeprecated(visiblePos);
} }
bool ReplaceSelectionCommand::shouldPerformSmartReplace() const { bool ReplaceSelectionCommand::shouldPerformSmartReplace() const {
...@@ -1703,7 +1726,7 @@ void ReplaceSelectionCommand::addSpacesForSmartReplace( ...@@ -1703,7 +1726,7 @@ void ReplaceSelectionCommand::addSpacesForSmartReplace(
} }
bool needsTrailingSpace = bool needsTrailingSpace =
!isEndOfParagraphDeprecated(endOfInsertedContent) && !isEndOfParagraph(endOfInsertedContent) &&
!isCharacterSmartReplaceExemptConsideringNonBreakingSpace( !isCharacterSmartReplaceExemptConsideringNonBreakingSpace(
characterAfter(endOfInsertedContent), false); characterAfter(endOfInsertedContent), false);
if (needsTrailingSpace && endNode) { if (needsTrailingSpace && endNode) {
...@@ -1742,7 +1765,7 @@ void ReplaceSelectionCommand::addSpacesForSmartReplace( ...@@ -1742,7 +1765,7 @@ void ReplaceSelectionCommand::addSpacesForSmartReplace(
} }
bool needsLeadingSpace = bool needsLeadingSpace =
!isStartOfParagraphDeprecated(startOfInsertedContent) && !isStartOfParagraph(startOfInsertedContent) &&
!isCharacterSmartReplaceExemptConsideringNonBreakingSpace( !isCharacterSmartReplaceExemptConsideringNonBreakingSpace(
characterBefore(startOfInsertedContent), true); characterBefore(startOfInsertedContent), true);
if (needsLeadingSpace && startNode) { if (needsLeadingSpace && startNode) {
...@@ -1806,11 +1829,13 @@ void ReplaceSelectionCommand::completeHTMLReplacement( ...@@ -1806,11 +1829,13 @@ void ReplaceSelectionCommand::completeHTMLReplacement(
m_startOfInsertedRange = start; m_startOfInsertedRange = start;
m_endOfInsertedRange = end; m_endOfInsertedRange = end;
document().updateStyleAndLayoutIgnorePendingStylesheets();
if (m_selectReplacement) if (m_selectReplacement)
setEndingSelection(createVisibleSelectionDeprecated( setEndingSelection(createVisibleSelection(
start, end, SelDefaultAffinity, endingSelection().isDirectional())); start, end, SelDefaultAffinity, endingSelection().isDirectional()));
else else
setEndingSelection(createVisibleSelectionDeprecated( setEndingSelection(createVisibleSelection(
end, SelDefaultAffinity, endingSelection().isDirectional())); end, SelDefaultAffinity, endingSelection().isDirectional()));
} }
...@@ -1922,10 +1947,9 @@ Node* ReplaceSelectionCommand::insertAsListItems(HTMLElement* listElement, ...@@ -1922,10 +1947,9 @@ Node* ReplaceSelectionCommand::insertAsListItems(HTMLElement* listElement,
isHTMLListElement(listElement->firstChild())) isHTMLListElement(listElement->firstChild()))
listElement = toHTMLElement(listElement->firstChild()); listElement = toHTMLElement(listElement->firstChild());
bool isStart = document().updateStyleAndLayoutIgnorePendingStylesheets();
isStartOfParagraphDeprecated(createVisiblePositionDeprecated(insertPos)); bool isStart = isStartOfParagraph(createVisiblePosition(insertPos));
bool isEnd = bool isEnd = isEndOfParagraph(createVisiblePosition(insertPos));
isEndOfParagraphDeprecated(createVisiblePositionDeprecated(insertPos));
bool isMiddle = !isStart && !isEnd; bool isMiddle = !isStart && !isEnd;
Node* lastNode = insertionBlock; Node* lastNode = insertionBlock;
...@@ -2020,8 +2044,9 @@ bool ReplaceSelectionCommand::performTrivialReplace( ...@@ -2020,8 +2044,9 @@ bool ReplaceSelectionCommand::performTrivialReplace(
m_startOfInsertedRange = start; m_startOfInsertedRange = start;
m_endOfInsertedRange = end; m_endOfInsertedRange = end;
document().updateStyleAndLayoutIgnorePendingStylesheets();
VisibleSelection selectionAfterReplace = VisibleSelection selectionAfterReplace =
createVisibleSelectionDeprecated(m_selectReplacement ? start : end, end); createVisibleSelection(m_selectReplacement ? start : end, end);
setEndingSelection(selectionAfterReplace); setEndingSelection(selectionAfterReplace);
......
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