diff --git a/layout/printing/nsPrintEngine.cpp b/layout/printing/nsPrintEngine.cpp index c1de2aa8ceac..b767d92c1e37 100644 --- a/layout/printing/nsPrintEngine.cpp +++ b/layout/printing/nsPrintEngine.cpp @@ -2821,24 +2821,33 @@ already_AddRefed nsPrintEngine::FindFocusedDOMWindow() { nsIFocusManager* fm = nsFocusManager::GetFocusManager(); - if (fm) { - nsCOMPtr domWin; - fm->GetFocusedWindow(getter_AddRefs(domWin)); - if (domWin && IsWindowsInOurSubTree(domWin)) - return domWin.forget(); + NS_ENSURE_TRUE(fm, nsnull); + + nsCOMPtr window(mDocument->GetWindow()); + NS_ENSURE_TRUE(window, nsnull); + + nsCOMPtr rootWindow = window->GetPrivateRoot(); + NS_ENSURE_TRUE(rootWindow, nsnull); + + nsPIDOMWindow* focusedWindow; + nsFocusManager::GetFocusedDescendant(rootWindow, PR_TRUE, &focusedWindow); + NS_ENSURE_TRUE(focusedWindow, nsnull); + + if (IsWindowsInOurSubTree(focusedWindow)) { + return focusedWindow; } + NS_IF_RELEASE(focusedWindow); return nsnull; } //--------------------------------------------------------------------- PRBool -nsPrintEngine::IsWindowsInOurSubTree(nsIDOMWindow * aDOMWindow) +nsPrintEngine::IsWindowsInOurSubTree(nsPIDOMWindow * window) { PRBool found = PR_FALSE; // now check to make sure it is in "our" tree of docshells - nsCOMPtr window(do_QueryInterface(aDOMWindow)); if (window) { nsCOMPtr docShellAsItem = do_QueryInterface(window->GetDocShell()); diff --git a/layout/printing/nsPrintEngine.h b/layout/printing/nsPrintEngine.h index 6428750a7d28..6c08d1e72149 100644 --- a/layout/printing/nsPrintEngine.h +++ b/layout/printing/nsPrintEngine.h @@ -165,7 +165,7 @@ public: // Timer Methods nsresult StartPagePrintTimer(nsPrintObject* aPO); - PRBool IsWindowsInOurSubTree(nsIDOMWindow * aDOMWindow); + PRBool IsWindowsInOurSubTree(nsPIDOMWindow * aDOMWindow); static PRBool IsParentAFrameSet(nsIDocShell * aParent); PRBool IsThereAnIFrameSelected(nsIDocShell* aDocShell, nsIDOMWindow* aDOMWin,