From 711e479cf02a77d62ef43688972ed89fe2030668 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Thu, 19 Aug 2010 20:27:04 +0900 Subject: [PATCH] Bug 581576 hung up or too slow when press Enter key on Gmail editor which has a lot of misspelled words r=ehsan, a2.0=dbaron --- editor/libeditor/base/nsEditor.cpp | 27 ++++++++++++++++++--------- editor/libeditor/base/nsEditor.h | 7 +++++++ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index 1ddfff6074c..cf53116a970 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -281,8 +281,12 @@ nsEditor::Init(nsIDOMDocument *aDoc, nsIPresShell* aPresShell, nsIContent *aRoot NS_IMETHODIMP nsEditor::PostCreate() { - // Synchronize some stuff for the flags - nsresult rv = SetFlags(mFlags); + // Synchronize some stuff for the flags. SetFlags() will initialize + // something by the flag difference. This is first time of that, so, all + // initializations must be run. For such reason, we need to invert mFlags + // value first. + mFlags = ~mFlags; + nsresult rv = SetFlags(~mFlags); NS_ENSURE_SUCCESS(rv, rv); // Set up listeners @@ -368,9 +372,7 @@ nsEditor::GetDesiredSpellCheckState() return PR_FALSE; // Spellchecking forced off globally } - // Check for password/readonly/disabled, which are not spellchecked - // regardless of DOM - if (IsPasswordEditor() || IsReadonly() || IsDisabled()) { + if (!CanEnableSpellCheck()) { return PR_FALSE; } @@ -443,6 +445,11 @@ nsEditor::GetFlags(PRUint32 *aFlags) NS_IMETHODIMP nsEditor::SetFlags(PRUint32 aFlags) { + if (mFlags == aFlags) { + return NS_OK; + } + + PRBool spellcheckerWasEnabled = CanEnableSpellCheck(); mFlags = aFlags; if (!mDocWeak || !mPresShellWeak) { @@ -452,9 +459,11 @@ nsEditor::SetFlags(PRUint32 aFlags) return NS_OK; } - // Changing the flags can change whether spellchecking is on, so re-sync it - nsresult rv = SyncRealTimeSpell(); - NS_ENSURE_SUCCESS(rv, rv); + // The flag change may cause the spellchecker state change + if (CanEnableSpellCheck() != spellcheckerWasEnabled) { + nsresult rv = SyncRealTimeSpell(); + NS_ENSURE_SUCCESS(rv, rv); + } // Might be changing editable state, so, we need to reset current IME state // if we're focused and the flag change causes IME state change. @@ -462,7 +471,7 @@ nsEditor::SetFlags(PRUint32 aFlags) // Use "enable" for the default value because if IME is disabled // unexpectedly, it makes serious a11y problem. PRUint32 newState = nsIContent::IME_STATUS_ENABLE; - rv = GetPreferredIMEState(&newState); + nsresult rv = GetPreferredIMEState(&newState); if (NS_SUCCEEDED(rv)) { // NOTE: When the enabled state isn't going to be modified, this method // is going to do nothing. diff --git a/editor/libeditor/base/nsEditor.h b/editor/libeditor/base/nsEditor.h index 83e3178da6e..126039168f6 100644 --- a/editor/libeditor/base/nsEditor.h +++ b/editor/libeditor/base/nsEditor.h @@ -360,6 +360,13 @@ protected: nsKeyEvent* GetNativeKeyEvent(nsIDOMKeyEvent* aDOMKeyEvent); + PRBool CanEnableSpellCheck() + { + // Check for password/readonly/disabled, which are not spellchecked + // regardless of DOM + return !IsPasswordEditor() && !IsReadonly() && !IsDisabled(); + } + public: /** All editor operations which alter the doc should be prefaced