зеркало из https://github.com/mozilla/gecko-dev.git
Bug 697981 - Prevent reloading of spelling dictionary on unfocused editors; r=roc
This commit is contained in:
Родитель
249da3eb76
Коммит
dd4cd7d08c
|
@ -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"
|
||||
%}
|
||||
|
|
Загрузка…
Ссылка в новой задаче