Bug 584193. Allow print preview to work without its own widget. r=smaug a=blocking beta5
authorRobert O'Callahan <roc@ocallahan.org>
Fri, 27 Aug 2010 18:15:08 -0500
changeset 51637 0886ad6e6aaa2c33e7ad319d1b80aa0f3f35c9e8
parent 51636 7804b5cf4313ff729f2de821f3ccec73c6f46486
child 51638 0cfd71b0b6a4491d42541f24b6d4e7120704c081
child 51693 f290d1fe95448796ec925471e833348bbc181f07
child 54053 5061e3023aaef211904bb2e2bdf4263629620f58
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, blocking
bugs584193
milestone2.0b5pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 584193. Allow print preview to work without its own widget. r=smaug a=blocking beta5
layout/base/nsDocumentViewer.cpp
layout/base/nsIDocumentViewer.h
layout/base/nsIDocumentViewerPrint.h
layout/printing/nsPrintEngine.cpp
layout/printing/nsPrintEngine.h
layout/printing/nsPrintObject.cpp
layout/printing/nsPrintObject.h
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -321,16 +321,23 @@ public:
   NS_DECL_ISUPPORTS
 
   // nsIContentViewer interface...
   NS_DECL_NSICONTENTVIEWER
 
   // nsIDocumentViewer interface...
   NS_IMETHOD GetPresShell(nsIPresShell** aResult);
   NS_IMETHOD GetPresContext(nsPresContext** aResult);
+  /**
+   * Find the view to use as the container view for MakeWindow. Returns
+   * null if this will be the root of a view manager hierarchy. In that
+   * case, if mParentWidget is null then this document should not even
+   * be displayed.
+   */
+  virtual nsIView* FindContainerView();
 
   // nsIContentViewerEdit
   NS_DECL_NSICONTENTVIEWEREDIT
 
   // nsIContentViewerFile
   NS_DECL_NSICONTENTVIEWERFILE
 
   // nsIMarkupDocumentViewer
@@ -357,37 +364,28 @@ private:
    * mViewManager and mWindow.
    * @param aSize the initial size in appunits
    * @param aContainerView the container view to hook our root view up
    * to as a child, or null if this will be the root view manager
    */
   nsresult MakeWindow(const nsSize& aSize, nsIView* aContainerView);
 
   /**
-   * Find the view to use as the container view for MakeWindow. Returns
-   * null if this will be the root of a view manager hierarchy. In that
-   * case, if mParentWidget is null then this document should not even
-   * be displayed.
-   */
-  nsIView* FindContainerView();
-
-  /**
    * Create our device context
    */
   nsresult CreateDeviceContext(nsIView* aContainerView);
 
   /**
    * If aDoCreation is true, this creates the device context, creates a
    * prescontext if necessary, and calls MakeWindow.
    */
   nsresult InitInternal(nsIWidget* aParentWidget,
                         nsISupports *aState,
                         const nsIntRect& aBounds,
                         PRBool aDoCreation,
-                        PRBool aInPrintPreview,
                         PRBool aNeedMakeCX = PR_TRUE);
   /**
    * @param aDoInitialReflow set to true if you want to kick off the initial
    * reflow
    */
   nsresult InitPresentationStuff(PRBool aDoInitialReflow);
 
   nsresult GetPopupNode(nsIDOMNode** aNode);
