Index: Source/core/editing/CompositeEditCommand.cpp |
diff --git a/Source/core/editing/CompositeEditCommand.cpp b/Source/core/editing/CompositeEditCommand.cpp |
index 3cda9358a6b8e38d6f28f91aefa35da7d821d0c9..0d1079292aac91956df0635200139c303d742ff9 100644 |
--- a/Source/core/editing/CompositeEditCommand.cpp |
+++ b/Source/core/editing/CompositeEditCommand.cpp |
@@ -158,7 +158,7 @@ void applyCommand(PassRefPtr<CompositeEditCommand> command) |
command->apply(); |
} |
-CompositeEditCommand::CompositeEditCommand(Document *document) |
+CompositeEditCommand::CompositeEditCommand(Document& document) |
: EditCommand(document) |
{ |
} |
@@ -189,10 +189,9 @@ void CompositeEditCommand::apply() |
// Changes to the document may have been made since the last editing operation that require a layout, as in <rdar://problem/5658603>. |
// Low level operations, like RemoveNodeCommand, don't require a layout because the high level operations that use them perform one |
// if one is necessary (like for the creation of VisiblePositions). |
- ASSERT(document()); |
- document()->updateLayoutIgnorePendingStylesheets(); |
+ document().updateLayoutIgnorePendingStylesheets(); |
- Frame* frame = document()->frame(); |
+ Frame* frame = document().frame(); |
ASSERT(frame); |
{ |
EventQueueScope scope; |
@@ -212,7 +211,7 @@ EditCommandComposition* CompositeEditCommand::ensureComposition() |
while (command && command->parent()) |
command = command->parent(); |
if (!command->m_composition) |
- command->m_composition = EditCommandComposition::create(document(), startingSelection(), endingSelection(), editingAction()); |
+ command->m_composition = EditCommandComposition::create(&document(), startingSelection(), endingSelection(), editingAction()); |
return command->m_composition.get(); |
} |
@@ -518,11 +517,11 @@ static void copyMarkers(const Vector<DocumentMarker*>& markerPointers, Vector<Do |
void CompositeEditCommand::replaceTextInNodePreservingMarkers(PassRefPtr<Text> prpNode, unsigned offset, unsigned count, const String& replacementText) |
{ |
RefPtr<Text> node(prpNode); |
- DocumentMarkerController* markerController = document()->markers(); |
+ DocumentMarkerController* markerController = document().markers(); |
Vector<DocumentMarker> markers; |
- copyMarkers(markerController->markersInRange(Range::create(document(), node.get(), offset, node.get(), offset + count).get(), DocumentMarker::AllMarkers()), markers); |
+ copyMarkers(markerController->markersInRange(Range::create(&document(), node.get(), offset, node.get(), offset + count).get(), DocumentMarker::AllMarkers()), markers); |
replaceTextInNode(node, offset, count, replacementText); |
- RefPtr<Range> newRange = Range::create(document(), node.get(), offset, node.get(), offset + replacementText.length()); |
+ RefPtr<Range> newRange = Range::create(&document(), node.get(), offset, node.get(), offset + replacementText.length()); |
for (size_t i = 0; i < markers.size(); ++i) |
markerController->addMarker(newRange.get(), markers[i].type(), markers[i].description()); |
} |
@@ -719,7 +718,7 @@ void CompositeEditCommand::deleteInsignificantText(PassRefPtr<Text> textNode, un |
if (!textNode || start >= end) |
return; |
- document()->updateLayout(); |
+ document().updateLayout(); |
RenderText* textRenderer = toRenderText(textNode->renderer()); |
if (!textRenderer) |
@@ -830,12 +829,12 @@ PassRefPtr<Node> CompositeEditCommand::appendBlockPlaceholder(PassRefPtr<Element |
if (!container) |
return 0; |
- document()->updateLayoutIgnorePendingStylesheets(); |
+ document().updateLayoutIgnorePendingStylesheets(); |
// Should assert isBlockFlow || isInlineFlow when deletion improves. See 4244964. |
ASSERT(container->renderer()); |
- RefPtr<Node> placeholder = createBlockPlaceholderElement(document()); |
+ RefPtr<Node> placeholder = createBlockPlaceholderElement(&document()); |
appendNode(placeholder, container); |
return placeholder.release(); |
} |
@@ -848,7 +847,7 @@ PassRefPtr<Node> CompositeEditCommand::insertBlockPlaceholder(const Position& po |
// Should assert isBlockFlow || isInlineFlow when deletion improves. See 4244964. |
ASSERT(pos.deprecatedNode()->renderer()); |
- RefPtr<Node> placeholder = createBlockPlaceholderElement(document()); |
+ RefPtr<Node> placeholder = createBlockPlaceholderElement(&document()); |
insertNodeAt(placeholder, pos); |
return placeholder.release(); |
} |
@@ -858,7 +857,7 @@ PassRefPtr<Node> CompositeEditCommand::addBlockPlaceholderIfNeeded(Element* cont |
if (!container) |
return 0; |
- document()->updateLayoutIgnorePendingStylesheets(); |
+ document().updateLayoutIgnorePendingStylesheets(); |
RenderObject* renderer = container->renderer(); |
if (!renderer || !renderer->isBlockFlow()) |
@@ -889,8 +888,8 @@ void CompositeEditCommand::removePlaceholderAt(const Position& p) |
PassRefPtr<Node> CompositeEditCommand::insertNewDefaultParagraphElementAt(const Position& position) |
{ |
- RefPtr<Element> paragraphElement = createDefaultParagraphElement(document()); |
- paragraphElement->appendChild(createBreakElement(document())); |
+ RefPtr<Element> paragraphElement = createDefaultParagraphElement(&document()); |
+ paragraphElement->appendChild(createBreakElement(&document())); |
insertNodeAt(paragraphElement, position); |
return paragraphElement.release(); |
} |
@@ -902,7 +901,7 @@ PassRefPtr<Node> CompositeEditCommand::moveParagraphContentsToNewBlockIfNecessar |
if (pos.isNull()) |
return 0; |
- document()->updateLayoutIgnorePendingStylesheets(); |
+ document().updateLayoutIgnorePendingStylesheets(); |
// It's strange that this function is responsible for verifying that pos has not been invalidated |
// by an earlier call to this function. The caller, applyBlockStyle, should do this. |
@@ -1127,7 +1126,7 @@ void CompositeEditCommand::moveParagraphWithClones(const VisiblePosition& startO |
if (beforeParagraph.isNotNull() && !isTableElement(beforeParagraph.deepEquivalent().deprecatedNode()) |
&& ((!isEndOfParagraph(beforeParagraph) && !isStartOfParagraph(beforeParagraph)) || beforeParagraph == afterParagraph)) { |
// FIXME: Trim text between beforeParagraph and afterParagraph if they aren't equal. |
- insertNodeAt(createBreakElement(document()), beforeParagraph.deepEquivalent()); |
+ insertNodeAt(createBreakElement(&document()), beforeParagraph.deepEquivalent()); |
} |
} |
@@ -1160,13 +1159,13 @@ void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap |
startIndex = 0; |
if (startInParagraph) { |
- RefPtr<Range> startRange = Range::create(document(), startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), visibleStart.deepEquivalent().parentAnchoredEquivalent()); |
+ RefPtr<Range> startRange = Range::create(&document(), startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), visibleStart.deepEquivalent().parentAnchoredEquivalent()); |
startIndex = TextIterator::rangeLength(startRange.get(), true); |
} |
endIndex = 0; |
if (endInParagraph) { |
- RefPtr<Range> endRange = Range::create(document(), startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), visibleEnd.deepEquivalent().parentAnchoredEquivalent()); |
+ RefPtr<Range> endRange = Range::create(&document(), startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), visibleEnd.deepEquivalent().parentAnchoredEquivalent()); |
endIndex = TextIterator::rangeLength(endRange.get(), true); |
} |
} |
@@ -1183,12 +1182,12 @@ void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap |
// start and end can't be used directly to create a Range; they are "editing positions" |
Position startRangeCompliant = start.parentAnchoredEquivalent(); |
Position endRangeCompliant = end.parentAnchoredEquivalent(); |
- RefPtr<Range> range = Range::create(document(), startRangeCompliant.deprecatedNode(), startRangeCompliant.deprecatedEditingOffset(), endRangeCompliant.deprecatedNode(), endRangeCompliant.deprecatedEditingOffset()); |
+ RefPtr<Range> range = Range::create(&document(), startRangeCompliant.deprecatedNode(), startRangeCompliant.deprecatedEditingOffset(), endRangeCompliant.deprecatedNode(), endRangeCompliant.deprecatedEditingOffset()); |
// FIXME: This is an inefficient way to preserve style on nodes in the paragraph to move. It |
// shouldn't matter though, since moved paragraphs will usually be quite small. |
RefPtr<DocumentFragment> fragment = startOfParagraphToMove != endOfParagraphToMove ? |
- createFragmentFromMarkup(document(), createMarkup(range.get(), 0, DoNotAnnotateForInterchange, true, DoNotResolveURLs, constrainingAncestor), "") : 0; |
+ createFragmentFromMarkup(&document(), createMarkup(range.get(), 0, DoNotAnnotateForInterchange, true, DoNotResolveURLs, constrainingAncestor), "") : 0; |
// A non-empty paragraph's style is moved when we copy and move it. We don't move |
// anything if we're given an empty paragraph, but an empty paragraph can have style |
@@ -1196,7 +1195,7 @@ void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap |
RefPtr<EditingStyle> styleInEmptyParagraph; |
if (startOfParagraphToMove == endOfParagraphToMove && preserveStyle) { |
styleInEmptyParagraph = EditingStyle::create(startOfParagraphToMove.deepEquivalent()); |
- styleInEmptyParagraph->mergeTypingStyle(document()); |
+ styleInEmptyParagraph->mergeTypingStyle(&document()); |
// The moved paragraph should assume the block style of the destination. |
styleInEmptyParagraph->removeBlockProperties(); |
} |
@@ -1204,7 +1203,7 @@ void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap |
// FIXME (5098931): We should add a new insert action "WebViewInsertActionMoved" and call shouldInsertFragment here. |
setEndingSelection(VisibleSelection(start, end, DOWNSTREAM)); |
- document()->frame()->editor().clearMisspellingsAndBadGrammar(endingSelection()); |
+ document().frame()->editor().clearMisspellingsAndBadGrammar(endingSelection()); |
deleteSelection(false, false, false, false); |
ASSERT(destination.deepEquivalent().anchorNode()->inDocument()); |
@@ -1222,12 +1221,12 @@ void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap |
afterParagraph = VisiblePosition(afterParagraph.deepEquivalent()); |
if (beforeParagraph.isNotNull() && (!isEndOfParagraph(beforeParagraph) || beforeParagraph == afterParagraph)) { |
// FIXME: Trim text between beforeParagraph and afterParagraph if they aren't equal. |
- insertNodeAt(createBreakElement(document()), beforeParagraph.deepEquivalent()); |
+ insertNodeAt(createBreakElement(&document()), beforeParagraph.deepEquivalent()); |
// Need an updateLayout here in case inserting the br has split a text node. |
- document()->updateLayoutIgnorePendingStylesheets(); |
+ document().updateLayoutIgnorePendingStylesheets(); |
} |
- RefPtr<Range> startToDestinationRange(Range::create(document(), firstPositionInNode(document()->documentElement()), destination.deepEquivalent().parentAnchoredEquivalent())); |
+ RefPtr<Range> startToDestinationRange(Range::create(&document(), firstPositionInNode(document().documentElement()), destination.deepEquivalent().parentAnchoredEquivalent())); |
destinationIndex = TextIterator::rangeLength(startToDestinationRange.get(), true); |
setEndingSelection(VisibleSelection(destination, originalIsDirectional)); |
@@ -1237,7 +1236,7 @@ void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap |
options |= ReplaceSelectionCommand::MatchStyle; |
applyCommandToComposite(ReplaceSelectionCommand::create(document(), fragment, options)); |
- document()->frame()->editor().markMisspellingsAndBadGrammar(endingSelection()); |
+ document().frame()->editor().markMisspellingsAndBadGrammar(endingSelection()); |
// If the selection is in an empty paragraph, restore styles from the old empty paragraph to the new empty paragraph. |
bool selectionIsEmptyParagraph = endingSelection().isCaret() && isStartOfParagraph(endingSelection().visibleStart()) && isEndOfParagraph(endingSelection().visibleStart()); |
@@ -1250,8 +1249,8 @@ void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap |
// causes spaces to be collapsed during the move operation. This results |
// in a call to rangeFromLocationAndLength with a location past the end |
// of the document (which will return null). |
- RefPtr<Range> start = TextIterator::rangeFromLocationAndLength(document()->documentElement(), destinationIndex + startIndex, 0, true); |
- RefPtr<Range> end = TextIterator::rangeFromLocationAndLength(document()->documentElement(), destinationIndex + endIndex, 0, true); |
+ RefPtr<Range> start = TextIterator::rangeFromLocationAndLength(document().documentElement(), destinationIndex + startIndex, 0, true); |
+ RefPtr<Range> end = TextIterator::rangeFromLocationAndLength(document().documentElement(), destinationIndex + endIndex, 0, true); |
if (start && end) |
setEndingSelection(VisibleSelection(start->startPosition(), end->startPosition(), DOWNSTREAM, originalIsDirectional)); |
} |
@@ -1265,7 +1264,7 @@ bool CompositeEditCommand::breakOutOfEmptyListItem() |
return false; |
RefPtr<EditingStyle> style = EditingStyle::create(endingSelection().start()); |
- style->mergeTypingStyle(document()); |
+ style->mergeTypingStyle(&document()); |
RefPtr<ContainerNode> listNode = emptyListItem->parentNode(); |
// FIXME: Can't we do something better when the immediate parent wasn't a list node? |
@@ -1285,14 +1284,15 @@ bool CompositeEditCommand::breakOutOfEmptyListItem() |
// e.g. <ul><li> <ul><li><br></li></ul> hello</li></ul> should become <ul><li> <div><br></div> hello</li></ul> at the end |
splitElement(toElement(blockEnclosingList), listNode); |
removeNodePreservingChildren(listNode->parentNode()); |
- newBlock = createListItemElement(document()); |
+ newBlock = createListItemElement(&document()); |
} |
// If listNode does NOT appear at the end of the outer list item, then behave as if in a regular paragraph. |
- } else if (blockEnclosingList->hasTagName(olTag) || blockEnclosingList->hasTagName(ulTag)) |
- newBlock = createListItemElement(document()); |
+ } else if (blockEnclosingList->hasTagName(olTag) || blockEnclosingList->hasTagName(ulTag)) { |
+ newBlock = createListItemElement(&document()); |
+ } |
} |
if (!newBlock) |
- newBlock = createDefaultParagraphElement(document()); |
+ newBlock = createDefaultParagraphElement(&document()); |
RefPtr<Node> previousListNode = emptyListItem->isElementNode() ? toElement(emptyListItem.get())->previousElementSibling(): emptyListItem->previousSibling(); |
RefPtr<Node> nextListNode = emptyListItem->isElementNode() ? toElement(emptyListItem.get())->nextElementSibling(): emptyListItem->nextSibling(); |
@@ -1343,7 +1343,7 @@ bool CompositeEditCommand::breakOutOfEmptyMailBlockquotedParagraph() |
if (enclosingNodeOfType(previous.deepEquivalent(), &isMailBlockquote)) |
return false; |
- RefPtr<Node> br = createBreakElement(document()); |
+ RefPtr<Node> br = createBreakElement(&document()); |
// We want to replace this quoted paragraph with an unquoted one, so insert a br |
// to hold the caret before the highest blockquote. |
insertNodeBefore(br, highestBlockquote); |
@@ -1351,7 +1351,7 @@ bool CompositeEditCommand::breakOutOfEmptyMailBlockquotedParagraph() |
// If the br we inserted collapsed, for example foo<br><blockquote>...</blockquote>, insert |
// a second one. |
if (!isStartOfParagraph(atBR)) |
- insertNodeBefore(createBreakElement(document()), br); |
+ insertNodeBefore(createBreakElement(&document()), br); |
setEndingSelection(VisibleSelection(atBR, endingSelection().isDirectional())); |
// If this is an empty paragraph there must be a line break here. |