Bug 1430319 - Get rid of nsIEditActionListener::Will*() which are not used by anybody r=m_kato

Most nsIEditActionListener::Will*() are not implemented, except
WillDeleteText() and WillDeleteSelection() which are implemented by
FinderHighlighter.  So, we can get rid of the other Will*() from it.

This patch removes a lot of unnecessary virtual calls and copy of strong
pointers to edit action listeners of EditorBase.

MozReview-Commit-ID: EsqI2tZoBG1

--HG--
extra : rebase_source : cf78eb8d33b12ca65177b0676f6e45d02e7c0688
This commit is contained in:
Masayuki Nakano 2018-01-13 10:10:05 +09:00
Родитель 31d493d9fa
Коммит 397a47c1b9
5 изменённых файлов: 51 добавлений и 258 удалений

Просмотреть файл

@ -1430,14 +1430,6 @@ EditorBase::CreateNode(nsAtom* aTag,
AutoRules beginRulesSniffing(this, EditAction::createNode, nsIEditor::eNext);
if (!mActionListeners.IsEmpty()) {
AutoActionListenerArray listeners(mActionListeners);
for (auto& listener : listeners) {
listener->WillCreateNode(nsDependentAtomString(aTag),
GetAsDOMNode(pointToInsert.GetChild()));
}
}
nsCOMPtr<Element> ret;
RefPtr<CreateElementTransaction> transaction =
@ -1500,15 +1492,6 @@ EditorBase::InsertNode(nsIContent& aContentToInsert,
AutoRules beginRulesSniffing(this, EditAction::insertNode, nsIEditor::eNext);
if (!mActionListeners.IsEmpty()) {
AutoActionListenerArray listeners(mActionListeners);
for (auto& listener : listeners) {
listener->WillInsertNode(
aContentToInsert.AsDOMNode(),
GetAsDOMNode(aPointToInsert.GetNextSiblingOfChild()));
}
}
RefPtr<InsertNodeTransaction> transaction =
InsertNodeTransaction::Create(*this, aContentToInsert, aPointToInsert);
nsresult rv = DoTransaction(transaction);
@ -1565,24 +1548,10 @@ EditorBase::SplitNode(const EditorRawDOMPoint& aStartOfRightNode,
AutoRules beginRulesSniffing(this, EditAction::splitNode, nsIEditor::eNext);
// Different from CreateNode(), we need offset at start of right node only
// for WillSplitNode() since the offset is always same as the length of new
// left node.
if (!mActionListeners.IsEmpty()) {
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.GetContainerAsDOMNode(),
aStartOfRightNode.Offset());
}
} else {
// 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();
}
// 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);
@ -1648,14 +1617,6 @@ EditorBase::JoinNodes(nsINode& aLeftNode,
htmlEditRules->WillJoinNodes(aLeftNode, aRightNode);
}
if (!mActionListeners.IsEmpty()) {
AutoActionListenerArray listeners(mActionListeners);
for (auto& listener : listeners) {
listener->WillJoinNodes(aLeftNode.AsDOMNode(), aRightNode.AsDOMNode(),
parent->AsDOMNode());
}
}
nsresult rv = NS_OK;
RefPtr<JoinNodeTransaction> transaction =
JoinNodeTransaction::MaybeCreate(*this, aLeftNode, aRightNode);
@ -1707,14 +1668,6 @@ EditorBase::DeleteNode(nsINode* aNode)
htmlEditRules->WillDeleteNode(aNode);
}
// save node location for selection updating code.
if (!mActionListeners.IsEmpty()) {
AutoActionListenerArray listeners(mActionListeners);
for (auto& listener : listeners) {
listener->WillDeleteNode(aNode->AsDOMNode());
}
}
RefPtr<DeleteNodeTransaction> deleteNodeTransaction =
DeleteNodeTransaction::MaybeCreate(*this, *aNode);
nsresult rv = deleteNodeTransaction ? DoTransaction(deleteNodeTransaction) :
@ -2845,16 +2798,6 @@ EditorBase::InsertTextIntoTextNodeImpl(const nsAString& aStringToInsert,
InsertTextTransaction::Create(*this, aStringToInsert, aTextNode, aOffset);
}
// Let listeners know what's up
if (!mActionListeners.IsEmpty()) {
AutoActionListenerArray listeners(mActionListeners);
for (auto& listener : listeners) {
listener->WillInsertText(
static_cast<nsIDOMCharacterData*>(insertedTextNode->AsDOMNode()),
insertedOffset, aStringToInsert);
}
}
// XXX We may not need these view batches anymore. This is handled at a
// higher level now I believe.
BeginUpdateViewBatch();
@ -2996,19 +2939,11 @@ EditorBase::SetTextImpl(Selection& aSelection, const nsAString& aString,
nsIEditor::eNext);
// Let listeners know what's up
if (!mActionListeners.IsEmpty()) {
if (!mActionListeners.IsEmpty() && length) {
AutoActionListenerArray listeners(mActionListeners);
for (auto& listener : listeners) {
if (length) {
listener->WillDeleteText(
static_cast<nsIDOMCharacterData*>(aCharData.AsDOMNode()), 0,
length);
}
if (!aString.IsEmpty()) {
listener->WillInsertText(
static_cast<nsIDOMCharacterData*>(aCharData.AsDOMNode()), 0,
aString);
}
listener->WillDeleteText(
static_cast<nsIDOMCharacterData*>(aCharData.AsDOMNode()), 0, length);
}
}
@ -4434,21 +4369,18 @@ EditorBase::DeleteSelectionImpl(EDirection aAction,
}
}
// Notify nsIEditActionListener::WillDelete[Selection|Text|Node]
// Notify nsIEditActionListener::WillDelete[Selection|Text]
if (!mActionListeners.IsEmpty()) {
AutoActionListenerArray listeners(mActionListeners);
if (!deleteNode) {
AutoActionListenerArray listeners(mActionListeners);
for (auto& listener : listeners) {
listener->WillDeleteSelection(selection);
}
} else if (deleteCharData) {
AutoActionListenerArray listeners(mActionListeners);
for (auto& listener : listeners) {
listener->WillDeleteText(deleteCharData, deleteCharOffset, 1);
}
} else {
for (auto& listener : listeners) {
listener->WillDeleteNode(deleteNode->AsDOMNode());
}
}
}

