Move printing code out of the DocumentViewer

add in #defines to turn on and off printing and print preview
Bug 139905 r=dcone sr=jst
This commit is contained in:
rods%netscape.com 2002-08-21 12:01:05 +00:00
Родитель abee960a1b
Коммит 64dbd3ade1
24 изменённых файлов: 14784 добавлений и 11426 удалений

Просмотреть файл

@ -82,6 +82,7 @@ xpctools 0 XPC_TOOLS_SUPPORT
smime 1
mdn 1
print_preview 1 NS_PRINT_PREVIEW
printing 1 NS_PRINTING
moz_xul 1 MOZ_XUL
filepath_flags

4
configure поставляемый
Просмотреть файл

@ -14244,6 +14244,10 @@ cat >> confdefs.h <<\EOF
#define NS_PRINT_PREVIEW 1
EOF
cat >> confdefs.h <<\EOF
#define NS_PRINTING 1
EOF
if test "$MOZ_DEBUG"; then
cat >> confdefs.h <<\EOF

Просмотреть файл

@ -4715,6 +4715,7 @@ AC_SUBST(MOZ_MOVEMAIL)
AC_DEFINE(JS_THREADSAFE)
AC_DEFINE(NS_PRINT_PREVIEW)
AC_DEFINE(NS_PRINTING)
if test "$MOZ_DEBUG"; then
AC_DEFINE(MOZ_REFLOW_PERF)

Просмотреть файл

@ -59,6 +59,10 @@ REQUIRES = xpcom \
$(NULL)
CPPSRCS = \
nsPrintEngine.cpp \
nsPrintData.cpp \
nsPrintObject.cpp \
nsPagePrintTimer.cpp \
nsPrintPreviewListener.cpp \
nsCommentNode.cpp \
nsContentIterator.cpp \

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,90 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Communicator client code.
*
* The Initial Developer of the Original Code is
* 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
* either 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"),
* 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
* use your version of this file under the terms of the NPL, indicate your
* 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
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsIDocumentViewerPrint_h___
#define nsIDocumentViewerPrint_h___
#include "nsISupports.h"
class nsIPresContext;
class nsIPrintSettings;
class nsPrintObject;
class nsISelection;
class nsIPresShell;
class nsIDocument;
class nsIStyleSet;
class nsIContent;
class nsIWebShell;
// {D0B7F354-D575-43fd-903D-5AA35A193EDA}
#define NS_IDOCUMENT_VIEWER_PRINT_IID \
{ 0xd0b7f354, 0xd575, 0x43fd, { 0x90, 0x3d, 0x5a, 0xa3, 0x5a, 0x19, 0x3e, 0xda } }
/**
* A document viewer is a kind of content viewer that uses NGLayout
* to manage the presentation of the content.
*/
class nsIDocumentViewerPrint : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_VIEWER_PRINT_IID)
virtual void SetIsPrinting(PRBool aIsPrinting) = 0;
virtual void SetIsPrintPreview(PRBool aIsPrintPreview) = 0;
virtual void SetIsCreatingPrintPreview(PRBool aIsCreatingPrintPreview) = 0;
virtual nsresult CreateStyleSet(nsIDocument* aDocument, nsIStyleSet** aStyleSet) = 0;
virtual nsresult GetDocumentSelection(nsISelection **aSelection,
nsIPresShell * aPresShell = nsnull) = 0;
virtual void IncrementDestroyRefCount() = 0;
virtual void ReturnToGalleyPresentation() = 0;
virtual void InstallNewPresentation() = 0;
virtual void OnDonePrinting() = 0;
virtual nsresult FindFrameSetWithIID(nsIContent * aParentContent, const nsIID& aIID) = 0;
virtual void GetPresShellAndRootContent(nsIWebShell * aWebShell, nsIPresShell** aPresShell, nsIContent** aContent) = 0;
};
#endif /* nsIDocumentViewerPrint_h___ */

Просмотреть файл

