1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/printing/nsPrintObject.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,110 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "nsPrintObject.h" 1.10 +#include "nsIContentViewer.h" 1.11 +#include "nsIDOMDocument.h" 1.12 +#include "nsContentUtils.h" // for nsAutoScriptBlocker 1.13 +#include "nsIInterfaceRequestorUtils.h" 1.14 +#include "nsPIDOMWindow.h" 1.15 +#include "nsGkAtoms.h" 1.16 +#include "nsComponentManagerUtils.h" 1.17 +#include "nsIDocShellTreeItem.h" 1.18 +#include "nsIBaseWindow.h" 1.19 +#include "nsIDocument.h" 1.20 + 1.21 +//--------------------------------------------------- 1.22 +//-- nsPrintObject Class Impl 1.23 +//--------------------------------------------------- 1.24 +nsPrintObject::nsPrintObject() : 1.25 + mContent(nullptr), mFrameType(eFrame), mParent(nullptr), 1.26 + mHasBeenPrinted(false), mDontPrint(true), mPrintAsIs(false), 1.27 + mInvisible(false), mDidCreateDocShell(false), 1.28 + mShrinkRatio(1.0), mZoomRatio(1.0) 1.29 +{ 1.30 + MOZ_COUNT_CTOR(nsPrintObject); 1.31 +} 1.32 + 1.33 + 1.34 +nsPrintObject::~nsPrintObject() 1.35 +{ 1.36 + MOZ_COUNT_DTOR(nsPrintObject); 1.37 + for (uint32_t i=0;i<mKids.Length();i++) { 1.38 + nsPrintObject* po = mKids[i]; 1.39 + delete po; 1.40 + } 1.41 + 1.42 + DestroyPresentation(); 1.43 + if (mDidCreateDocShell && mDocShell) { 1.44 + nsCOMPtr<nsIBaseWindow> baseWin(do_QueryInterface(mDocShell)); 1.45 + if (baseWin) { 1.46 + baseWin->Destroy(); 1.47 + } 1.48 + } 1.49 + mDocShell = nullptr; 1.50 + mTreeOwner = nullptr; // mTreeOwner must be released after mDocShell; 1.51 +} 1.52 + 1.53 +//------------------------------------------------------------------ 1.54 +nsresult 1.55 +nsPrintObject::Init(nsIDocShell* aDocShell, nsIDOMDocument* aDoc, 1.56 + bool aPrintPreview) 1.57 +{ 1.58 + mPrintPreview = aPrintPreview; 1.59 + 1.60 + if (mPrintPreview || mParent) { 1.61 + mDocShell = aDocShell; 1.62 + } else { 1.63 + mTreeOwner = do_GetInterface(aDocShell); 1.64 + // Create a container docshell for printing. 1.65 + mDocShell = do_CreateInstance("@mozilla.org/docshell;1"); 1.66 + NS_ENSURE_TRUE(mDocShell, NS_ERROR_OUT_OF_MEMORY); 1.67 + mDidCreateDocShell = true; 1.68 + mDocShell->SetItemType(aDocShell->ItemType()); 1.69 + mDocShell->SetTreeOwner(mTreeOwner); 1.70 + } 1.71 + NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE); 1.72 + 1.73 + nsCOMPtr<nsIDOMDocument> dummy = do_GetInterface(mDocShell); 1.74 + nsCOMPtr<nsIContentViewer> viewer; 1.75 + mDocShell->GetContentViewer(getter_AddRefs(viewer)); 1.76 + NS_ENSURE_STATE(viewer); 1.77 + 1.78 + nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDoc); 1.79 + NS_ENSURE_STATE(doc); 1.80 + 1.81 + if (mParent) { 1.82 + nsCOMPtr<nsPIDOMWindow> window = doc->GetWindow(); 1.83 + if (window) { 1.84 + mContent = do_QueryInterface(window->GetFrameElementInternal()); 1.85 + } 1.86 + mDocument = doc; 1.87 + return NS_OK; 1.88 + } 1.89 + 1.90 + mDocument = doc->CreateStaticClone(mDocShell); 1.91 + nsCOMPtr<nsIDOMDocument> clonedDOMDoc = do_QueryInterface(mDocument); 1.92 + NS_ENSURE_STATE(clonedDOMDoc); 1.93 + 1.94 + viewer->SetDOMDocument(clonedDOMDoc); 1.95 + return NS_OK; 1.96 +} 1.97 + 1.98 +//------------------------------------------------------------------ 1.99 +// Resets PO by destroying the presentation 1.100 +void 1.101 +nsPrintObject::DestroyPresentation() 1.102 +{ 1.103 + if (mPresShell) { 1.104 + mPresShell->EndObservingDocument(); 1.105 + nsAutoScriptBlocker scriptBlocker; 1.106 + nsCOMPtr<nsIPresShell> shell = mPresShell; 1.107 + mPresShell = nullptr; 1.108 + shell->Destroy(); 1.109 + } 1.110 + mPresContext = nullptr; 1.111 + mViewManager = nullptr; 1.112 +} 1.113 +