2002-08-21 12:01:05 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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/. */
|
2002-08-21 12:01:05 +00:00
|
|
|
|
|
|
|
#include "nsPrintObject.h"
|
2006-12-10 08:05:05 +00:00
|
|
|
#include "nsIContentViewer.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
2013-08-14 06:56:21 +00:00
|
|
|
#include "nsContentUtils.h" // for nsAutoScriptBlocker
|
2009-12-11 04:02:13 +00:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
|
|
|
#include "nsIDocShellTreeItem.h"
|
2011-01-14 12:27:31 +00:00
|
|
|
#include "nsIBaseWindow.h"
|
2013-10-02 20:09:18 +00:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
|
2002-08-21 12:01:05 +00:00
|
|
|
//---------------------------------------------------
|
|
|
|
//-- nsPrintObject Class Impl
|
|
|
|
//---------------------------------------------------
|
|
|
|
nsPrintObject::nsPrintObject() :
|
2012-07-30 14:20:58 +00:00
|
|
|
mContent(nullptr), mFrameType(eFrame), mParent(nullptr),
|
2011-10-17 14:59:28 +00:00
|
|
|
mHasBeenPrinted(false), mDontPrint(true), mPrintAsIs(false),
|
2013-01-07 01:57:19 +00:00
|
|
|
mInvisible(false), mDidCreateDocShell(false),
|
2007-02-07 07:46:44 +00:00
|
|
|
mShrinkRatio(1.0), mZoomRatio(1.0)
|
2002-08-21 12:01:05 +00:00
|
|
|
{
|
2011-06-16 18:20:13 +00:00
|
|
|
MOZ_COUNT_CTOR(nsPrintObject);
|
2002-08-21 12:01:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsPrintObject::~nsPrintObject()
|
|
|
|
{
|
2011-06-16 18:20:13 +00:00
|
|
|
MOZ_COUNT_DTOR(nsPrintObject);
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i=0;i<mKids.Length();i++) {
|
2009-02-03 14:42:18 +00:00
|
|
|
nsPrintObject* po = mKids[i];
|
2002-08-21 12:01:05 +00:00
|
|
|
delete po;
|
|
|
|
}
|
|
|
|
|
2006-12-10 08:05:05 +00:00
|
|
|
DestroyPresentation();
|
2011-01-14 12:27:31 +00:00
|
|
|
if (mDidCreateDocShell && mDocShell) {
|
|
|
|
nsCOMPtr<nsIBaseWindow> baseWin(do_QueryInterface(mDocShell));
|
|
|
|
if (baseWin) {
|
|
|
|
baseWin->Destroy();
|
|
|
|
}
|
|
|
|
}
|
2012-07-30 14:20:58 +00:00
|
|
|
mDocShell = nullptr;
|
|
|
|
mTreeOwner = nullptr; // mTreeOwner must be released after mDocShell;
|
2002-08-21 12:01:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
nsresult
|
2009-12-11 04:02:13 +00:00
|
|
|
nsPrintObject::Init(nsIDocShell* aDocShell, nsIDOMDocument* aDoc,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aPrintPreview)
|
2002-08-21 12:01:05 +00:00
|
|
|
{
|
2009-12-11 04:02:13 +00:00
|
|
|
mPrintPreview = aPrintPreview;
|
|
|
|
|
|
|
|
if (mPrintPreview || mParent) {
|
|
|
|
mDocShell = aDocShell;
|
|
|
|
} else {
|
2010-11-10 21:15:21 +00:00
|
|
|
mTreeOwner = do_GetInterface(aDocShell);
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t itemType = 0;
|
2013-02-12 22:02:51 +00:00
|
|
|
aDocShell->GetItemType(&itemType);
|
2009-12-11 04:02:13 +00:00
|
|
|
// 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 14:59:28 +00:00
|
|
|
mDidCreateDocShell = true;
|
2013-02-12 22:02:51 +00:00
|
|
|
mDocShell->SetItemType(itemType);
|
|
|
|
mDocShell->SetTreeOwner(mTreeOwner);
|
2009-12-11 04:02:13 +00:00
|
|
|
}
|
2002-08-21 12:01:05 +00:00
|
|
|
NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);
|
2009-12-11 04:02:13 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> dummy = do_GetInterface(mDocShell);
|
2006-12-10 08:05:05 +00:00
|
|
|
nsCOMPtr<nsIContentViewer> viewer;
|
2009-12-11 04:02:13 +00: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);
|
2002-08-21 12:01:05 +00:00
|
|
|
|
2009-12-11 04:02:13 +00:00
|
|
|
viewer->SetDOMDocument(clonedDOMDoc);
|
2002-08-21 12:01:05 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Resets PO by destroying the presentation
|
|
|
|
void
|
|
|
|
nsPrintObject::DestroyPresentation()
|
|
|
|
{
|
2006-12-10 08:05:05 +00:00
|
|
|
if (mPresShell) {
|
|
|
|
mPresShell->EndObservingDocument();
|
2009-05-15 03:08:41 +00:00
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
2013-01-15 20:47:10 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell = mPresShell;
|
|
|
|
mPresShell = nullptr;
|
|
|
|
shell->Destroy();
|
2006-12-10 08:05:05 +00:00
|
|
|
}
|
2012-12-18 04:32:34 +00:00
|
|
|
mPresContext = nullptr;
|
2012-07-30 14:20:58 +00:00
|
|
|
mViewManager = nullptr;
|
2002-08-21 12:01:05 +00:00
|
|
|
}
|
|
|
|
|