diff --git a/dom/src/base/nsGlobalWindow.cpp b/dom/src/base/nsGlobalWindow.cpp index 6002045b0f16..53a3329ccec3 100644 --- a/dom/src/base/nsGlobalWindow.cpp +++ b/dom/src/base/nsGlobalWindow.cpp @@ -2241,45 +2241,45 @@ nsGlobalWindow::PostHandleEvent(nsEventChainPostVisitor& aVisitor) // Set / unset the "active" attribute on the documentElement // of the top level window nsCOMPtr mainWidget = GetMainWidget(); - if (mainWidget) { - // Get the top level widget (if the main widget is a sheet, this will - // be the sheet's top (non-sheet) parent). - nsCOMPtr topLevelWidget = mainWidget->GetSheetWindowParent(); - if (!topLevelWidget) - topLevelWidget = mainWidget; + NS_ENSURE_TRUE(mainWidget, nsnull); - // Get the top level widget's nsGlobalWindow - nsCOMPtr topLevelWindow; - if (topLevelWidget == mainWidget) { - topLevelWindow = static_cast(this); - } else { - // This is a workaround for the following problem: - // When a window with an open sheet loses focus, only the sheet window - // receives the NS_DEACTIVATE event. However, it's not the sheet that - // should lose the "active" attribute, but the containing top level window. - void* clientData; - topLevelWidget->GetClientData(clientData); // clientData is nsXULWindow - nsISupports* data = static_cast(clientData); - nsCOMPtr req(do_QueryInterface(data)); - topLevelWindow = do_GetInterface(req); - } + // Get the top level widget (if the main widget is a sheet, this will + // be the sheet's top (non-sheet) parent). + nsCOMPtr topLevelWidget = mainWidget->GetSheetWindowParent(); + if (!topLevelWidget) + topLevelWidget = mainWidget; - if (topLevelWindow) { - // Only set the attribute if the document is a XUL document and the - // window is a chrome window - nsCOMPtr domDoc; - topLevelWindow->GetDocument(getter_AddRefs(domDoc)); - nsCOMPtr doc(do_QueryInterface(domDoc)); - nsCOMPtr xulDoc(do_QueryInterface(doc)); - nsCOMPtr chromeWin = do_QueryInterface(topLevelWindow); - if (xulDoc && chromeWin) { - nsCOMPtr rootElem = doc->GetRootContent(); - if (aVisitor.mEvent->message == NS_ACTIVATE) - rootElem->SetAttr(kNameSpaceID_None, nsGkAtoms::active, - NS_LITERAL_STRING("true"), PR_TRUE); - else - rootElem->UnsetAttr(kNameSpaceID_None, nsGkAtoms::active, PR_TRUE); - } + // Get the top level widget's nsGlobalWindow + nsCOMPtr topLevelWindow; + if (topLevelWidget == mainWidget) { + topLevelWindow = static_cast(this); + } else { + // This is a workaround for the following problem: + // When a window with an open sheet loses focus, only the sheet window + // receives the NS_DEACTIVATE event. However, it's not the sheet that + // should lose the "active" attribute, but the containing top level window. + void* clientData; + topLevelWidget->GetClientData(clientData); // clientData is nsXULWindow + nsISupports* data = static_cast(clientData); + nsCOMPtr req(do_QueryInterface(data)); + topLevelWindow = do_GetInterface(req); + } + + if (topLevelWindow) { + // Only set the attribute if the document is a XUL document and the + // window is a chrome window + nsCOMPtr domDoc; + topLevelWindow->GetDocument(getter_AddRefs(domDoc)); + nsCOMPtr doc(do_QueryInterface(domDoc)); + nsCOMPtr xulDoc(do_QueryInterface(doc)); + nsCOMPtr chromeWin = do_QueryInterface(topLevelWindow); + if (xulDoc && chromeWin) { + nsCOMPtr rootElem = doc->GetRootContent(); + if (aVisitor.mEvent->message == NS_ACTIVATE) + rootElem->SetAttr(kNameSpaceID_None, nsGkAtoms::active, + NS_LITERAL_STRING("true"), PR_TRUE); + else + rootElem->UnsetAttr(kNameSpaceID_None, nsGkAtoms::active, PR_TRUE); } } }