Bug 697981 - Prevent reloading of spelling dictionary on unfocused editors; r=roc

This commit is contained in:
Jorg K 2015-09-15 11:35:10 +05:30
Родитель 249da3eb76
Коммит dd4cd7d08c
5 изменённых файлов: 46 добавлений и 2 удалений

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

@ -148,6 +148,7 @@ nsEditor::nsEditor()
, mDispatchInputEvent(true)
, mIsInEditAction(false)
, mHidingCaret(false)
, mObservingDictionaryUpdates(false)
{
}
@ -307,7 +308,7 @@ nsEditor::PostCreate()
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (obs) {
obs->AddObserver(this,
SPELLCHECK_DICTIONARY_UPDATE_NOTIFICATION,
SPELLCHECK_DICTIONARY_REMOVE_NOTIFICATION,
false);
}
}
@ -451,6 +452,8 @@ nsEditor::PreDestroy(bool aDestroyingFrames)
if (obs) {
obs->RemoveObserver(this,
SPELLCHECK_DICTIONARY_UPDATE_NOTIFICATION);
obs->RemoveObserver(this,
SPELLCHECK_DICTIONARY_REMOVE_NOTIFICATION);
}
// Let spellchecker clean up its observers etc. It is important not to
@ -1315,7 +1318,9 @@ NS_IMETHODIMP nsEditor::Observe(nsISupports* aSubj, const char *aTopic,
const char16_t *aData)
{
NS_ASSERTION(!strcmp(aTopic,
SPELLCHECK_DICTIONARY_UPDATE_NOTIFICATION),
SPELLCHECK_DICTIONARY_UPDATE_NOTIFICATION) ||
!strcmp(aTopic,
SPELLCHECK_DICTIONARY_REMOVE_NOTIFICATION),
"Unexpected observer topic");
// When mozInlineSpellChecker::CanEnableInlineSpellChecking changes
@ -5202,6 +5207,29 @@ nsEditor::OnFocus(nsIDOMEventTarget* aFocusEventTarget)
}
}
void
nsEditor::StartWatchingDictionaryChanges()
{
if (!mObservingDictionaryUpdates) {
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (obs) {
obs->AddObserver(this, SPELLCHECK_DICTIONARY_UPDATE_NOTIFICATION, false);
}
mObservingDictionaryUpdates = true;
}
}
void
nsEditor::StopWatchingDictionaryChanges()
{
// Removing an observer that wasn't added doesn't cause any harm.
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (obs) {
obs->RemoveObserver(this, SPELLCHECK_DICTIONARY_UPDATE_NOTIFICATION);
}
mObservingDictionaryUpdates = false;
}
NS_IMETHODIMP
nsEditor::GetSuppressDispatchingInputEvent(bool *aSuppressed)
{

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

@ -249,6 +249,9 @@ public:
void SwitchTextDirectionTo(uint32_t aDirection);
void StartWatchingDictionaryChanges();
void StopWatchingDictionaryChanges();
protected:
nsresult DetermineCurrentDirection();
void FireInputEvent();
@ -891,6 +894,7 @@ protected:
bool mDispatchInputEvent;
bool mIsInEditAction; // true while the instance is handling an edit action
bool mHidingCaret; // whether caret is hidden forcibly.
bool mObservingDictionaryUpdates; // whether the editor is observing dictionary changes.
friend bool NSCanUnload(nsISupports* serviceMgr);
friend class nsAutoTxnsConserveSelection;

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

@ -1114,6 +1114,8 @@ nsEditorEventListener::Focus(nsIDOMEvent* aEvent)
}
}
mEditor->StartWatchingDictionaryChanges();
mEditor->OnFocus(target);
nsCOMPtr<nsIPresShell> ps = GetPresShell();
@ -1130,6 +1132,8 @@ nsEditorEventListener::Blur(nsIDOMEvent* aEvent)
{
NS_ENSURE_TRUE(aEvent, NS_OK);
mEditor->StopWatchingDictionaryChanges();
// check if something else is focused. If another element is focused, then
// we should not change the selection.
nsIFocusManager* fm = nsFocusManager::GetFocusManager();

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

@ -604,5 +604,11 @@ NS_IMETHODIMP mozHunspell::RemoveDirectory(nsIFile *aDir)
{
mDynamicDirectories.RemoveObject(aDir);
LoadDictionaryList(true);
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (obs) {
obs->NotifyObservers(nullptr,
SPELLCHECK_DICTIONARY_REMOVE_NOTIFICATION,
nullptr);
}
return NS_OK;
}

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

@ -104,4 +104,6 @@ interface mozISpellCheckingEngine : nsISupports {
#define SPELLCHECK_DICTIONARY_UPDATE_NOTIFICATION \
"spellcheck-dictionary-update"
#define SPELLCHECK_DICTIONARY_REMOVE_NOTIFICATION \
"spellcheck-dictionary-remove"
%}