Bug 550878, cannot print child frames if window is not focused, r=neil, patch by arno renevier
authorNeil Deakin <neil@mozilla.com>
Thu, 29 Apr 2010 10:14:09 -0400
changeset 41536 88295b6d23c269d0b8b932a924596103e18622ff
parent 41535 b8c6a4f81a58ae6641c23c64552ead38c8e7d927
child 41537 74e96463cdf935b5f55348a9405fbcbd223a8c5b
push idunknown
push userunknown
push dateunknown
reviewersneil, patch
bugs550878
milestone1.9.3a5pre
Bug 550878, cannot print child frames if window is not focused, r=neil, patch by arno renevier
layout/printing/nsPrintEngine.cpp
layout/printing/nsPrintEngine.h
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -2816,34 +2816,43 @@ PRBool nsPrintEngine::HasFramesetChild(n
 
 /** ---------------------------------------------------
  *  Get the Focused Frame for a documentviewer
  */
 already_AddRefed<nsIDOMWindow>
 nsPrintEngine::FindFocusedDOMWindow()
 {
   nsIFocusManager* fm = nsFocusManager::GetFocusManager();
-  if (fm) {
-    nsCOMPtr<nsIDOMWindow> domWin;
-    fm->GetFocusedWindow(getter_AddRefs(domWin));
-    if (domWin && IsWindowsInOurSubTree(domWin))
-      return domWin.forget();
+  NS_ENSURE_TRUE(fm, nsnull);
+
+  nsCOMPtr<nsPIDOMWindow> window(mDocument->GetWindow());
+  NS_ENSURE_TRUE(window, nsnull);
+
+  nsCOMPtr<nsPIDOMWindow> 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<nsPIDOMWindow> window(do_QueryInterface(aDOMWindow));
   if (window) {
     nsCOMPtr<nsIDocShellTreeItem> docShellAsItem =
       do_QueryInterface(window->GetDocShell());
 
     if (docShellAsItem) {
       // get this DocViewer docshell
       nsCOMPtr<nsIDocShell> thisDVDocShell(do_QueryInterface(mContainer));
       while (!found) {
--- a/layout/printing/nsPrintEngine.h
+++ b/layout/printing/nsPrintEngine.h
@@ -160,17 +160,17 @@ public:
   PRBool IsThereARangeSelection(nsIDOMWindow * aDOMWin);
 
   //---------------------------------------------------------------------
 
 
   // 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,
                                  PRPackedBool& aIsParentFrameSet);
 
   static nsPrintObject* FindPrintObjectByDOMWin(nsPrintObject* aParentObject,
                                                 nsIDOMWindow* aDOMWin);