Bug 365467 Focus controller's initial window and element can get out of sync r+sr=jst
☠☠ backed out by cfaa8db2c177 ☠ ☠
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Wed, 08 Oct 2008 13:24:58 +0100
changeset 20144 893b2c3b521fe8fd24da4abada4efe94220b370b
parent 20143 6a0437ba9680298e7c7e1a791e5d59984db188aa
child 20145 2bf271f5e732ad71a4d27933cd53d7504c20eb31
child 20165 cfaa8db2c177f79ebc5392db50bc0d7cdcc97b6f
push idunknown
push userunknown
push dateunknown
bugs365467
milestone1.9.1b2pre
Bug 365467 Focus controller's initial window and element can get out of sync r+sr=jst
layout/base/nsPresShell.cpp
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -2281,29 +2281,27 @@ static void CheckForFocus(nsPIDOMWindow*
 
   // Now that we have a root frame, we can set focus on the presshell.
   // We do this only if our DOM window is currently focused or is an
   // an ancestor of a previously focused window.
 
   if (!aFocusController)
     return;
 
-  nsCOMPtr<nsIDOMWindowInternal> ourWin = do_QueryInterface(aOurWindow);
-
   nsCOMPtr<nsIDOMWindowInternal> focusedWindow;
   aFocusController->GetFocusedWindow(getter_AddRefs(focusedWindow));
   if (!focusedWindow) {
-    // This should never really happen, but if it does, assume
-    // we can focus ourself to keep the window from being keydead.
-    focusedWindow = ourWin;
+    // This happens if the window has not been shown yet. We don't need to
+    // focus anything now because showing the window will set the focus.
+    return;
   }
 
   // Walk up the document chain, starting with focusedWindow's document.
   // We stop walking when we find a document that has a null DOMWindow
-  // (meaning that the DOMWindow has a new document now) or find ourWin
+  // (meaning that the DOMWindow has a new document now) or find aOurWindow
   // as the document's window.  We also stop if we hit aDocument, since
   // that means there is a child document which loaded before us that's
   // already been given focus.
 
   nsCOMPtr<nsIDOMDocument> focusedDOMDoc;
   focusedWindow->GetDocument(getter_AddRefs(focusedDOMDoc));
 
   nsCOMPtr<nsIDocument> curDoc = do_QueryInterface(focusedDOMDoc);
@@ -2316,39 +2314,39 @@ static void CheckForFocus(nsPIDOMWindow*
     // ends up focused.
 
     curDoc = aDocument;
   }
 
   while (curDoc) {
     nsPIDOMWindow *curWin = curDoc->GetWindow();
 
-    if (!curWin || curWin == ourWin)
+    if (!curWin || curWin == aOurWindow)
       break;
 
     curDoc = curDoc->GetParentDocument();
     if (curDoc == aDocument)
       return;
   }
 
   if (!curDoc) {
-    // We reached the top of the document chain, and did not encounter ourWin
-    // or a windowless document. So, focus should be unaffected by this
-    // document load.
+    // We reached the top of the document chain, and did not encounter
+    // aOurWindow or a windowless document. So, focus should be unaffected
+    // by this document load.
     return;
   }
 
   PRBool active;
   aFocusController->GetActive(&active);
   if (active)
-    ourWin->Focus();
+    aOurWindow->Focus();
 
   // We need to ensure that the focus controller is updated, since it may be
   // suppressed when this function is called.
-  aFocusController->SetFocusedWindow(ourWin);
+  aFocusController->SetFocusedWindow(aOurWindow);
 }
 
 NS_IMETHODIMP
 PresShell::GetDidInitialReflow(PRBool *aDidInitialReflow)
 {
   if (!aDidInitialReflow)
     return NS_ERROR_FAILURE;