@ -0,0 +1,166 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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.
*
* The Initial Developer of the Original Code is
* 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
* either 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"),
* 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
* use your version of this file under the terms of the NPL, indicate your
* 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
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsPagePrintTimer.h"
#include "nsPrintEngine.h"
#include "nsIContentViewer.h"
NS_IMPL_ISUPPORTS1(nsPagePrintTimer, nsITimerCallback)
nsPagePrintTimer::nsPagePrintTimer() :
mDocViewerPrint(nsnull),
mPresContext(nsnull),
mPrintSettings(nsnull),
mDelay(0)
{
NS_INIT_ISUPPORTS();
}
nsPagePrintTimer::~nsPagePrintTimer()
{
if (mTimer) {
mTimer->Cancel();
}
mPrintEngine->SetIsPrinting(PR_FALSE); // this will notify the DV also
nsCOMPtr<nsIContentViewer> cv(do_QueryInterface(mDocViewerPrint));
if (cv) {
cv->Destroy();
}
}
nsresult
nsPagePrintTimer::StartTimer(PRBool aUseDelay)
{
nsresult result;
mTimer = do_CreateInstance("@mozilla.org/timer;1", &result);
if (NS_FAILED(result)) {
NS_WARNING("unable to start the timer");
} else {
mTimer->Init(this, aUseDelay?mDelay:0, PR_TRUE, NS_TYPE_ONE_SHOT);
}
return result;
}
// nsITimerCallback
NS_IMETHODIMP_(void)
nsPagePrintTimer::Notify(nsITimer *timer)
{
if (mPresContext && mDocViewerPrint) {
PRPackedBool initNewTimer = PR_TRUE;
// Check to see if we are done
// donePrinting will be true if it completed successfully or
// if the printing was cancelled
PRBool inRange;
PRBool donePrinting = mPrintEngine->PrintPage(mPresContext, mPrintSettings, mPrintObj, inRange);
if (donePrinting) {
// now clean up print or print the next webshell
if (mPrintEngine->DonePrintingPages(mPrintObj, NS_OK)) {
initNewTimer = PR_FALSE;
}
}
Stop();
if (initNewTimer) {
nsresult result = StartTimer(inRange);
if (NS_FAILED(result)) {
donePrinting = PR_TRUE; // had a failure.. we are finished..
mPrintEngine->SetIsPrinting(PR_FALSE);
}
}
}
}
void
nsPagePrintTimer::Init(nsPrintEngine* aPrintEngine,
nsIDocumentViewerPrint* aDocViewerPrint,
nsIPresContext* aPresContext,
nsIPrintSettings* aPrintSettings,
nsPrintObject* aPO,
PRUint32 aDelay)
{
mPrintEngine = aPrintEngine;
mDocViewerPrint = aDocViewerPrint;
mPresContext = aPresContext;
mPrintSettings = aPrintSettings;
mPrintObj = aPO;
mDelay = aDelay;
}
nsresult
nsPagePrintTimer::Start(nsPrintEngine* aPrintEngine,
nsIDocumentViewerPrint* aDocViewerPrint,
nsIPresContext* aPresContext,
nsIPrintSettings* aPrintSettings,
nsPrintObject* aPO,
PRUint32 aDelay)
{
Init(aPrintEngine, aDocViewerPrint, aPresContext, aPrintSettings, aPO, aDelay);
return StartTimer(PR_FALSE);
}
void
nsPagePrintTimer::Stop()
{
if (mTimer) {
mTimer->Cancel();
mTimer = nsnull;
}
}
nsresult NS_NewPagePrintTimer(nsPagePrintTimer **aResult)
{
NS_PRECONDITION(aResult, "null param");
nsPagePrintTimer* result = new nsPagePrintTimer;
if (!result) {
*aResult = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(result);
*aResult = result;
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,102 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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.
*
* The Initial Developer of the Original Code is
* 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
* either 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"),
* 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
* use your version of this file under the terms of the NPL, indicate your
* 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
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsPagePrintTimer_h___
#define nsPagePrintTimer_h___
// Timer Includes
#include "nsITimer.h"
#include "nsITimerCallback.h"
#include "nsITimelineService.h"
// Interfaces
#include "nsIDocumentViewerPrint.h"
#include "nsIPresContext.h"
#include "nsIPrintSettings.h"
// Other Includes
#include "nsPrintObject.h"
#include "nsRect.h"
class nsPrintEngine;
//---------------------------------------------------
//-- Page Timer Class
//---------------------------------------------------
class nsPagePrintTimer : public nsITimerCallback
{
public:
NS_DECL_ISUPPORTS
nsPagePrintTimer();
virtual ~nsPagePrintTimer();
// nsITimerCallback
NS_IMETHOD_(void) Notify(nsITimer *timer);
// Other Methods
nsresult StartTimer(PRBool aUseDelay = PR_TRUE);
void Init(nsPrintEngine* aPrintEngine,
nsIDocumentViewerPrint* aDocViewerPrint,
nsIPresContext* aPresContext,
nsIPrintSettings* aPrintSettings,
nsPrintObject* aPO,
PRUint32 aDelay);
nsresult Start(nsPrintEngine* aPrintEngine,
nsIDocumentViewerPrint* aDocViewerPrint,
nsIPresContext* aPresContext,
nsIPrintSettings* aPrintSettings,
nsPrintObject* aPO,
PRUint32 aDelay);
void Stop();
private:
nsPrintEngine* mPrintEngine;
nsCOMPtr<nsIDocumentViewerPrint> mDocViewerPrint;
nsIPresContext* mPresContext;
nsCOMPtr<nsIPrintSettings> mPrintSettings;
nsCOMPtr<nsITimer> mTimer;
PRUint32 mDelay;
nsPrintObject * mPrintObj;
};
extern nsresult NS_NewPagePrintTimer(nsPagePrintTimer **aResult);
#endif /* nsPagePrintTimer_h___ */

Просмотреть файл

@ -0,0 +1,200 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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.
*
* The Initial Developer of the Original Code is
* 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
* either 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"),
* 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
* use your version of this file under the terms of the NPL, indicate your
* 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
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsPrintData.h"
#include "nsIStringBundle.h"
#include "nsIServiceManager.h"
#include "nsReadableUtils.h"
#include "nsCRT.h"
#include "nsISelection.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDocShell.h"
#include "nsIHTMLContent.h"
#include "nsIURI.h"
#include "nsINodeInfo.h"
//-----------------------------------------------------
// PR LOGGING
#ifdef MOZ_LOGGING
#define FORCE_PR_LOG /* Allow logging in the release build */
#endif
#include "prlog.h"
#ifdef PR_LOGGING
#ifdef NS_DEBUG
// PR_LOGGING is force to always be on (even in release builds)
// but we only want some of it on,
//#define EXTENDED_DEBUG_PRINTING
#endif
#define DUMP_LAYOUT_LEVEL 9 // this turns on the dumping of each doucment's layout info
static PRLogModuleInfo * kPrintingLogMod = PR_NewLogModule("printing");
#define PR_PL(_p1) PR_LOG(kPrintingLogMod, PR_LOG_DEBUG, _p1);
#else
#define PRT_YESNO(_p)
#define PR_PL(_p1)
#endif
//---------------------------------------------------
//-- nsPrintData Class Impl
//---------------------------------------------------
nsPrintData::nsPrintData(ePrintDataType aType) :
mType(aType), mPrintView(nsnull), mDebugFilePtr(nsnull), mPrintObject(nsnull), mSelectedPO(nsnull),
mShowProgressDialog(PR_TRUE), mProgressDialogIsShown(PR_FALSE), mPrintDocList(nsnull), mIsIFrameSelected(PR_FALSE),
mIsParentAFrameSet(PR_FALSE), mPrintingAsIsSubDoc(PR_FALSE), mOnStartSent(PR_FALSE),
mIsAborted(PR_FALSE), mPreparingForPrint(PR_FALSE), mDocWasToBeDestroyed(PR_FALSE),
mShrinkToFit(PR_FALSE), mPrintFrameType(nsIPrintSettings::kFramesAsIs),
mNumPrintableDocs(0), mNumDocsPrinted(0), mNumPrintablePages(0), mNumPagesPrinted(0),
mShrinkRatio(1.0), mOrigDCScale(1.0), mOrigTextZoom(1.0), mOrigZoom(1.0), mPPEventListeners(NULL),
mBrandName(nsnull)
{
nsCOMPtr<nsIStringBundle> brandBundle;
nsCOMPtr<nsIStringBundleService> svc( do_GetService( NS_STRINGBUNDLE_CONTRACTID ) );
if (svc) {
svc->CreateBundle( "chrome://global/locale/brand.properties", getter_AddRefs( brandBundle ) );
if (brandBundle) {
brandBundle->GetStringFromName(NS_LITERAL_STRING("brandShortName").get(), &mBrandName );
}
}
if (!mBrandName) {
mBrandName = ToNewUnicode(NS_LITERAL_STRING("Mozilla Document"));
}
}
nsPrintData::~nsPrintData()
{
// Set the cached Zoom value back into the DC
if (mPrintDC) {
mPrintDC->SetTextZoom(mOrigTextZoom);
mPrintDC->SetZoom(mOrigZoom);
}
// remove the event listeners
if (mPPEventListeners) {
mPPEventListeners->RemoveListeners();
NS_RELEASE(mPPEventListeners);
}
// Only Send an OnEndPrinting if we have started printing
if (mOnStartSent && mType != eIsPrintPreview) {
OnEndPrinting();
}
if (mPrintDC && !mDebugFilePtr) {
PR_PL(("****************** End Document ************************\n"));
PR_PL(("\n"));
PRBool isCancelled = PR_FALSE;
mPrintSettings->GetIsCancelled(&isCancelled);
nsresult rv = NS_OK;
if (mType == eIsPrinting) {
if (!isCancelled && !mIsAborted) {
rv = mPrintDC->EndDocument();
} else {
rv = mPrintDC->AbortDocument();
}
if (NS_FAILED(rv)) {
// XXX nsPrintData::ShowPrintErrorDialog(rv);
}
}
}
delete mPrintObject;
if (mPrintDocList != nsnull) {
mPrintDocList->Clear();
delete mPrintDocList;
}
if (mBrandName) {
nsCRT::free(mBrandName);
}
for (PRInt32 i=0;i<mPrintProgressListeners.Count();i++) {
nsIWebProgressListener* wpl = NS_STATIC_CAST(nsIWebProgressListener*, mPrintProgressListeners.ElementAt(i));
NS_ASSERTION(wpl, "nsIWebProgressListener is NULL!");
NS_RELEASE(wpl);
}
}
void nsPrintData::OnStartPrinting()
{
if (!mOnStartSent) {
DoOnProgressChange(mPrintProgressListeners, 0, 0, PR_TRUE, nsIWebProgressListener::STATE_START|nsIWebProgressListener::STATE_IS_DOCUMENT);
mOnStartSent = PR_TRUE;
}
}
void nsPrintData::OnEndPrinting()
{
DoOnProgressChange(mPrintProgressListeners, 100, 100, PR_TRUE, nsIWebProgressListener::STATE_STOP|nsIWebProgressListener::STATE_IS_DOCUMENT);
if (mPrintProgress && mShowProgressDialog) {
mPrintProgress->CloseProgressDialog(PR_TRUE);
}
}
void
nsPrintData::DoOnProgressChange(nsVoidArray& aListeners,
PRInt32 aProgess,
PRInt32 aMaxProgress,
PRBool aDoStartStop,
PRInt32 aFlag)
{
if (aProgess == 0) return;
for (PRInt32 i=0;i<aListeners.Count();i++) {
nsIWebProgressListener* wpl = NS_STATIC_CAST(nsIWebProgressListener*, aListeners.ElementAt(i));
NS_ASSERTION(wpl, "nsIWebProgressListener is NULL!");
wpl->OnProgressChange(nsnull, nsnull, aProgess, aMaxProgress, aProgess, aMaxProgress);
if (aDoStartStop) {
wpl->OnStateChange(nsnull, nsnull, aFlag, 0);
}
}
}

Просмотреть файл

@ -0,0 +1,318 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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.
*
* The Initial Developer of the Original Code is
* 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
* either 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"),
* 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
* use your version of this file under the terms of the NPL, indicate your
* 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
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsPrintData_h___
#define nsPrintData_h___
#include "nsPrintObject.h"
// Interfaces
#include "nsIDeviceContext.h"
#include "nsIDocument.h"
#include "nsIDOMWindow.h"
#include "nsIDOMWindowInternal.h"
#include "nsIObserver.h"
#include "nsIPrintProgress.h"
#include "nsIPrintProgressParams.h"
#include "nsIPrintOptions.h"
#include "nsIPrintSettings.h"
#include "nsIWebProgressListener.h"
#include "nsIPrintSession.h"
// Other Includes
#include "nsPrintPreviewListener.h"
#include "nsIDocShellTreeNode.h"
// Classes
class nsIPageSequenceFrame;
class nsPagePrintTimer;
// Special Interfaces
#include "nsIDocumentViewer.h"
#include "nsIDocumentViewerPrint.h"
//---------------------------------------------------
//-- Object for Caching the Presentation
//---------------------------------------------------
class CachedPresentationObj
{
public:
CachedPresentationObj(nsIPresShell* aShell, nsIPresContext* aPC,
nsIViewManager* aVM, nsIWidget* aW):
mWindow(aW), mViewManager(aVM), mPresShell(aShell), mPresContext(aPC)
{
}
// The order here is important because the order of destruction is the
// reverse of the order listed here, and the view manager must outlive
// the pres shell.
nsCOMPtr<nsIWidget> mWindow;
nsCOMPtr<nsIViewManager> mViewManager;
nsCOMPtr<nsIPresShell> mPresShell;
nsCOMPtr<nsIPresContext> mPresContext;
};
//------------------------------------------------------------------------
// nsPrintData Class
//
// mPreparingForPrint - indicates that we have started Printing but
// have not gone to the timer to start printing the pages. It gets turned
// off right before we go to the timer.
//
// mDocWasToBeDestroyed - Gets set when "someone" tries to unload the document
// while we were prparing to Print. This typically happens if a user starts
// to print while a page is still loading. If they start printing and pause
// at the print dialog and then the page comes in, we then abort printing
// because the document is no longer stable.
//
//------------------------------------------------------------------------
class nsPrintData {
public:
typedef enum {eIsPrinting, eIsPrintPreview } ePrintDataType;
// This enum tells indicates what the default should be for the title
// if the title from the document is null
enum eDocTitleDefault {
eDocTitleDefNone,
eDocTitleDefBlank,
eDocTitleDefURLDoc
};
nsPrintData(ePrintDataType aType);
~nsPrintData(); // non-virtual
// Listener Helper Methods
void OnEndPrinting();
void OnStartPrinting();
static void DoOnProgressChange(nsVoidArray& aListeners,
PRInt32 aProgess,
PRInt32 aMaxProgress,
PRBool aDoStartStop = PR_FALSE,
PRInt32 aFlag = 0);
//
// The following three methods are used for printing...
//
nsresult DocumentReadyForPrinting();
nsresult GetSelectionDocument(nsIDeviceContextSpec * aDevSpec,
nsIDocument ** aNewDoc);
nsresult SetupToPrintContent(nsIWebShell* aParent,
nsIDeviceContext* aDContext,
nsIDOMWindowInternal* aCurrentFocusedDOMWin);
nsresult EnablePOsForPrinting();
nsPrintObject* FindXMostPO();
void FindXMostFrameSize(nsIPresContext* aPresContext,
nsIRenderingContext* aRC, nsIFrame* aFrame,
nscoord aX, nscoord aY, PRInt32& aMaxWidth);
void FindXMostFrameInList(nsIPresContext* aPresContext,
nsIRenderingContext* aRC, nsIAtom* aList,
nsIFrame* aFrame, nscoord aX, nscoord aY,
PRInt32& aMaxWidth);
PRBool PrintDocContent(nsPrintObject* aPO, nsresult& aStatus);
nsresult DoPrint(nsPrintObject * aPO, PRBool aDoSyncPrinting,
PRBool& aDonePrinting);
void SetPrintAsIs(nsPrintObject* aPO, PRBool aAsIs = PR_TRUE);
enum ePrintFlags {eSetPrintFlag = 1U, eSetHiddenFlag = 2U };
void SetPrintPO(nsPrintObject* aPO, PRBool aPrint, PRBool aIsHidden = PR_FALSE, PRUint32 aFlags = eSetPrintFlag);
nsresult ShowDocList(nsPrintObject* aPO, PRBool aShow);
void InstallNewPresentation();
void ReturnToGalleyPresentation();
void TurnScriptingOn(PRBool aDoTurnOn);
PRBool CheckDocumentForPPCaching();
void InstallPrintPreviewListener();
// nsIDocumentViewerPrint Printing Methods
PRBool PrintPage(nsIPresContext* aPresContext,
nsIPrintSettings* aPrintSettings,
nsPrintObject* aPOect, PRBool& aInRange);
PRBool DonePrintingPages(nsPrintObject* aPO);
//---------------------------------------------------------------------
void BuildDocTree(nsIDocShellTreeNode * aParentNode,
nsVoidArray * aDocList,
nsPrintObject * aPO);
nsresult ReflowDocList(nsPrintObject * aPO, PRBool aSetPixelScale,
PRBool aDoCalcShrink);
void SetClipRect(nsPrintObject* aPO,
const nsRect& aClipRect,
nscoord aOffsetX,
nscoord aOffsetY,
PRBool aDoingSetClip);
nsresult ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink);
nsresult CalcPageFrameLocation(nsIPresShell * aPresShell,
nsPrintObject* aPO);
nsPrintObject * FindPrintObjectByWS(nsPrintObject* aPO, nsIWebShell * aWebShell);
void MapContentForPO(nsPrintObject* aRootObject,
nsIPresShell* aPresShell,
nsIContent* aContent);
void MapContentToWebShells(nsPrintObject* aRootPO, nsPrintObject* aPO);
nsresult MapSubDocFrameLocations(nsPrintObject* aPO);
void CalcNumPrintableDocsAndPages(PRInt32& aNumDocs, PRInt32& aNumPages);
void DoProgressForAsIsFrames();
void DoProgressForSeparateFrames();
void ShowPrintProgress(PRBool aIsForPrinting, PRBool& aDoNotify);
void CleanUpBeforeReflow(nsresult aResult);
nsresult FinishPrintPreview();
void CloseProgressDialog(nsIWebProgressListener* aWebProgressListener);
void SetDocAndURLIntoProgress(nsPrintObject* aPO,
nsIPrintProgressParams* aParams);
void ElipseLongString(PRUnichar *& aStr, const PRUint32 aLen, PRBool aDoFront);
void CleanupDocTitleArray(PRUnichar**& aArray, PRInt32& aCount);
void CheckForHiddenFrameSetFrames();
PRBool IsThereARangeSelection(nsIDOMWindowInternal * aDOMWin);
//---------------------------------------------------------------------
#ifdef NS_PRINT_PREVIEW
PRBool mIsDoingPrintPreview; // per DocumentViewer
nsIWidget* mParentWidget; // purposely won't be ref counted
nsPrintData* mPrtPreview;
nsPrintData* mOldPrtPreview;
#endif
nsIPresContext* mPresContext; // XXX
nsIDeviceContext* mDeviceContext; // XXX
// Timer Methods
nsresult StartPagePrintTimer(nsIPresContext * aPresContext,
nsIPrintSettings* aPrintSettings,
nsPrintObject* aPO,
PRUint32 aDelay);
//---------------------------------------------------------------------
// Static Methods
//---------------------------------------------------------------------
static nsresult FindFrameSetWithIID(nsIContent * aParentContent, const nsIID& aIID);
static PRBool IsWindowsInOurSubTree(nsIDOMWindowInternal * aDOMWindow, nsISupports* aContainer);
static PRBool IsWebShellAFrameSet(nsIWebShell * aParent);
static void GetPresShellAndRootContent(nsIWebShell * aWebShell,
nsIPresShell** aPresShell,
nsIContent** aContent);
static nsPrintObject* FindPrintObjectByDOMWin(nsPrintObject* aParentObject,
nsIDOMWindowInternal * aDOMWin);
// get the DOMWindow for a given WebShell
static nsIDOMWindowInternal * GetDOMWinForWebShell(nsIWebShell* aWebShell);
static void GetWebShellTitleAndURL(nsIWebShell* aWebShell,
PRUnichar** aTitle, PRUnichar** aURLStr);
static void GetDisplayTitleAndURL(nsPrintObject* aPO,
nsIPrintSettings* aPrintSettings,
const PRUnichar* aBrandName,
PRUnichar** aTitle,
PRUnichar** aURLStr,
eDocTitleDefault aDefType = eDocTitleDefNone);
static void ShowPrintErrorDialog(nsresult printerror,
PRBool aIsPrinting = PR_TRUE);
nsIDocumentViewerPrint* mDocViewerPrint; // [WEAK] it owns me!
nsIDocumentViewer* mDocViewer; // [WEAK] it owns me!
nsISupports* mContainer; // [WEAK] it owns me!
nsCOMPtr<nsIDocument> mDocument;
ePrintDataType mType; // the type of data this is (Printing or Print Preview)
nsCOMPtr<nsIDeviceContext> mPrintDC;
nsIView *mPrintView;
FILE *mDebugFilePtr; // a file where information can go to when printing
nsPrintObject * mPrintObject;
nsPrintObject * mSelectedPO;
nsVoidArray mPrintProgressListeners;
nsCOMPtr<nsIWebProgressListener> mPrintProgressListener;
nsCOMPtr<nsIPrintProgress> mPrintProgress;
nsCOMPtr<nsIPrintProgressParams> mPrintProgressParams;
PRBool mShowProgressDialog; // means we should try to show it
PRPackedBool mProgressDialogIsShown; // means it is already being shown
nsCOMPtr<nsIDOMWindowInternal> mCurrentFocusWin; // cache a pointer to the currently focused window
nsVoidArray* mPrintDocList;
nsCOMPtr<nsIDeviceContext> mPrintDocDC;
nsCOMPtr<nsIDOMWindow> mPrintDocDW;
PRPackedBool mIsIFrameSelected;
PRPackedBool mIsParentAFrameSet;
PRPackedBool mPrintingAsIsSubDoc;
PRPackedBool mOnStartSent;
PRPackedBool mIsAborted; // tells us the document is being aborted
PRPackedBool mPreparingForPrint; // see comments above
PRPackedBool mDocWasToBeDestroyed; // see comments above
PRBool mShrinkToFit;
PRInt16 mPrintFrameType;
PRInt32 mNumPrintableDocs;
PRInt32 mNumDocsPrinted;
PRInt32 mNumPrintablePages;
PRInt32 mNumPagesPrinted;
float mShrinkRatio;
float mOrigDCScale;
float mOrigTextZoom;
float mOrigZoom;
nsCOMPtr<nsIPrintSession> mPrintSession;
nsCOMPtr<nsIPrintSettings> mPrintSettings;
nsCOMPtr<nsIPrintOptions> mPrintOptions;
nsPrintPreviewListener* mPPEventListeners;
PRUnichar* mBrandName; // needed as a substitute name for a document
nsPagePrintTimer* mPagePrintTimer;
nsIPageSequenceFrame* mPageSeqFrame;
private:
nsPrintData() {}
nsPrintData& operator=(const nsPrintData& aOther); // not implemented
};
#endif /* nsPrintData_h___ */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,333 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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.
*
* The Initial Developer of the Original Code is
* 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
* either 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"),
* 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
* use your version of this file under the terms of the NPL, indicate your
* 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
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsPrintEngine_h___
#define nsPrintEngine_h___
#include "nsPrintObject.h"
#include "nsPrintData.h"
// Interfaces
#include "nsIDeviceContext.h"
#include "nsIDocument.h"
#include "nsIDOMWindow.h"
#include "nsIDOMWindowInternal.h"
#include "nsIObserver.h"
#include "nsIPrintProgress.h"
#include "nsIPrintProgressParams.h"
#include "nsIPrintOptions.h"
#include "nsIPrintSettings.h"
#include "nsIWebProgressListener.h"
#include "nsISelectionListener.h"
// Other Includes
#include "nsPrintPreviewListener.h"
#include "nsIDocShellTreeNode.h"
// Classes
class nsIPageSequenceFrame;
class nsPagePrintTimer;
// Special Interfaces
#include "nsIWebBrowserPrint.h"
#include "nsIDocumentViewer.h"
#include "nsIDocumentViewerPrint.h"
//------------------------------------------------------------------------
// nsPrintEngine Class
//
// mPreparingForPrint - indicates that we have started Printing but
// have not gone to the timer to start printing the pages. It gets turned
// off right before we go to the timer.
//
// mDocWasToBeDestroyed - Gets set when "someone" tries to unload the document
// while we were prparing to Print. This typically happens if a user starts
// to print while a page is still loading. If they start printing and pause
// at the print dialog and then the page comes in, we then abort printing
// because the document is no longer stable.
//
//------------------------------------------------------------------------
class nsPrintEngine : public nsIWebBrowserPrint, public nsIObserver {
public:
//NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
// nsISupports interface...
NS_DECL_ISUPPORTS
// nsIWebBrowserPrint
NS_DECL_NSIWEBBROWSERPRINT
// nsIObserver
NS_DECL_NSIOBSERVER
// This enum tells indicates what the default should be for the title
// if the title from the document is null
enum eDocTitleDefault {
eDocTitleDefNone,
eDocTitleDefBlank,
eDocTitleDefURLDoc
};
nsPrintEngine();
~nsPrintEngine(); // non-virtual
void Destroy();
nsresult Initialize(nsIDocumentViewer* aDocViewer,
nsIDocumentViewerPrint* aDocViewerPrint,
nsISupports* aContainer,
nsIDocument* aDocument,
nsIDeviceContext* aDevContext,
nsIPresContext* aPresContext,
nsIWidget* aWindow,
nsIWidget* aParentWidget,
FILE* aDebugFile);
nsresult GetSeqFrameAndCountPages(nsIFrame*& aSeqFrame, PRInt32& aCount);
PRBool IsOldPrintPreviewPres() { return mOldPrtPreview != nsnull; }
//
// The following three methods are used for printing...
//
nsresult DocumentReadyForPrinting();
nsresult GetSelectionDocument(nsIDeviceContextSpec * aDevSpec,
nsIDocument ** aNewDoc);
nsresult SetupToPrintContent(nsIWebShell* aParent,
nsIDeviceContext* aDContext,
nsIDOMWindowInternal* aCurrentFocusedDOMWin);
nsresult EnablePOsForPrinting();
nsPrintObject* FindXMostPO();
void FindXMostFrameSize(nsIPresContext* aPresContext,
nsIRenderingContext* aRC, nsIFrame* aFrame,
nscoord aX, nscoord aY, PRInt32& aMaxWidth);
void FindXMostFrameInList(nsIPresContext* aPresContext,
nsIRenderingContext* aRC, nsIAtom* aList,
nsIFrame* aFrame, nscoord aX, nscoord aY,
PRInt32& aMaxWidth);
PRBool PrintDocContent(nsPrintObject* aPO, nsresult& aStatus);
nsresult DoPrint(nsPrintObject * aPO, PRBool aDoSyncPrinting,
PRBool& aDonePrinting);
void SetPrintAsIs(nsPrintObject* aPO, PRBool aAsIs = PR_TRUE);
enum ePrintFlags {eSetPrintFlag = 1U, eSetHiddenFlag = 2U };
void SetPrintPO(nsPrintObject* aPO, PRBool aPrint, PRBool aIsHidden = PR_FALSE, PRUint32 aFlags = eSetPrintFlag);
void TurnScriptingOn(PRBool aDoTurnOn);
PRBool CheckDocumentForPPCaching();
void InstallPrintPreviewListener();
// nsIDocumentViewerPrint Printing Methods
PRBool PrintPage(nsIPresContext* aPresContext,
nsIPrintSettings* aPrintSettings,
nsPrintObject* aPOect, PRBool& aInRange);
PRBool DonePrintingPages(nsPrintObject* aPO, nsresult aResult);
//---------------------------------------------------------------------
void BuildDocTree(nsIDocShellTreeNode * aParentNode,
nsVoidArray * aDocList,
nsPrintObject * aPO);
nsresult ReflowDocList(nsPrintObject * aPO, PRBool aSetPixelScale,
PRBool aDoCalcShrink);
void SetClipRect(nsPrintObject* aPO,
const nsRect& aClipRect,
nscoord aOffsetX,
nscoord aOffsetY,
PRBool aDoingSetClip);
nsresult ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink);
nsresult CalcPageFrameLocation(nsIPresShell * aPresShell,
nsPrintObject* aPO);
nsPrintObject * FindPrintObjectByWS(nsPrintObject* aPO, nsIWebShell * aWebShell);
void MapContentForPO(nsPrintObject* aRootObject,
nsIPresShell* aPresShell,
nsIContent* aContent);
void MapContentToWebShells(nsPrintObject* aRootPO, nsPrintObject* aPO);
void CheckForChildFrameSets(nsPrintObject* aPO);
nsresult MapSubDocFrameLocations(nsPrintObject* aPO);
void CalcNumPrintableDocsAndPages(PRInt32& aNumDocs, PRInt32& aNumPages);
void DoProgressForAsIsFrames();
void DoProgressForSeparateFrames();
void ShowPrintProgress(PRBool aIsForPrinting, PRBool& aDoNotify);
nsresult CleanupOnFailure(nsresult aResult, PRBool aIsPrinting);
nsresult FinishPrintPreview();
static void CloseProgressDialog(nsIWebProgressListener* aWebProgressListener);
void SetDocAndURLIntoProgress(nsPrintObject* aPO,
nsIPrintProgressParams* aParams);
void ElipseLongString(PRUnichar *& aStr, const PRUint32 aLen, PRBool aDoFront);
nsresult CheckForPrinters(nsIPrintOptions* aPrintOptions,
nsIPrintSettings* aPrintSettings,
PRUint32 aErrorCode,
PRBool aIsPrinting);
void CleanupDocTitleArray(PRUnichar**& aArray, PRInt32& aCount);
void CheckForHiddenFrameSetFrames();
PRBool IsThereARangeSelection(nsIDOMWindowInternal * aDOMWin);
//---------------------------------------------------------------------
// Timer Methods
nsresult StartPagePrintTimer(nsIPresContext * aPresContext,
nsIPrintSettings* aPrintSettings,
nsPrintObject* aPO,
PRUint32 aDelay);
//---------------------------------------------------------------------
// Static Methods
//---------------------------------------------------------------------
PRBool IsWindowsInOurSubTree(nsIDOMWindowInternal * aDOMWindow);
PRBool IsParentAFrameSet(nsIWebShell * aParent);
PRBool IsThereAnIFrameSelected(nsIWebShell* aWebShell,
nsIDOMWindowInternal * aDOMWin,
PRPackedBool& aIsParentFrameSet);
nsPrintObject* FindPrintObjectByDOMWin(nsPrintObject* aParentObject,
nsIDOMWindowInternal * aDOMWin);
// get the DOMWindow for a given WebShell
nsIDOMWindowInternal * GetDOMWinForWebShell(nsIWebShell* aWebShell);
// get the currently infocus frame for the document viewer
nsIDOMWindowInternal * FindFocusedDOMWindowInternal();
void GetWebShellTitleAndURL(nsIWebShell* aWebShell, nsIDocument* aDoc,
PRUnichar** aTitle, PRUnichar** aURLStr);
void GetDisplayTitleAndURL(nsPrintObject* aPO,
nsIPrintSettings* aPrintSettings,
const PRUnichar* aBrandName,
PRUnichar** aTitle,
PRUnichar** aURLStr,
eDocTitleDefault aDefType = eDocTitleDefNone);
static void ShowPrintErrorDialog(nsresult printerror,
PRBool aIsPrinting = PR_TRUE);
PRBool CheckBeforeDestroy();
nsresult Cancelled();
nsresult ShowDocList(PRBool aShow);
void GetNewPresentation(nsCOMPtr<nsIPresShell>& aShell,
nsCOMPtr<nsIPresContext>& aPC,
nsCOMPtr<nsIViewManager>& aVM,
nsCOMPtr<nsIWidget>& aW);
// CachedPresentationObj is used to cache the presentation
// so we can bring it back later
PRBool HasCachedPres() { return mIsCachingPresentation && mCachedPresObj; }
PRBool IsCachingPres() { return mIsCachingPresentation; }
void SetCacheOldPres(PRBool aDoCache) { mIsCachingPresentation = aDoCache; }
void CachePresentation(nsIPresShell* aShell, nsIPresContext* aPC, nsIViewManager* aVM, nsIWidget* aW);
void GetCachedPresentation(nsCOMPtr<nsIPresShell>& aShell,
nsCOMPtr<nsIPresContext>& aPC,
nsCOMPtr<nsIViewManager>& aVM,
nsCOMPtr<nsIWidget>& aW);
// These calls also update the DocViewer
void SetIsPrinting(PRBool aIsPrinting) { mIsDoingPrinting = aIsPrinting; }
PRBool GetIsPrinting() { return mIsDoingPrinting; }
void SetIsPrintPreview(PRBool aIsPrintPreview) { mIsDoingPrintPreview = aIsPrintPreview; }
PRBool GetIsPrintPreview() { return mIsDoingPrintPreview; }
void SetIsCreatingPrintPreview(PRBool aIsCreatingPrintPreview) { mIsCreatingPrintPreview = aIsCreatingPrintPreview; }
PRBool GetIsCreatingPrintPreview() { return mIsCreatingPrintPreview; }
protected:
static nsIPresShell* GetPresShellFor(nsIDocShell* aDocShell);
void FirePrintCompletionEvent();
nsresult ShowDocListInternal(nsPrintObject* aPO, PRBool aShow);
nsresult GetSeqFrameAndCountPagesInternal(nsPrintObject* aPO,
nsIFrame*& aSeqFrame,
PRInt32& aCount);
static nsresult GetPageRangeForSelection(nsIPresShell * aPresShell,
nsIPresContext* aPresContext,
nsIRenderingContext& aRC,
nsISelection* aSelection,
nsIPageSequenceFrame* aPageSeqFrame,
nsIFrame** aStartFrame,
PRInt32& aStartPageNum,
nsRect& aStartRect,
nsIFrame** aEndFrame,
PRInt32& aEndPageNum,
nsRect& aEndRect);
static nsIFrame * FindFrameByType(nsIPresContext* aPresContext,
nsIFrame * aParentFrame,
nsIAtom * aType,
nsRect& aRect,
nsRect& aChildRect);
// Static memeber variables
PRBool mIsCreatingPrintPreview;
PRBool mIsDoingPrinting;
nsIDocumentViewerPrint* mDocViewerPrint; // [WEAK] it owns me!
nsIDocumentViewer* mDocViewer; // [WEAK] it owns me!
nsISupports* mContainer; // [WEAK] it owns me!
nsIDeviceContext* mDeviceContext; // not ref counted
nsIPresContext* mPresContext; // not ref counted
nsCOMPtr<nsIWidget> mWindow;
nsPrintData* mPrt;
nsPagePrintTimer* mPagePrintTimer;
nsIPageSequenceFrame* mPageSeqFrame;
// Print Preview
PRBool mIsDoingPrintPreview; // per DocumentViewer
nsCOMPtr<nsIWidget> mParentWidget;
nsPrintData* mPrtPreview;
nsPrintData* mOldPrtPreview;
nsCOMPtr<nsIDocument> mDocument;
PRBool mIsCachingPresentation;
CachedPresentationObj* mCachedPresObj;
FILE* mDebugFile;
private:
nsPrintEngine& operator=(const nsPrintEngine& aOther); // not implemented
};
#endif /* nsPrintEngine_h___ */

