Bug 1430785 - Make mozInlineSpellChecker not derived from nsIEditActionListener r=m_kato

mozInlineSpellChecker listens to only DidSplitNode() and DidJoinNodes().
So, EditorBase should call them directly rather than treating it as an
nsIEditActionListener since its runtime cost becomes really cheaper.

Different from EditorSpellCheck, nobody creates instance of
nsIInlineSpellChecker.  So, we can now stop supporting createInstance() for it
in chrome JS and should do this since EditorBase cannot support multiple
mozInlineSpellChecker instances without nsIEditActionListener interface.
Therefore, this patch removes the entry from factory.

MozReview-Commit-ID: W1CLdsJaaB

--HG--
extra : rebase_source : 2319999e4b1fc8978386c49236d5d24d78d86047
This commit is contained in:
Masayuki Nakano 2018-01-17 14:05:06 +09:00
parent 2020349542
commit 92d5c4cdd8
5 changed files with 44 additions and 92 deletions

View File

@ -1575,6 +1575,11 @@ EditorBase::SplitNode(const EditorRawDOMPoint& aStartOfRightNode,
htmlEditRules->DidSplitNode(aStartOfRightNode.GetContainer(), newNode);
}
if (mInlineSpellChecker) {
RefPtr<mozInlineSpellChecker> spellChecker = mInlineSpellChecker;
spellChecker->DidSplitNode(aStartOfRightNode.GetContainer(), newNode);
}
if (!mActionListeners.IsEmpty()) {
AutoActionListenerArray listeners(mActionListeners);
for (auto& listener : listeners) {
@ -1639,6 +1644,11 @@ EditorBase::JoinNodes(nsINode& aLeftNode,
htmlEditRules->DidJoinNodes(aLeftNode, aRightNode);
}
if (mInlineSpellChecker) {
RefPtr<mozInlineSpellChecker> spellChecker = mInlineSpellChecker;
spellChecker->DidJoinNodes(aLeftNode, aRightNode);
}
if (mTextServicesDocument && NS_SUCCEEDED(rv)) {
RefPtr<TextServicesDocument> textServicesDocument = mTextServicesDocument;
textServicesDocument->DidJoinNodes(aLeftNode, aRightNode);
@ -2213,6 +2223,8 @@ EditorBase::AddEditActionListener(nsIEditActionListener* aListener)
// Make sure the listener isn't already on the list
if (!mActionListeners.Contains(aListener)) {
mActionListeners.AppendElement(*aListener);
NS_WARNING_ASSERTION(mActionListeners.Length() != 1,
"nsIEditActionListener installed, this editor becomes slower");
}
return NS_OK;
@ -2228,6 +2240,8 @@ EditorBase::RemoveEditActionListener(nsIEditActionListener* aListener)
return NS_OK;
}
NS_WARNING_ASSERTION(mActionListeners.Length() != 1,
"All nsIEditActionListeners have been removed, this editor becomes faster");
mActionListeners.RemoveElement(aListener);
return NS_OK;

View File

@ -48,9 +48,3 @@ interface nsIInlineSpellChecker : nsISupports
readonly attribute boolean spellCheckPending;
};
%{C++
#define MOZ_INLINESPELLCHECKER_CONTRACTID "@mozilla.org/spellchecker-inline;1"
%}

View File

@ -527,7 +527,6 @@ NS_IMPL_ISUPPORTS(InitEditorSpellCheckCallback, nsIEditorSpellCheckCallback)
NS_INTERFACE_MAP_BEGIN(mozInlineSpellChecker)
NS_INTERFACE_MAP_ENTRY(nsIInlineSpellChecker)
NS_INTERFACE_MAP_ENTRY(nsIEditActionListener)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMEventListener)
@ -705,7 +704,7 @@ mozInlineSpellChecker::RegisterEventListeners()
return NS_ERROR_FAILURE;
}
mTextEditor->AddEditActionListener(this);
StartToListenToEditActions();
nsCOMPtr<nsIDocument> doc = mTextEditor->GetDocument();
if (NS_WARN_IF(!doc)) {
@ -726,7 +725,7 @@ mozInlineSpellChecker::UnregisterEventListeners()
return NS_ERROR_FAILURE;
}
mTextEditor->RemoveEditActionListener(this);
EndListeningToEditActions();
nsCOMPtr<nsIDocument> doc = mTextEditor->GetDocument();
if (NS_WARN_IF(!doc)) {
@ -1038,80 +1037,26 @@ mozInlineSpellChecker::IgnoreWords(const char16_t **aWordsToIgnore,
return ScheduleSpellCheck(Move(status));
}
NS_IMETHODIMP
mozInlineSpellChecker::DidCreateNode(const nsAString& aTag,
nsIDOMNode* aNewNode,
nsresult aResult)
void
mozInlineSpellChecker::DidSplitNode(nsINode* aExistingRightNode,
nsINode* aNewLeftNode)
{
return NS_OK;
if (!mIsListeningToEditActions) {
return;
}
nsIDOMNode* newLeftDOMNode =
aNewLeftNode ? aNewLeftNode->AsDOMNode() : nullptr;
SpellCheckBetweenNodes(newLeftDOMNode, 0, newLeftDOMNode, 0);
}
NS_IMETHODIMP
mozInlineSpellChecker::DidInsertNode(nsIDOMNode* aNode,
nsresult aResult)
void
mozInlineSpellChecker::DidJoinNodes(nsINode& aLeftNode,
nsINode& aRightNode)
{
return NS_OK;
}
NS_IMETHODIMP
mozInlineSpellChecker::DidDeleteNode(nsIDOMNode* aChild,
nsresult aResult)
{
return NS_OK;
}
NS_IMETHODIMP
mozInlineSpellChecker::DidSplitNode(nsIDOMNode* aExistingRightNode,
nsIDOMNode* aNewLeftNode)
{
return SpellCheckBetweenNodes(aNewLeftNode, 0, aNewLeftNode, 0);
}
NS_IMETHODIMP
mozInlineSpellChecker::DidJoinNodes(nsIDOMNode* aLeftNode,
nsIDOMNode* aRightNode,
nsIDOMNode* aParent,
nsresult aResult)
{
return SpellCheckBetweenNodes(aRightNode, 0, aRightNode, 0);
}
NS_IMETHODIMP
mozInlineSpellChecker::DidInsertText(nsIDOMCharacterData* aTextNode,
int32_t aOffset,
const nsAString& aString,
nsresult aResult)
{
return NS_OK;
}
NS_IMETHODIMP
mozInlineSpellChecker::WillDeleteText(nsIDOMCharacterData* aTextNode,
int32_t aOffset,
int32_t aLength)
{
return NS_OK;
}
NS_IMETHODIMP
mozInlineSpellChecker::DidDeleteText(nsIDOMCharacterData* aTextNode,
int32_t aOffset,
int32_t aLength,
nsresult aResult)
{
return NS_OK;
}
NS_IMETHODIMP
mozInlineSpellChecker::WillDeleteSelection(nsISelection* aSelection)
{
return NS_OK;
}
NS_IMETHODIMP
mozInlineSpellChecker::DidDeleteSelection(nsISelection* aSelection)
{
return NS_OK;
if (!mIsListeningToEditActions) {
return;
}
SpellCheckBetweenNodes(aRightNode.AsDOMNode(), 0, aRightNode.AsDOMNode(), 0);
}
// mozInlineSpellChecker::MakeSpellCheckRange

View File

@ -9,7 +9,6 @@
#include "nsCycleCollectionParticipant.h"
#include "nsIDOMEventListener.h"
#include "nsIDOMTreeWalker.h"
#include "nsIEditActionListener.h"
#include "nsIEditorSpellCheck.h"
#include "nsIInlineSpellChecker.h"
#include "nsRange.h"
@ -112,7 +111,6 @@ protected:
};
class mozInlineSpellChecker final : public nsIInlineSpellChecker,
public nsIEditActionListener,
public nsIDOMEventListener,
public nsSupportsWeakReference
{
@ -176,10 +174,13 @@ private:
// the whole document.
bool mFullSpellCheckScheduled;
// Set to true when this instance needs to listen to edit actions of
// the editor.
bool mIsListeningToEditActions;
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_NSIEDITACTIONLISTENER
NS_DECL_NSIINLINESPELLCHECKER
NS_DECL_NSIDOMEVENTLISTENER
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(mozInlineSpellChecker, nsIDOMEventListener)
@ -250,6 +251,11 @@ public:
nsresult ResumeCheck(mozilla::UniquePtr<mozInlineSpellStatus>&& aStatus);
// Those methods are called when mTextEditor splits a node or joins the
// given nodes.
void DidSplitNode(nsINode* aExistingRightNode, nsINode* aNewLeftNode);
void DidJoinNodes(nsINode& aRightNode, nsINode& aLeftNode);
protected:
virtual ~mozInlineSpellChecker();
@ -262,6 +268,9 @@ protected:
void ChangeNumPendingSpellChecks(int32_t aDelta,
mozilla::TextEditor* aTextEditor = nullptr);
void NotifyObservers(const char* aTopic, mozilla::TextEditor* aTextEditor);
void StartToListenToEditActions() { mIsListeningToEditActions = true; }
void EndListeningToEditActions() { mIsListeningToEditActions = false; }
};
#endif // #ifndef mozilla_mozInlineSpellChecker_h

