Bug 1330912 - Part 3. Don't update dictionary during onfocus when spellcheck is unnecessary. r?masayuki
Such as <input type=password>, focused element doesn't use spellchecker, we should not call UpdateCurrentDictionary. Also, when the attribute is changed, we should call UpdateCurrentDictionary if uninitialized.
MozReview-Commit-ID: LSfDTAszviE
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -140,16 +140,17 @@ EditorBase::EditorBase()
, mDocDirtyState(-1)
, mSpellcheckCheckboxState(eTriUnset)
, mShouldTxnSetSelection(true)
, mDidPreDestroy(false)
, mDidPostCreate(false)
, mDispatchInputEvent(true)
, mIsInEditAction(false)
, mHidingCaret(false)
+ , mSpellCheckerDictionaryUpdated(true)
{
}
EditorBase::~EditorBase()
{
NS_ASSERTION(!mDocWeak || mDidPreDestroy, "Why PreDestroy hasn't been called?");
if (mComposition) {
@@ -1339,16 +1340,21 @@ EditorBase::SyncRealTimeSpell()
{
bool enable = GetDesiredSpellCheckState();
// Initializes mInlineSpellChecker
nsCOMPtr<nsIInlineSpellChecker> spellChecker;
GetInlineSpellChecker(enable, getter_AddRefs(spellChecker));
if (mInlineSpellChecker) {
+ if (!mSpellCheckerDictionaryUpdated && enable) {
+ mInlineSpellChecker->UpdateCurrentDictionary();
+ mSpellCheckerDictionaryUpdated = true;
+ }
+
// We might have a mInlineSpellChecker even if there are no dictionaries
// available since we don't destroy the mInlineSpellChecker when the last
// dictionariy is removed, but in that case spellChecker is null
mInlineSpellChecker->SetEnableRealTimeSpell(enable && spellChecker);
}
return NS_OK;
}
@@ -5210,18 +5216,20 @@ EditorBase::IsAcceptableInputEvent(Widge
// element of the DOM window.
return IsActiveInDOMWindow();
}
void
EditorBase::OnFocus(nsIDOMEventTarget* aFocusEventTarget)
{
InitializeSelection(aFocusEventTarget);
- if (mInlineSpellChecker) {
+ mSpellCheckerDictionaryUpdated = false;
+ if (mInlineSpellChecker && CanEnableSpellCheck()) {
mInlineSpellChecker->UpdateCurrentDictionary();
+ mSpellCheckerDictionaryUpdated = true;
}
}
NS_IMETHODIMP
EditorBase::GetSuppressDispatchingInputEvent(bool* aSuppressed)
{
NS_ENSURE_ARG_POINTER(aSuppressed);
*aSuppressed = !mDispatchInputEvent;
--- a/editor/libeditor/EditorBase.h
+++ b/editor/libeditor/EditorBase.h
@@ -1077,16 +1077,18 @@ protected:
bool mDidPreDestroy;
// Whether PostCreate has been called.
bool mDidPostCreate;
bool mDispatchInputEvent;
// True while the instance is handling an edit action.
bool mIsInEditAction;
// Whether caret is hidden forcibly.
bool mHidingCaret;
+ // Whether spellchecker dictionary is initialized after focused.
+ bool mSpellCheckerDictionaryUpdated;
friend bool NSCanUnload(nsISupports* serviceMgr);
friend class AutoRules;
friend class AutoSelectionRestorer;
friend class AutoTransactionsConserveSelection;
friend class RangeUpdater;
};