Bug 1408125 - part 3: Redesign nsIEditActionListener::(Will|Did)InsertNode() r?m_kato
Although nsIEditActionListener::WillInsertNode() nobody implements actually,
we should remove it in a follow up bug.
nsIEditActionListener::DidInsertNode() is implemented only by HTMLEditRules.
So, if we make it not use nsIEditActionListener, we can remove it too.
However, keep it for now.
On the other hand, they don't need to receive index of the insertion point.
WillInsertNode() needs next sibling of the insert point, but DidInsertNode()
needs nothing because listener can compute it with new inserted node.
MozReview-Commit-ID: GiTKkVyZJlN
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -1496,36 +1496,33 @@ EditorBase::InsertNode(nsIContent& aCont
}
MOZ_ASSERT(aPointToInsert.IsSetAndValid());
AutoRules beginRulesSniffing(this, EditAction::insertNode, nsIEditor::eNext);
{
AutoActionListenerArray listeners(mActionListeners);
for (auto& listener : listeners) {
- listener->WillInsertNode(aContentToInsert.AsDOMNode(),
- aPointToInsert.Container()->AsDOMNode(),
- aPointToInsert.Offset());
+ listener->WillInsertNode(
+ aContentToInsert.AsDOMNode(),
+ GetAsDOMNode(aPointToInsert.GetNextSiblingOfChildAtOffset()));
}
}
RefPtr<InsertNodeTransaction> transaction =
CreateTxnForInsertNode(aContentToInsert, aPointToInsert);
nsresult rv = DoTransaction(transaction);
mRangeUpdater.SelAdjInsertNode(aPointToInsert.Container(),
aPointToInsert.Offset());
{
AutoActionListenerArray listeners(mActionListeners);
for (auto& listener : listeners) {
- listener->DidInsertNode(aContentToInsert.AsDOMNode(),
- aPointToInsert.Container()->AsDOMNode(),
- aPointToInsert.Offset(),
- rv);
+ listener->DidInsertNode(aContentToInsert.AsDOMNode(), rv);
}
}
return rv;
}
NS_IMETHODIMP
EditorBase::SplitNode(nsIDOMNode* aNode,
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -8738,26 +8738,23 @@ HTMLEditRules::DidCreateNode(const nsASt
// assumption that Join keeps the righthand node
nsresult rv = mUtilRange->SelectNode(aNewNode);
NS_ENSURE_SUCCESS(rv, rv);
return UpdateDocChangeRange(mUtilRange);
}
NS_IMETHODIMP
HTMLEditRules::WillInsertNode(nsIDOMNode* aNode,
- nsIDOMNode* aParent,
- int32_t aPosition)
+ nsIDOMNode* aNextSiblingOfNewNode)
{
return NS_OK;
}
NS_IMETHODIMP
HTMLEditRules::DidInsertNode(nsIDOMNode* aNode,
- nsIDOMNode* aParent,
- int32_t aPosition,
nsresult aResult)
{
if (!mListenerEnabled) {
return NS_OK;
}
nsresult rv = mUtilRange->SelectNode(aNode);
NS_ENSURE_SUCCESS(rv, rv);
return UpdateDocChangeRange(mUtilRange);
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -106,20 +106,19 @@ public:
nsresult MakeSureElemStartsOrEndsOnCR(nsINode& aNode);
// nsIEditActionListener methods
NS_IMETHOD WillCreateNode(const nsAString& aTag,
nsIDOMNode* aNextSiblingOfNewNode) override;
NS_IMETHOD DidCreateNode(const nsAString& aTag, nsIDOMNode* aNewNode,
nsresult aResult) override;
- 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 WillInsertNode(nsIDOMNode* aNode,
+ nsIDOMNode* aNextSiblingOfNewNode) override;
+ NS_IMETHOD DidInsertNode(nsIDOMNode* aNode, 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,
nsIDOMNode* aNewLeftNode) override;
NS_IMETHOD WillJoinNodes(nsIDOMNode* aLeftNode, nsIDOMNode* aRightNode,
nsIDOMNode* aParent) override;
--- a/editor/nsIEditActionListener.idl
+++ b/editor/nsIEditActionListener.idl
@@ -45,39 +45,31 @@ interface nsIEditActionListener : nsISup
* @param aResult The result of the create node operation.
*/
void DidCreateNode(in DOMString aTag,
in nsIDOMNode aNewNode,
in nsresult aResult);
/**
* Called before the editor inserts a node.
- * @param aNode The DOM Node to insert.
- * @param aParent The node to insert the new object into
- * @param aPosition The place in aParent to insert the new node
- * 0=first child, 1=second child, etc.
- * any number > number of current children = last child
+ * @param aNode The DOM Node to insert.
+ * @param aNextSiblingOfNewNode The node which will be next sibling of
+ * new node. If the new node will be appended,
+ * this is null.
*/
void WillInsertNode(in nsIDOMNode aNode,
- in nsIDOMNode aParent,
- in long aPosition);
+ in nsIDOMNode aNextSiblingOfNewNode);
/**
* Called after the editor inserts a node.
* @param aNode The DOM Node to insert.
- * @param aParent The node to insert the new object into
- * @param aPosition The place in aParent to insert the new node
- * 0=first child, 1=second child, etc.
- * any number > number of current children = last child
* @param aResult The result of the insert node operation.
*/
void DidInsertNode(in nsIDOMNode aNode,
- in nsIDOMNode aParent,
- in long aPosition,
- in nsresult aResult);
+ in nsresult aResult);
/**
* Called before the editor deletes a node.
* @param aChild The node to delete
*/
void WillDeleteNode(in nsIDOMNode aChild);
/**
--- a/editor/txtsvc/nsTextServicesDocument.cpp
+++ b/editor/txtsvc/nsTextServicesDocument.cpp
@@ -1494,20 +1494,18 @@ nsTextServicesDocument::InsertText(const
rv = editor->EndTransaction();
UNLOCK_DOC(this);
return rv;
}
NS_IMETHODIMP
-nsTextServicesDocument::DidInsertNode(nsIDOMNode *aNode,
- nsIDOMNode *aParent,
- int32_t aPosition,
- nsresult aResult)
+nsTextServicesDocument::DidInsertNode(nsIDOMNode* aNode,
+ nsresult aResult)
{
return NS_OK;
}
NS_IMETHODIMP
nsTextServicesDocument::DidDeleteNode(nsIDOMNode *aChild, nsresult aResult)
{
NS_ENSURE_SUCCESS(aResult, NS_OK);
@@ -3236,19 +3234,18 @@ nsTextServicesDocument::FindWordBounds(n
}
}
return NS_OK;
}
NS_IMETHODIMP
-nsTextServicesDocument::WillInsertNode(nsIDOMNode *aNode,
- nsIDOMNode *aParent,
- int32_t aPosition)
+nsTextServicesDocument::WillInsertNode(nsIDOMNode* aNode,
+ nsIDOMNode* aNextSiblingOfNewNode)
{
return NS_OK;
}
NS_IMETHODIMP
nsTextServicesDocument::WillDeleteNode(nsIDOMNode *aChild)
{
return NS_OK;
--- a/editor/txtsvc/nsTextServicesDocument.h
+++ b/editor/txtsvc/nsTextServicesDocument.h
@@ -86,23 +86,19 @@ public:
NS_IMETHOD NextBlock() override;
NS_IMETHOD IsDone(bool *aIsDone) override;
NS_IMETHOD SetSelection(int32_t aOffset, int32_t aLength) override;
NS_IMETHOD ScrollSelectionIntoView() override;
NS_IMETHOD DeleteSelection() override;
NS_IMETHOD InsertText(const nsString *aText) override;
/* nsIEditActionListener method implementations. */
- 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 WillInsertNode(nsIDOMNode* aNode,
+ nsIDOMNode* aNextSiblingOfNewNode) override;
+ NS_IMETHOD DidInsertNode(nsIDOMNode* aNode, 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,
nsIDOMNode* aNewLeftNode) override;
--- a/extensions/spellcheck/src/mozInlineSpellChecker.cpp
+++ b/extensions/spellcheck/src/mozInlineSpellChecker.cpp
@@ -1049,26 +1049,27 @@ mozInlineSpellChecker::WillCreateNode(co
NS_IMETHODIMP
mozInlineSpellChecker::DidCreateNode(const nsAString& aTag,
nsIDOMNode* aNewNode,
nsresult aResult)
{
return NS_OK;
}
-NS_IMETHODIMP mozInlineSpellChecker::WillInsertNode(nsIDOMNode *aNode, nsIDOMNode *aParent,
- int32_t aPosition)
+NS_IMETHODIMP
+mozInlineSpellChecker::WillInsertNode(nsIDOMNode* aNode,
+ nsIDOMNode* aNextSiblingOfNewNode)
{
return NS_OK;
}
-NS_IMETHODIMP mozInlineSpellChecker::DidInsertNode(nsIDOMNode *aNode, nsIDOMNode *aParent,
- int32_t aPosition, nsresult aResult)
+NS_IMETHODIMP
+mozInlineSpellChecker::DidInsertNode(nsIDOMNode* aNode,
+ nsresult aResult)
{
-
return NS_OK;
}
NS_IMETHODIMP mozInlineSpellChecker::WillDeleteNode(nsIDOMNode *aChild)
{
return NS_OK;
}