Bug 361844: Printing cleanup; r+sr=roc. Changes the way the presentation is managed for print preview, plus many smaller cleanups.

This commit is contained in:
sharparrow1%yahoo.com 2006-12-10 08:05:05 +00:00
parent 2850aaa1e1
commit 01ccd95a11
10 changed files with 315 additions and 1046 deletions

View File

@ -374,6 +374,8 @@ private:
nsresult SyncParentSubDocMap();
nsresult GetDocumentSelection(nsISelection **aSelection);
#ifdef NS_PRINTING
// Called when the DocViewer is notified that the state
// of Printing or PP has changed
@ -435,8 +437,7 @@ protected:
nsCOMPtr<nsIPrintSettings> mCachedPrintSettings;
nsCOMPtr<nsIWebProgressListener> mCachedPrintWebProgressListner;
nsPrintEngine* mPrintEngine;
nsCOMPtr<nsIDOMWindowInternal> mDialogParentWin;
nsCOMPtr<nsPrintEngine> mPrintEngine;
#endif // NS_PRINT_PREVIEW
#ifdef NS_DEBUG
@ -491,7 +492,7 @@ void DocumentViewerImpl::PrepareToStartLoad()
// Make sure we have destroyed it and cleared the data member
if (mPrintEngine) {
mPrintEngine->Destroy();
NS_RELEASE(mPrintEngine);
mPrintEngine = nsnull;
}
#ifdef NS_PRINT_PREVIEW
@ -808,15 +809,11 @@ DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget,
if (aDoCreation) {
if (aParentWidget && !mPresContext) {
// Create presentation context
if (GetIsCreatingPrintPreview())
mPresContext =
new nsPresContext(mDocument, nsPresContext::eContext_PrintPreview);
if (mIsPageMode) {
//Presentation context already created in SetPageMode which is calling this method
}
else
if (mIsPageMode) {
//Presentation context already created in SetPageMode which is calling this method
}
else
mPresContext =
mPresContext =
new nsPresContext(mDocument, nsPresContext::eContext_Galley);
NS_ENSURE_TRUE(mPresContext, NS_ERROR_OUT_OF_MEMORY);
@ -1582,7 +1579,7 @@ DocumentViewerImpl::Destroy()
#ifdef NS_PRINTING
if (mPrintEngine) {
mPrintEngine->Destroy();
NS_RELEASE(mPrintEngine);
mPrintEngine = nsnull;
}
#endif
@ -1874,6 +1871,10 @@ DocumentViewerImpl::SetBounds(const nsRect& aBounds)
if (mPreviousViewer)
mPreviousViewer->SetBounds(aBounds);
if (GetIsPrintPreview()) {
mPrintEngine->GetPrintPreviewWindow()->Resize(aBounds.x, aBounds.y, aBounds.width, aBounds.height,
PR_FALSE);
}
return NS_OK;
}
@ -1950,12 +1951,6 @@ DocumentViewerImpl::Show(void)
#endif
// Create presentation context
if (GetIsCreatingPrintPreview()) {
NS_ERROR("Whoa, we should not get here!");
return NS_ERROR_UNEXPECTED;
}
NS_ASSERTION(!mPresContext, "Shouldn't have a prescontext if we have no shell!");
mPresContext = new nsPresContext(mDocument, nsPresContext::eContext_Galley);
NS_ENSURE_TRUE(mPresContext, NS_ERROR_OUT_OF_MEMORY);
@ -2002,42 +1997,13 @@ DocumentViewerImpl::Show(void)
NS_IMETHODIMP
DocumentViewerImpl::Hide(void)
{
PRBool is_in_print_mode = PR_FALSE;
#ifdef NS_PRINTING
GetDoingPrint(&is_in_print_mode);
if (is_in_print_mode) {
// If we, or one of our parents, is in print mode it means we're
// right now returning from print and the layout frame that was
// created for this document is being destroyed. In such a case we
// ignore the Hide() call.
// XXX The above statement is a lie. We do not check our parents.
// in fact it always returns false for subdocuments.
return NS_OK;
}
GetDoingPrintPreview(&is_in_print_mode);
if (is_in_print_mode) {
// If we, or one of our parents, is in print preview mode it means
// we're right now returning from print preview and the layout
// frame that was created for this document is being destroyed. In
// such a case we ignore the Hide() call.
// XXX The above statement is a lie. We do not check our parents.
// in fact it always returns false for subdocuments.
return NS_OK;
}
#endif
NS_PRECONDITION(mWindow, "null window");
if (mWindow) {
mWindow->Show(PR_FALSE);
}
if (!mPresShell || GetIsPrintPreview()) {
if (!mPresShell)
return NS_OK;
}
NS_ASSERTION(mPresContext, "Can't have a presshell and no prescontext!");
@ -2391,22 +2357,15 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget,
// Return the selection for the document. Note that text fields have their
// own selection, which cannot be accessed with this method. Use
// mPresShell->GetSelectionForCopy() instead.
nsresult DocumentViewerImpl::GetDocumentSelection(nsISelection **aSelection,
nsIPresShell *aPresShell)
nsresult DocumentViewerImpl::GetDocumentSelection(nsISelection **aSelection)
{
if (!aPresShell) {
if (!mPresShell) {
return NS_ERROR_NOT_INITIALIZED;
}
aPresShell = mPresShell;
NS_ENSURE_ARG_POINTER(aSelection);
if (!mPresShell) {
return NS_ERROR_NOT_INITIALIZED;
}
if (!aSelection)
return NS_ERROR_NULL_POINTER;
if (!aPresShell)
return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsISelectionController> selcon;
selcon = do_QueryInterface(aPresShell);
selcon = do_QueryInterface(mPresShell);
if (selcon)
return selcon->GetSelection(nsISelectionController::SELECTION_NORMAL,
aSelection);
@ -2651,7 +2610,6 @@ NS_IMETHODIMP
DocumentViewerImpl::PrintWithParent(nsIDOMWindowInternal *aParentWin, nsIPrintSettings *aThePrintSettings, nsIWebProgressListener *aWPListener)
{
#ifdef NS_PRINTING
mDialogParentWin = aParentWin;
return Print(aThePrintSettings, aWPListener);
#else
return NS_ERROR_FAILURE;
@ -2669,10 +2627,6 @@ DocumentViewerImpl::GetPrintable(PRBool *aPrintable)
return NS_OK;
}
#ifdef XP_MAC
#pragma mark -
#endif
//*****************************************************************************
// nsIMarkupDocumentViewer
//*****************************************************************************
@ -3185,11 +3139,6 @@ NS_IMETHODIMP DocumentViewerImpl::SizeToContent()
}
#ifdef XP_MAC
#pragma mark -
#endif
NS_IMPL_ISUPPORTS1(nsDocViewerSelectionListener, nsISelectionListener)
nsresult nsDocViewerSelectionListener::Init(DocumentViewerImpl *aDocViewer)
@ -3541,14 +3490,13 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings,
if (!mPrintEngine) {
mPrintEngine = new nsPrintEngine();
NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_OUT_OF_MEMORY);
NS_ADDREF(mPrintEngine);
#ifdef NS_DEBUG
mPrintEngine->Initialize(this, this, docShell, mDocument,
mDeviceContext, mPresContext, mWindow, mParentWidget, mDebugFile);
mPrintEngine->Initialize(this, docShell, mDocument,
mDeviceContext, mParentWidget, mDebugFile);
#else
mPrintEngine->Initialize(this, this, docShell, mDocument,
mDeviceContext, mPresContext, mWindow, mParentWidget, nsnull);
mPrintEngine->Initialize(this, docShell, mDocument,
mDeviceContext, mParentWidget, nsnull);
#endif
}
@ -3592,12 +3540,10 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
if (!mPrintEngine) {
mPrintEngine = new nsPrintEngine();
NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_OUT_OF_MEMORY);
NS_ADDREF(mPrintEngine);
mPrintEngine->Initialize(this, this,
mPrintEngine->Initialize(this,
nsCOMPtr<nsISupports>(do_QueryReferent(mContainer)),
mDocument, mDeviceContext, mPresContext,
mWindow, mParentWidget,
mDocument, mDeviceContext, mParentWidget,
#ifdef NS_DEBUG
mDebugFile
#else
@ -3620,12 +3566,10 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
NS_IMETHODIMP
DocumentViewerImpl::PrintPreviewNavigate(PRInt16 aType, PRInt32 aPageNum)
{
if (GetIsPrinting()) return NS_ERROR_FAILURE;
if (!GetIsPrintPreview()) return NS_ERROR_FAILURE;
if (!mPrintEngine) return NS_ERROR_FAILURE;
nsIScrollableView* scrollableView;
mViewManager->GetRootScrollableView(&scrollableView);
nsIScrollableView* scrollableView = nsnull;
mPrintEngine->GetPrintPreviewViewManager()->GetRootScrollableView(&scrollableView);
if (scrollableView == nsnull) return NS_OK;
// Check to see if we can short circut scrolling to the top
@ -3992,20 +3936,6 @@ DocumentViewerImpl::SetIsPrintPreview(PRBool aIsPrintPreview)
#endif
}
//------------------------------------------------------------
// The PrintEngine holds the current value
// this called from inside the DocViewer
PRBool
DocumentViewerImpl::GetIsCreatingPrintPreview()
{
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
if (mPrintEngine) {
return mPrintEngine->GetIsCreatingPrintPreview();
}
#endif
return PR_FALSE;
}
//----------------------------------------------------------------------------------
// nsIDocumentViewerPrint IFace
//----------------------------------------------------------------------------------
@ -4018,6 +3948,9 @@ DocumentViewerImpl::IncrementDestroyRefCount()
}
//------------------------------------------------------------
static void ResetFocusState(nsIDocShell* aDocShell);
void
DocumentViewerImpl::ReturnToGalleyPresentation()
{
@ -4027,99 +3960,17 @@ DocumentViewerImpl::ReturnToGalleyPresentation()
return;
}
// Get the current size of what is being viewed
nsRect bounds;
mWindow->GetBounds(bounds);
// In case we have focus focus the parent DocShell
// which in this case should always be chrome
nsCOMPtr<nsIDocShellTreeItem> dstParentItem;
nsCOMPtr<nsIDocShellTreeItem> dstItem(do_QueryReferent(mContainer));
if (dstItem) {
dstItem->GetParent(getter_AddRefs(dstParentItem));
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(dstParentItem));
if (docShell) {
docShell->SetHasFocus(PR_TRUE);
}
}
// Start to kill off the old Presentation
// by cleaning up the PresShell
if (mPresShell) {
// Break circular reference (or something)
mPresShell->EndObservingDocument();
nsCOMPtr<nsISelection> selection;
nsresult rv = GetDocumentSelection(getter_AddRefs(selection));
nsCOMPtr<nsISelectionPrivate> selPrivate(do_QueryInterface(selection));
if (NS_SUCCEEDED(rv) && selPrivate && mSelectionListener)
selPrivate->RemoveSelectionListener(mSelectionListener);
mPresShell->Destroy();
}
// clear weak references before we go away
if (mPresContext) {
mPresContext->SetContainer(nsnull);
mPresContext->SetLinkHandler(nsnull);
}
//------------------------------------------------
// NOTE:
// Here is why the code below is a little confusing:
// 1) Scripting needs to be turned back on before
// the print engine is destroyed
// 2) The PrintEngine must be destroyed BEFORE
// calling InitInternal when caching documents (framesets)
// BUT the PrintEngine must be destroyed AFTER
// calling InitInternal when NOT caching documents (no framesets)
//------------------------------------------------
// wasCached will be used below to indicate whether the
// InitInternal should create all new objects or just
// initialize the existing ones
PRBool wasCached = PR_FALSE;
if (mPrintEngine && mPrintEngine->HasCachedPres()) {
mPrintEngine->GetCachedPresentation(mPresShell, mPresContext, mViewManager, mWindow);
// Tell the "real" presshell to start observing the document
// again.
mPresShell->BeginObservingDocument();
mWindow->Show(PR_TRUE);
wasCached = PR_TRUE;
} else {
// Destroy the old Presentation
mPresShell = nsnull;
mPresContext = nsnull;
mViewManager = nsnull;
mWindow = nsnull;
}
if (mPrintEngine) {
// Very important! Turn On scripting
mPrintEngine->TurnScriptingOn(PR_TRUE);
if (wasCached) {
mPrintEngine->Destroy();
NS_RELEASE(mPrintEngine);
}
}
InitInternal(mParentWidget, nsnull, mDeviceContext, bounds, !wasCached, PR_TRUE);
if (mPrintEngine && !wasCached) {
mPrintEngine->Destroy();
NS_RELEASE(mPrintEngine);
}
// this needs to be set here not earlier,
// because it is needing when re-constructing the Galley Mode)
SetIsPrintPreview(PR_FALSE);
mPrintEngine->TurnScriptingOn(PR_TRUE);
mPrintEngine->Destroy();
mPrintEngine = nsnull;
mViewManager->EnableRefresh(NS_VMREFRESH_DEFERRED);
nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mContainer));
ResetFocusState(docShell);
Show();
#endif // NS_PRINTING && NS_PRINT_PREVIEW
@ -4156,104 +4007,6 @@ ResetFocusState(nsIDocShell* aDocShell)
}
}
//------------------------------------------------------------
void
DocumentViewerImpl::InstallNewPresentation()
{
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
// Get the current size of what is being viewed
nsRect bounds;
mWindow->GetBounds(bounds);
// In case we have focus focus the parent DocShell
// which in this case should always be chrome
nsCOMPtr<nsIDocShellTreeItem> dstParentItem;
nsCOMPtr<nsIDocShellTreeItem> dstItem(do_QueryReferent(mContainer));
if (dstItem) {
dstItem->GetParent(getter_AddRefs(dstParentItem));
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(dstParentItem));
if (docShell) {
docShell->SetHasFocus(PR_TRUE);
::ResetFocusState(docShell);
}
}
// turn off selection painting
nsCOMPtr<nsISelectionController> selectionController =
do_QueryInterface(mPresShell);
if (selectionController) {
selectionController->SetDisplaySelection(nsISelectionController::SELECTION_OFF);
}
// Start to kill off the old Presentation
// by cleaning up the PresShell
if (mPresShell) {
// Break circular reference (or something)
mPresShell->EndObservingDocument();
nsCOMPtr<nsISelection> selection;
nsresult rv = GetDocumentSelection(getter_AddRefs(selection));
nsCOMPtr<nsISelectionPrivate> selPrivate(do_QueryInterface(selection));
if (NS_SUCCEEDED(rv) && selPrivate && mSelectionListener)
selPrivate->RemoveSelectionListener(mSelectionListener);
// We need to destroy the PreShell if there is an existing PP
// or we are not caching the original Presentation
if (!mPrintEngine->IsCachingPres() || mPrintEngine->IsOldPrintPreviewPres()) {
mPresShell->Destroy();
}
}
// clear weak references before we go away
if (mPresContext) {
mPresContext->SetContainer(nsnull);
mPresContext->SetLinkHandler(nsnull);
}
// See if we are suppose to be caching the old Presentation
// and then check to see if we already have.
if (mPrintEngine->IsCachingPres() && !mPrintEngine->HasCachedPres()) {
// Cach old presentation
mPrintEngine->CachePresentation(mPresShell, mPresContext, mViewManager, mWindow);
mWindow->Show(PR_FALSE);
} else {
// Destroy the old Presentation
mPresShell = nsnull;
mPresContext = nsnull;
mViewManager = nsnull;
mWindow = nsnull;
}
mPrintEngine->InstallPrintPreviewListener();
mPrintEngine->GetNewPresentation(mPresShell, mPresContext, mViewManager, mWindow);
mPresShell->BeginObservingDocument();
// Make sure we have focus in a context that has a container, bug 244128.
nsIEventStateManager* esm = mPresContext->EventStateManager();
if (esm) {
esm->SetContentState(nsnull, NS_EVENT_STATE_FOCUS);
esm->SetFocusedContent(nsnull);
}
nscoord width = bounds.width;
nscoord height = bounds.height;
float p2t;
p2t = mPresContext->PixelsToTwips();
width = NSIntPixelsToTwips(width, p2t);
height = NSIntPixelsToTwips(height, p2t);
mViewManager->DisableRefresh();
mViewManager->SetWindowDimensions(width, height);
mDeviceContext->SetUseAltDC(kUseAltDCFor_FONTMETRICS, PR_FALSE);
mDeviceContext->SetUseAltDC(kUseAltDCFor_CREATERC_PAINT, PR_TRUE);
mViewManager->EnableRefresh(NS_VMREFRESH_DEFERRED);
Show();
#endif // NS_PRINTING && NS_PRINT_PREVIEW
}
//------------------------------------------------------------
// This called ONLY when printing has completed and the DV
// is being notified that it should get rid of the PrintEngine.
@ -4275,7 +4028,7 @@ DocumentViewerImpl::OnDonePrinting()
mPrintEngine->DestroyPrintingData();
} else {
mPrintEngine->Destroy();
NS_RELEASE(mPrintEngine);
mPrintEngine = nsnull;
}
// We are done printing, now cleanup