Просмотреть файл

@ -0,0 +1,114 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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.
*
* The Initial Developer of the Original Code is
* 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
* either 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"),
* 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
* use your version of this file under the terms of the NPL, indicate your
* 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
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsPrintObject.h"
#include "imgIContainer.h"
//---------------------------------------------------
//-- nsPrintObject Class Impl
//---------------------------------------------------
nsPrintObject::nsPrintObject() :
mFrameType(eFrame),
mRootView(nsnull), mContent(nsnull),
mSeqFrame(nsnull), mPageFrame(nsnull), mPageNum(-1),
mRect(0,0,0,0), mReflowRect(0,0,0,0),
mParent(nsnull), mHasBeenPrinted(PR_FALSE), mDontPrint(PR_TRUE),
mPrintAsIs(PR_FALSE), mSkippedPageEject(PR_FALSE), mSharedPresShell(PR_FALSE), mIsHidden(PR_FALSE),
mClipRect(-1,-1, -1, -1),
mImgAnimationMode(imgIContainer::kNormalAnimMode),
mDocTitle(nsnull), mDocURL(nsnull), mShrinkRatio(1.0), mXMost(0)
{
}
nsPrintObject::~nsPrintObject()
{
if (mPresContext) {
mPresContext->SetImageAnimationMode(mImgAnimationMode);
}
for (PRInt32 i=0;i<mKids.Count();i++) {
nsPrintObject* po = (nsPrintObject*)mKids[i];
NS_ASSERTION(po, "nsPrintObject can't be null!");
delete po;
}
if (mPresShell && !mSharedPresShell) {
mPresShell->EndObservingDocument();
mPresShell->Destroy();
}
if (mDocTitle) nsMemory::Free(mDocTitle);
if (mDocURL) nsMemory::Free(mDocURL);
}
//------------------------------------------------------------------
// Resets PO by destroying the presentation
nsresult
nsPrintObject::Init(nsIWebShell* aWebShell)
{
mWebShell = aWebShell;
mDocShell = do_QueryInterface(mWebShell);
NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);
mDocShell->GetPresShell(getter_AddRefs(mDisplayPresShell));
NS_ENSURE_TRUE(mDisplayPresShell, NS_ERROR_FAILURE);
mDocShell->GetPresContext(getter_AddRefs(mDisplayPresContext));
NS_ENSURE_TRUE(mDisplayPresContext, NS_ERROR_FAILURE);
mDisplayPresShell->GetDocument(getter_AddRefs(mDocument));
NS_ENSURE_TRUE(mDocument, NS_ERROR_FAILURE);
return NS_OK;
}
//------------------------------------------------------------------
// Resets PO by destroying the presentation
void
nsPrintObject::DestroyPresentation()
{
mWindow = nsnull;
mPresContext = nsnull;
if (mPresShell) mPresShell->Destroy();
mPresShell = nsnull;
mViewManager = nsnull;
mStyleSet = nsnull;
}

