/* -*- 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/. */
#include"JoinNodesTransaction.h"
#include"EditorDOMPoint.h"// for EditorDOMPoint, etc. #include"HTMLEditHelpers.h"// for SplitNodeResult #include"HTMLEditor.h"// for HTMLEditor #include"HTMLEditorInlines.h" #include"HTMLEditUtils.h"
#include"nsAString.h" #include"nsDebug.h"// for NS_ASSERTION, etc. #include"nsError.h"// for NS_ERROR_NULL_POINTER, etc. #include"nsIContent.h"// for nsIContent #include"nsISupportsImpl.h"// for QueryInterface, etc.
JoinNodesTransaction::JoinNodesTransaction(HTMLEditor& aHTMLEditor,
nsIContent& aLeftContent,
nsIContent& aRightContent)
: mHTMLEditor(&aHTMLEditor),
mRemovedContent(&aRightContent),
mKeepingContent(&aLeftContent) { // printf("JoinNodesTransaction size: %zu\n", sizeof(JoinNodesTransaction));
static_assert(sizeof(JoinNodesTransaction) <= 64, "Transaction classes may be created a lot and may be alive " "long so that keep the foot print smaller as far as possible");
}
// After DoTransaction() and RedoTransaction(), the left node is removed from // the content tree and right node remains.
NS_IMETHODIMP JoinNodesTransaction::DoTransaction() {
MOZ_LOG(GetLogModule(), LogLevel::Info,
("%p JoinNodesTransaction::%s this=%s", this, __FUNCTION__,
ToString(*this).c_str()));
nsINode* removingContentParentNode = mRemovedContent->GetParentNode(); if (MOZ_UNLIKELY(NS_WARN_IF(!removingContentParentNode))) { return NS_ERROR_NOT_AVAILABLE;
}
// Verify that the joining content nodes have the same parent if (MOZ_UNLIKELY(removingContentParentNode !=
mKeepingContent->GetParentNode())) {
NS_ASSERTION(false, "Nodes do not have same parent"); return NS_ERROR_NOT_AVAILABLE;
}
// Set this instance's mParentNode. Other methods will see a non-null // mParentNode and know all is well
mParentNode = removingContentParentNode; // For now, setting mJoinedOffset to removed content length so that // CreateJoinedPoint returns a point in mKeepingContent whose offset is // the result if all content in mRemovedContent are moved to start or end of // mKeepingContent without any intervention. The offset will be adjusted // below.
mJoinedOffset = mKeepingContent->Length();
const OwningNonNull<HTMLEditor> htmlEditor = *mHTMLEditor; const OwningNonNull<nsIContent> removingContent = *mRemovedContent; const OwningNonNull<nsIContent> keepingContent = *mKeepingContent;
nsresult rv; // Let's try to get actual joined point with the tacker. auto joinNodesPoint = EditorDOMPoint::AtEndOf(keepingContent);
{
AutoTrackDOMPoint trackJoinNodePoint(htmlEditor->RangeUpdaterRef(),
&joinNodesPoint);
rv = htmlEditor->DoJoinNodes(keepingContent, removingContent);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "HTMLEditor::DoJoinNodes() failed");
} // Adjust join node offset to the actual offset where the original first // content of the right node is.
mJoinedOffset = joinNodesPoint.Offset();
if (aRedoingTransaction == RedoingTransaction::No) {
htmlEditor->DidJoinNodesTransaction(*this, rv);
}
return rv;
}
// XXX: What if instead of split, we just deleted the unneeded children of // mRight and re-inserted mLeft?
NS_IMETHODIMP JoinNodesTransaction::UndoTransaction() {
MOZ_LOG(GetLogModule(), LogLevel::Info,
("%p JoinNodesTransaction::%s this=%s", this, __FUNCTION__,
ToString(*this).c_str()));
Result<SplitNodeResult, nsresult> splitNodeResult = htmlEditor->DoSplitNode(
CreateJoinedPoint<EditorDOMPoint>(), removedContent); if (MOZ_UNLIKELY(splitNodeResult.isErr())) {
NS_WARNING("HTMLEditor::DoSplitNode() failed"); return splitNodeResult.unwrapErr();
} // When adding caret suggestion to SplitNodeResult, here didn't change // selection so that just ignore it.
splitNodeResult.inspect().IgnoreCaretPointSuggestion(); 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.