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

Unified Diff: Source/core/editing/InsertListCommand.cpp

Issue 182383012: Have positionInParentBeforeNode() / positionInParentAfterNode() take a reference (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 10 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
« no previous file with comments | « Source/core/editing/InsertListCommand.h ('k') | Source/core/editing/InsertParagraphSeparatorCommand.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/editing/InsertListCommand.cpp
diff --git a/Source/core/editing/InsertListCommand.cpp b/Source/core/editing/InsertListCommand.cpp
index ed84e3a7f4588d94c5ac47f8e3e20589485da99f..df9cb378959c13b2bc5e9afe24d067c4a0ae7413 100644
--- a/Source/core/editing/InsertListCommand.cpp
+++ b/Source/core/editing/InsertListCommand.cpp
@@ -156,7 +156,7 @@ void InsertListCommand::doApply()
// FIXME: This is an inefficient way to keep selection alive because indexForVisiblePosition walks from
// the beginning of the document to the endOfSelection everytime this code is executed.
// But not using index is hard because there are so many ways we can lose selection inside doApplyForSingleParagraph.
- doApplyForSingleParagraph(forceCreateList, listTag, currentSelection.get());
+ doApplyForSingleParagraph(forceCreateList, listTag, *currentSelection);
if (endOfSelection.isNull() || endOfSelection.isOrphan() || startOfLastParagraph.isNull() || startOfLastParagraph.isOrphan()) {
endOfSelection = visiblePositionForIndex(indexForEndOfSelection, scope.get());
// If endOfSelection is null, then some contents have been deleted from the document.
@@ -177,7 +177,7 @@ void InsertListCommand::doApply()
startOfCurrentParagraph = startOfNextParagraph(endingSelection().visibleStart());
}
setEndingSelection(endOfSelection);
- doApplyForSingleParagraph(forceCreateList, listTag, currentSelection.get());
+ doApplyForSingleParagraph(forceCreateList, listTag, *currentSelection);
// Fetch the end of the selection, for the reason mentioned above.
if (endOfSelection.isNull() || endOfSelection.isOrphan()) {
endOfSelection = visiblePositionForIndex(indexForEndOfSelection, scope.get());
@@ -189,10 +189,11 @@ void InsertListCommand::doApply()
}
}
- doApplyForSingleParagraph(false, listTag, endingSelection().firstRange().get());
+ ASSERT(endingSelection().firstRange());
+ doApplyForSingleParagraph(false, listTag, *endingSelection().firstRange());
}
-void InsertListCommand::doApplyForSingleParagraph(bool forceCreateList, const QualifiedName& listTag, Range* currentSelection)
+void InsertListCommand::doApplyForSingleParagraph(bool forceCreateList, const QualifiedName& listTag, Range& currentSelection)
{
// FIXME: This will produce unexpected results for a selection that starts just before a
// table and ends inside the first cell, selectionForParagraphIteration should probably
@@ -216,9 +217,9 @@ void InsertListCommand::doApplyForSingleParagraph(bool forceCreateList, const Qu
return;
// If the entire list is selected, then convert the whole list.
- if (switchListType && isNodeVisiblyContainedWithin(listNode.get(), currentSelection)) {
- bool rangeStartIsInList = visiblePositionBeforeNode(listNode.get()) == VisiblePosition(currentSelection->startPosition());
- bool rangeEndIsInList = visiblePositionAfterNode(listNode.get()) == VisiblePosition(currentSelection->endPosition());
+ if (switchListType && isNodeVisiblyContainedWithin(*listNode, currentSelection)) {
+ bool rangeStartIsInList = visiblePositionBeforeNode(*listNode) == VisiblePosition(currentSelection.startPosition());
+ bool rangeEndIsInList = visiblePositionAfterNode(*listNode) == VisiblePosition(currentSelection.endPosition());
RefPtr<HTMLElement> newList = createHTMLElement(document(), listTag);
insertNodeBefore(newList, listNode);
@@ -239,9 +240,9 @@ void InsertListCommand::doApplyForSingleParagraph(bool forceCreateList, const Qu
// Restore the start and the end of current selection if they started inside listNode
// because moveParagraphWithClones could have removed them.
if (rangeStartIsInList && newList)
- currentSelection->setStart(newList, 0, IGNORE_EXCEPTION);
+ currentSelection.setStart(newList, 0, IGNORE_EXCEPTION);
if (rangeEndIsInList && newList)
- currentSelection->setEnd(newList, lastOffsetInNode(newList.get()), IGNORE_EXCEPTION);
+ currentSelection.setEnd(newList, lastOffsetInNode(newList.get()), IGNORE_EXCEPTION);
setEndingSelection(VisiblePosition(firstPositionInNode(newList.get())));
@@ -374,7 +375,7 @@ PassRefPtr<HTMLElement> InsertListCommand::listifyParagraph(const VisiblePositio
// Also avoid the containing list item.
Node* listChild = enclosingListChild(insertionPos.deprecatedNode());
if (listChild && listChild->hasTagName(liTag))
- insertionPos = positionInParentBeforeNode(listChild);
+ insertionPos = positionInParentBeforeNode(*listChild);
insertNodeAt(listElement, insertionPos);
« no previous file with comments | « Source/core/editing/InsertListCommand.h ('k') | Source/core/editing/InsertParagraphSeparatorCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698