Просмотреть файл

@ -0,0 +1,121 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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.
*
* The Initial Developer of the Original Code is
* 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
* either 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"),
* 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
* use your version of this file under the terms of the NPL, indicate your
* 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
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsPrintObject_h___
#define nsPrintObject_h___
// Interfaces
#include "nsCOMPtr.h"
#include "nsIContent.h"
#include "nsIPresContext.h"
#include "nsIPresShell.h"
#include "nsIStyleSet.h"
#include "nsIViewManager.h"
#include "nsIWebShell.h"
#include "nsIDocShell.h"
#include "nsIDocument.h"
#include "nsIWidget.h"
// Other Includes
#include "nsRect.h"
// nsPrintObject Document Type
enum PrintObjectType {eDoc = 0, eFrame = 1, eIFrame = 2, eFrameSet = 3};
//---------------------------------------------------
//-- nsPrintObject Class
//---------------------------------------------------
class nsPrintObject
{
public:
nsPrintObject();
~nsPrintObject(); // non-virtual
// Methods
nsresult Init(nsIWebShell* aWebShell);
PRBool IsPrintable() { return !mDontPrint; }
void DestroyPresentation();
// Data Members
nsCOMPtr<nsIWebShell> mWebShell;
nsCOMPtr<nsIDocShell> mDocShell;
nsCOMPtr<nsIPresShell> mDisplayPresShell;
nsCOMPtr<nsIPresContext> mDisplayPresContext;
nsCOMPtr<nsIDocument> mDocument;
PrintObjectType mFrameType;
nsCOMPtr<nsIPresContext> mPresContext;
nsCOMPtr<nsIStyleSet> mStyleSet;
nsCOMPtr<nsIPresShell> mPresShell;
nsCOMPtr<nsIViewManager> mViewManager;
nsCOMPtr<nsIWidget> mWindow;
nsIView *mRootView;
nsIContent *mContent;
nsIFrame *mSeqFrame;
nsIFrame *mPageFrame;
PRInt32 mPageNum;
nsRect mRect;
nsRect mReflowRect;
nsVoidArray mKids;
nsPrintObject* mParent;
PRPackedBool mHasBeenPrinted;
PRPackedBool mDontPrint;
PRPackedBool mPrintAsIs;
PRPackedBool mSkippedPageEject;
PRPackedBool mSharedPresShell;
PRPackedBool mIsHidden; // Indicates PO is hidden, not reflowed, not shown
nsRect mClipRect;
PRUint16 mImgAnimationMode;
PRUnichar* mDocTitle;
PRUnichar* mDocURL;
float mShrinkRatio;
nscoord mXMost;
private:
nsPrintObject& operator=(const nsPrintObject& aOther); // not implemented
};
#endif /* nsPrintObject_h___ */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,90 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Communicator client code.
*
* The Initial Developer of the Original Code is
* 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
* either 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"),
* 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
* use your version of this file under the terms of the NPL, indicate your
* 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
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsIDocumentViewerPrint_h___
#define nsIDocumentViewerPrint_h___
#include "nsISupports.h"
class nsIPresContext;
class nsIPrintSettings;
class nsPrintObject;
class nsISelection;
class nsIPresShell;
class nsIDocument;
class nsIStyleSet;
class nsIContent;
class nsIWebShell;
// {D0B7F354-D575-43fd-903D-5AA35A193EDA}
#define NS_IDOCUMENT_VIEWER_PRINT_IID \
{ 0xd0b7f354, 0xd575, 0x43fd, { 0x90, 0x3d, 0x5a, 0xa3, 0x5a, 0x19, 0x3e, 0xda } }
/**
* A document viewer is a kind of content viewer that uses NGLayout
* to manage the presentation of the content.
*/
class nsIDocumentViewerPrint : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_VIEWER_PRINT_IID)
virtual void SetIsPrinting(PRBool aIsPrinting) = 0;
virtual void SetIsPrintPreview(PRBool aIsPrintPreview) = 0;
virtual void SetIsCreatingPrintPreview(PRBool aIsCreatingPrintPreview) = 0;
virtual nsresult CreateStyleSet(nsIDocument* aDocument, nsIStyleSet** aStyleSet) = 0;
virtual nsresult GetDocumentSelection(nsISelection **aSelection,
nsIPresShell * aPresShell = nsnull) = 0;
virtual void IncrementDestroyRefCount() = 0;
virtual void ReturnToGalleyPresentation() = 0;
virtual void InstallNewPresentation() = 0;
virtual void OnDonePrinting() = 0;
virtual nsresult FindFrameSetWithIID(nsIContent * aParentContent, const nsIID& aIID) = 0;
virtual void GetPresShellAndRootContent(nsIWebShell * aWebShell, nsIPresShell** aPresShell, nsIContent** aContent) = 0;
};
#endif /* nsIDocumentViewerPrint_h___ */