View File

@ -39,23 +39,16 @@
#include "nsISupports.h"
class nsPresContext;
class nsIPrintSettings;
class nsPrintObject;
class nsISelection;
class nsIPresShell;
class nsIDocument;
class nsStyleSet;
class nsIContent;
// {D0B7F354-D575-43fd-903D-5AA35A193EDA}
#define NS_IDOCUMENT_VIEWER_PRINT_IID \
{ 0xd0b7f354, 0xd575, 0x43fd, { 0x90, 0x3d, 0x5a, 0xa3, 0x5a, 0x19, 0x3e, 0xda } }
/**
* A DocumentViewerPrint is an INTERNAL Interface mainly used for interaction
* between the DocumentViewer and the PrintEngine, although other objects may
* use to find out if printing or print preview is currently underway
* A DocumentViewerPrint is an INTERNAL Interface used for interaction
* between the DocumentViewer and the PrintEngine
*/
class nsIDocumentViewerPrint : public nsISupports
{
@ -68,22 +61,15 @@ public:
virtual void SetIsPrintPreview(PRBool aIsPrintPreview) = 0;
virtual PRBool GetIsPrintPreview() = 0;
virtual PRBool GetIsCreatingPrintPreview() = 0;
// The style set returned by CreateStyleSet is in the middle of an
// update batch so that the caller can add sheets to it if needed.
// Callers should call EndUpdate() on it when ready to use.
virtual nsresult CreateStyleSet(nsIDocument* aDocument, nsStyleSet** 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;
};
@ -97,12 +83,9 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumentViewerPrint,
virtual PRBool GetIsPrinting(); \
virtual void SetIsPrintPreview(PRBool aIsPrintPreview); \
virtual PRBool GetIsPrintPreview(); \
virtual PRBool GetIsCreatingPrintPreview(); \
virtual nsresult CreateStyleSet(nsIDocument* aDocument, nsStyleSet** aStyleSet); \
virtual nsresult GetDocumentSelection(nsISelection **aSelection, nsIPresShell * aPresShell = nsnull); \
virtual void IncrementDestroyRefCount(); \
virtual void ReturnToGalleyPresentation(); \
virtual void InstallNewPresentation(); \
virtual void OnDonePrinting();
#endif /* nsIDocumentViewerPrint_h___ */

View File

@ -36,27 +36,25 @@
* ***** END LICENSE BLOCK ***** */
#include "nsPagePrintTimer.h"
#include "nsPrintEngine.h"
#include "nsIContentViewer.h"
#include "nsIServiceManager.h"
#include "nsPrintEngine.h"
NS_IMPL_ISUPPORTS1(nsPagePrintTimer, nsITimerCallback)
nsPagePrintTimer::nsPagePrintTimer() :
mDocViewerPrint(nsnull),
mPresContext(nsnull),
mPrintSettings(nsnull),
mPrintEngine(nsnull),
mPrintObj(nsnull),
mDelay(0)
{
}
nsPagePrintTimer::~nsPagePrintTimer()
{
if (mTimer) {
mTimer->Cancel();
}
mPrintEngine->SetIsPrinting(PR_FALSE); // this will notify the DV also
// "Destroy" the document viewer; this normally doesn't actually
// destroy it because of the IncrementDestroyRefCount call below
// XXX This is messy; the document viewer should use a single approach
// to keep itself alive during printing
nsCOMPtr<nsIContentViewer> cv(do_QueryInterface(mDocViewerPrint));
if (cv) {
cv->Destroy();
@ -82,13 +80,14 @@ nsPagePrintTimer::StartTimer(PRBool aUseDelay)
NS_IMETHODIMP
nsPagePrintTimer::Notify(nsITimer *timer)
{
if (mPresContext && mDocViewerPrint) {
if (mDocViewerPrint) {
PRPackedBool initNewTimer = PR_TRUE;
// Check to see if we are done
// inRange will be true if a page is actually printed
PRBool inRange;
// donePrinting will be true if it completed successfully or
// if the printing was cancelled
PRBool inRange;
PRBool donePrinting = mPrintEngine->PrintPage(mPresContext, mPrintSettings, mPrintObj, inRange);
PRBool donePrinting = mPrintEngine->PrintPage(mPrintObj, inRange);
if (donePrinting) {
// now clean up print or print the next webshell
if (mPrintEngine->DonePrintingPages(mPrintObj, NS_OK)) {
@ -96,7 +95,10 @@ nsPagePrintTimer::Notify(nsITimer *timer)
}
}
Stop();
// Note that the Stop() destroys this after the print job finishes
// (The PrintEngine stops holding a reference when DonePrintingPages
// returns true.)
Stop();
if (initNewTimer) {
nsresult result = StartTimer(inRange);
if (NS_FAILED(result)) {
@ -111,29 +113,19 @@ nsPagePrintTimer::Notify(nsITimer *timer)
void
nsPagePrintTimer::Init(nsPrintEngine* aPrintEngine,
nsIDocumentViewerPrint* aDocViewerPrint,
nsPresContext* aPresContext,
nsIPrintSettings* aPrintSettings,
nsPrintObject* aPO,
PRUint32 aDelay)
{
mPrintEngine = aPrintEngine;
mDocViewerPrint = aDocViewerPrint;
mPresContext = aPresContext;
mPrintSettings = aPrintSettings;
mPrintObj = aPO;
mDelay = aDelay;
mDocViewerPrint->IncrementDestroyRefCount();
}
nsresult
nsPagePrintTimer::Start(nsPrintEngine* aPrintEngine,
nsIDocumentViewerPrint* aDocViewerPrint,
nsPresContext* aPresContext,
nsIPrintSettings* aPrintSettings,
nsPrintObject* aPO,
PRUint32 aDelay)
nsPagePrintTimer::Start(nsPrintObject* aPO)
{
Init(aPrintEngine, aDocViewerPrint, aPresContext, aPrintSettings, aPO, aDelay);
mPrintObj = aPO;
return StartTimer(PR_FALSE);
}

View File

@ -41,14 +41,8 @@
#include "nsITimer.h"
#include "nsITimelineService.h"
// Interfaces
#include "nsIDocumentViewerPrint.h"
#include "nsPresContext.h"
#include "nsIPrintSettings.h"
// Other Includes
#include "nsPrintObject.h"
#include "nsRect.h"
class nsPrintEngine;
@ -62,34 +56,23 @@ public:
NS_DECL_ISUPPORTS
nsPagePrintTimer();
virtual ~nsPagePrintTimer();
~nsPagePrintTimer();
// nsITimerCallback
NS_DECL_NSITIMERCALLBACK
// Other Methods
nsresult StartTimer(PRBool aUseDelay = PR_TRUE);
void Init(nsPrintEngine* aPrintEngine,
nsIDocumentViewerPrint* aDocViewerPrint,
nsPresContext* aPresContext,
nsIPrintSettings* aPrintSettings,
nsPrintObject* aPO,
PRUint32 aDelay);
nsresult Start(nsPrintEngine* aPrintEngine,
nsIDocumentViewerPrint* aDocViewerPrint,
nsPresContext* aPresContext,
nsIPrintSettings* aPrintSettings,
nsPrintObject* aPO,
PRUint32 aDelay);
nsresult Start(nsPrintObject* aPO);
void Stop();
private:
nsresult StartTimer(PRBool aUseDelay);
nsPrintEngine* mPrintEngine;
nsCOMPtr<nsIDocumentViewerPrint> mDocViewerPrint;
nsPresContext* mPresContext;
nsCOMPtr<nsIPrintSettings> mPrintSettings;
nsCOMPtr<nsITimer> mTimer;
PRUint32 mDelay;
nsPrintObject * mPrintObj;

View File

@ -39,12 +39,9 @@
#include "nsIStringBundle.h"
#include "nsIServiceManager.h"
#include "nsReadableUtils.h"
#include "nsCRT.h"
#include "nsISelection.h"
#include "nsIDocShell.h"
#include "nsIURI.h"
#include "nsPrintObject.h"
#include "nsPrintPreviewListener.h"
#include "nsIWebProgressListener.h"
//-----------------------------------------------------
// PR LOGGING
@ -55,13 +52,6 @@
#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);
@ -75,11 +65,11 @@ static PRLogModuleInfo * kPrintingLogMod = PR_NewLogModule("printing");
//---------------------------------------------------
nsPrintData::nsPrintData(ePrintDataType aType) :
mType(aType), mDebugFilePtr(nsnull), mPrintObject(nsnull), mSelectedPO(nsnull),
mShowProgressDialog(PR_TRUE), mProgressDialogIsShown(PR_FALSE), mPrintDocList(nsnull), mIsIFrameSelected(PR_FALSE),
mProgressDialogIsShown(PR_FALSE), mPrintDocList(nsnull), mIsIFrameSelected(PR_FALSE),
mIsParentAFrameSet(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),
mNumPrintablePages(0), mNumPagesPrinted(0),
mShrinkRatio(1.0), mOrigDCScale(1.0), mPPEventListeners(NULL),
mBrandName(nsnull)
{
@ -141,43 +131,31 @@ nsPrintData::~nsPrintData()
if (mBrandName) {
NS_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);
DoOnProgressChange(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);
}
DoOnProgressChange(100, 100, PR_TRUE, nsIWebProgressListener::STATE_STOP|nsIWebProgressListener::STATE_IS_DOCUMENT);
}
void
nsPrintData::DoOnProgressChange(nsVoidArray& aListeners,
PRInt32 aProgess,
PRInt32 aMaxProgress,
PRBool aDoStartStop,
PRInt32 aFlag)
nsPrintData::DoOnProgressChange(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!");
for (PRInt32 i=0;i<mPrintProgressListeners.Count();i++) {
nsIWebProgressListener* wpl = mPrintProgressListeners.ObjectAt(i);
wpl->OnProgressChange(nsnull, nsnull, aProgess, aMaxProgress, aProgess, aMaxProgress);
if (aDoStartStop) {
wpl->OnStateChange(nsnull, nsnull, aFlag, 0);
@ -185,6 +163,3 @@ nsPrintData::DoOnProgressChange(nsVoidArray& aListeners,
}
}

View File

@ -37,52 +37,18 @@
#ifndef nsPrintData_h___
#define nsPrintData_h___
#include "nsPrintObject.h"
// Interfaces
#include "nsIDeviceContext.h"
#include "nsIDocument.h"
#include "nsIDOMWindow.h"
#include "nsIObserver.h"
#include "nsIPrintProgress.h"
#include "nsIDeviceContext.h"
#include "nsIPrintProgressParams.h"
#include "nsIPrintOptions.h"
#include "nsIPrintSettings.h"
#include "nsIWebProgressListener.h"
#include "nsIPrintSession.h"
// Other Includes
#include "nsPrintPreviewListener.h"
#include "nsIDocShellTreeNode.h"
#include "nsVoidArray.h"
#include "nsCOMArray.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, nsPresContext* 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<nsPresContext> mPresContext;
};
class nsPrintObject;
class nsPrintPreviewListener;
class nsIWebProgressListener;
//------------------------------------------------------------------------
// nsPrintData Class
@ -118,11 +84,10 @@ public:
// Listener Helper Methods
void OnEndPrinting();
void OnStartPrinting();
static void DoOnProgressChange(nsVoidArray& aListeners,
PRInt32 aProgess,
PRInt32 aMaxProgress,
PRBool aDoStartStop = PR_FALSE,
PRInt32 aFlag = 0);
void DoOnProgressChange(PRInt32 aProgess,
PRInt32 aMaxProgress,
PRBool aDoStartStop,
PRInt32 aFlag);
ePrintDataType mType; // the type of data this is (Printing or Print Preview)
@ -132,28 +97,21 @@ public:
nsPrintObject * mPrintObject;
nsPrintObject * mSelectedPO;
nsVoidArray mPrintProgressListeners;
nsCOMPtr<nsIWebProgressListener> mPrintProgressListener;
nsCOMPtr<nsIPrintProgress> mPrintProgress;
nsCOMArray<nsIWebProgressListener> mPrintProgressListeners;
nsCOMPtr<nsIPrintProgressParams> mPrintProgressParams;
PRBool mShowProgressDialog; // means we should try to show it
PRPackedBool mProgressDialogIsShown; // means it is already being shown
nsCOMPtr<nsIDOMWindow> mCurrentFocusWin; // cache a pointer to the currently focused window
nsVoidArray* mPrintDocList;
nsCOMPtr<nsIDeviceContext> mPrintDocDC;
nsCOMPtr<nsIDOMWindow> mPrintDocDW;
PRPackedBool mIsIFrameSelected;
PRPackedBool mIsParentAFrameSet;
PRPackedBool mOnStartSent;
PRPackedBool mIsAborted; // tells us the document is being aborted
PRPackedBool mPreparingForPrint; // see comments above
PRPackedBool mDocWasToBeDestroyed; // see comments above
PRPackedBool mProgressDialogIsShown; // it is being shown
PRBool mShrinkToFit;
PRInt16 mPrintFrameType;
PRInt32 mNumPrintableDocs;
PRInt32 mNumDocsPrinted;
PRInt32 mNumPrintablePages;
PRInt32 mNumPagesPrinted;
float mShrinkRatio;
@ -166,7 +124,7 @@ public:
PRUnichar* mBrandName; // needed as a substitute name for a document
private:
nsPrintData() {}
nsPrintData(); //not implemented
nsPrintData& operator=(const nsPrintData& aOther); // not implemented
};

File diff suppressed because it is too large Load Diff

View File

@ -43,29 +43,18 @@
#include "nsPrintData.h"
// Interfaces
#include "nsIDeviceContext.h"
#include "nsIDocument.h"
#include "nsIDOMWindow.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"
class nsIDocShellTreeNode;
class nsIDeviceContext;
class nsIDocumentViewerPrint;
class nsPrintObject;
class nsIDocShell;
class nsIPageSequenceFrame;
//------------------------------------------------------------------------
// nsPrintEngine Class
@ -106,7 +95,6 @@ public:
NS_IMETHOD GetDoingPrint(PRBool *aDoingPrint);
NS_IMETHOD GetDoingPrintPreview(PRBool *aDoingPrintPreview);
NS_IMETHOD GetCurrentPrintSettings(nsIPrintSettings **aCurrentPrintSettings);
NS_IMETHOD Cancel();
// This enum tells indicates what the default should be for the title
@ -117,28 +105,21 @@ public:
eDocTitleDefURLDoc
};
nsPrintEngine();
virtual ~nsPrintEngine();
~nsPrintEngine();
void Destroy();
void DestroyPrintingData();
nsresult Initialize(nsIDocumentViewer* aDocViewer,
nsIDocumentViewerPrint* aDocViewerPrint,
nsresult Initialize(nsIDocumentViewerPrint* aDocViewerPrint,
nsISupports* aContainer,
nsIDocument* aDocument,
nsIDeviceContext* aDevContext,
nsPresContext* 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...
//
@ -146,8 +127,7 @@ public:
nsresult GetSelectionDocument(nsIDeviceContextSpec * aDevSpec,
nsIDocument ** aNewDoc);
nsresult SetupToPrintContent(nsIDeviceContext* aDContext,
nsIDOMWindow* aCurrentFocusedDOMWin);
nsresult SetupToPrintContent();
nsresult EnablePOsForPrinting();
nsPrintObject* FindSmallestSTF();
@ -161,9 +141,7 @@ public:
void InstallPrintPreviewListener();
// nsIDocumentViewerPrint Printing Methods
PRBool PrintPage(nsPresContext* aPresContext,
nsIPrintSettings* aPrintSettings,
nsPrintObject* aPOect, PRBool& aInRange);
PRBool PrintPage(nsPrintObject* aPOect, PRBool& aInRange);
PRBool DonePrintingPages(nsPrintObject* aPO, nsresult aResult);
//---------------------------------------------------------------------
@ -176,9 +154,7 @@ public:
void CheckForChildFrameSets(nsPrintObject* aPO);
void CalcNumPrintableDocsAndPages(PRInt32& aNumDocs, PRInt32& aNumPages);
void DoProgressForAsIsFrames();
void DoProgressForSeparateFrames();
void CalcNumPrintablePages(PRInt32& aNumPages);
void ShowPrintProgress(PRBool aIsForPrinting, PRBool& aDoNotify);
nsresult CleanupOnFailure(nsresult aResult, PRBool aIsPrinting);
nsresult FinishPrintPreview();
@ -196,19 +172,16 @@ public:
// Timer Methods
nsresult StartPagePrintTimer(nsPresContext * aPresContext,
nsIPrintSettings* aPrintSettings,
nsPrintObject* aPO,
PRUint32 aDelay);
nsresult StartPagePrintTimer(nsPrintObject* aPO);
PRBool IsWindowsInOurSubTree(nsIDOMWindow * aDOMWindow);
PRBool IsParentAFrameSet(nsIDocShell * aParent);
static PRBool IsParentAFrameSet(nsIDocShell * aParent);
PRBool IsThereAnIFrameSelected(nsIDocShell* aDocShell,
nsIDOMWindow* aDOMWin,
PRPackedBool& aIsParentFrameSet);
nsPrintObject* FindPrintObjectByDOMWin(nsPrintObject* aParentObject,
nsIDOMWindow* aDOMWin);
static nsPrintObject* FindPrintObjectByDOMWin(nsPrintObject* aParentObject,
nsIDOMWindow* aDOMWin);
// get the currently infocus frame for the document viewer
already_AddRefed<nsIDOMWindow> FindFocusedDOMWindow();
@ -219,12 +192,10 @@ public:
static void GetDocumentTitleAndURL(nsIDocument* aDoc,
PRUnichar** aTitle,
PRUnichar** aURLStr);
static void GetDisplayTitleAndURL(nsPrintObject* aPO,
nsIPrintSettings* aPrintSettings,
const PRUnichar* aBrandName,
PRUnichar** aTitle,
PRUnichar** aURLStr,
eDocTitleDefault aDefType = eDocTitleDefNone);
void GetDisplayTitleAndURL(nsPrintObject* aPO,
PRUnichar** aTitle,
PRUnichar** aURLStr,
eDocTitleDefault aDefType);
static void ShowPrintErrorDialog(nsresult printerror,
PRBool aIsPrinting = PR_TRUE);
@ -233,31 +204,9 @@ public:
PRBool CheckBeforeDestroy();
nsresult Cancelled();
void GetNewPresentation(nsCOMPtr<nsIPresShell>& aShell,
nsCOMPtr<nsPresContext>& aPC,
nsCOMPtr<nsIViewManager>& aVM,
nsCOMPtr<nsIWidget>& aW);
nsIWidget* GetPrintPreviewWindow() {return mPrtPreview->mPrintObject->mWindow;}
// 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, nsPresContext* aPC,
nsIViewManager* aVM, nsIWidget* aW);
void GetCachedPresentation(nsCOMPtr<nsIPresShell>& aShell,
nsCOMPtr<nsPresContext>& aPC,
nsCOMPtr<nsIViewManager>& aVM,
nsCOMPtr<nsIWidget>& aW);
nsIViewManager* GetPrintPreviewViewManager() {return mPrtPreview->mPrintObject->mViewManager;}
static nsIPresShell* GetPresShellFor(nsIDocShell* aDocShell);
@ -283,9 +232,9 @@ public:
protected:
void FirePrintCompletionEvent();
nsresult GetSeqFrameAndCountPagesInternal(nsPrintObject* aPO,
nsIFrame*& aSeqFrame,
PRInt32& aCount);
static nsresult GetSeqFrameAndCountPagesInternal(nsPrintObject* aPO,
nsIFrame*& aSeqFrame,
PRInt32& aCount);
static nsresult FindSelectionBoundsWithList(nsPresContext* aPresContext,
nsIRenderingContext& aRC,
@ -318,12 +267,6 @@ protected:
PRInt32& aEndPageNum,
nsRect& aEndRect);
static nsIFrame * FindFrameByType(nsPresContext* aPresContext,
nsIFrame * aParentFrame,
nsIAtom * aType,
nsRect& aRect,
nsRect& aChildRect);
static void MapContentForPO(nsPrintObject* aPO, nsIContent* aContent);
static void MapContentToWebShells(nsPrintObject* aRootPO, nsPrintObject* aPO);
@ -335,10 +278,8 @@ protected:
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
nsCOMPtr<nsIWidget> mWindow;
nsPrintData* mPrt;
nsPagePrintTimer* mPagePrintTimer;
@ -352,8 +293,6 @@ protected:
nsCOMPtr<nsIDocument> mDocument;
PRBool mIsCachingPresentation;
CachedPresentationObj* mCachedPresObj;
FILE* mDebugFile;
private:

View File

@ -36,15 +36,17 @@
* ***** END LICENSE BLOCK ***** */
#include "nsPrintObject.h"
#include "nsIContentViewer.h"
#include "nsIDOMDocument.h"
//---------------------------------------------------
//-- nsPrintObject Class Impl
//---------------------------------------------------
nsPrintObject::nsPrintObject() :
mFrameType(eFrame), mRootView(nsnull), mContent(nsnull), mParent(nsnull),
mFrameType(eFrame), mContent(nsnull), mParent(nsnull),
mHasBeenPrinted(PR_FALSE), mDontPrint(PR_TRUE), mPrintAsIs(PR_FALSE),
mSharedPresShell(PR_FALSE), mInvisible(PR_FALSE),
mDocTitle(nsnull), mDocURL(nsnull), mShrinkRatio(1.0)
mShrinkRatio(1.0)
{
}
@ -56,14 +58,7 @@ nsPrintObject::~nsPrintObject()
delete po;
}
if (mPresShell && !mSharedPresShell) {
mPresShell->EndObservingDocument();
mPresShell->Destroy();
}
if (mDocTitle) nsMemory::Free(mDocTitle);
if (mDocURL) nsMemory::Free(mDocURL);
DestroyPresentation();
}
//------------------------------------------------------------------
@ -73,11 +68,17 @@ nsPrintObject::Init(nsIDocShell* aDocShell)
{
mDocShell = aDocShell;
NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);
mDocShell->GetPresShell(getter_AddRefs(mDisplayPresShell));
NS_ENSURE_TRUE(mDisplayPresShell, NS_ERROR_FAILURE);
mDocument = mDisplayPresShell->GetDocument();
nsresult rv;
nsCOMPtr<nsIContentViewer> viewer;
rv = mDocShell->GetContentViewer(getter_AddRefs(viewer));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMDocument> doc;
viewer->GetDOMDocument(getter_AddRefs(doc));
NS_ENSURE_SUCCESS(rv, rv);
mDocument = do_QueryInterface(doc);
NS_ENSURE_TRUE(mDocument, NS_ERROR_FAILURE);
return NS_OK;
@ -90,7 +91,10 @@ nsPrintObject::DestroyPresentation()
{
mWindow = nsnull;
mPresContext = nsnull;
if (mPresShell) mPresShell->Destroy();
if (mPresShell) {
mPresShell->EndObservingDocument();
mPresShell->Destroy();
}
mPresShell = nsnull;
mViewManager = nsnull;
}

View File

@ -39,7 +39,6 @@
// Interfaces
#include "nsCOMPtr.h"
#include "nsAutoPtr.h"
#include "nsIContent.h"
#include "nsPresContext.h"
#include "nsIPresShell.h"
@ -49,9 +48,6 @@
#include "nsIDocument.h"
#include "nsIWidget.h"
// Other Includes
#include "nsRect.h"
// nsPrintObject Document Type
enum PrintObjectType {eDoc = 0, eFrame = 1, eIFrame = 2, eFrameSet = 3};
@ -73,14 +69,12 @@ public:
// Data Members
nsCOMPtr<nsIDocShell> mDocShell;
nsCOMPtr<nsIPresShell> mDisplayPresShell;
nsCOMPtr<nsIDocument> mDocument;
nsCOMPtr<nsPresContext> mPresContext;
nsCOMPtr<nsIPresShell> mPresShell;
nsCOMPtr<nsIViewManager> mViewManager;
nsCOMPtr<nsIWidget> mWindow;
nsIView* mRootView;
nsIContent* mContent;
PrintObjectType mFrameType;
@ -93,8 +87,6 @@ public:
PRPackedBool mSharedPresShell;
PRPackedBool mInvisible; // Indicates PO is set to not visible by CSS
PRUnichar* mDocTitle;
PRUnichar* mDocURL;
float mShrinkRatio;
private: