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