Просмотреть файл

@ -0,0 +1,166 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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.
*
* The Initial Developer of the Original Code is
* 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
* either 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"),
* 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
* use your version of this file under the terms of the NPL, indicate your
* 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
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsPagePrintTimer.h"
#include "nsPrintEngine.h"
#include "nsIContentViewer.h"
NS_IMPL_ISUPPORTS1(nsPagePrintTimer, nsITimerCallback)
nsPagePrintTimer::nsPagePrintTimer() :
mDocViewerPrint(nsnull),
mPresContext(nsnull),
mPrintSettings(nsnull),
mDelay(0)
{
NS_INIT_ISUPPORTS();
}
nsPagePrintTimer::~nsPagePrintTimer()
{
if (mTimer) {
mTimer->Cancel();
}
mPrintEngine->SetIsPrinting(PR_FALSE); // this will notify the DV also
nsCOMPtr<nsIContentViewer> cv(do_QueryInterface(mDocViewerPrint));
if (cv) {
cv->Destroy();
}
}
nsresult
nsPagePrintTimer::StartTimer(PRBool aUseDelay)
{
nsresult result;
mTimer = do_CreateInstance("@mozilla.org/timer;1", &result);
if (NS_FAILED(result)) {
NS_WARNING("unable to start the timer");
} else {
mTimer->Init(this, aUseDelay?mDelay:0, PR_TRUE, NS_TYPE_ONE_SHOT);
}
return result;
}
// nsITimerCallback
NS_IMETHODIMP_(void)
nsPagePrintTimer::Notify(nsITimer *timer)
{
if (mPresContext && mDocViewerPrint) {
PRPackedBool initNewTimer = PR_TRUE;
// Check to see if we are done
// donePrinting will be true if it completed successfully or
// if the printing was cancelled
PRBool inRange;
PRBool donePrinting = mPrintEngine->PrintPage(mPresContext, mPrintSettings, mPrintObj, inRange);
if (donePrinting) {
// now clean up print or print the next webshell
if (mPrintEngine->DonePrintingPages(mPrintObj, NS_OK)) {
initNewTimer = PR_FALSE;
}
}
Stop();
if (initNewTimer) {
nsresult result = StartTimer(inRange);
if (NS_FAILED(result)) {
donePrinting = PR_TRUE; // had a failure.. we are finished..
mPrintEngine->SetIsPrinting(PR_FALSE);
}
}
}
}
void
nsPagePrintTimer::Init(nsPrintEngine* aPrintEngine,
nsIDocumentViewerPrint* aDocViewerPrint,
nsIPresContext* aPresContext,
nsIPrintSettings* aPrintSettings,
nsPrintObject* aPO,
PRUint32 aDelay)
{
mPrintEngine = aPrintEngine;
mDocViewerPrint = aDocViewerPrint;
mPresContext = aPresContext;
mPrintSettings = aPrintSettings;
mPrintObj = aPO;
mDelay = aDelay;
}
nsresult
nsPagePrintTimer::Start(nsPrintEngine* aPrintEngine,
nsIDocumentViewerPrint* aDocViewerPrint,
nsIPresContext* aPresContext,
nsIPrintSettings* aPrintSettings,
nsPrintObject* aPO,
PRUint32 aDelay)
{
Init(aPrintEngine, aDocViewerPrint, aPresContext, aPrintSettings, aPO, aDelay);
return StartTimer(PR_FALSE);
}
void
nsPagePrintTimer::Stop()
{
if (mTimer) {
mTimer->Cancel();
mTimer = nsnull;
}
}
nsresult NS_NewPagePrintTimer(nsPagePrintTimer **aResult)
{
NS_PRECONDITION(aResult, "null param");
nsPagePrintTimer* result = new nsPagePrintTimer;
if (!result) {
*aResult = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(result);
*aResult = result;
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,102 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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.
*
* The Initial Developer of the Original Code is
* 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
* either 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"),
* 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
* use your version of this file under the terms of the NPL, indicate your
* 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
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsPagePrintTimer_h___
#define nsPagePrintTimer_h___
// Timer Includes
#include "nsITimer.h"
#include "nsITimerCallback.h"
#include "nsITimelineService.h"
// Interfaces
#include "nsIDocumentViewerPrint.h"
#include "nsIPresContext.h"
#include "nsIPrintSettings.h"
// Other Includes
#include "nsPrintObject.h"
#include "nsRect.h"
class nsPrintEngine;
//---------------------------------------------------
//-- Page Timer Class
//---------------------------------------------------
class nsPagePrintTimer : public nsITimerCallback
{
public:
NS_DECL_ISUPPORTS
nsPagePrintTimer();
virtual ~nsPagePrintTimer();
// nsITimerCallback
NS_IMETHOD_(void) Notify(nsITimer *timer);
// Other Methods
nsresult StartTimer(PRBool aUseDelay = PR_TRUE);
void Init(nsPrintEngine* aPrintEngine,
nsIDocumentViewerPrint* aDocViewerPrint,
nsIPresContext* aPresContext,
nsIPrintSettings* aPrintSettings,
nsPrintObject* aPO,
PRUint32 aDelay);
nsresult Start(nsPrintEngine* aPrintEngine,
nsIDocumentViewerPrint* aDocViewerPrint,
nsIPresContext* aPresContext,
nsIPrintSettings* aPrintSettings,
nsPrintObject* aPO,
PRUint32 aDelay);
void Stop();
private:
nsPrintEngine* mPrintEngine;
nsCOMPtr<nsIDocumentViewerPrint> mDocViewerPrint;
nsIPresContext* mPresContext;
nsCOMPtr<nsIPrintSettings> mPrintSettings;
nsCOMPtr<nsITimer> mTimer;
PRUint32 mDelay;
nsPrintObject * mPrintObj;
};
extern nsresult NS_NewPagePrintTimer(nsPagePrintTimer **aResult);
#endif /* nsPagePrintTimer_h___ */

Просмотреть файл

@ -0,0 +1,200 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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.
*
* The Initial Developer of the Original Code is
* 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
* either 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"),
* 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
* use your version of this file under the terms of the NPL, indicate your
* 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
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsPrintData.h"
#include "nsIStringBundle.h"
#include "nsIServiceManager.h"
#include "nsReadableUtils.h"
#include "nsCRT.h"
#include "nsISelection.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDocShell.h"
#include "nsIHTMLContent.h"
#include "nsIURI.h"
#include "nsINodeInfo.h"
//-----------------------------------------------------
// PR LOGGING
#ifdef MOZ_LOGGING
#define FORCE_PR_LOG /* Allow logging in the release build */
#endif
#include "prlog.h"
#ifdef PR_LOGGING
#ifdef NS_DEBUG
// PR_LOGGING is force to always be on (even in release builds)
// but we only want some of it on,
//#define EXTENDED_DEBUG_PRINTING
#endif
#define DUMP_LAYOUT_LEVEL 9 // this turns on the dumping of each doucment's layout info
static PRLogModuleInfo * kPrintingLogMod = PR_NewLogModule("printing");
#define PR_PL(_p1) PR_LOG(kPrintingLogMod, PR_LOG_DEBUG, _p1);
#else
#define PRT_YESNO(_p)
#define PR_PL(_p1)
#endif
//---------------------------------------------------
//-- nsPrintData Class Impl
//---------------------------------------------------
nsPrintData::nsPrintData(ePrintDataType aType) :
mType(aType), mPrintView(nsnull), mDebugFilePtr(nsnull), mPrintObject(nsnull), mSelectedPO(nsnull),
mShowProgressDialog(PR_TRUE), mProgressDialogIsShown(PR_FALSE), mPrintDocList(nsnull), mIsIFrameSelected(PR_FALSE),
mIsParentAFrameSet(PR_FALSE), mPrintingAsIsSubDoc(PR_FALSE), mOnStartSent(PR_FALSE),
mIsAborted(PR_FALSE), mPreparingForPrint(PR_FALSE), mDocWasToBeDestroyed(PR_FALSE),
mShrinkToFit(PR_FALSE), mPrintFrameType(nsIPrintSettings::kFramesAsIs),
mNumPrintableDocs(0), mNumDocsPrinted(0), mNumPrintablePages(0), mNumPagesPrinted(0),
mShrinkRatio(1.0), mOrigDCScale(1.0), mOrigTextZoom(1.0), mOrigZoom(1.0), mPPEventListeners(NULL),
mBrandName(nsnull)
{
nsCOMPtr<nsIStringBundle> brandBundle;
nsCOMPtr<nsIStringBundleService> svc( do_GetService( NS_STRINGBUNDLE_CONTRACTID ) );
if (svc) {
svc->CreateBundle( "chrome://global/locale/brand.properties", getter_AddRefs( brandBundle ) );
if (brandBundle) {
brandBundle->GetStringFromName(NS_LITERAL_STRING("brandShortName").get(), &mBrandName );
}
}
if (!mBrandName) {
mBrandName = ToNewUnicode(NS_LITERAL_STRING("Mozilla Document"));
}
}
nsPrintData::~nsPrintData()
{
// Set the cached Zoom value back into the DC
if (mPrintDC) {
mPrintDC->SetTextZoom(mOrigTextZoom);
mPrintDC->SetZoom(mOrigZoom);
}
// remove the event listeners
if (mPPEventListeners) {
mPPEventListeners->RemoveListeners();
NS_RELEASE(mPPEventListeners);
}
// Only Send an OnEndPrinting if we have started printing
if (mOnStartSent && mType != eIsPrintPreview) {
OnEndPrinting();
}
if (mPrintDC && !mDebugFilePtr) {
PR_PL(("****************** End Document ************************\n"));
PR_PL(("\n"));
PRBool isCancelled = PR_FALSE;
mPrintSettings->GetIsCancelled(&isCancelled);
nsresult rv = NS_OK;
if (mType == eIsPrinting) {
if (!isCancelled && !mIsAborted) {
rv = mPrintDC->EndDocument();
} else {
rv = mPrintDC->AbortDocument();
}
if (NS_FAILED(rv)) {
// XXX nsPrintData::ShowPrintErrorDialog(rv);
}
}
}
delete mPrintObject;
if (mPrintDocList != nsnull) {
mPrintDocList->Clear();
delete mPrintDocList;
}
if (mBrandName) {
nsCRT::free(mBrandName);
}
for (PRInt32 i=0;i<mPrintProgressListeners.Count();i++) {
nsIWebProgressListener* wpl = NS_STATIC_CAST(nsIWebProgressListener*, mPrintProgressListeners.ElementAt(i));
NS_ASSERTION(wpl, "nsIWebProgressListener is NULL!");
NS_RELEASE(wpl);
}
}
void nsPrintData::OnStartPrinting()
{
if (!mOnStartSent) {
DoOnProgressChange(mPrintProgressListeners, 0, 0, PR_TRUE, nsIWebProgressListener::STATE_START|nsIWebProgressListener::STATE_IS_DOCUMENT);
mOnStartSent = PR_TRUE;
}
}
void nsPrintData::OnEndPrinting()
{
DoOnProgressChange(mPrintProgressListeners, 100, 100, PR_TRUE, nsIWebProgressListener::STATE_STOP|nsIWebProgressListener::STATE_IS_DOCUMENT);
if (mPrintProgress && mShowProgressDialog) {
mPrintProgress->CloseProgressDialog(PR_TRUE);
}
}
void
nsPrintData::DoOnProgressChange(nsVoidArray& aListeners,
PRInt32 aProgess,
PRInt32 aMaxProgress,
PRBool aDoStartStop,
PRInt32 aFlag)
{
if (aProgess == 0) return;
for (PRInt32 i=0;i<aListeners.Count();i++) {
nsIWebProgressListener* wpl = NS_STATIC_CAST(nsIWebProgressListener*, aListeners.ElementAt(i));
NS_ASSERTION(wpl, "nsIWebProgressListener is NULL!");
wpl->OnProgressChange(nsnull, nsnull, aProgess, aMaxProgress, aProgess, aMaxProgress);
if (aDoStartStop) {
wpl->OnStateChange(nsnull, nsnull, aFlag, 0);
}
}
}

Просмотреть файл

@ -0,0 +1,318 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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.
*
* The Initial Developer of the Original Code is
* 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
* either 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"),
* 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
* use your version of this file under the terms of the NPL, indicate your
* 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
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsPrintData_h___
#define nsPrintData_h___
#include "nsPrintObject.h"
// Interfaces
#include "nsIDeviceContext.h"
#include "nsIDocument.h"
#include "nsIDOMWindow.h"
#include "nsIDOMWindowInternal.h"
#include "nsIObserver.h"
#include "nsIPrintProgress.h"
#include "nsIPrintProgressParams.h"
#include "nsIPrintOptions.h"
#include "nsIPrintSettings.h"
#include "nsIWebProgressListener.h"
#include "nsIPrintSession.h"
// Other Includes
#include "nsPrintPreviewListener.h"
#include "nsIDocShellTreeNode.h"
// Classes
class nsIPageSequenceFrame;
class nsPagePrintTimer;
// Special Interfaces
#include "nsIDocumentViewer.h"
#include "nsIDocumentViewerPrint.h"
//---------------------------------------------------
//-- Object for Caching the Presentation
//---------------------------------------------------
class CachedPresentationObj
{
public:
CachedPresentationObj(nsIPresShell* aShell, nsIPresContext* aPC,
nsIViewManager* aVM, nsIWidget* aW):
mWindow(aW), mViewManager(aVM), mPresShell(aShell), mPresContext(aPC)
{
}
// The order here is important because the order of destruction is the
// reverse of the order listed here, and the view manager must outlive
// the pres shell.
nsCOMPtr<nsIWidget> mWindow;
nsCOMPtr<nsIViewManager> mViewManager;
nsCOMPtr<nsIPresShell> mPresShell;
nsCOMPtr<nsIPresContext> mPresContext;
};
//------------------------------------------------------------------------
// nsPrintData Class
//
// mPreparingForPrint - indicates that we have started Printing but
// have not gone to the timer to start printing the pages. It gets turned
// off right before we go to the timer.
//
// mDocWasToBeDestroyed - Gets set when "someone" tries to unload the document
// while we were prparing to Print. This typically happens if a user starts
// to print while a page is still loading. If they start printing and pause
// at the print dialog and then the page comes in, we then abort printing
// because the document is no longer stable.
//
//------------------------------------------------------------------------
class nsPrintData {
public:
typedef enum {eIsPrinting, eIsPrintPreview } ePrintDataType;
// This enum tells indicates what the default should be for the title
// if the title from the document is null
enum eDocTitleDefault {
eDocTitleDefNone,
eDocTitleDefBlank,
eDocTitleDefURLDoc
};
nsPrintData(ePrintDataType aType);
~nsPrintData(); // non-virtual
// Listener Helper Methods
void OnEndPrinting();
void OnStartPrinting();
static void DoOnProgressChange(nsVoidArray& aListeners,
PRInt32 aProgess,
PRInt32 aMaxProgress,
PRBool aDoStartStop = PR_FALSE,
PRInt32 aFlag = 0);
//
// The following three methods are used for printing...
//
nsresult DocumentReadyForPrinting();
nsresult GetSelectionDocument(nsIDeviceContextSpec * aDevSpec,
nsIDocument ** aNewDoc);
nsresult SetupToPrintContent(nsIWebShell* aParent,
nsIDeviceContext* aDContext,
nsIDOMWindowInternal* aCurrentFocusedDOMWin);
nsresult EnablePOsForPrinting();
nsPrintObject* FindXMostPO();
void FindXMostFrameSize(nsIPresContext* aPresContext,
nsIRenderingContext* aRC, nsIFrame* aFrame,
nscoord aX, nscoord aY, PRInt32& aMaxWidth);
void FindXMostFrameInList(nsIPresContext* aPresContext,
nsIRenderingContext* aRC, nsIAtom* aList,
nsIFrame* aFrame, nscoord aX, nscoord aY,
PRInt32& aMaxWidth);
PRBool PrintDocContent(nsPrintObject* aPO, nsresult& aStatus);
nsresult DoPrint(nsPrintObject * aPO, PRBool aDoSyncPrinting,
PRBool& aDonePrinting);
void SetPrintAsIs(nsPrintObject* aPO, PRBool aAsIs = PR_TRUE);
enum ePrintFlags {eSetPrintFlag = 1U, eSetHiddenFlag = 2U };
void SetPrintPO(nsPrintObject* aPO, PRBool aPrint, PRBool aIsHidden = PR_FALSE, PRUint32 aFlags = eSetPrintFlag);
nsresult ShowDocList(nsPrintObject* aPO, PRBool aShow);
void InstallNewPresentation();
void ReturnToGalleyPresentation();
void TurnScriptingOn(PRBool aDoTurnOn);
PRBool CheckDocumentForPPCaching();
void InstallPrintPreviewListener();
// nsIDocumentViewerPrint Printing Methods
PRBool PrintPage(nsIPresContext* aPresContext,
nsIPrintSettings* aPrintSettings,
nsPrintObject* aPOect, PRBool& aInRange);
PRBool DonePrintingPages(nsPrintObject* aPO);
//---------------------------------------------------------------------
void BuildDocTree(nsIDocShellTreeNode * aParentNode,
nsVoidArray * aDocList,
nsPrintObject * aPO);
nsresult ReflowDocList(nsPrintObject * aPO, PRBool aSetPixelScale,
PRBool aDoCalcShrink);
void SetClipRect(nsPrintObject* aPO,
const nsRect& aClipRect,
nscoord aOffsetX,
nscoord aOffsetY,
PRBool aDoingSetClip);
nsresult ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink);
nsresult CalcPageFrameLocation(nsIPresShell * aPresShell,
nsPrintObject* aPO);
nsPrintObject * FindPrintObjectByWS(nsPrintObject* aPO, nsIWebShell * aWebShell);
void MapContentForPO(nsPrintObject* aRootObject,
nsIPresShell* aPresShell,
nsIContent* aContent);
void MapContentToWebShells(nsPrintObject* aRootPO, nsPrintObject* aPO);
nsresult MapSubDocFrameLocations(nsPrintObject* aPO);
void CalcNumPrintableDocsAndPages(PRInt32& aNumDocs, PRInt32& aNumPages);
void DoProgressForAsIsFrames();
void DoProgressForSeparateFrames();
void ShowPrintProgress(PRBool aIsForPrinting, PRBool& aDoNotify);
void CleanUpBeforeReflow(nsresult aResult);
nsresult FinishPrintPreview();
void CloseProgressDialog(nsIWebProgressListener* aWebProgressListener);
void SetDocAndURLIntoProgress(nsPrintObject* aPO,
nsIPrintProgressParams* aParams);
void ElipseLongString(PRUnichar *& aStr, const PRUint32 aLen, PRBool aDoFront);
void CleanupDocTitleArray(PRUnichar**& aArray, PRInt32& aCount);
void CheckForHiddenFrameSetFrames();
PRBool IsThereARangeSelection(nsIDOMWindowInternal * aDOMWin);
//---------------------------------------------------------------------
#ifdef NS_PRINT_PREVIEW
PRBool mIsDoingPrintPreview; // per DocumentViewer
nsIWidget* mParentWidget; // purposely won't be ref counted
nsPrintData* mPrtPreview;
nsPrintData* mOldPrtPreview;
#endif
nsIPresContext* mPresContext; // XXX
nsIDeviceContext* mDeviceContext; // XXX
// Timer Methods
nsresult StartPagePrintTimer(nsIPresContext * aPresContext,
nsIPrintSettings* aPrintSettings,
nsPrintObject* aPO,
PRUint32 aDelay);
//---------------------------------------------------------------------
// Static Methods
//---------------------------------------------------------------------
static nsresult FindFrameSetWithIID(nsIContent * aParentContent, const nsIID& aIID);
static PRBool IsWindowsInOurSubTree(nsIDOMWindowInternal * aDOMWindow, nsISupports* aContainer);
static PRBool IsWebShellAFrameSet(nsIWebShell * aParent);
static void GetPresShellAndRootContent(nsIWebShell * aWebShell,
nsIPresShell** aPresShell,
nsIContent** aContent);
static nsPrintObject* FindPrintObjectByDOMWin(nsPrintObject* aParentObject,
nsIDOMWindowInternal * aDOMWin);
// get the DOMWindow for a given WebShell
static nsIDOMWindowInternal * GetDOMWinForWebShell(nsIWebShell* aWebShell);
static void GetWebShellTitleAndURL(nsIWebShell* aWebShell,
PRUnichar** aTitle, PRUnichar** aURLStr);
static void GetDisplayTitleAndURL(nsPrintObject* aPO,
nsIPrintSettings* aPrintSettings,
const PRUnichar* aBrandName,
PRUnichar** aTitle,
PRUnichar** aURLStr,
eDocTitleDefault aDefType = eDocTitleDefNone);
static void ShowPrintErrorDialog(nsresult printerror,
PRBool aIsPrinting = PR_TRUE);
nsIDocumentViewerPrint* mDocViewerPrint; // [WEAK] it owns me!
nsIDocumentViewer* mDocViewer; // [WEAK] it owns me!
nsISupports* mContainer; // [WEAK] it owns me!
nsCOMPtr<nsIDocument> mDocument;
ePrintDataType mType; // the type of data this is (Printing or Print Preview)
nsCOMPtr<nsIDeviceContext> mPrintDC;
nsIView *mPrintView;
FILE *mDebugFilePtr; // a file where information can go to when printing
nsPrintObject * mPrintObject;
nsPrintObject * mSelectedPO;
nsVoidArray mPrintProgressListeners;
nsCOMPtr<nsIWebProgressListener> mPrintProgressListener;
nsCOMPtr<nsIPrintProgress> mPrintProgress;
nsCOMPtr<nsIPrintProgressParams> mPrintProgressParams;
PRBool mShowProgressDialog; // means we should try to show it
PRPackedBool mProgressDialogIsShown; // means it is already being shown
nsCOMPtr<nsIDOMWindowInternal> mCurrentFocusWin; // cache a pointer to the currently focused window
nsVoidArray* mPrintDocList;
nsCOMPtr<nsIDeviceContext> mPrintDocDC;
nsCOMPtr<nsIDOMWindow> mPrintDocDW;
PRPackedBool mIsIFrameSelected;
PRPackedBool mIsParentAFrameSet;
PRPackedBool mPrintingAsIsSubDoc;
PRPackedBool mOnStartSent;
PRPackedBool mIsAborted; // tells us the document is being aborted
PRPackedBool mPreparingForPrint; // see comments above
PRPackedBool mDocWasToBeDestroyed; // see comments above
PRBool mShrinkToFit;
PRInt16 mPrintFrameType;
PRInt32 mNumPrintableDocs;
PRInt32 mNumDocsPrinted;
PRInt32 mNumPrintablePages;
PRInt32 mNumPagesPrinted;
float mShrinkRatio;
float mOrigDCScale;
float mOrigTextZoom;
float mOrigZoom;
nsCOMPtr<nsIPrintSession> mPrintSession;
nsCOMPtr<nsIPrintSettings> mPrintSettings;
nsCOMPtr<nsIPrintOptions> mPrintOptions;
nsPrintPreviewListener* mPPEventListeners;
PRUnichar* mBrandName; // needed as a substitute name for a document
nsPagePrintTimer* mPagePrintTimer;
nsIPageSequenceFrame* mPageSeqFrame;
private:
nsPrintData() {}
nsPrintData& operator=(const nsPrintData& aOther); // not implemented
};
#endif /* nsPrintData_h___ */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,333 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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.
*
* The Initial Developer of the Original Code is
* 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
* either 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"),
* 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
* use your version of this file under the terms of the NPL, indicate your
* 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
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsPrintEngine_h___
#define nsPrintEngine_h___
#include "nsPrintObject.h"
#include "nsPrintData.h"
// Interfaces
#include "nsIDeviceContext.h"
#include "nsIDocument.h"
#include "nsIDOMWindow.h"
#include "nsIDOMWindowInternal.h"
#include "nsIObserver.h"
#include "nsIPrintProgress.h"
#include "nsIPrintProgressParams.h"
#include "nsIPrintOptions.h"
#include "nsIPrintSettings.h"
#include "nsIWebProgressListener.h"
#include "nsISelectionListener.h"
// Other Includes
#include "nsPrintPreviewListener.h"
#include "nsIDocShellTreeNode.h"
// Classes
class nsIPageSequenceFrame;
class nsPagePrintTimer;
// Special Interfaces
#include "nsIWebBrowserPrint.h"
#include "nsIDocumentViewer.h"
#include "nsIDocumentViewerPrint.h"
//------------------------------------------------------------------------
// nsPrintEngine Class
//
// mPreparingForPrint - indicates that we have started Printing but
// have not gone to the timer to start printing the pages. It gets turned
// off right before we go to the timer.
//
// mDocWasToBeDestroyed - Gets set when "someone" tries to unload the document
// while we were prparing to Print. This typically happens if a user starts
// to print while a page is still loading. If they start printing and pause
// at the print dialog and then the page comes in, we then abort printing
// because the document is no longer stable.
//
//------------------------------------------------------------------------
class nsPrintEngine : public nsIWebBrowserPrint, public nsIObserver {
public:
//NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
// nsISupports interface...
NS_DECL_ISUPPORTS
// nsIWebBrowserPrint
NS_DECL_NSIWEBBROWSERPRINT
// nsIObserver
NS_DECL_NSIOBSERVER
// This enum tells indicates what the default should be for the title
// if the title from the document is null
enum eDocTitleDefault {
eDocTitleDefNone,
eDocTitleDefBlank,
eDocTitleDefURLDoc
};
nsPrintEngine();
~nsPrintEngine(); // non-virtual
void Destroy();
nsresult Initialize(nsIDocumentViewer* aDocViewer,
nsIDocumentViewerPrint* aDocViewerPrint,
nsISupports* aContainer,
nsIDocument* aDocument,
nsIDeviceContext* aDevContext,
nsIPresContext* aPresContext,
nsIWidget* aWindow,
nsIWidget* aParentWidget,
FILE* aDebugFile);
nsresult GetSeqFrameAndCountPages(nsIFrame*& aSeqFrame, PRInt32& aCount);
PRBool IsOldPrintPreviewPres() { return mOldPrtPreview != nsnull; }
//
// The following three methods are used for printing...
//
nsresult DocumentReadyForPrinting();
nsresult GetSelectionDocument(nsIDeviceContextSpec * aDevSpec,
nsIDocument ** aNewDoc);
nsresult SetupToPrintContent(nsIWebShell* aParent,
nsIDeviceContext* aDContext,
nsIDOMWindowInternal* aCurrentFocusedDOMWin);
nsresult EnablePOsForPrinting();
nsPrintObject* FindXMostPO();
void FindXMostFrameSize(nsIPresContext* aPresContext,
nsIRenderingContext* aRC, nsIFrame* aFrame,
nscoord aX, nscoord aY, PRInt32& aMaxWidth);
void FindXMostFrameInList(nsIPresContext* aPresContext,
nsIRenderingContext* aRC, nsIAtom* aList,
nsIFrame* aFrame, nscoord aX, nscoord aY,
PRInt32& aMaxWidth);
PRBool PrintDocContent(nsPrintObject* aPO, nsresult& aStatus);
nsresult DoPrint(nsPrintObject * aPO, PRBool aDoSyncPrinting,
PRBool& aDonePrinting);
void SetPrintAsIs(nsPrintObject* aPO, PRBool aAsIs = PR_TRUE);
enum ePrintFlags {eSetPrintFlag = 1U, eSetHiddenFlag = 2U };
void SetPrintPO(nsPrintObject* aPO, PRBool aPrint, PRBool aIsHidden = PR_FALSE, PRUint32 aFlags = eSetPrintFlag);
void TurnScriptingOn(PRBool aDoTurnOn);
PRBool CheckDocumentForPPCaching();
void InstallPrintPreviewListener();
// nsIDocumentViewerPrint Printing Methods
PRBool PrintPage(nsIPresContext* aPresContext,
nsIPrintSettings* aPrintSettings,
nsPrintObject* aPOect, PRBool& aInRange);
PRBool DonePrintingPages(nsPrintObject* aPO, nsresult aResult);
//---------------------------------------------------------------------
void BuildDocTree(nsIDocShellTreeNode * aParentNode,
nsVoidArray * aDocList,
nsPrintObject * aPO);
nsresult ReflowDocList(nsPrintObject * aPO, PRBool aSetPixelScale,
PRBool aDoCalcShrink);
void SetClipRect(nsPrintObject* aPO,
const nsRect& aClipRect,
nscoord aOffsetX,
nscoord aOffsetY,
PRBool aDoingSetClip);
nsresult ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink);
nsresult CalcPageFrameLocation(nsIPresShell * aPresShell,
nsPrintObject* aPO);
nsPrintObject * FindPrintObjectByWS(nsPrintObject* aPO, nsIWebShell * aWebShell);
void MapContentForPO(nsPrintObject* aRootObject,
nsIPresShell* aPresShell,
nsIContent* aContent);
void MapContentToWebShells(nsPrintObject* aRootPO, nsPrintObject* aPO);
void CheckForChildFrameSets(nsPrintObject* aPO);
nsresult MapSubDocFrameLocations(nsPrintObject* aPO);
void CalcNumPrintableDocsAndPages(PRInt32& aNumDocs, PRInt32& aNumPages);
void DoProgressForAsIsFrames();
void DoProgressForSeparateFrames();
void ShowPrintProgress(PRBool aIsForPrinting, PRBool& aDoNotify);
nsresult CleanupOnFailure(nsresult aResult, PRBool aIsPrinting);
nsresult FinishPrintPreview();
static void CloseProgressDialog(nsIWebProgressListener* aWebProgressListener);
void SetDocAndURLIntoProgress(nsPrintObject* aPO,
nsIPrintProgressParams* aParams);
void ElipseLongString(PRUnichar *& aStr, const PRUint32 aLen, PRBool aDoFront);
nsresult CheckForPrinters(nsIPrintOptions* aPrintOptions,
nsIPrintSettings* aPrintSettings,
PRUint32 aErrorCode,
PRBool aIsPrinting);
void CleanupDocTitleArray(PRUnichar**& aArray, PRInt32& aCount);
void CheckForHiddenFrameSetFrames();
PRBool IsThereARangeSelection(nsIDOMWindowInternal * aDOMWin);
//---------------------------------------------------------------------
// Timer Methods
nsresult StartPagePrintTimer(nsIPresContext * aPresContext,
nsIPrintSettings* aPrintSettings,
nsPrintObject* aPO,
PRUint32 aDelay);
//---------------------------------------------------------------------
// Static Methods
//---------------------------------------------------------------------
PRBool IsWindowsInOurSubTree(nsIDOMWindowInternal * aDOMWindow);
PRBool IsParentAFrameSet(nsIWebShell * aParent);
PRBool IsThereAnIFrameSelected(nsIWebShell* aWebShell,
nsIDOMWindowInternal * aDOMWin,
PRPackedBool& aIsParentFrameSet);
nsPrintObject* FindPrintObjectByDOMWin(nsPrintObject* aParentObject,
nsIDOMWindowInternal * aDOMWin);
// get the DOMWindow for a given WebShell
nsIDOMWindowInternal * GetDOMWinForWebShell(nsIWebShell* aWebShell);
// get the currently infocus frame for the document viewer
nsIDOMWindowInternal * FindFocusedDOMWindowInternal();
void GetWebShellTitleAndURL(nsIWebShell* aWebShell, nsIDocument* aDoc,
PRUnichar** aTitle, PRUnichar** aURLStr);
void GetDisplayTitleAndURL(nsPrintObject* aPO,
nsIPrintSettings* aPrintSettings,
const PRUnichar* aBrandName,
PRUnichar** aTitle,
PRUnichar** aURLStr,
eDocTitleDefault aDefType = eDocTitleDefNone);
static void ShowPrintErrorDialog(nsresult printerror,
PRBool aIsPrinting = PR_TRUE);
PRBool CheckBeforeDestroy();
nsresult Cancelled();
nsresult ShowDocList(PRBool aShow);
void GetNewPresentation(nsCOMPtr<nsIPresShell>& aShell,
nsCOMPtr<nsIPresContext>& aPC,
nsCOMPtr<nsIViewManager>& aVM,
nsCOMPtr<nsIWidget>& aW);
// CachedPresentationObj is used to cache the presentation
// so we can bring it back later
PRBool HasCachedPres() { return mIsCachingPresentation && mCachedPresObj; }
PRBool IsCachingPres() { return mIsCachingPresentation; }
void SetCacheOldPres(PRBool aDoCache) { mIsCachingPresentation = aDoCache; }
void CachePresentation(nsIPresShell* aShell, nsIPresContext* aPC, nsIViewManager* aVM, nsIWidget* aW);
void GetCachedPresentation(nsCOMPtr<nsIPresShell>& aShell,
nsCOMPtr<nsIPresContext>& aPC,
nsCOMPtr<nsIViewManager>& aVM,
nsCOMPtr<nsIWidget>& aW);
// These calls also update the DocViewer
void SetIsPrinting(PRBool aIsPrinting) { mIsDoingPrinting = aIsPrinting; }
PRBool GetIsPrinting() { return mIsDoingPrinting; }
void SetIsPrintPreview(PRBool aIsPrintPreview) { mIsDoingPrintPreview = aIsPrintPreview; }
PRBool GetIsPrintPreview() { return mIsDoingPrintPreview; }
void SetIsCreatingPrintPreview(PRBool aIsCreatingPrintPreview) { mIsCreatingPrintPreview = aIsCreatingPrintPreview; }
PRBool GetIsCreatingPrintPreview() { return mIsCreatingPrintPreview; }
protected:
static nsIPresShell* GetPresShellFor(nsIDocShell* aDocShell);
void FirePrintCompletionEvent();
nsresult ShowDocListInternal(nsPrintObject* aPO, PRBool aShow);
nsresult GetSeqFrameAndCountPagesInternal(nsPrintObject* aPO,
nsIFrame*& aSeqFrame,
PRInt32& aCount);
static nsresult GetPageRangeForSelection(nsIPresShell * aPresShell,
nsIPresContext* aPresContext,
nsIRenderingContext& aRC,
nsISelection* aSelection,
nsIPageSequenceFrame* aPageSeqFrame,
nsIFrame** aStartFrame,
PRInt32& aStartPageNum,
nsRect& aStartRect,
nsIFrame** aEndFrame,
PRInt32& aEndPageNum,
nsRect& aEndRect);
static nsIFrame * FindFrameByType(nsIPresContext* aPresContext,
nsIFrame * aParentFrame,
nsIAtom * aType,
nsRect& aRect,
nsRect& aChildRect);
// Static memeber variables
PRBool mIsCreatingPrintPreview;
PRBool mIsDoingPrinting;
nsIDocumentViewerPrint* mDocViewerPrint; // [WEAK] it owns me!
nsIDocumentViewer* mDocViewer; // [WEAK] it owns me!
nsISupports* mContainer; // [WEAK] it owns me!
nsIDeviceContext* mDeviceContext; // not ref counted
nsIPresContext* mPresContext; // not ref counted
nsCOMPtr<nsIWidget> mWindow;
nsPrintData* mPrt;
nsPagePrintTimer* mPagePrintTimer;
nsIPageSequenceFrame* mPageSeqFrame;
// Print Preview
PRBool mIsDoingPrintPreview; // per DocumentViewer
nsCOMPtr<nsIWidget> mParentWidget;
nsPrintData* mPrtPreview;
nsPrintData* mOldPrtPreview;
nsCOMPtr<nsIDocument> mDocument;
PRBool mIsCachingPresentation;
CachedPresentationObj* mCachedPresObj;
FILE* mDebugFile;
private:
nsPrintEngine& operator=(const nsPrintEngine& aOther); // not implemented
};
#endif /* nsPrintEngine_h___ */

