2002-08-21 16:01:05 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 01:52:36 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2002-08-21 16:01:05 +04:00
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2002-08-21 16:01:05 +04:00
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2002-08-21 16:01:05 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 01:52:36 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2002-08-21 16:01:05 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 01:52:36 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2002-08-21 16:01:05 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 01:52:36 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2002-08-21 16:01:05 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#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() :
|
2007-02-16 11:04:44 +03:00
|
|
|
mContent(nsnull), mFrameType(eFrame), mParent(nsnull),
|
2006-04-11 05:48:48 +04:00
|
|
|
mHasBeenPrinted(PR_FALSE), mDontPrint(PR_TRUE), mPrintAsIs(PR_FALSE),
|
2011-01-14 15:27:31 +03:00
|
|
|
mSharedPresShell(PR_FALSE), mInvisible(PR_FALSE), mDidCreateDocShell(PR_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);
|
2009-02-03 17:42:18 +03:00
|
|
|
for (PRUint32 i=0;i<mKids.Length();i++) {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
2010-11-11 00:15:21 +03:00
|
|
|
mDocShell = nsnull;
|
|
|
|
mTreeOwner = nsnull; // 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);
|
2009-12-11 07:02:13 +03:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> item = do_QueryInterface(aDocShell);
|
|
|
|
PRInt32 itemType = 0;
|
|
|
|
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-01-14 15:27:31 +03:00
|
|
|
mDidCreateDocShell = PR_TRUE;
|
2009-12-11 07:02:13 +03:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> newItem = do_QueryInterface(mDocShell);
|
|
|
|
newItem->SetItemType(itemType);
|
2010-11-11 00:15:21 +03:00
|
|
|
newItem->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()
|
|
|
|
{
|
|
|
|
mPresContext = nsnull;
|
2006-12-10 11:05:05 +03:00
|
|
|
if (mPresShell) {
|
|
|
|
mPresShell->EndObservingDocument();
|
2009-05-15 07:08:41 +04:00
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
2006-12-10 11:05:05 +03:00
|
|
|
mPresShell->Destroy();
|
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
mPresShell = nsnull;
|
|
|
|
mViewManager = nsnull;
|
|
|
|
}
|
|
|
|
|