diff --git a/mozilla/content/events/src/nsEventStateManager.cpp b/mozilla/content/events/src/nsEventStateManager.cpp index 525f5ef3e63..a4d3b55b5c7 100644 --- a/mozilla/content/events/src/nsEventStateManager.cpp +++ b/mozilla/content/events/src/nsEventStateManager.cpp @@ -851,6 +851,13 @@ nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext, } if (focusController) { + // Make sure the focus controller is up-to-date, since restoring + // focus memory may have caused focus to go elsewhere. + + if (gLastFocusedDocument && gLastFocusedDocument == mDocument) { + nsCOMPtr focusElement = do_QueryInterface(mCurrentFocus); + focusController->SetFocusedElement(focusElement); + } PRBool isSuppressed; focusController->GetSuppressFocus(&isSuppressed); @@ -862,14 +869,6 @@ nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext, focusController->GetSuppressFocus(&isSuppressed); } focusController->SetSuppressFocusScroll(PR_FALSE); - - // Make sure the focus controller is up-to-date, since restoring - // focus memory may have caused focus to go elsewhere. - - if (gLastFocusedDocument && gLastFocusedDocument == mDocument) { - nsCOMPtr focusElement = do_QueryInterface(mCurrentFocus); - focusController->SetFocusedElement(focusElement); - } } } break; diff --git a/mozilla/dom/src/base/nsFocusController.cpp b/mozilla/dom/src/base/nsFocusController.cpp index 67766ea6d00..a7603c51a85 100644 --- a/mozilla/dom/src/base/nsFocusController.cpp +++ b/mozilla/dom/src/base/nsFocusController.cpp @@ -360,8 +360,7 @@ nsFocusController::Focus(nsIDOMEvent* aEvent) else mPreviousElement = nsnull; - if (!mCurrentElement && mCurrentWindow != mPreviousWindow) { - mNeedUpdateCommands = PR_TRUE; + if (!mCurrentElement) { UpdateCommands(); } } @@ -518,6 +517,8 @@ nsFocusController::SetSuppressFocus(PRBool aSuppressFocus, const char* aReason) // because nsPresShell::UnsuppressPainting may have just now unsuppressed // focus on the currently focused window if (!mSuppressFocus) { + // Always update commands if we have a current element + mNeedUpdateCommands = mNeedUpdateCommands || mCurrentElement; UpdateCommands(); } diff --git a/mozilla/mail/components/compose/content/MsgComposeCommands.js b/mozilla/mail/components/compose/content/MsgComposeCommands.js index 497cc5460a4..0769bd19e71 100644 --- a/mozilla/mail/components/compose/content/MsgComposeCommands.js +++ b/mozilla/mail/components/compose/content/MsgComposeCommands.js @@ -1446,10 +1446,13 @@ var gMsgEditorCreationObserver = editorStyle.addStyleSheet("chrome://messenger/skin/messageQuotes.css"); InitEditor(); } - // Now that we know this document is an editor, ensure - // that CommandUpdate_MsgCompose() will update commands - // next time the editable document receives focus - gLastWindowToHaveFocus = null; + // Now that we know this document is an editor, update commands now if + // the document has focus, or next time it receives focus via + // CommandUpdate_MsgCompose() + if (gLastWindowToHaveFocus == document.commandDispatcher.focusedWindow) + updateComposeItems(); + else + gLastWindowToHaveFocus = null; } } } diff --git a/mozilla/mailnews/compose/resources/content/MsgComposeCommands.js b/mozilla/mailnews/compose/resources/content/MsgComposeCommands.js index ec89c6b771a..45f7fb0b25c 100644 --- a/mozilla/mailnews/compose/resources/content/MsgComposeCommands.js +++ b/mozilla/mailnews/compose/resources/content/MsgComposeCommands.js @@ -1425,10 +1425,13 @@ var gMsgEditorCreationObserver = var editor = GetCurrentEditor(); if (editor && GetCurrentCommandManager() == aSubject) InitEditor(editor); - // Now that we know this document is an editor, ensure - // that CommandUpdate_MsgCompose() will update commands - // next time the editable document receives focus - gLastWindowToHaveFocus = null; + // Now that we know this document is an editor, update commands now if + // the document has focus, or next time it receives focus via + // CommandUpdate_MsgCompose() + if (gLastWindowToHaveFocus == document.commandDispatcher.focusedWindow) + updateComposeItems(); + else + gLastWindowToHaveFocus = null; } } }