Bug 1413181 - part 4: Redesign nsIEditActionListener::DidSplitNode() r?m_kato
nsIEditActionListner::DidSplitNode() takes 4 arguments, the right node,
old offset in the old right node before splitting, the new left node and
nsresult.
Computing offset for this doesn't make sense because it's always same as
the length of the left node. Additionally, nobody currently use nsersult.
So, we can get rid of it now.
Fortunately, nobody including comm-central and BlueGriffon implements
WillSplitNode(). So, we can get rid of it. However, removing interface
method should be done in a follow up bug. So, we can remove offset computation
in EditorBase::SplitNode() completely in the future.
MozReview-Commit-ID: JWj34SjBNJh
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -1541,48 +1541,47 @@ EditorBase::SplitNode(const EditorRawDOM
aError.Throw(NS_ERROR_INVALID_ARG);
return nullptr;
}
MOZ_ASSERT(aStartOfRightNode.IsSetAndValid());
AutoRules beginRulesSniffing(this, EditAction::splitNode, nsIEditor::eNext);
// Different from CreateNode(), we need offset at start of right node only
- // for WillSplitNode() and DidSplitNoe() since the offset is always same as
- // the length of new left node.
+ // for WillSplitNode() since the offset is always same as the length of new
+ // left node.
{
AutoActionListenerArray listeners(mActionListeners);
for (auto& listener : listeners) {
+ // XXX Unfortunately, we need to compute offset here because the container
+ // may be a data node like text node. However, nobody implements this
+ // method actually. So, we should get rid of this in a follow up bug.
listener->WillSplitNode(aStartOfRightNode.Container()->AsDOMNode(),
aStartOfRightNode.Offset());
}
}
RefPtr<SplitNodeTransaction> transaction =
CreateTxnForSplitNode(aStartOfRightNode);
aError = DoTransaction(transaction);
nsCOMPtr<nsIContent> newNode = transaction->GetNewNode();
NS_WARNING_ASSERTION(newNode, "Failed to create a new left node");
mRangeUpdater.SelAdjSplitNode(*aStartOfRightNode.Container()->AsContent(),
newNode);
- nsresult rv = aError.StealNSResult();
{
AutoActionListenerArray listeners(mActionListeners);
for (auto& listener : listeners) {
listener->DidSplitNode(aStartOfRightNode.Container()->AsDOMNode(),
- aStartOfRightNode.Offset(),
- GetAsDOMNode(newNode), rv);
+ GetAsDOMNode(newNode));
}
}
- // Note: result might be a success code, so we can't use Throw() to
- // set it on aResult.
- aError = rv;
+
if (NS_WARN_IF(aError.Failed())) {
return nullptr;
}
return newNode.forget();
}
NS_IMETHODIMP
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -8674,19 +8674,17 @@ NS_IMETHODIMP
HTMLEditRules::WillSplitNode(nsIDOMNode* aExistingRightNode,
int32_t aOffset)
{
return NS_OK;
}
NS_IMETHODIMP
HTMLEditRules::DidSplitNode(nsIDOMNode* aExistingRightNode,
- int32_t aOffset,
- nsIDOMNode* aNewLeftNode,
- nsresult aResult)
+ nsIDOMNode* aNewLeftNode)
{
if (!mListenerEnabled) {
return NS_OK;
}
nsCOMPtr<nsINode> newLeftNode = do_QueryInterface(aNewLeftNode);
nsCOMPtr<nsINode> existingRightNode = do_QueryInterface(aExistingRightNode);
nsresult rv = mUtilRange->SetStartAndEnd(newLeftNode, 0,
existingRightNode, 0);
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -113,18 +113,18 @@ public:
NS_IMETHOD WillInsertNode(nsIDOMNode* aNode, nsIDOMNode* aParent,
int32_t aPosition) override;
NS_IMETHOD DidInsertNode(nsIDOMNode* aNode, nsIDOMNode* aParent,
int32_t aPosition, nsresult aResult) override;
NS_IMETHOD WillDeleteNode(nsIDOMNode* aChild) override;
NS_IMETHOD DidDeleteNode(nsIDOMNode* aChild, nsresult aResult) override;
NS_IMETHOD WillSplitNode(nsIDOMNode* aExistingRightNode,
int32_t aOffset) override;
- NS_IMETHOD DidSplitNode(nsIDOMNode* aExistingRightNode, int32_t aOffset,
- nsIDOMNode* aNewLeftNode, nsresult aResult) override;
+ NS_IMETHOD DidSplitNode(nsIDOMNode* aExistingRightNode,
+ nsIDOMNode* aNewLeftNode) override;
NS_IMETHOD WillJoinNodes(nsIDOMNode* aLeftNode, nsIDOMNode* aRightNode,
nsIDOMNode* aParent) override;
NS_IMETHOD DidJoinNodes(nsIDOMNode* aLeftNode, nsIDOMNode* aRightNode,
nsIDOMNode* aParent, nsresult aResult) override;
NS_IMETHOD WillInsertText(nsIDOMCharacterData* aTextNode, int32_t aOffset,
const nsAString &aString) override;
NS_IMETHOD DidInsertText(nsIDOMCharacterData* aTextNode, int32_t aOffset,
const nsAString &aString, nsresult aResult) override;
--- a/editor/nsIEditActionListener.idl
+++ b/editor/nsIEditActionListener.idl
@@ -93,24 +93,23 @@ interface nsIEditActionListener : nsISup
* @param aOffset the offset of aExistingRightNode's content|children to do the split at
* @param aNewLeftNode [OUT] the new node resulting from the split, becomes aExistingRightNode's previous sibling.
*/
void WillSplitNode(in nsIDOMNode aExistingRightNode,
in long aOffset);
/**
* Called after the editor splits a node.
- * @param aExistingRightNode the node to split. It will become the new node's next sibling.
- * @param aOffset the offset of aExistingRightNode's content|children to do the split at
- * @param aNewLeftNode [OUT] the new node resulting from the split, becomes aExistingRightNode's previous sibling.
+ * @param aExistingRightNode The node which was split. It will become the
+ * next sibling of the new left node.
+ * @param aNewLeftNode The new node resulting from the split, becomes
+ * the previous sibling of aExistingRightNode.
*/
void DidSplitNode(in nsIDOMNode aExistingRightNode,
- in long aOffset,
- in nsIDOMNode aNewLeftNode,
- in nsresult aResult);
+ in nsIDOMNode aNewLeftNode);
/**
* Called before the editor joins 2 nodes.
* @param aLeftNode This node will be merged into the right node
* @param aRightNode The node that will be merged into.
* There is no requirement that the two nodes be of
* the same type.
* @param aParent The parent of aRightNode
--- a/editor/txtsvc/nsTextServicesDocument.cpp
+++ b/editor/txtsvc/nsTextServicesDocument.cpp
@@ -1615,25 +1615,19 @@ nsTextServicesDocument::DidDeleteNode(ns
}
UNLOCK_DOC(this);
return NS_OK;
}
NS_IMETHODIMP
-nsTextServicesDocument::DidSplitNode(nsIDOMNode *aExistingRightNode,
- int32_t aOffset,
- nsIDOMNode *aNewLeftNode,
- nsresult aResult)
+nsTextServicesDocument::DidSplitNode(nsIDOMNode* aExistingRightNode,
+ nsIDOMNode* aNewLeftNode)
{
- //**** KDEBUG ****
- // printf("** SplitNode: 0x%.8x %d 0x%.8x\n", aExistingRightNode, aOffset, aNewLeftNode);
- // fflush(stdout);
- //**** KDEBUG ****
return NS_OK;
}
NS_IMETHODIMP
nsTextServicesDocument::DidJoinNodes(nsIDOMNode *aLeftNode,
nsIDOMNode *aRightNode,
nsIDOMNode *aParent,
nsresult aResult)
--- a/editor/txtsvc/nsTextServicesDocument.h
+++ b/editor/txtsvc/nsTextServicesDocument.h
@@ -100,20 +100,18 @@ public:
int32_t aPosition,
nsresult aResult) override;
NS_IMETHOD WillDeleteNode(nsIDOMNode *aChild) override;
NS_IMETHOD DidDeleteNode(nsIDOMNode *aChild, nsresult aResult) override;
NS_IMETHOD WillSplitNode(nsIDOMNode * aExistingRightNode,
int32_t aOffset) override;
- NS_IMETHOD DidSplitNode(nsIDOMNode *aExistingRightNode,
- int32_t aOffset,
- nsIDOMNode *aNewLeftNode,
- nsresult aResult) override;
+ NS_IMETHOD DidSplitNode(nsIDOMNode* aExistingRightNode,
+ nsIDOMNode* aNewLeftNode) override;
NS_IMETHOD WillJoinNodes(nsIDOMNode *aLeftNode,
nsIDOMNode *aRightNode,
nsIDOMNode *aParent) override;
NS_IMETHOD DidJoinNodes(nsIDOMNode *aLeftNode,
nsIDOMNode *aRightNode,
nsIDOMNode *aParent,
nsresult aResult) override;
--- a/extensions/spellcheck/src/mozInlineSpellChecker.cpp
+++ b/extensions/spellcheck/src/mozInlineSpellChecker.cpp
@@ -1087,25 +1087,26 @@ NS_IMETHODIMP mozInlineSpellChecker::Wil
return NS_OK;
}
NS_IMETHODIMP mozInlineSpellChecker::DidDeleteNode(nsIDOMNode *aChild, nsresult aResult)
{
return NS_OK;
}
-NS_IMETHODIMP mozInlineSpellChecker::WillSplitNode(nsIDOMNode *aExistingRightNode, int32_t aOffset)
+NS_IMETHODIMP
+mozInlineSpellChecker::WillSplitNode(nsIDOMNode* aExistingRightNode,
+ int32_t aOffset)
{
return NS_OK;
}
NS_IMETHODIMP
-mozInlineSpellChecker::DidSplitNode(nsIDOMNode *aExistingRightNode,
- int32_t aOffset,
- nsIDOMNode *aNewLeftNode, nsresult aResult)
+mozInlineSpellChecker::DidSplitNode(nsIDOMNode* aExistingRightNode,
+ nsIDOMNode* aNewLeftNode)
{
return SpellCheckBetweenNodes(aNewLeftNode, 0, aNewLeftNode, 0);
}
NS_IMETHODIMP mozInlineSpellChecker::WillJoinNodes(nsIDOMNode *aLeftNode, nsIDOMNode *aRightNode, nsIDOMNode *aParent)
{
return NS_OK;
}