Bug 1451672 - part 2: Rename EditorBase::InsertNode() to EditorBase::InsertNodeWithTransaction() r?m_kato
MozReview-Commit-ID: 4n5EVvUKrux
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -123,21 +123,21 @@ using namespace widget;
template already_AddRefed<Element>
EditorBase::CreateNodeWithTransaction(nsAtom& aTag,
const EditorDOMPoint& aPointToInsert);
template already_AddRefed<Element>
EditorBase::CreateNodeWithTransaction(nsAtom& aTag,
const EditorRawDOMPoint& aPointToInsert);
template nsresult
-EditorBase::InsertNode(nsIContent& aContentToInsert,
- const EditorDOMPoint& aPointToInsert);
+EditorBase::InsertNodeWithTransaction(nsIContent& aContentToInsert,
+ const EditorDOMPoint& aPointToInsert);
template nsresult
-EditorBase::InsertNode(nsIContent& aContentToInsert,
- const EditorRawDOMPoint& aPointToInsert);
+EditorBase::InsertNodeWithTransaction(nsIContent& aContentToInsert,
+ const EditorRawDOMPoint& aPointToInsert);
template already_AddRefed<nsIContent>
EditorBase::SplitNode(const EditorDOMPoint& aStartOfRightNode,
ErrorResult& aError);
template already_AddRefed<nsIContent>
EditorBase::SplitNode(const EditorRawDOMPoint& aStartOfRightNode,
ErrorResult& aError);
template SplitNodeResult
EditorBase::SplitNodeDeep(nsIContent& aMostAncestorToSplit,
@@ -1411,23 +1411,25 @@ EditorBase::InsertNode(nsIDOMNode* aNode
}
nsCOMPtr<nsINode> container = do_QueryInterface(aContainer);
if (NS_WARN_IF(!container)) {
return NS_ERROR_NULL_POINTER;
}
int32_t offset =
aOffset < 0 ? static_cast<int32_t>(container->Length()) :
std::min(aOffset, static_cast<int32_t>(container->Length()));
- return InsertNode(*contentToInsert, EditorRawDOMPoint(container, offset));
+ return InsertNodeWithTransaction(*contentToInsert,
+ EditorRawDOMPoint(container, offset));
}
template<typename PT, typename CT>
nsresult
-EditorBase::InsertNode(nsIContent& aContentToInsert,
- const EditorDOMPointBase<PT, CT>& aPointToInsert)
+EditorBase::InsertNodeWithTransaction(
+ nsIContent& aContentToInsert,
+ const EditorDOMPointBase<PT, CT>& aPointToInsert)
{
if (NS_WARN_IF(!aPointToInsert.IsSet())) {
return NS_ERROR_INVALID_ARG;
}
MOZ_ASSERT(aPointToInsert.IsSetAndValid());
AutoRules beginRulesSniffing(this, EditAction::insertNode, nsIEditor::eNext);
@@ -1691,28 +1693,29 @@ EditorBase::ReplaceContainer(Element* aO
while (aOldContainer->HasChildren()) {
nsCOMPtr<nsIContent> child = aOldContainer->GetFirstChild();
nsresult rv = DeleteNode(child);
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
- rv = InsertNode(*child, EditorRawDOMPoint(newContainer,
- newContainer->Length()));
+ rv = InsertNodeWithTransaction(*child,
+ EditorRawDOMPoint(newContainer,
+ newContainer->Length()));
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
}
}
// Insert new container into tree.
NS_WARNING_ASSERTION(atOldContainer.IsSetAndValid(),
"The old container might be moved by mutation observer");
- nsresult rv = InsertNode(*newContainer, atOldContainer);
+ nsresult rv = InsertNodeWithTransaction(*newContainer, atOldContainer);
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
// Delete old container.
rv = DeleteNode(aOldContainer);
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
@@ -1747,19 +1750,20 @@ EditorBase::RemoveContainer(nsIContent*
nsresult rv = DeleteNode(child);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// Insert the last child before the previous last child. So, we need to
// use offset here because previous child might have been moved to
// container.
- rv = InsertNode(*child,
- EditorRawDOMPoint(pointToInsertChildren.GetContainer(),
- pointToInsertChildren.Offset()));
+ rv = InsertNodeWithTransaction(*child,
+ EditorRawDOMPoint(
+ pointToInsertChildren.GetContainer(),
+ pointToInsertChildren.Offset()));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
return DeleteNode(aNode);
}
@@ -1809,24 +1813,24 @@ EditorBase::InsertContainerAbove(nsICont
// Put aNode in the new container, first.
nsresult rv = DeleteNode(aNode);
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
{
AutoTransactionsConserveSelection conserveSelection(this);
- rv = InsertNode(*aNode, EditorRawDOMPoint(newContainer, 0));
+ rv = InsertNodeWithTransaction(*aNode, EditorRawDOMPoint(newContainer, 0));
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
}
// Put the new container where aNode was.
- rv = InsertNode(*newContainer, pointToInsertNewContainer);
+ rv = InsertNodeWithTransaction(*newContainer, pointToInsertNewContainer);
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
return newContainer.forget();
}
/**
@@ -1872,17 +1876,17 @@ EditorBase::MoveNode(nsIContent* aNode,
// Hold a reference so aNode doesn't go away when we remove it (bug 772282)
nsCOMPtr<nsINode> kungFuDeathGrip = aNode;
nsresult rv = DeleteNode(aNode);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
- rv = InsertNode(*aNode, EditorRawDOMPoint(aParent, aOffset));
+ rv = InsertNodeWithTransaction(*aNode, EditorRawDOMPoint(aParent, aOffset));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
void
EditorBase::MoveAllChildren(nsINode& aContainer,
@@ -2746,18 +2750,20 @@ EditorBase::InsertTextImpl(nsIDocument&
if (ShouldHandleIMEComposition()) {
CheckedInt<int32_t> newOffset;
if (!pointToInsert.IsInTextNode()) {
// create a text node
RefPtr<nsTextNode> newNode =
EditorBase::CreateTextNode(aDocument, EmptyString());
// then we insert it into the dom tree
- nsresult rv = InsertNode(*newNode, pointToInsert);
- NS_ENSURE_SUCCESS(rv, rv);
+ nsresult rv = InsertNodeWithTransaction(*newNode, pointToInsert);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
pointToInsert.Set(newNode, 0);
newOffset = lengthToInsert;
} else {
newOffset = lengthToInsert + pointToInsert.Offset();
NS_ENSURE_TRUE(newOffset.isValid(), NS_ERROR_FAILURE);
}
nsresult rv =
InsertTextIntoTextNodeImpl(aStringToInsert,
@@ -2787,18 +2793,20 @@ EditorBase::InsertTextImpl(nsIDocument&
return NS_OK;
}
// we are inserting text into a non-text node. first we have to create a
// textnode (this also populates it with the text)
RefPtr<nsTextNode> newNode =
EditorBase::CreateTextNode(aDocument, aStringToInsert);
// then we insert it into the dom tree
- nsresult rv = InsertNode(*newNode, pointToInsert);
- NS_ENSURE_SUCCESS(rv, rv);
+ nsresult rv = InsertNodeWithTransaction(*newNode, pointToInsert);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
if (aPointAfterInsertedString) {
aPointAfterInsertedString->Set(newNode, lengthToInsert.value());
}
return NS_OK;
}
nsresult
EditorBase::InsertTextIntoTextNodeImpl(const nsAString& aStringToInsert,
--- a/editor/libeditor/EditorBase.h
+++ b/editor/libeditor/EditorBase.h
@@ -334,29 +334,30 @@ public:
already_AddRefed<Element> DeleteSelectionAndCreateElement(nsAtom& aTag);
/**
* Helper routines for node/parent manipulations.
*/
nsresult DeleteNode(nsINode* aNode);
/**
- * InsertNode() inserts aContentToInsert before the child specified by
- * aPointToInsert.
+ * InsertNodeWithTransaction() inserts aContentToInsert before the child
+ * specified by aPointToInsert.
*
* @param aContentToInsert The node to be inserted.
* @param aPointToInsert The insertion point of aContentToInsert.
* If this refers end of the container, the
* transaction will append the node to the
* container. Otherwise, will insert the node
* before child node referred by this.
*/
template<typename PT, typename CT>
- nsresult InsertNode(nsIContent& aContentToInsert,
- const EditorDOMPointBase<PT, CT>& aPointToInsert);
+ nsresult
+ InsertNodeWithTransaction(nsIContent& aContentToInsert,
+ const EditorDOMPointBase<PT, CT>& aPointToInsert);
enum ECloneAttributes { eDontCloneAttributes, eCloneAttributes };
already_AddRefed<Element> ReplaceContainer(Element* aOldContainer,
nsAtom* aNodeType,
nsAtom* aAttribute = nullptr,
const nsAString* aValue = nullptr,
ECloneAttributes aCloneAttributes
= eDontCloneAttributes);
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -5008,18 +5008,21 @@ HTMLEditRules::CreateStyleForInsertText(
offset = splitPoint.Offset();
}
if (!htmlEditor->IsContainer(node)) {
return NS_OK;
}
OwningNonNull<Text> newNode =
EditorBase::CreateTextNode(aDoc, EmptyString());
nsresult rv =
- htmlEditor->InsertNode(*newNode, EditorRawDOMPoint(node, offset));
- NS_ENSURE_SUCCESS(rv, rv);
+ htmlEditor->InsertNodeWithTransaction(*newNode,
+ EditorRawDOMPoint(node, offset));
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
node = newNode;
offset = 0;
weDidSomething = true;
if (relFontSize) {
// dir indicated bigger versus smaller. 1 = bigger, -1 = smaller
HTMLEditor::FontSize dir = relFontSize > 0 ?
HTMLEditor::FontSize::incr : HTMLEditor::FontSize::decr;
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -1261,17 +1261,18 @@ HTMLEditor::ReplaceHeadContentsWithHTML(
}
// Now insert the new nodes
int32_t offsetOfNewNode = 0;
// Loop over the contents of the fragment and move into the document
while (nsCOMPtr<nsIContent> child = docfrag->GetFirstChild()) {
nsresult rv =
- InsertNode(*child, EditorRawDOMPoint(headNode, offsetOfNewNode++));
+ InsertNodeWithTransaction(*child,
+ EditorRawDOMPoint(headNode, offsetOfNewNode++));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
return NS_OK;
}
@@ -1671,17 +1672,17 @@ HTMLEditor::InsertNodeIntoProperAncestor
// After inserting a node, pointToInsert will refer next sibling of
// the new node but keep referring the new node's offset.
// This method's result should be the point at insertion, it's useful
// even if the new node is moved by mutation observer immediately.
// So, let's lock only the offset and child node should be recomputed
// when it's necessary.
AutoEditorDOMPointChildInvalidator lockOffset(pointToInsert);
// Now we can insert the new node.
- nsresult rv = InsertNode(aNode, pointToInsert);
+ nsresult rv = InsertNodeWithTransaction(aNode, pointToInsert);
if (NS_WARN_IF(NS_FAILED(rv))) {
return EditorDOMPoint();
}
}
return pointToInsert;
}
NS_IMETHODIMP
--- a/editor/libeditor/HTMLEditorDataTransfer.cpp
+++ b/editor/libeditor/HTMLEditorDataTransfer.cpp
@@ -136,17 +136,17 @@ HTMLEditor::LoadHTML(const nsAString& aI
// behavior since using only child node to pointing insertion point
// changes the behavior when inserted child is moved by mutation
// observer. We need to investigate what we should do here.
Unused << pointToInsert.Offset();
for (nsCOMPtr<nsIContent> contentToInsert =
documentFragment->GetFirstChild();
contentToInsert;
contentToInsert = documentFragment->GetFirstChild()) {
- rv = InsertNode(*contentToInsert, pointToInsert);
+ rv = InsertNodeWithTransaction(*contentToInsert, pointToInsert);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// XXX If the inserted node has been moved by mutation observer,
// incrementing offset will cause odd result. Next new node
// will be inserted after existing node and the offset will be
// overflown from the container node.
pointToInsert.Set(pointToInsert.GetContainer(),
--- a/editor/libeditor/HTMLTableEditor.cpp
+++ b/editor/libeditor/HTMLTableEditor.cpp
@@ -146,17 +146,17 @@ HTMLEditor::InsertCell(nsIDOMElement* aD
if (aAfter) {
DebugOnly<bool> advanced = pointToInsert.AdvanceOffset();
NS_WARNING_ASSERTION(advanced,
"Failed to advance offset to after the old cell");
}
// Don't let Rules System change the selection.
AutoTransactionsConserveSelection dontChangeSelection(this);
- return InsertNode(*newCell, pointToInsert);
+ return InsertNodeWithTransaction(*newCell, pointToInsert);
}
nsresult
HTMLEditor::SetColSpan(nsIDOMElement* aCell,
int32_t aColSpan)
{
NS_ENSURE_TRUE(aCell, NS_ERROR_NULL_POINTER);
nsAutoString newSpan;
@@ -215,24 +215,25 @@ HTMLEditor::InsertTableCell(int32_t aNum
if (NS_SUCCEEDED(rv) && newCell) {
if (aAfter) {
cellOffset++;
}
nsCOMPtr<nsIContent> cell = do_QueryInterface(newCell);
if (NS_WARN_IF(!cell)) {
return NS_ERROR_FAILURE;
}
- rv = InsertNode(*cell, EditorRawDOMPoint(cellParent, cellOffset));
+ rv = InsertNodeWithTransaction(*cell,
+ EditorRawDOMPoint(cellParent, cellOffset));
if (NS_FAILED(rv)) {
break;
}
}
}
- // XXX This is perhaps the result of the last call of InsertNode() or
- // CreateElementWithDefaults().
+ // XXX This is perhaps the result of the last call of
+ // InsertNodeWithTransaction() or CreateElementWithDefaults().
return rv;
}
NS_IMETHODIMP
HTMLEditor::GetFirstRow(nsIDOMElement* aTableElement,
nsIDOMNode** aRowNode)
{
NS_ENSURE_TRUE(aRowNode, NS_ERROR_NULL_POINTER);
@@ -656,18 +657,22 @@ HTMLEditor::InsertTableRow(int32_t aNumb
newRow->AppendChild(*newCell, result);
if (NS_WARN_IF(result.Failed())) {
return result.StealNSResult();
}
}
// Use transaction system to insert the entire row+cells
// (Note that rows are inserted at same childoffset each time)
- rv = InsertNode(*newRow, EditorRawDOMPoint(parentOfRow, newRowOffset));
- NS_ENSURE_SUCCESS(rv, rv);
+ rv = InsertNodeWithTransaction(*newRow,
+ EditorRawDOMPoint(parentOfRow,
+ newRowOffset));
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
}
}
// SetSelectionAfterTableEdit from AutoSelectionSetterAfterTableEdit will
// access frame selection, so we need reframe.
// Because GetCellAt depends on frame.
nsCOMPtr<nsIPresShell> ps = GetPresShell();
if (ps) {
@@ -2297,18 +2302,22 @@ HTMLEditor::MergeCells(nsCOMPtr<nsIDOMEl
// Move the contents
while (cellToMerge->HasChildren()) {
nsCOMPtr<nsIContent> cellChild = cellToMerge->GetLastChild();
// XXX We need HTMLEditor::DeleteNode(nsINode&).
nsresult rv = DeleteNode(cellChild->AsDOMNode());
NS_ENSURE_SUCCESS(rv, rv);
- rv = InsertNode(*cellChild, EditorRawDOMPoint(aTargetCell, insertIndex));
- NS_ENSURE_SUCCESS(rv, rv);
+ rv = InsertNodeWithTransaction(*cellChild,
+ EditorRawDOMPoint(aTargetCell,
+ insertIndex));
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
}
}
// Delete cells whose contents were moved
if (aDeleteCellToMerge) {
return DeleteNode(aCellToMerge);
}
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -877,17 +877,18 @@ TextEditRules::WillSetText(Selection& aS
if (NS_WARN_IF(!doc)) {
return NS_OK;
}
RefPtr<nsTextNode> newNode = EditorBase::CreateTextNode(*doc, tString);
if (NS_WARN_IF(!newNode)) {
return NS_OK;
}
nsresult rv =
- textEditor->InsertNode(*newNode, EditorRawDOMPoint(rootElement, 0));
+ textEditor->InsertNodeWithTransaction(*newNode,
+ EditorRawDOMPoint(rootElement, 0));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
*aHandled = true;
ASSERT_PASSWORD_LENGTHS_EQUAL();
return NS_OK;
@@ -1453,17 +1454,18 @@ TextEditRules::CreateBogusNodeIfNeeded(S
mBogusNode = newContent;
// Give it a special attribute.
newContent->SetAttr(kNameSpaceID_None, kMOZEditorBogusNodeAttrAtom,
kMOZEditorBogusNodeValue, false);
// Put the node in the document.
nsresult rv =
- mTextEditor->InsertNode(*mBogusNode, EditorRawDOMPoint(body, 0));
+ mTextEditor->InsertNodeWithTransaction(*mBogusNode,
+ EditorRawDOMPoint(body, 0));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// Set selection.
ErrorResult error;
aSelection->Collapse(EditorRawDOMPoint(body, 0), error);
if (NS_WARN_IF(error.Failed())) {