diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp
index 28f9bb04bfd..a36e7d325f7 100644
--- a/mozilla/layout/html/base/src/nsPresShell.cpp
+++ b/mozilla/layout/html/base/src/nsPresShell.cpp
@@ -2381,23 +2381,15 @@ PresShell::EndObservingDocument()
char* nsPresShell_ReflowStackPointerTop;
#endif
-static void CheckForFocus(nsIDocument* aDocument)
+static void CheckForFocus(nsPIDOMWindow* aOurWindow, nsIFocusController* aFocusController, nsIDocument* aDocument)
{
// Now that we have a root frame, set focus in to the presshell, but
// only do this if our window is currently focused
// Restore focus if we're the active window or a parent of a previously
// active window.
- nsCOMPtr globalObject;
- aDocument->GetScriptGlobalObject(getter_AddRefs(globalObject));
- nsCOMPtr ourWindow = do_QueryInterface(globalObject);
- nsCOMPtr focusController;
- ourWindow->GetRootFocusController(getter_AddRefs(focusController));
-
- if (focusController) {
- // Suppress the command dispatcher.
- focusController->SetSuppressFocus(PR_TRUE, "PresShell suppression on Web page loads");
+ if (aFocusController) {
nsCOMPtr focusedWindow;
- focusController->GetFocusedWindow(getter_AddRefs(focusedWindow));
+ aFocusController->GetFocusedWindow(getter_AddRefs(focusedWindow));
// See if the command dispatcher is holding on to an orphan window.
// This happens when you move from an inner frame to an outer frame
@@ -2408,23 +2400,22 @@ static void CheckForFocus(nsIDocument* aDocument)
if (!domDoc) {
// We're pointing to garbage. Go ahead and let this
// presshell take the focus.
- focusedWindow = do_QueryInterface(ourWindow);
- focusController->SetFocusedWindow(focusedWindow);
+ focusedWindow = do_QueryInterface(aOurWindow);
+ aFocusController->SetFocusedWindow(focusedWindow);
}
}
- nsCOMPtr domWindow = do_QueryInterface(ourWindow);
+ nsCOMPtr domWindow = do_QueryInterface(aOurWindow);
if (domWindow == focusedWindow) {
PRBool active;
- focusController->GetActive(&active);
- focusController->SetFocusedElement(nsnull);
+ aFocusController->GetActive(&active);
+ aFocusController->SetFocusedElement(nsnull);
if(active) {
// We need to restore focus and make sure we null
// out the focused element.
domWindow->Focus();
}
}
- focusController->SetSuppressFocus(PR_FALSE, "PresShell suppression on Web page loads");
}
}
@@ -4458,6 +4449,16 @@ PresShell::IsPaintingSuppressed(PRBool* aResult)
void
PresShell::UnsuppressAndInvalidate()
{
+ nsCOMPtr globalObject;
+ mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject));
+ nsCOMPtr ourWindow = do_QueryInterface(globalObject);
+ nsCOMPtr focusController;
+ ourWindow->GetRootFocusController(getter_AddRefs(focusController));
+ if (focusController)
+ // Suppress focus. The act of tearing down the old content viewer
+ // causes us to blur incorrectly.
+ focusController->SetSuppressFocus(PR_TRUE, "PresShell suppression on Web page loads");
+
nsCOMPtr container;
nsCOMPtr cv;
nsCOMPtr dv;
@@ -4485,7 +4486,10 @@ PresShell::UnsuppressAndInvalidate()
((nsFrame*)rootFrame)->Invalidate(mPresContext, rect, PR_FALSE);
}
- CheckForFocus(mDocument);
+ CheckForFocus(ourWindow, focusController, mDocument);
+
+ if (focusController) // Unsuppress now that we've shown the new window and focused it.
+ focusController->SetSuppressFocus(PR_FALSE, "PresShell suppression on Web page loads");
}
NS_IMETHODIMP