@@ -686,17 +684,17 @@ DocumentViewerImpl::GetContainer(nsISupp
    container.swap(*aResult);
    return NS_OK;
 }
 
 NS_IMETHODIMP
 DocumentViewerImpl::Init(nsIWidget* aParentWidget,
                          const nsIntRect& aBounds)
 {
-  return InitInternal(aParentWidget, nsnull, aBounds, PR_TRUE, PR_FALSE);
+  return InitInternal(aParentWidget, nsnull, aBounds, PR_TRUE);
 }
 
 nsresult
 DocumentViewerImpl::InitPresentationStuff(PRBool aDoInitialReflow)
 {
   if (GetIsPrintPreview())
     return NS_OK;
 
@@ -828,17 +826,16 @@ CreatePresContext(nsIDocument* aDocument
 // This method can be used to initial the "presentation"
 // The aDoCreation indicates whether it should create
 // all the new objects or just initialize the existing ones
 nsresult
 DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget,
                                  nsISupports *aState,
                                  const nsIntRect& aBounds,
                                  PRBool aDoCreation,
-                                 PRBool aInPrintPreview,
                                  PRBool aNeedMakeCX /*= PR_TRUE*/)
 {
   // We don't want any scripts to run here. That can cause flushing,
   // which can cause reentry into initialization of this document viewer,
   // which would be disastrous.
   nsAutoScriptBlocker blockScripts;
 
   mParentWidget = aParentWidget; // not ref counted
@@ -940,30 +937,28 @@ DocumentViewerImpl::InitInternal(nsIWidg
       nsCOMPtr<nsILinkHandler> linkHandler;
       requestor->GetInterface(NS_GET_IID(nsILinkHandler),
                               getter_AddRefs(linkHandler));
 
       mPresContext->SetContainer(requestor);
       mPresContext->SetLinkHandler(linkHandler);
     }
 
-    if (!aInPrintPreview) {
-      // Set script-context-owner in the document
-
-      nsCOMPtr<nsPIDOMWindow> window;
-      requestor->GetInterface(NS_GET_IID(nsPIDOMWindow),
-                              getter_AddRefs(window));
-
-      if (window) {
-        nsCOMPtr<nsIDocument> curDoc =
-          do_QueryInterface(window->GetExtantDocument());
-        if (!mIsPageMode || curDoc != mDocument) {
-          window->SetNewDocument(mDocument, aState);
-          nsJSContext::LoadStart();
-        }
+    // Set script-context-owner in the document
+
+    nsCOMPtr<nsPIDOMWindow> window;
+    requestor->GetInterface(NS_GET_IID(nsPIDOMWindow),
+                            getter_AddRefs(window));
+
+    if (window) {
+      nsCOMPtr<nsIDocument> curDoc =
+        do_QueryInterface(window->GetExtantDocument());
+      if (!mIsPageMode || curDoc != mDocument) {
+        window->SetNewDocument(mDocument, aState);
+        nsJSContext::LoadStart();
       }
     }
   }
 
   if (aDoCreation && mPresContext) {
     // The ViewManager and Root View was created above (in
     // MakeWindow())...
 
@@ -1355,17 +1350,17 @@ AttachContainerRecurse(nsIDocShell* aShe
 NS_IMETHODIMP
 DocumentViewerImpl::Open(nsISupports *aState, nsISHEntry *aSHEntry)
 {
   NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_INITIALIZED);
 
   if (mDocument)
     mDocument->SetContainer(nsCOMPtr<nsISupports>(do_QueryReferent(mContainer)));
 
-  nsresult rv = InitInternal(mParentWidget, aState, mBounds, PR_FALSE, PR_FALSE);
+  nsresult rv = InitInternal(mParentWidget, aState, mBounds, PR_FALSE);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (mPresShell)
     mPresShell->SetForwardingContainer(nsnull);
 
   // Rehook the child presentations.  The child shells are still in
   // session history, so get them from there.
 
@@ -1879,23 +1874,16 @@ DocumentViewerImpl::SetBounds(const nsIn
   // This may slow down the performance of the new page load, but resize
   // during load is also probably a relatively unusual condition
   // relating to things being hidden while something is loaded.  It so
   // happens that Firefox does this a good bit with its infobar, and it
   // looks ugly if we don't do this.
   if (mPreviousViewer)
     mPreviousViewer->SetBounds(aBounds);
 
-#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
-  if (GetIsPrintPreview() && !mPrintEngine->GetIsCreatingPrintPreview()) {
-    mPrintEngine->GetPrintPreviewWindow()->Resize(aBounds.x, aBounds.y,
-                                                  aBounds.width, aBounds.height,
-                                                  PR_FALSE);
-  }
-#endif
   return NS_OK;
 }
 
 NS_IMETHODIMP
 DocumentViewerImpl::Move(PRInt32 aX, PRInt32 aY)
 {
   NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
   mBounds.MoveTo(aX, aY);
@@ -3652,17 +3640,16 @@ DocumentViewerImpl::Print(nsIPrintSettin
   if (!mPrintEngine) {
     mPrintEngine = new nsPrintEngine();
     NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_OUT_OF_MEMORY);
 
     rv = mPrintEngine->Initialize(this, docShell, mDocument, 
                                   float(mDeviceContext->AppUnitsPerCSSInch()) /
                                   float(mDeviceContext->AppUnitsPerDevPixel()) /
                                   mPageZoom,
-                                  mParentWidget,
 #ifdef NS_DEBUG
                                   mDebugFile
 #else
                                   nsnull
 #endif
                                   );
     if (NS_FAILED(rv)) {
       mPrintEngine->Destroy();
@@ -3702,35 +3689,34 @@ DocumentViewerImpl::PrintPreview(nsIPrin
     nsPrintEngine::CloseProgressDialog(aWebProgressListener);
     nsPrintEngine::ShowPrintErrorDialog(NS_ERROR_GFX_PRINTER_NO_XUL, PR_FALSE);
     return NS_ERROR_FAILURE;
   }
 #endif
 
   nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mContainer));
   NS_ASSERTION(docShell, "This has to be a docshell");
-  if (!docShell ||! mDeviceContext || !mParentWidget) {
-    PR_PL(("Can't Print Preview without device context, docshell etc"));
+  if (!docShell || !mDeviceContext) {
+    PR_PL(("Can't Print Preview without device context and docshell"));
     return NS_ERROR_FAILURE;
   }
 
   if (!mPrintEngine) {
     nsCOMPtr<nsIDOMDocument> domDoc;
     aChildDOMWin->GetDocument(getter_AddRefs(domDoc));
     nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
     NS_ENSURE_STATE(doc);
 
     mPrintEngine = new nsPrintEngine();
     NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_OUT_OF_MEMORY);
 
     rv = mPrintEngine->Initialize(this, docShell, doc,
                                   float(mDeviceContext->AppUnitsPerCSSInch()) /
                                   float(mDeviceContext->AppUnitsPerDevPixel()) /
                                   mPageZoom,
-                                  mParentWidget,
 #ifdef NS_DEBUG
                                   mDebugFile
 #else
                                   nsnull
 #endif
                                   );
     if (NS_FAILED(rv)) {
       mPrintEngine->Destroy();
@@ -4278,17 +4264,17 @@ NS_IMETHODIMP DocumentViewerImpl::SetPag
     mPresContext = CreatePresContext(mDocument,
         nsPresContext::eContext_PageLayout, FindContainerView());
     NS_ENSURE_TRUE(mPresContext, NS_ERROR_OUT_OF_MEMORY);
     mPresContext->SetPaginatedScrolling(PR_TRUE);
     mPresContext->SetPrintSettings(aPrintSettings);
     nsresult rv = mPresContext->Init(mDeviceContext);
     NS_ENSURE_SUCCESS(rv, rv);
   }
-  InitInternal(mParentWidget, nsnull, mBounds, PR_TRUE, PR_FALSE, PR_FALSE);
+  InitInternal(mParentWidget, nsnull, mBounds, PR_TRUE, PR_FALSE);
 
   Show();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 DocumentViewerImpl::GetHistoryEntry(nsISHEntry **aHistoryEntry)
 {
@@ -4321,22 +4307,21 @@ DocumentViewerImpl::IsInitializedForPrin
 
 void
 DocumentViewerImpl::InitializeForPrintPreview()
 {
   mInitializedForPrintPreview = PR_TRUE;
 }
 
 void
-DocumentViewerImpl::SetPrintPreviewPresentation(nsIWidget* aWidget,
-                                                nsIViewManager* aViewManager,
+DocumentViewerImpl::SetPrintPreviewPresentation(nsIViewManager* aViewManager,
                                                 nsPresContext* aPresContext,
                                                 nsIPresShell* aPresShell)
 {
   if (mPresShell) {
     DestroyPresShell();
   }
 
-  mWindow = aWidget;
+  mWindow = nsnull;
   mViewManager = aViewManager;
   mPresContext = aPresContext;
   mPresShell = aPresShell;
 }
--- a/layout/base/nsIDocumentViewer.h
+++ b/layout/base/nsIDocumentViewer.h
@@ -41,29 +41,33 @@
 #define nsIDocumentViewer_h___
 
 #include "nsIContentViewer.h"
 
 class nsIDocument;
 class nsPresContext;
 class nsIPresShell;
 class nsIStyleSheet;
+class nsIView;
 
 #define NS_IDOCUMENT_VIEWER_IID \
-  { 0xf29e5537, 0x0763, 0x4977, \
-    { 0x83, 0xc2, 0x3c, 0x93, 0x6c, 0x66, 0xa9, 0xfc } }
+  { 0x79c0bdbf, 0xf508, 0x4970, \
+    { 0x94, 0x65, 0x03, 0x5e, 0xda, 0x2c, 0x02, 0x72 } }
+
 /**
  * A document viewer is a kind of content viewer that uses NGLayout
  * to manage the presentation of the content.
  */
 class nsIDocumentViewer : public nsIContentViewer
 {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_VIEWER_IID)
   
   NS_IMETHOD GetPresShell(nsIPresShell** aResult) = 0;
   
   NS_IMETHOD GetPresContext(nsPresContext** aResult) = 0;
+
+  virtual nsIView* FindContainerView() = 0;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumentViewer, NS_IDOCUMENT_VIEWER_IID)
 
 #endif /* nsIDocumentViewer_h___ */
--- a/layout/base/nsIDocumentViewerPrint.h
+++ b/layout/base/nsIDocumentViewerPrint.h
@@ -85,18 +85,17 @@ public:
   /**
    * Marks this viewer to be used for print preview.
    */
   virtual void InitializeForPrintPreview() = 0;
 
   /**
    * Replaces the current presentation with print preview presentation.
    */
-  virtual void SetPrintPreviewPresentation(nsIWidget* aWidget,
-                                           nsIViewManager* aViewManager,
+  virtual void SetPrintPreviewPresentation(nsIViewManager* aViewManager,
                                            nsPresContext* aPresContext,
                                            nsIPresShell* aPresShell) = 0;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumentViewerPrint,
                               NS_IDOCUMENT_VIEWER_PRINT_IID)
 
 /* Use this macro when declaring classes that implement this interface. */
@@ -106,14 +105,13 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumen
   virtual void     SetIsPrintPreview(PRBool aIsPrintPreview); \
   virtual PRBool   GetIsPrintPreview(); \
   virtual nsresult CreateStyleSet(nsIDocument* aDocument, nsStyleSet** aStyleSet); \
   virtual void     IncrementDestroyRefCount(); \
   virtual void     ReturnToGalleyPresentation(); \
   virtual void     OnDonePrinting(); \
   virtual PRBool   IsInitializedForPrintPreview(); \
   virtual void     InitializeForPrintPreview(); \
-  virtual void     SetPrintPreviewPresentation(nsIWidget* aWidget, \
-                                               nsIViewManager* aViewManager, \
+  virtual void     SetPrintPreviewPresentation(nsIViewManager* aViewManager, \
                                                nsPresContext* aPresContext, \
                                                nsIPresShell* aPresShell);
 
 #endif /* nsIDocumentViewerPrint_h___ */
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -150,16 +150,17 @@ static const char kPrintingPromptService
 #include "nsGUIEvent.h"
 #include "nsHTMLReflowState.h"
 #include "nsIDOMHTMLAnchorElement.h"
 #include "nsIDOMHTMLAreaElement.h"
 #include "nsIDOMHTMLLinkElement.h"
 #include "nsIDOMHTMLImageElement.h"
 #include "nsIContentViewerContainer.h"
 #include "nsIContentViewer.h"
+#include "nsIDocumentViewer.h"
 #include "nsIDocumentViewerPrint.h"
 
 #include "nsPIDOMWindow.h"
 #include "nsFocusManager.h"
 #include "nsRange.h"
 #include "nsCDefaultURIFixup.h"
 #include "nsIURIFixup.h"
 #include "mozilla/dom/Element.h"
@@ -260,17 +261,16 @@ nsPrintEngine::nsPrintEngine() :
   mIsDoingPrinting(PR_FALSE),
   mIsDoingPrintPreview(PR_FALSE),
   mProgressDialogIsShown(PR_FALSE),
   mContainer(nsnull),
   mScreenDPI(115.0f),
   mPrt(nsnull),
   mPagePrintTimer(nsnull),
   mPageSeqFrame(nsnull),
-  mParentWidget(nsnull),
   mPrtPreview(nsnull),
   mOldPrtPreview(nsnull),
   mDebugFile(nsnull)
 {
 }
 
 //-------------------------------------------------------
 nsPrintEngine::~nsPrintEngine()
@@ -315,28 +315,26 @@ void nsPrintEngine::DestroyPrintingData(
 //-- Section: Methods needed by the DocViewer
 //---------------------------------------------------------------------------------
 
 //--------------------------------------------------------
 nsresult nsPrintEngine::Initialize(nsIDocumentViewerPrint* aDocViewerPrint, 
                                    nsISupports*            aContainer,
                                    nsIDocument*            aDocument,
                                    float                   aScreenDPI,
-                                   nsIWidget*              aParentWidget,
                                    FILE*                   aDebugFile)
 {
   NS_ENSURE_ARG_POINTER(aDocViewerPrint);
   NS_ENSURE_ARG_POINTER(aContainer);
   NS_ENSURE_ARG_POINTER(aDocument);
 
   mDocViewerPrint = aDocViewerPrint;
   mContainer      = aContainer;      // weak reference
   mDocument       = aDocument;
   mScreenDPI      = aScreenDPI;
-  mParentWidget   = aParentWidget;    
 
   mDebugFile      = aDebugFile;      // ok to be NULL
 
   return NS_OK;
 }
 
 //-------------------------------------------------------
 PRBool
@@ -1879,35 +1877,47 @@ nsPrintEngine::ReflowDocList(nsPrintObje
 nsresult
 nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO)
 {
   NS_ASSERTION(aPO, "Pointer is null!");
   if (!aPO) return NS_ERROR_FAILURE;
 
   nsSize adjSize;
   PRBool documentIsTopLevel;
-  nsIFrame* frame = nsnull;
   if (!aPO->IsPrintable())
     return NS_OK;
 
+  PRBool canCreateScrollbars = PR_TRUE;
+  nsIView* parentView = nsnull;
+
   if (aPO->mParent && aPO->mParent->IsPrintable()) {
-    frame = aPO->mContent->GetPrimaryFrame();
+    nsIFrame* frame = aPO->mContent->GetPrimaryFrame();
     // Without a frame, this document can't be displayed; therefore, there is no
     // point to reflowing it
     if (!frame) {
       SetPrintPO(aPO, PR_FALSE);
       return NS_OK;
     }
 
     //XXX If printing supported printing document hierarchies with non-constant
     // zoom this would be wrong as we use the same mPrt->mPrintDC for all
     // subdocuments.
     adjSize = frame->GetContentRect().Size();
     documentIsTopLevel = PR_FALSE;
     // presshell exists because parent is printable
+
+    // the top nsPrintObject's widget will always have scrollbars
+    if (frame && frame->GetType() == nsGkAtoms::subDocumentFrame) {
+      nsIView* view = frame->GetView();
+      NS_ENSURE_TRUE(view, NS_ERROR_FAILURE);
+      view = view->GetFirstChild();
+      NS_ENSURE_TRUE(view, NS_ERROR_FAILURE);
+      parentView = view;
+      canCreateScrollbars = PR_FALSE;
+    }
   } else {
     nscoord pageWidth, pageHeight;
     mPrt->mPrintDC->GetDeviceSurfaceDimensions(pageWidth, pageHeight);
 #if defined(XP_UNIX) && !defined(XP_MACOSX)
     // If we're in landscape mode on Linux, the device surface will have 
     // been rotated, so for the purposes of reflowing content, we'll 
     // treat device's height as our width and its width as our height, 
     PRInt32 orientation;
@@ -1916,41 +1926,27 @@ nsPrintEngine::ReflowPrintObject(nsPrint
       adjSize = nsSize(pageHeight, pageWidth);
     } else {
       adjSize = nsSize(pageWidth, pageHeight);
     }
 #else
     adjSize = nsSize(pageWidth, pageHeight);
 #endif // XP_UNIX && !XP_MACOSX
     documentIsTopLevel = PR_TRUE;
-  }
-
-  // Here we decide whether we need scrollbars and
-  // what the parent will be of the widget
-  // How this logic presently works: Print Preview is always as-is (as far
-  // as I can tell; not sure how it would work in other cases); only the root 
-  // is not eIFrame or eFrame.  The child documents get a parent widget from
-  // logic in nsFrameFrame.  In any case, a child widget is created for the root
-  // view of the document.
-  PRBool canCreateScrollbars = PR_TRUE;
-  nsIView* parentView = nsnull;
-  // the top nsPrintObject's widget will always have scrollbars
-  if (frame && frame->GetType() == nsGkAtoms::subDocumentFrame) {
-    nsIView* view = frame->GetView();
-    NS_ENSURE_TRUE(view, NS_ERROR_FAILURE);
-    view = view->GetFirstChild();
-    NS_ENSURE_TRUE(view, NS_ERROR_FAILURE);
-    parentView = view;
-    canCreateScrollbars = PR_FALSE;
+
+    nsCOMPtr<nsIDocumentViewer> dv = do_QueryInterface(mDocViewerPrint);
+    if (dv) {
+      parentView = dv->FindContainerView();
+    }
   }
 
   NS_ASSERTION(!aPO->mPresContext, "Recreating prescontext");
 
   // create the PresContext
-  aPO->mPresContext = new nsRootPresContext(aPO->mDocument,
+  aPO->mPresContext = new nsPresContext(aPO->mDocument,
     mIsCreatingPrintPreview ? nsPresContext::eContext_PrintPreview:
                               nsPresContext::eContext_Print);
   NS_ENSURE_TRUE(aPO->mPresContext, NS_ERROR_OUT_OF_MEMORY);
   aPO->mPresContext->SetPrintSettings(mPrt->mPrintSettings);
 
   // set the presentation context to the value in the print settings
   PRBool printBGColors;
   mPrt->mPrintSettings->GetPrintBGColors(&printBGColors);
@@ -1986,31 +1982,17 @@ nsPrintEngine::ReflowPrintObject(nsPrint
   PR_PL(("In DV::ReflowPrintObject PO: %p (%9s) Setting w,h to %d,%d\n", aPO,
          gFrameTypesStr[aPO->mFrameType], adjSize.width, adjSize.height));
 
   // Create a child window of the parent that is our "root view/window"
   nsRect tbounds = nsRect(nsPoint(0, 0), adjSize);
   nsIView* rootView = aPO->mViewManager->CreateView(tbounds, parentView);
   NS_ENSURE_TRUE(rootView, NS_ERROR_OUT_OF_MEMORY);
 
-  // Only create a widget for print preview; when printing, a widget is
-  // unnecessary and unexpected
-  // Also, no widget should be needed except for the top-level document
   if (mIsCreatingPrintPreview && documentIsTopLevel) {
-    nsIWidget* widget = nsnull;
-    if (!frame)
-      widget = mParentWidget;
-    rv = widget ? rootView->CreateWidgetForParent(widget, nsnull,
-                                                  PR_TRUE, PR_TRUE,
-                                                  eContentTypeContent)
-                : rootView->CreateWidget(nsnull,
-                                         PR_TRUE, PR_TRUE,
-                                         eContentTypeContent);
-    NS_ENSURE_SUCCESS(rv, rv);
-    aPO->mWindow = rootView->GetWidget();
     aPO->mPresContext->SetPaginatedScrolling(canCreateScrollbars);
   }
 
   // Setup hierarchical relationship in view manager
   aPO->mViewManager->SetRootView(rootView);
 
   // This docshell stuff is weird; will go away when we stop having multiple
   // presentations per document
@@ -2023,18 +2005,17 @@ nsPrintEngine::ReflowPrintObject(nsPrint
   aPO->mPresContext->SetIsRootPaginatedDocument(documentIsTopLevel);
   aPO->mPresContext->SetPageScale(aPO->mZoomRatio);
   // Calculate scale factor from printer to screen
   float printDPI = float(mPrt->mPrintDC->AppUnitsPerCSSInch()) /
                    float(mPrt->mPrintDC->AppUnitsPerDevPixel());
   aPO->mPresContext->SetPrintPreviewScale(mScreenDPI / printDPI);
 
   if (mIsCreatingPrintPreview && documentIsTopLevel) {
-    mDocViewerPrint->SetPrintPreviewPresentation(aPO->mWindow,
-                                                 aPO->mViewManager,
+    mDocViewerPrint->SetPrintPreviewPresentation(aPO->mViewManager,
                                                  aPO->mPresContext,
                                                  aPO->mPresShell);
   }
 
   rv = aPO->mPresShell->InitialReflow(adjSize.width, adjSize.height);
 
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ASSERTION(aPO->mPresShell, "Presshell should still be here");
--- a/layout/printing/nsPrintEngine.h
+++ b/layout/printing/nsPrintEngine.h
@@ -100,17 +100,16 @@ public:
 
   void Destroy();
   void DestroyPrintingData();
 
   nsresult Initialize(nsIDocumentViewerPrint* aDocViewerPrint, 
                       nsISupports*            aContainer,
                       nsIDocument*            aDocument,
                       float                   aScreenDPI,
-                      nsIWidget*              aParentWidget,
                       FILE*                   aDebugFile);
 
   nsresult GetSeqFrameAndCountPages(nsIFrame*& aSeqFrame, PRInt32& aCount);
 
   //
   // The following three methods are used for printing...
   //
   nsresult DocumentReadyForPrinting();
@@ -190,18 +189,16 @@ public:
   static void ShowPrintErrorDialog(nsresult printerror,
                                    PRBool aIsPrinting = PR_TRUE);
 
   static PRBool HasFramesetChild(nsIContent* aContent);
 
   PRBool   CheckBeforeDestroy();
   nsresult Cancelled();
 
-  nsIWidget* GetPrintPreviewWindow() {return mPrtPreview->mPrintObject->mWindow;}
-
   nsIPresShell* GetPrintPreviewPresShell() {return mPrtPreview->mPrintObject->mPresShell;}
 
   float GetPrintPreviewScale() { return mPrtPreview->mPrintObject->
                                         mPresContext->GetPrintPreviewScale(); }
   
   static nsIPresShell* GetPresShellFor(nsIDocShell* aDocShell);
 
   // These calls also update the DocViewer
@@ -286,17 +283,16 @@ protected:
   nsISupports*            mContainer;      // [WEAK] it owns me!
   float                   mScreenDPI;
   
   nsPrintData*            mPrt;
   nsPagePrintTimer*       mPagePrintTimer;
   nsIPageSequenceFrame*   mPageSeqFrame;
 
   // Print Preview
-  nsCOMPtr<nsIWidget>     mParentWidget;        
   nsPrintData*            mPrtPreview;
   nsPrintData*            mOldPrtPreview;
 
   nsCOMPtr<nsIDocument>   mDocument;
 
   FILE* mDebugFile;
 
 private:
--- a/layout/printing/nsPrintObject.cpp
+++ b/layout/printing/nsPrintObject.cpp
@@ -117,17 +117,16 @@ nsPrintObject::Init(nsIDocShell* aDocShe
   return NS_OK;
 }
 
 //------------------------------------------------------------------
 // Resets PO by destroying the presentation
 void 
 nsPrintObject::DestroyPresentation()
 {
-  mWindow      = nsnull;
   mPresContext = nsnull;
   if (mPresShell) {
     mPresShell->EndObservingDocument();
     nsAutoScriptBlocker scriptBlocker;
     mPresShell->Destroy();
   }
   mPresShell   = nsnull;
   mViewManager = nsnull;
--- a/layout/printing/nsPrintObject.h
+++ b/layout/printing/nsPrintObject.h
@@ -40,17 +40,16 @@
 // Interfaces
 #include "nsCOMPtr.h"
 #include "nsIContent.h"
 #include "nsIPresShell.h"
 #include "nsStyleSet.h"
 #include "nsIViewManager.h"
 #include "nsIDocShell.h"
 #include "nsIDocument.h"
-#include "nsIWidget.h"
 
 class nsPresContext;
 
 // nsPrintObject Document Type
 enum PrintObjectType  {eDoc = 0, eFrame = 1, eIFrame = 2, eFrameSet = 3};
 
 //---------------------------------------------------
 //-- nsPrintObject Class
@@ -71,17 +70,16 @@ public:
 
   // Data Members
   nsCOMPtr<nsIDocShell>    mDocShell;
   nsCOMPtr<nsIDocument>    mDocument;
 
   nsRefPtr<nsPresContext>  mPresContext;
   nsCOMPtr<nsIPresShell>   mPresShell;
   nsCOMPtr<nsIViewManager> mViewManager;
-  nsCOMPtr<nsIWidget>      mWindow;
 
   nsCOMPtr<nsIContent>     mContent;
   PrintObjectType  mFrameType;
   
   nsTArray<nsPrintObject*> mKids;
   nsPrintObject*   mParent;
   PRPackedBool     mHasBeenPrinted;
   PRPackedBool     mDontPrint;