зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1540037 - part 8: Move `EditorBase::SplitNodeWithTransaction()` to `HTMLEditor` r=m_kato
Now, it's used only by `HTMLEditor` so that we can move it. Differential Revision: https://phabricator.services.mozilla.com/D72832
This commit is contained in:
Родитель
ec22b93111
Коммит
63f8d6da50
|
@ -1609,77 +1609,6 @@ EditorBase::InsertPaddingBRElementForEmptyLastLineWithTransaction(
|
|||
return CreateElementResult(std::move(newBRElement));
|
||||
}
|
||||
|
||||
already_AddRefed<nsIContent> EditorBase::SplitNodeWithTransaction(
|
||||
const EditorDOMPoint& aStartOfRightNode, ErrorResult& aError) {
|
||||
MOZ_ASSERT(IsEditActionDataAvailable());
|
||||
|
||||
if (NS_WARN_IF(!aStartOfRightNode.IsInContentNode())) {
|
||||
aError.Throw(NS_ERROR_INVALID_ARG);
|
||||
return nullptr;
|
||||
}
|
||||
MOZ_ASSERT(aStartOfRightNode.IsSetAndValid());
|
||||
|
||||
AutoEditSubActionNotifier startToHandleEditSubAction(
|
||||
*this, EditSubAction::eSplitNode, nsIEditor::eNext, aError);
|
||||
if (NS_WARN_IF(aError.ErrorCodeIs(NS_ERROR_EDITOR_DESTROYED))) {
|
||||
return nullptr;
|
||||
}
|
||||
NS_WARNING_ASSERTION(
|
||||
!aError.Failed(),
|
||||
"OnStartToHandleTopLevelEditSubAction() failed, but ignored");
|
||||
aError.SuppressException();
|
||||
|
||||
// XXX Unfortunately, storing offset of the split point in
|
||||
// SplitNodeTransaction is necessary for now. We should fix this
|
||||
// in a follow up bug.
|
||||
Unused << aStartOfRightNode.Offset();
|
||||
|
||||
RefPtr<SplitNodeTransaction> transaction =
|
||||
SplitNodeTransaction::Create(*this, aStartOfRightNode);
|
||||
aError = DoTransactionInternal(transaction);
|
||||
NS_WARNING_ASSERTION(!aError.Failed(),
|
||||
"EditorBase::DoTransactionInternal() failed");
|
||||
|
||||
nsCOMPtr<nsIContent> newLeftContent = transaction->GetNewLeftContent();
|
||||
NS_WARNING_ASSERTION(newLeftContent, "Failed to create a new left node");
|
||||
|
||||
if (newLeftContent) {
|
||||
// XXX Some other transactions manage range updater by themselves.
|
||||
// Why doesn't SplitNodeTransaction do it?
|
||||
DebugOnly<nsresult> rvIgnored = RangeUpdaterRef().SelAdjSplitNode(
|
||||
*aStartOfRightNode.GetContainerAsContent(), *newLeftContent);
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
|
||||
"RangeUpdater::SelAdjSplitNode() failed, but ignored");
|
||||
}
|
||||
if (AsHTMLEditor() && newLeftContent) {
|
||||
TopLevelEditSubActionDataRef().DidSplitContent(
|
||||
*this, *aStartOfRightNode.GetContainerAsContent(), *newLeftContent);
|
||||
}
|
||||
|
||||
if (mInlineSpellChecker) {
|
||||
RefPtr<mozInlineSpellChecker> spellChecker = mInlineSpellChecker;
|
||||
spellChecker->DidSplitNode(aStartOfRightNode.GetContainer(),
|
||||
newLeftContent);
|
||||
}
|
||||
|
||||
if (!mActionListeners.IsEmpty()) {
|
||||
AutoActionListenerArray listeners(mActionListeners);
|
||||
for (auto& listener : listeners) {
|
||||
DebugOnly<nsresult> rvIgnored = listener->DidSplitNode(
|
||||
aStartOfRightNode.GetContainer(), newLeftContent);
|
||||
NS_WARNING_ASSERTION(
|
||||
NS_SUCCEEDED(rvIgnored),
|
||||
"nsIEditActionListener::DidSplitNode() failed, but ignored");
|
||||
}
|
||||
}
|
||||
|
||||
if (aError.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return newLeftContent.forget();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP EditorBase::DeleteNode(nsINode* aNode) {
|
||||
if (NS_WARN_IF(!aNode) || NS_WARN_IF(!aNode->IsContent())) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
|
|
@ -1454,22 +1454,6 @@ class EditorBase : public nsIEditor,
|
|||
MOZ_CAN_RUN_SCRIPT void CloneAttributesWithTransaction(
|
||||
Element& aDestElement, Element& aSourceElement);
|
||||
|
||||
/**
|
||||
* SplitNodeWithTransaction() creates a transaction to create a new node
|
||||
* (left node) identical to an existing node (right node), and split the
|
||||
* contents between the same point in both nodes, then, execute the
|
||||
* transaction.
|
||||
*
|
||||
* @param aStartOfRightNode The point to split. Its container will be
|
||||
* the right node, i.e., become the new node's
|
||||
* next sibling. And the point will be start
|
||||
* of the right node.
|
||||
* @param aError If succeed, returns no error. Otherwise, an
|
||||
* error.
|
||||
*/
|
||||
MOZ_CAN_RUN_SCRIPT already_AddRefed<nsIContent> SplitNodeWithTransaction(
|
||||
const EditorDOMPoint& aStartOfRightNode, ErrorResult& aResult);
|
||||
|
||||
/**
|
||||
* MoveNodeWithTransaction() moves aContent to aPointToInsert.
|
||||
*
|
||||
|
|
|
@ -4730,7 +4730,7 @@ EditActionResult HTMLEditor::ChangeSelectedHardLinesToList(
|
|||
return EditActionResult(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
if (error.Failed()) {
|
||||
NS_WARNING("EditorBase::SplitNodeWithTransaction() failed");
|
||||
NS_WARNING("HTMLEditor::SplitNodeWithTransaction() failed");
|
||||
return EditActionResult(error.StealNSResult());
|
||||
}
|
||||
curList = CreateNodeWithTransaction(
|
||||
|
@ -8197,7 +8197,7 @@ nsresult HTMLEditor::SplitTextNodesAtRangeEnd(
|
|||
}
|
||||
if (error.Failed()) {
|
||||
NS_WARNING_ASSERTION(error.ErrorCodeIs(NS_ERROR_EDITOR_DESTROYED),
|
||||
"EditorBase::SplitNodeWithTransaction() failed");
|
||||
"HTMLEditor::SplitNodeWithTransaction() failed");
|
||||
return error.StealNSResult();
|
||||
}
|
||||
|
||||
|
@ -8917,7 +8917,7 @@ EditActionResult HTMLEditor::HandleInsertParagraphInParagraph(
|
|||
}
|
||||
if (error.Failed()) {
|
||||
NS_WARNING_ASSERTION(error.ErrorCodeIs(NS_ERROR_EDITOR_DESTROYED),
|
||||
"EditorBase::SplitNodeWithTransaction() failed");
|
||||
"HTMLEditor::SplitNodeWithTransaction() failed");
|
||||
return EditActionResult(error.StealNSResult());
|
||||
}
|
||||
pointToSplitParentDivOrP.SetToEndOf(newLeftDivOrP);
|
||||
|
@ -9115,7 +9115,7 @@ nsresult HTMLEditor::HandleInsertParagraphInListItemElement(Element& aListItem,
|
|||
}
|
||||
if (error.Failed()) {
|
||||
NS_WARNING_ASSERTION(error.ErrorCodeIs(NS_ERROR_EDITOR_DESTROYED),
|
||||
"EditorBase::SplitNodeWithTransaction() failed");
|
||||
"HTMLEditor::SplitNodeWithTransaction() failed");
|
||||
return error.StealNSResult();
|
||||
}
|
||||
}
|
||||
|
@ -10745,12 +10745,12 @@ nsresult HTMLEditor::LiftUpListItemElement(
|
|||
}
|
||||
if (error.Failed()) {
|
||||
NS_WARNING_ASSERTION(error.ErrorCodeIs(NS_ERROR_EDITOR_DESTROYED),
|
||||
"EditorBase::SplitNodeWithTransaction() failed");
|
||||
"HTMLEditor::SplitNodeWithTransaction() failed");
|
||||
return error.StealNSResult();
|
||||
}
|
||||
if (!maybeLeftListContent->IsElement()) {
|
||||
NS_WARNING(
|
||||
"EditorBase::SplitNodeWithTransaction() didn't return left list "
|
||||
"HTMLEditor::SplitNodeWithTransaction() didn't return left list "
|
||||
"element");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "HTMLEditorEventListener.h"
|
||||
#include "HTMLEditUtils.h"
|
||||
#include "JoinNodeTransaction.h"
|
||||
#include "SplitNodeTransaction.h"
|
||||
#include "TypeInState.h"
|
||||
#include "WSRunObject.h"
|
||||
|
||||
|
@ -3315,7 +3316,7 @@ EditorDOMPoint HTMLEditor::PrepareToInsertBRElement(
|
|||
nsCOMPtr<nsIContent> newLeftNode =
|
||||
SplitNodeWithTransaction(aPointToInsert, ignoredError);
|
||||
NS_WARNING_ASSERTION(!ignoredError.Failed(),
|
||||
"EditorBase::SplitNodeWithTransaction() failed");
|
||||
"HTMLEditor::SplitNodeWithTransaction() failed");
|
||||
if (ignoredError.Failed()) {
|
||||
return EditorDOMPoint();
|
||||
}
|
||||
|
@ -4029,6 +4030,77 @@ nsresult HTMLEditor::RemoveBlockContainerWithTransaction(Element& aElement) {
|
|||
return rv;
|
||||
}
|
||||
|
||||
already_AddRefed<nsIContent> HTMLEditor::SplitNodeWithTransaction(
|
||||
const EditorDOMPoint& aStartOfRightNode, ErrorResult& aError) {
|
||||
MOZ_ASSERT(IsEditActionDataAvailable());
|
||||
|
||||
if (NS_WARN_IF(!aStartOfRightNode.IsInContentNode())) {
|
||||
aError.Throw(NS_ERROR_INVALID_ARG);
|
||||
return nullptr;
|
||||
}
|
||||
MOZ_ASSERT(aStartOfRightNode.IsSetAndValid());
|
||||
|
||||
AutoEditSubActionNotifier startToHandleEditSubAction(
|
||||
*this, EditSubAction::eSplitNode, nsIEditor::eNext, aError);
|
||||
if (NS_WARN_IF(aError.ErrorCodeIs(NS_ERROR_EDITOR_DESTROYED))) {
|
||||
return nullptr;
|
||||
}
|
||||
NS_WARNING_ASSERTION(
|
||||
!aError.Failed(),
|
||||
"OnStartToHandleTopLevelEditSubAction() failed, but ignored");
|
||||
aError.SuppressException();
|
||||
|
||||
// XXX Unfortunately, storing offset of the split point in
|
||||
// SplitNodeTransaction is necessary for now. We should fix this
|
||||
// in a follow up bug.
|
||||
Unused << aStartOfRightNode.Offset();
|
||||
|
||||
RefPtr<SplitNodeTransaction> transaction =
|
||||
SplitNodeTransaction::Create(*this, aStartOfRightNode);
|
||||
aError = DoTransactionInternal(transaction);
|
||||
NS_WARNING_ASSERTION(!aError.Failed(),
|
||||
"EditorBase::DoTransactionInternal() failed");
|
||||
|
||||
nsCOMPtr<nsIContent> newLeftContent = transaction->GetNewLeftContent();
|
||||
NS_WARNING_ASSERTION(newLeftContent, "Failed to create a new left node");
|
||||
|
||||
if (newLeftContent) {
|
||||
// XXX Some other transactions manage range updater by themselves.
|
||||
// Why doesn't SplitNodeTransaction do it?
|
||||
DebugOnly<nsresult> rvIgnored = RangeUpdaterRef().SelAdjSplitNode(
|
||||
*aStartOfRightNode.GetContainerAsContent(), *newLeftContent);
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
|
||||
"RangeUpdater::SelAdjSplitNode() failed, but ignored");
|
||||
}
|
||||
if (AsHTMLEditor() && newLeftContent) {
|
||||
TopLevelEditSubActionDataRef().DidSplitContent(
|
||||
*this, *aStartOfRightNode.GetContainerAsContent(), *newLeftContent);
|
||||
}
|
||||
|
||||
if (mInlineSpellChecker) {
|
||||
RefPtr<mozInlineSpellChecker> spellChecker = mInlineSpellChecker;
|
||||
spellChecker->DidSplitNode(aStartOfRightNode.GetContainer(),
|
||||
newLeftContent);
|
||||
}
|
||||
|
||||
if (!mActionListeners.IsEmpty()) {
|
||||
AutoActionListenerArray listeners(mActionListeners);
|
||||
for (auto& listener : listeners) {
|
||||
DebugOnly<nsresult> rvIgnored = listener->DidSplitNode(
|
||||
aStartOfRightNode.GetContainer(), newLeftContent);
|
||||
NS_WARNING_ASSERTION(
|
||||
NS_SUCCEEDED(rvIgnored),
|
||||
"nsIEditActionListener::DidSplitNode() failed, but ignored");
|
||||
}
|
||||
}
|
||||
|
||||
if (aError.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return newLeftContent.forget();
|
||||
}
|
||||
|
||||
SplitNodeResult HTMLEditor::SplitNodeDeepWithTransaction(
|
||||
nsIContent& aMostAncestorToSplit,
|
||||
const EditorDOMPoint& aStartOfDeepestRightNode,
|
||||
|
@ -4072,7 +4144,7 @@ SplitNodeResult HTMLEditor::SplitNodeDeepWithTransaction(
|
|||
nsCOMPtr<nsIContent> newLeftNode =
|
||||
SplitNodeWithTransaction(atStartOfRightNode, error);
|
||||
if (error.Failed()) {
|
||||
NS_WARNING("EditorBase::SplitNodeWithTransaction() failed");
|
||||
NS_WARNING("HTMLEditor::SplitNodeWithTransaction() failed");
|
||||
return SplitNodeResult(error.StealNSResult());
|
||||
}
|
||||
|
||||
|
@ -4282,7 +4354,7 @@ nsresult HTMLEditor::DeleteSelectionAndPrepareToCreateNode() {
|
|||
ErrorResult error;
|
||||
nsCOMPtr<nsIContent> newLeftNode = SplitNodeWithTransaction(atAnchor, error);
|
||||
if (error.Failed()) {
|
||||
NS_WARNING("EditorBase::SplitNodeWithTransaction() failed");
|
||||
NS_WARNING("HTMLEditor::SplitNodeWithTransaction() failed");
|
||||
return error.StealNSResult();
|
||||
}
|
||||
|
||||
|
|
|
@ -2170,6 +2170,22 @@ class HTMLEditor final : public TextEditor,
|
|||
const EditorDOMPoint& aPointToInsert,
|
||||
MoveToEndOfContainer aMoveToEndOfContainer = MoveToEndOfContainer::No);
|
||||
|
||||
/**
|
||||
* SplitNodeWithTransaction() creates a transaction to create a new node
|
||||
* (left node) identical to an existing node (right node), and split the
|
||||
* contents between the same point in both nodes, then, execute the
|
||||
* transaction.
|
||||
*
|
||||
* @param aStartOfRightNode The point to split. Its container will be
|
||||
* the right node, i.e., become the new node's
|
||||
* next sibling. And the point will be start
|
||||
* of the right node.
|
||||
* @param aError If succeed, returns no error. Otherwise, an
|
||||
* error.
|
||||
*/
|
||||
MOZ_CAN_RUN_SCRIPT already_AddRefed<nsIContent> SplitNodeWithTransaction(
|
||||
const EditorDOMPoint& aStartOfRightNode, ErrorResult& aResult);
|
||||
|
||||
enum class SplitAtEdges {
|
||||
// SplitNodeDeepWithTransaction() won't split container element
|
||||
// nodes at their edges. I.e., when split point is start or end of
|
||||
|
|
|
@ -427,7 +427,7 @@ nsresult HTMLEditor::SetInlinePropertyOnTextNode(
|
|||
}
|
||||
if (error.Failed()) {
|
||||
NS_WARNING_ASSERTION(error.ErrorCodeIs(NS_ERROR_EDITOR_DESTROYED),
|
||||
"EditorBase::SplitNodeWithTransaction() failed");
|
||||
"HTMLEditor::SplitNodeWithTransaction() failed");
|
||||
return error.StealNSResult();
|
||||
}
|
||||
}
|
||||
|
@ -443,7 +443,7 @@ nsresult HTMLEditor::SetInlinePropertyOnTextNode(
|
|||
}
|
||||
if (error.Failed()) {
|
||||
NS_WARNING_ASSERTION(error.ErrorCodeIs(NS_ERROR_EDITOR_DESTROYED),
|
||||
"EditorBase::SplitNodeWithTransaction() failed");
|
||||
"HTMLEditor::SplitNodeWithTransaction() failed");
|
||||
return error.StealNSResult();
|
||||
}
|
||||
Unused << newLeftNode;
|
||||
|
@ -2259,7 +2259,7 @@ nsresult HTMLEditor::RelativeFontChangeOnTextNode(FontSize aDir,
|
|||
ErrorResult error;
|
||||
textNodeForTheRange = SplitNodeWithTransaction(atEnd, error);
|
||||
if (error.Failed()) {
|
||||
NS_WARNING("EditorBase::SplitNodeWithTransaction() failed");
|
||||
NS_WARNING("HTMLEditor::SplitNodeWithTransaction() failed");
|
||||
return error.StealNSResult();
|
||||
}
|
||||
}
|
||||
|
@ -2271,7 +2271,7 @@ nsresult HTMLEditor::RelativeFontChangeOnTextNode(FontSize aDir,
|
|||
ErrorResult error;
|
||||
nsCOMPtr<nsIContent> newLeftNode = SplitNodeWithTransaction(atStart, error);
|
||||
if (error.Failed()) {
|
||||
NS_WARNING("EditorBase::SplitNodeWithTransaction() failed");
|
||||
NS_WARNING("HTMLEditor::SplitNodeWithTransaction() failed");
|
||||
return error.StealNSResult();
|
||||
}
|
||||
Unused << newLeftNode;
|
||||
|
|
Загрузка…
Ссылка в новой задаче