/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
DeleteNodeTransaction::DeleteNodeTransaction(EditorBase& aEditorBase,
nsIContent& aContentToDelete)
: DeleteContentTransactionBase(aEditorBase),
mContentToDelete(&aContentToDelete),
mParentNode(aContentToDelete.GetParentNode()) {
MOZ_DIAGNOSTIC_ASSERT_IF(
aEditorBase.IsHTMLEditor(),
HTMLEditUtils::IsRemovableNode(aContentToDelete) || // It's okay to delete text node if it's added by `HTMLEditor` since // remaining it may be noisy for the users.
(aContentToDelete.IsText() &&
aContentToDelete.HasFlag(NS_MAYBE_MODIFIED_FREQUENTLY)));
NS_ASSERTION(
!aEditorBase.IsHTMLEditor() ||
HTMLEditUtils::IsRemovableNode(aContentToDelete), "Deleting non-editable text node, please write a test for this!!");
}
// Remember which child mContentToDelete was (by remembering which child was // next). Note that mRefContent can be nullptr.
mRefContent = mContentToDelete->GetNextSibling();
// give range updater a chance. SelAdjDeleteNode() needs to be called // *before* we do the action, unlike some of the other RangeItem update // methods.
mEditorBase->RangeUpdaterRef().SelAdjDeleteNode(*mContentToDelete);
if (NS_WARN_IF(!CanDoIt())) { // This is a legal state, the transaction is a no-op. return NS_OK;
}
ErrorResult error;
OwningNonNull<EditorBase> editorBase = *mEditorBase;
OwningNonNull<nsINode> parentNode = *mParentNode;
OwningNonNull<nsIContent> contentToDelete = *mContentToDelete;
nsCOMPtr<nsIContent> refContent = mRefContent; // XXX Perhaps, we should check `refContent` is a child of `parentNode`, // and if it's not, we should stop undoing or something.
parentNode->InsertBefore(contentToDelete, refContent, error); // InsertBefore() may call MightThrowJSException() even if there is no error. // We don't need the flag here.
error.WouldReportJSException(); if (error.Failed()) {
NS_WARNING("nsINode::InsertBefore() failed"); return error.StealNSResult();
} return NS_OK;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.