View File

@ -8,7 +8,6 @@
#include "mozHunspell.h"
#include "mozHunspellDirProvider.h"
#include "mozSpellChecker.h"
#include "mozInlineSpellChecker.h"
#include "mozPersonalDictionary.h"
#include "mozSpellI18NManager.h"
#include "nsIFile.h"
@ -18,24 +17,17 @@
0x8227F019, 0xAFC7, 0x461e, \
{ 0xB0, 0x30, 0x9F, 0x18, 0x5D, 0x7A, 0x0E, 0x29} }
#define MOZ_INLINESPELLCHECKER_CID \
{ /* 9FE5D975-09BD-44aa-A01A-66402EA28657 */ \
0x9fe5d975, 0x9bd, 0x44aa, \
{ 0xa0, 0x1a, 0x66, 0x40, 0x2e, 0xa2, 0x86, 0x57} }
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(mozHunspell, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(mozHunspellDirProvider)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(mozSpellChecker, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(mozPersonalDictionary, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(mozSpellI18NManager)
NS_GENERIC_FACTORY_CONSTRUCTOR(mozInlineSpellChecker)
NS_DEFINE_NAMED_CID(MOZ_HUNSPELL_CID);
NS_DEFINE_NAMED_CID(HUNSPELLDIRPROVIDER_CID);
NS_DEFINE_NAMED_CID(NS_SPELLCHECKER_CID);
NS_DEFINE_NAMED_CID(MOZ_PERSONALDICTIONARY_CID);
NS_DEFINE_NAMED_CID(MOZ_SPELLI18NMANAGER_CID);
NS_DEFINE_NAMED_CID(MOZ_INLINESPELLCHECKER_CID);
static const mozilla::Module::CIDEntry kSpellcheckCIDs[] = {
{ &kMOZ_HUNSPELL_CID, false, nullptr, mozHunspellConstructor },
@ -43,7 +35,6 @@ static const mozilla::Module::CIDEntry kSpellcheckCIDs[] = {
{ &kNS_SPELLCHECKER_CID, false, nullptr, mozSpellCheckerConstructor },
{ &kMOZ_PERSONALDICTIONARY_CID, false, nullptr, mozPersonalDictionaryConstructor },
{ &kMOZ_SPELLI18NMANAGER_CID, false, nullptr, mozSpellI18NManagerConstructor },
{ &kMOZ_INLINESPELLCHECKER_CID, false, nullptr, mozInlineSpellCheckerConstructor },
{ nullptr }
};
@ -53,7 +44,6 @@ static const mozilla::Module::ContractIDEntry kSpellcheckContracts[] = {
{ NS_SPELLCHECKER_CONTRACTID, &kNS_SPELLCHECKER_CID },
{ MOZ_PERSONALDICTIONARY_CONTRACTID, &kMOZ_PERSONALDICTIONARY_CID },
{ MOZ_SPELLI18NMANAGER_CONTRACTID, &kMOZ_SPELLI18NMANAGER_CID },
{ MOZ_INLINESPELLCHECKER_CONTRACTID, &kMOZ_INLINESPELLCHECKER_CID },
{ nullptr }
};