2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsPrintObject.h"
|
|
|
|
#include "nsIContentViewer.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
2009-05-14 20:08:41 -07:00
|
|
|
#include "nsContentUtils.h"
|
2009-12-10 20:02:13 -08:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
|
|
|
#include "nsIDocShellTreeItem.h"
|
2011-01-14 04:27:31 -08:00
|
|
|
#include "nsIBaseWindow.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//---------------------------------------------------
|
|
|
|
//-- nsPrintObject Class Impl
|
|
|
|
//---------------------------------------------------
|
|
|
|
nsPrintObject::nsPrintObject() :
|
2012-07-30 07:20:58 -07:00
|
|
|
mContent(nullptr), mFrameType(eFrame), mParent(nullptr),
|
2011-10-17 07:59:28 -07:00
|
|
|
mHasBeenPrinted(false), mDontPrint(true), mPrintAsIs(false),
|
2013-01-06 17:57:19 -08:00
|
|
|
mInvisible(false), mDidCreateDocShell(false),
|
2007-03-22 10:30:00 -07:00
|
|
|
mShrinkRatio(1.0), mZoomRatio(1.0)
|
|
|
|
{
|
2011-06-16 11:20:13 -07:00
|
|
|
MOZ_COUNT_CTOR(nsPrintObject);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsPrintObject::~nsPrintObject()
|
|
|
|
{
|
2011-06-16 11:20:13 -07:00
|
|
|
MOZ_COUNT_DTOR(nsPrintObject);
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i=0;i<mKids.Length();i++) {
|
2009-02-03 06:42:18 -08:00
|
|
|
nsPrintObject* po = mKids[i];
|
2007-03-22 10:30:00 -07:00
|
|
|
delete po;
|
|
|
|
}
|
|
|
|
|
|
|
|
DestroyPresentation();
|
2011-01-14 04:27:31 -08:00
|
|
|
if (mDidCreateDocShell && mDocShell) {
|
|
|
|
nsCOMPtr<nsIBaseWindow> baseWin(do_QueryInterface(mDocShell));
|
|
|
|
if (baseWin) {
|
|
|
|
baseWin->Destroy();
|
|
|
|
}
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
mDocShell = nullptr;
|
|
|
|
mTreeOwner = nullptr; // mTreeOwner must be released after mDocShell;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
nsresult
|
2009-12-10 20:02:13 -08:00
|
|
|
nsPrintObject::Init(nsIDocShell* aDocShell, nsIDOMDocument* aDoc,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aPrintPreview)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-12-10 20:02:13 -08:00
|
|
|
mPrintPreview = aPrintPreview;
|
|
|
|
|
|
|
|
if (mPrintPreview || mParent) {
|
|
|
|
mDocShell = aDocShell;
|
|
|
|
} else {
|
2010-11-10 13:15:21 -08:00
|
|
|
mTreeOwner = do_GetInterface(aDocShell);
|
2009-12-10 20:02:13 -08:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> item = do_QueryInterface(aDocShell);
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t itemType = 0;
|
2009-12-10 20:02:13 -08:00
|
|
|
item->GetItemType(&itemType);
|
|
|
|
// Create a container docshell for printing.
|
|
|
|
mDocShell = do_CreateInstance("@mozilla.org/docshell;1");
|
|
|
|
NS_ENSURE_TRUE(mDocShell, NS_ERROR_OUT_OF_MEMORY);
|
2011-10-17 07:59:28 -07:00
|
|
|
mDidCreateDocShell = true;
|
2009-12-10 20:02:13 -08:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> newItem = do_QueryInterface(mDocShell);
|
|
|
|
newItem->SetItemType(itemType);
|
2010-11-10 13:15:21 -08:00
|
|
|
newItem->SetTreeOwner(mTreeOwner);
|
2009-12-10 20:02:13 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);
|
2009-12-10 20:02:13 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> dummy = do_GetInterface(mDocShell);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIContentViewer> viewer;
|
2009-12-10 20:02:13 -08:00
|
|
|
mDocShell->GetContentViewer(getter_AddRefs(viewer));
|
|
|
|
NS_ENSURE_STATE(viewer);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDoc);
|
|
|
|
NS_ENSURE_STATE(doc);
|
|
|
|
|
|
|
|
if (mParent) {
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window = doc->GetWindow();
|
|
|
|
if (window) {
|
|
|
|
mContent = do_QueryInterface(window->GetFrameElementInternal());
|
|
|
|
}
|
|
|
|
mDocument = doc;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDocument = doc->CreateStaticClone(mDocShell);
|
|
|
|
nsCOMPtr<nsIDOMDocument> clonedDOMDoc = do_QueryInterface(mDocument);
|
|
|
|
NS_ENSURE_STATE(clonedDOMDoc);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-10 20:02:13 -08:00
|
|
|
viewer->SetDOMDocument(clonedDOMDoc);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Resets PO by destroying the presentation
|
|
|
|
void
|
|
|
|
nsPrintObject::DestroyPresentation()
|
|
|
|
{
|
|
|
|
if (mPresShell) {
|
|
|
|
mPresShell->EndObservingDocument();
|
2009-05-14 20:08:41 -07:00
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
2013-01-15 12:47:10 -08:00
|
|
|
nsCOMPtr<nsIPresShell> shell = mPresShell;
|
|
|
|
mPresShell = nullptr;
|
|
|
|
shell->Destroy();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-12-17 20:32:34 -08:00
|
|
|
mPresContext = nullptr;
|
2012-07-30 07:20:58 -07:00
|
|
|
mViewManager = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|