Просмотреть файл

@ -0,0 +1,114 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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.
*
* The Initial Developer of the Original Code is
* 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
* either 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"),
* 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
* use your version of this file under the terms of the NPL, indicate your
* 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
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsPrintObject.h"
#include "imgIContainer.h"
//---------------------------------------------------
//-- nsPrintObject Class Impl
//---------------------------------------------------
nsPrintObject::nsPrintObject() :
mFrameType(eFrame),
mRootView(nsnull), mContent(nsnull),
mSeqFrame(nsnull), mPageFrame(nsnull), mPageNum(-1),
mRect(0,0,0,0), mReflowRect(0,0,0,0),
mParent(nsnull), mHasBeenPrinted(PR_FALSE), mDontPrint(PR_TRUE),
mPrintAsIs(PR_FALSE), mSkippedPageEject(PR_FALSE), mSharedPresShell(PR_FALSE), mIsHidden(PR_FALSE),
mClipRect(-1,-1, -1, -1),
mImgAnimationMode(imgIContainer::kNormalAnimMode),
mDocTitle(nsnull), mDocURL(nsnull), mShrinkRatio(1.0), mXMost(0)
{
}
nsPrintObject::~nsPrintObject()
{
if (mPresContext) {
mPresContext->SetImageAnimationMode(mImgAnimationMode);
}
for (PRInt32 i=0;i<mKids.Count();i++) {
nsPrintObject* po = (nsPrintObject*)mKids[i];
NS_ASSERTION(po, "nsPrintObject can't be null!");
delete po;
}
if (mPresShell && !mSharedPresShell) {
mPresShell->EndObservingDocument();
mPresShell->Destroy();
}
if (mDocTitle) nsMemory::Free(mDocTitle);
if (mDocURL) nsMemory::Free(mDocURL);
}
//------------------------------------------------------------------
// Resets PO by destroying the presentation
nsresult
nsPrintObject::Init(nsIWebShell* aWebShell)
{
mWebShell = aWebShell;
mDocShell = do_QueryInterface(mWebShell);
NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);
mDocShell->GetPresShell(getter_AddRefs(mDisplayPresShell));
NS_ENSURE_TRUE(mDisplayPresShell, NS_ERROR_FAILURE);
mDocShell->GetPresContext(getter_AddRefs(mDisplayPresContext));
NS_ENSURE_TRUE(mDisplayPresContext, NS_ERROR_FAILURE);
mDisplayPresShell->GetDocument(getter_AddRefs(mDocument));
NS_ENSURE_TRUE(mDocument, NS_ERROR_FAILURE);
return NS_OK;
}
//------------------------------------------------------------------
// Resets PO by destroying the presentation
void
nsPrintObject::DestroyPresentation()
{
mWindow = nsnull;
mPresContext = nsnull;
if (mPresShell) mPresShell->Destroy();
mPresShell = nsnull;
mViewManager = nsnull;
mStyleSet = nsnull;
}

