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

This commit is contained in:
Masayuki Nakano 2010-08-19 20:27:04 +09:00
Родитель fc24e0c311
Коммит 711e479cf0
2 изменённых файлов: 25 добавлений и 9 удалений

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

@ -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.

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

@ -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