Просмотреть файл

@ -26,18 +26,8 @@ Editor Action Listener interface to outside world
*/
[scriptable, uuid(b22907b1-ee93-11d2-8d50-000064657374)]
interface nsIEditActionListener : nsISupports{
/**
* Called before the editor creates a node.
* @param aTag The tag name of the DOM Node to create.
* @param aNextSiblingOfNewNode The node which will be next sibling of
* new node. If the new node will be appended,
* this is null.
*/
void WillCreateNode(in DOMString aTag,
in nsIDOMNode aNextSiblingOfNewNode);
interface nsIEditActionListener : nsISupports
{
/**
* Called after the editor creates a node.
* @param aTag The tag name of the DOM Node to create.
@ -48,16 +38,6 @@ interface nsIEditActionListener : nsISupports{
in nsIDOMNode aNewNode,
in nsresult aResult);
/**
* Called before the editor inserts a node.
* @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 aNextSiblingOfNewNode);
/**
* Called after the editor inserts a node.
* @param aNode The DOM Node to insert.
@ -66,12 +46,6 @@ interface nsIEditActionListener : nsISupports{
void DidInsertNode(in nsIDOMNode aNode,
in nsresult aResult);
/**
* Called before the editor deletes a node.
* @param aChild The node to delete
*/
void WillDeleteNode(in nsIDOMNode aChild);
/**
* Called after the editor deletes a node.
* @param aChild The node to delete
@ -79,15 +53,6 @@ interface nsIEditActionListener : nsISupports{
*/
void DidDeleteNode(in nsIDOMNode aChild, in nsresult aResult);
/**
* Called before 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.
*/
void WillSplitNode(in nsIDOMNode aExistingRightNode,
in long aOffset);
/**
* Called after the editor splits a node.
* @param aExistingRightNode The node which was split. It will become the
@ -98,18 +63,6 @@ interface nsIEditActionListener : nsISupports{
void DidSplitNode(in nsIDOMNode aExistingRightNode,
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
*/
void WillJoinNodes(in nsIDOMNode aLeftNode,
in nsIDOMNode aRightNode,
in nsIDOMNode aParent);
/**
* Called after the editor joins 2 nodes.
* @param aLeftNode This node will be merged into the right node
@ -124,16 +77,6 @@ interface nsIEditActionListener : nsISupports{
in nsIDOMNode aParent,
in nsresult aResult);
/**
* Called before the editor inserts text.
* @param aTextNode This node getting inserted text
* @param aOffset The offset in aTextNode to insert at.
* @param aString The string that gets inserted.
*/
void WillInsertText(in nsIDOMCharacterData aTextNode,
in long aOffset,
in DOMString aString);
/**
* Called after the editor inserts text.
* @param aTextNode This node getting inserted text

Просмотреть файл

@ -3238,45 +3238,10 @@ nsTextServicesDocument::FindWordBounds(nsTArray<OffsetEntry*> *aOffsetTable,
return NS_OK;
}
NS_IMETHODIMP
nsTextServicesDocument::WillInsertNode(nsIDOMNode* aNode,
nsIDOMNode* aNextSiblingOfNewNode)
{
return NS_OK;
}
NS_IMETHODIMP
nsTextServicesDocument::WillDeleteNode(nsIDOMNode *aChild)
{
return NS_OK;
}
NS_IMETHODIMP
nsTextServicesDocument::WillSplitNode(nsIDOMNode *aExistingRightNode,
int32_t aOffset)
{
return NS_OK;
}
NS_IMETHODIMP
nsTextServicesDocument::WillJoinNodes(nsIDOMNode *aLeftNode,
nsIDOMNode *aRightNode,
nsIDOMNode *aParent)
{
return NS_OK;
}
// -------------------------------
// stubs for unused listen methods
// -------------------------------
NS_IMETHODIMP
nsTextServicesDocument::WillCreateNode(const nsAString& aTag,
nsIDOMNode* aNextSiblingOfNewNode)
{
return NS_OK;
}
NS_IMETHODIMP
nsTextServicesDocument::DidCreateNode(const nsAString& aTag,
nsIDOMNode* aNewNode,
@ -3286,37 +3251,39 @@ nsTextServicesDocument::DidCreateNode(const nsAString& aTag,
}
NS_IMETHODIMP
nsTextServicesDocument::WillInsertText(nsIDOMCharacterData *aTextNode, int32_t aOffset, const nsAString &aString)
nsTextServicesDocument::DidInsertText(nsIDOMCharacterData* aTextNode,
int32_t aOffset,
const nsAString& aString,
nsresult aResult)
{
return NS_OK;
}
NS_IMETHODIMP
nsTextServicesDocument::DidInsertText(nsIDOMCharacterData *aTextNode, int32_t aOffset, const nsAString &aString, nsresult aResult)
nsTextServicesDocument::WillDeleteText(nsIDOMCharacterData* aTextNode,
int32_t aOffset,
int32_t aLength)
{
return NS_OK;
}
NS_IMETHODIMP
nsTextServicesDocument::WillDeleteText(nsIDOMCharacterData *aTextNode, int32_t aOffset, int32_t aLength)
nsTextServicesDocument::DidDeleteText(nsIDOMCharacterData* aTextNode,
int32_t aOffset,
int32_t aLength,
nsresult aResult)
{
return NS_OK;
}
NS_IMETHODIMP
nsTextServicesDocument::DidDeleteText(nsIDOMCharacterData *aTextNode, int32_t aOffset, int32_t aLength, nsresult aResult)
nsTextServicesDocument::WillDeleteSelection(nsISelection* aSelection)
{
return NS_OK;
}
NS_IMETHODIMP
nsTextServicesDocument::WillDeleteSelection(nsISelection *aSelection)
{
return NS_OK;
}
NS_IMETHODIMP
nsTextServicesDocument::DidDeleteSelection(nsISelection *aSelection)
nsTextServicesDocument::DidDeleteSelection(nsISelection* aSelection)
{
return NS_OK;
}

Просмотреть файл

@ -91,37 +91,7 @@ public:
NS_IMETHOD InsertText(const nsString *aText) override;
/* nsIEditActionListener method implementations. */
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;
NS_IMETHOD DidJoinNodes(nsIDOMNode *aLeftNode,
nsIDOMNode *aRightNode,
nsIDOMNode *aParent,
nsresult aResult) override;
// these listen methods are unused:
NS_IMETHOD WillCreateNode(const nsAString& aTag,
nsIDOMNode* aNextSiblingOfNewNode) override;
NS_IMETHOD DidCreateNode(const nsAString& aTag,
nsIDOMNode* aNewNode,
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;
NS_IMETHOD WillDeleteText(nsIDOMCharacterData *aTextNode, int32_t aOffset, int32_t aLength) override;
NS_IMETHOD DidDeleteText(nsIDOMCharacterData *aTextNode, int32_t aOffset, int32_t aLength, nsresult aResult) override;
NS_IMETHOD WillDeleteSelection(nsISelection *aSelection) override;
NS_IMETHOD DidDeleteSelection(nsISelection *aSelection) override;
NS_DECL_NSIEDITACTIONLISTENER
/* Helper functions */
static nsresult GetRangeEndPoints(nsRange* aRange,

Просмотреть файл

@ -1038,13 +1038,6 @@ mozInlineSpellChecker::IgnoreWords(const char16_t **aWordsToIgnore,
return ScheduleSpellCheck(Move(status));
}
NS_IMETHODIMP
mozInlineSpellChecker::WillCreateNode(const nsAString& aTag,
nsIDOMNode* aNextSiblingOfNewNode)
{
return NS_OK;
}
NS_IMETHODIMP
mozInlineSpellChecker::DidCreateNode(const nsAString& aTag,
nsIDOMNode* aNewNode,
@ -1053,13 +1046,6 @@ mozInlineSpellChecker::DidCreateNode(const nsAString& aTag,
return NS_OK;
}
NS_IMETHODIMP
mozInlineSpellChecker::WillInsertNode(nsIDOMNode* aNode,
nsIDOMNode* aNextSiblingOfNewNode)
{
return NS_OK;
}
NS_IMETHODIMP
mozInlineSpellChecker::DidInsertNode(nsIDOMNode* aNode,
nsresult aResult)
@ -1067,19 +1053,9 @@ mozInlineSpellChecker::DidInsertNode(nsIDOMNode* aNode,
return NS_OK;
}
NS_IMETHODIMP mozInlineSpellChecker::WillDeleteNode(nsIDOMNode *aChild)
{
return NS_OK;
}
NS_IMETHODIMP mozInlineSpellChecker::DidDeleteNode(nsIDOMNode *aChild, nsresult aResult)
{
return NS_OK;
}
NS_IMETHODIMP
mozInlineSpellChecker::WillSplitNode(nsIDOMNode* aExistingRightNode,
int32_t aOffset)
mozInlineSpellChecker::DidDeleteNode(nsIDOMNode* aChild,
nsresult aResult)
{
return NS_OK;
}
@ -1091,44 +1067,49 @@ mozInlineSpellChecker::DidSplitNode(nsIDOMNode* aExistingRightNode,
return SpellCheckBetweenNodes(aNewLeftNode, 0, aNewLeftNode, 0);
}
NS_IMETHODIMP mozInlineSpellChecker::WillJoinNodes(nsIDOMNode *aLeftNode, nsIDOMNode *aRightNode, nsIDOMNode *aParent)
{
return NS_OK;
}
NS_IMETHODIMP mozInlineSpellChecker::DidJoinNodes(nsIDOMNode *aLeftNode, nsIDOMNode *aRightNode,
nsIDOMNode *aParent, nsresult aResult)
NS_IMETHODIMP
mozInlineSpellChecker::DidJoinNodes(nsIDOMNode* aLeftNode,
nsIDOMNode* aRightNode,
nsIDOMNode* aParent,
nsresult aResult)
{
return SpellCheckBetweenNodes(aRightNode, 0, aRightNode, 0);
}
NS_IMETHODIMP mozInlineSpellChecker::WillInsertText(nsIDOMCharacterData *aTextNode, int32_t aOffset, const nsAString & aString)
NS_IMETHODIMP
mozInlineSpellChecker::DidInsertText(nsIDOMCharacterData* aTextNode,
int32_t aOffset,
const nsAString& aString,
nsresult aResult)
{
return NS_OK;
}
NS_IMETHODIMP mozInlineSpellChecker::DidInsertText(nsIDOMCharacterData *aTextNode, int32_t aOffset,
const nsAString & aString, nsresult aResult)
NS_IMETHODIMP
mozInlineSpellChecker::WillDeleteText(nsIDOMCharacterData* aTextNode,
int32_t aOffset,
int32_t aLength)
{
return NS_OK;
}
NS_IMETHODIMP mozInlineSpellChecker::WillDeleteText(nsIDOMCharacterData *aTextNode, int32_t aOffset, int32_t aLength)
NS_IMETHODIMP
mozInlineSpellChecker::DidDeleteText(nsIDOMCharacterData* aTextNode,
int32_t aOffset,
int32_t aLength,
nsresult aResult)
{
return NS_OK;
}
NS_IMETHODIMP mozInlineSpellChecker::DidDeleteText(nsIDOMCharacterData *aTextNode, int32_t aOffset, int32_t aLength, nsresult aResult)
NS_IMETHODIMP
mozInlineSpellChecker::WillDeleteSelection(nsISelection* aSelection)
{
return NS_OK;
}
NS_IMETHODIMP mozInlineSpellChecker::WillDeleteSelection(nsISelection *aSelection)
{
return NS_OK;
}
NS_IMETHODIMP mozInlineSpellChecker::DidDeleteSelection(nsISelection *aSelection)
NS_IMETHODIMP
mozInlineSpellChecker::DidDeleteSelection(nsISelection* aSelection)
{
return NS_OK;
}