Просмотреть файл

@ -0,0 +1,121 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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.
*
* The Initial Developer of the Original Code is
* 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
* either 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"),
* 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
* use your version of this file under the terms of the NPL, indicate your
* 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
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsPrintObject_h___
#define nsPrintObject_h___
// Interfaces
#include "nsCOMPtr.h"
#include "nsIContent.h"
#include "nsIPresContext.h"
#include "nsIPresShell.h"
#include "nsIStyleSet.h"
#include "nsIViewManager.h"
#include "nsIWebShell.h"
#include "nsIDocShell.h"
#include "nsIDocument.h"
#include "nsIWidget.h"
// Other Includes
#include "nsRect.h"
// nsPrintObject Document Type
enum PrintObjectType {eDoc = 0, eFrame = 1, eIFrame = 2, eFrameSet = 3};
//---------------------------------------------------
//-- nsPrintObject Class
//---------------------------------------------------
class nsPrintObject
{
public:
nsPrintObject();
~nsPrintObject(); // non-virtual
// Methods
nsresult Init(nsIWebShell* aWebShell);
PRBool IsPrintable() { return !mDontPrint; }
void DestroyPresentation();
// Data Members
nsCOMPtr<nsIWebShell> mWebShell;
nsCOMPtr<nsIDocShell> mDocShell;
nsCOMPtr<nsIPresShell> mDisplayPresShell;
nsCOMPtr<nsIPresContext> mDisplayPresContext;
nsCOMPtr<nsIDocument> mDocument;
PrintObjectType mFrameType;
nsCOMPtr<nsIPresContext> mPresContext;
nsCOMPtr<nsIStyleSet> mStyleSet;
nsCOMPtr<nsIPresShell> mPresShell;
nsCOMPtr<nsIViewManager> mViewManager;
nsCOMPtr<nsIWidget> mWindow;
nsIView *mRootView;
nsIContent *mContent;
nsIFrame *mSeqFrame;
nsIFrame *mPageFrame;
PRInt32 mPageNum;
nsRect mRect;
nsRect mReflowRect;
nsVoidArray mKids;
nsPrintObject* mParent;
PRPackedBool mHasBeenPrinted;
PRPackedBool mDontPrint;
PRPackedBool mPrintAsIs;
PRPackedBool mSkippedPageEject;
PRPackedBool mSharedPresShell;
PRPackedBool mIsHidden; // Indicates PO is hidden, not reflowed, not shown
nsRect mClipRect;
PRUint16 mImgAnimationMode;
PRUnichar* mDocTitle;
PRUnichar* mDocURL;
float mShrinkRatio;
nscoord mXMost;
private:
nsPrintObject& operator=(const nsPrintObject& aOther); // not implemented
};
#endif /* nsPrintObject_h___ */