2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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"
|
2013-08-14 10:56:21 +04:00
|
|
|
#include "nsContentUtils.h" // for nsAutoScriptBlocker
|
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"
|
2013-10-03 00:09:18 +04:00
|
|
|
#include "nsIDocument.h"
|
2018-11-05 15:43:10 +03:00
|
|
|
#include "nsDocShell.h"
|
|
|
|
|
|
|
|
#include "mozilla/dom/BrowsingContext.h"
|
2013-10-03 00:09:18 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
//---------------------------------------------------
|
|
|
|
//-- nsPrintObject Class Impl
|
|
|
|
//---------------------------------------------------
|
2018-04-13 16:01:28 +03:00
|
|
|
nsPrintObject::nsPrintObject() :
|
|
|
|
mContent(nullptr), mFrameType(eFrame), mParent(nullptr),
|
|
|
|
mHasBeenPrinted(false), mDontPrint(true), mPrintAsIs(false),
|
2018-07-12 09:42:14 +03:00
|
|
|
mInvisible(false), mPrintPreview(false), mDidCreateDocShell(false),
|
2018-04-13 16:01:28 +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);
|
2002-08-21 16:01:05 +04:00
|
|
|
|
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();
|
|
|
|
}
|
2017-03-06 10:35:39 +03:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mDocShell = nullptr;
|
2017-03-06 10:35:39 +03:00
|
|
|
mTreeOwner = nullptr; // mTreeOwner must be released after mDocShell;
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
2017-03-06 10:35:39 +03:00
|
|
|
nsresult
|
2018-05-11 20:46:15 +03:00
|
|
|
nsPrintObject::Init(nsIDocShell* aDocShell, nsIDocument* aDoc,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aPrintPreview)
|
2002-08-21 16:01:05 +04:00
|
|
|
{
|
2018-05-11 20:46:15 +03:00
|
|
|
NS_ENSURE_STATE(aDoc);
|
|
|
|
|
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);
|
2018-11-05 15:43:10 +03:00
|
|
|
|
|
|
|
// Create a new BrowsingContext to create our DocShell in.
|
|
|
|
RefPtr<BrowsingContext> bc = BrowsingContext::Create(
|
|
|
|
nullptr,
|
|
|
|
EmptyString(),
|
|
|
|
aDocShell->ItemType() == nsIDocShellTreeItem::typeContent
|
|
|
|
? BrowsingContext::Type::Content
|
|
|
|
: BrowsingContext::Type::Chrome);
|
|
|
|
|
2009-12-11 07:02:13 +03:00
|
|
|
// Create a container docshell for printing.
|
2018-11-05 15:43:10 +03:00
|
|
|
mDocShell = nsDocShell::Create(bc);
|
2009-12-11 07:02:13 +03:00
|
|
|
NS_ENSURE_TRUE(mDocShell, NS_ERROR_OUT_OF_MEMORY);
|
2018-11-05 15:43:10 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mDidCreateDocShell = true;
|
2018-11-05 15:43:10 +03:00
|
|
|
MOZ_ASSERT(mDocShell->ItemType() == aDocShell->ItemType());
|
2013-02-13 02:02:51 +04:00
|
|
|
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
|
|
|
|
2016-07-18 19:37:11 +03:00
|
|
|
// Keep the document related to this docshell alive
|
2018-05-11 20:46:15 +03:00
|
|
|
nsCOMPtr<nsIDocument> dummy = do_GetInterface(mDocShell);
|
2016-07-18 19:37:11 +03:00
|
|
|
mozilla::Unused << dummy;
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (mParent) {
|
2018-05-11 20:46:15 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window = aDoc->GetWindow();
|
2009-12-11 07:02:13 +03:00
|
|
|
if (window) {
|
2014-01-24 01:14:29 +04:00
|
|
|
mContent = window->GetFrameElementInternal();
|
2009-12-11 07:02:13 +03:00
|
|
|
}
|
2018-05-11 20:46:15 +03:00
|
|
|
mDocument = aDoc;
|
2009-12-11 07:02:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-05-11 20:46:15 +03:00
|
|
|
mDocument = aDoc->CreateStaticClone(mDocShell);
|
2018-01-31 23:18:09 +03:00
|
|
|
NS_ENSURE_STATE(mDocument);
|
2002-08-21 16:01:05 +04:00
|
|
|
|
2018-01-31 23:18:09 +03:00
|
|
|
viewer->SetDocument(mDocument);
|
2002-08-21 16:01:05 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Resets PO by destroying the presentation
|
2017-03-06 10:35:39 +03:00
|
|
|
void
|
2002-08-21 16:01:05 +04:00
|
|
|
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
|
|
|
}
|