1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
37 #ifndef nsPrintEngine_h___
38 #define nsPrintEngine_h___
42 #include "nsPrintObject.h"
43 #include "nsPrintData.h"
46 #include "nsIDocument.h"
47 #include "nsIDOMWindow.h"
48 #include "nsIObserver.h"
51 class nsPagePrintTimer
;
52 class nsIDocShellTreeNode
;
53 class nsIDeviceContext
;
54 class nsIDocumentViewerPrint
;
57 class nsIPageSequenceFrame
;
59 //------------------------------------------------------------------------
60 // nsPrintEngine Class
62 //------------------------------------------------------------------------
63 class nsPrintEngine
: public nsIObserver
66 // nsISupports interface...
72 // Old nsIWebBrowserPrint methods; not cleaned up yet
73 NS_IMETHOD
Print(nsIPrintSettings
* aPrintSettings
,
74 nsIWebProgressListener
* aWebProgressListener
);
75 NS_IMETHOD
PrintPreview(nsIPrintSettings
* aPrintSettings
,
76 nsIDOMWindow
*aChildDOMWin
,
77 nsIWebProgressListener
* aWebProgressListener
);
78 NS_IMETHOD
GetIsFramesetDocument(PRBool
*aIsFramesetDocument
);
79 NS_IMETHOD
GetIsIFrameSelected(PRBool
*aIsIFrameSelected
);
80 NS_IMETHOD
GetIsRangeSelection(PRBool
*aIsRangeSelection
);
81 NS_IMETHOD
GetIsFramesetFrameSelected(PRBool
*aIsFramesetFrameSelected
);
82 NS_IMETHOD
GetPrintPreviewNumPages(PRInt32
*aPrintPreviewNumPages
);
83 NS_IMETHOD
EnumerateDocumentNames(PRUint32
* aCount
, PRUnichar
*** aResult
);
84 static nsresult
GetGlobalPrintSettings(nsIPrintSettings
** aPrintSettings
);
85 NS_IMETHOD
GetDoingPrint(PRBool
*aDoingPrint
);
86 NS_IMETHOD
GetDoingPrintPreview(PRBool
*aDoingPrintPreview
);
87 NS_IMETHOD
GetCurrentPrintSettings(nsIPrintSettings
**aCurrentPrintSettings
);
90 // This enum tells indicates what the default should be for the title
91 // if the title from the document is null
92 enum eDocTitleDefault
{
102 void DestroyPrintingData();
104 nsresult
Initialize(nsIDocumentViewerPrint
* aDocViewerPrint
,
105 nsISupports
* aContainer
,
106 nsIDocument
* aDocument
,
110 nsresult
GetSeqFrameAndCountPages(nsIFrame
*& aSeqFrame
, PRInt32
& aCount
);
113 // The following three methods are used for printing...
115 nsresult
DocumentReadyForPrinting();
116 nsresult
GetSelectionDocument(nsIDeviceContextSpec
* aDevSpec
,
117 nsIDocument
** aNewDoc
);
119 nsresult
SetupToPrintContent();
120 nsresult
EnablePOsForPrinting();
121 nsPrintObject
* FindSmallestSTF();
123 PRBool
PrintDocContent(nsPrintObject
* aPO
, nsresult
& aStatus
);
124 nsresult
DoPrint(nsPrintObject
* aPO
);
126 void SetPrintPO(nsPrintObject
* aPO
, PRBool aPrint
);
128 void TurnScriptingOn(PRBool aDoTurnOn
);
129 PRBool
CheckDocumentForPPCaching();
130 void InstallPrintPreviewListener();
132 // nsIDocumentViewerPrint Printing Methods
133 PRBool
PrintPage(nsPrintObject
* aPOect
, PRBool
& aInRange
);
134 PRBool
DonePrintingPages(nsPrintObject
* aPO
, nsresult aResult
);
136 //---------------------------------------------------------------------
137 void BuildDocTree(nsIDocShellTreeNode
* aParentNode
,
138 nsTArray
<nsPrintObject
*> * aDocList
,
139 nsPrintObject
* aPO
);
140 nsresult
ReflowDocList(nsPrintObject
* aPO
, PRBool aSetPixelScale
);
142 nsresult
ReflowPrintObject(nsPrintObject
* aPO
);
144 void CheckForChildFrameSets(nsPrintObject
* aPO
);
146 void CalcNumPrintablePages(PRInt32
& aNumPages
);
147 void ShowPrintProgress(PRBool aIsForPrinting
, PRBool
& aDoNotify
);
148 nsresult
CleanupOnFailure(nsresult aResult
, PRBool aIsPrinting
);
149 // If FinishPrintPreview() fails, caller may need to reset the state of the
150 // object, for example by calling CleanupOnFailure().
151 nsresult
FinishPrintPreview();
152 static void CloseProgressDialog(nsIWebProgressListener
* aWebProgressListener
);
153 void SetDocAndURLIntoProgress(nsPrintObject
* aPO
,
154 nsIPrintProgressParams
* aParams
);
155 void ElipseLongString(PRUnichar
*& aStr
, const PRUint32 aLen
, PRBool aDoFront
);
156 nsresult
CheckForPrinters(nsIPrintSettings
* aPrintSettings
);
157 void CleanupDocTitleArray(PRUnichar
**& aArray
, PRInt32
& aCount
);
159 PRBool
IsThereARangeSelection(nsIDOMWindow
* aDOMWin
);
161 //---------------------------------------------------------------------
165 nsresult
StartPagePrintTimer(nsPrintObject
* aPO
);
167 PRBool
IsWindowsInOurSubTree(nsPIDOMWindow
* aDOMWindow
);
168 static PRBool
IsParentAFrameSet(nsIDocShell
* aParent
);
169 PRBool
IsThereAnIFrameSelected(nsIDocShell
* aDocShell
,
170 nsIDOMWindow
* aDOMWin
,
171 PRPackedBool
& aIsParentFrameSet
);
173 static nsPrintObject
* FindPrintObjectByDOMWin(nsPrintObject
* aParentObject
,
174 nsIDOMWindow
* aDOMWin
);
176 // get the currently infocus frame for the document viewer
177 already_AddRefed
<nsIDOMWindow
> FindFocusedDOMWindow();
179 //---------------------------------------------------------------------
181 //---------------------------------------------------------------------
182 static void GetDocumentTitleAndURL(nsIDocument
* aDoc
,
184 PRUnichar
** aURLStr
);
185 void GetDisplayTitleAndURL(nsPrintObject
* aPO
,
188 eDocTitleDefault aDefType
);
189 static void ShowPrintErrorDialog(nsresult printerror
,
190 PRBool aIsPrinting
= PR_TRUE
);
192 static PRBool
HasFramesetChild(nsIContent
* aContent
);
194 PRBool
CheckBeforeDestroy();
195 nsresult
Cancelled();
197 nsIPresShell
* GetPrintPreviewPresShell() {return mPrtPreview
->mPrintObject
->mPresShell
;}
199 float GetPrintPreviewScale() { return mPrtPreview
->mPrintObject
->
200 mPresContext
->GetPrintPreviewScale(); }
202 static nsIPresShell
* GetPresShellFor(nsIDocShell
* aDocShell
);
204 // These calls also update the DocViewer
205 void SetIsPrinting(PRBool aIsPrinting
);
206 PRBool
GetIsPrinting()
208 return mIsDoingPrinting
;
210 void SetIsPrintPreview(PRBool aIsPrintPreview
);
211 PRBool
GetIsPrintPreview()
213 return mIsDoingPrintPreview
;
215 void SetIsCreatingPrintPreview(PRBool aIsCreatingPrintPreview
)
217 mIsCreatingPrintPreview
= aIsCreatingPrintPreview
;
219 PRBool
GetIsCreatingPrintPreview()
221 return mIsCreatingPrintPreview
;
226 nsresult
CommonPrint(PRBool aIsPrintPreview
, nsIPrintSettings
* aPrintSettings
,
227 nsIWebProgressListener
* aWebProgressListener
,
228 nsIDOMDocument
* aDoc
);
230 nsresult
DoCommonPrint(PRBool aIsPrintPreview
, nsIPrintSettings
* aPrintSettings
,
231 nsIWebProgressListener
* aWebProgressListener
,
232 nsIDOMDocument
* aDoc
);
234 void FirePrintCompletionEvent();
235 static nsresult
GetSeqFrameAndCountPagesInternal(nsPrintObject
* aPO
,
236 nsIFrame
*& aSeqFrame
,
239 static nsresult
FindSelectionBoundsWithList(nsPresContext
* aPresContext
,
240 nsIRenderingContext
& aRC
,
242 nsIFrame
* aParentFrame
,
244 nsIFrame
*& aStartFrame
,
246 nsIFrame
*& aEndFrame
,
249 static nsresult
FindSelectionBounds(nsPresContext
* aPresContext
,
250 nsIRenderingContext
& aRC
,
251 nsIFrame
* aParentFrame
,
253 nsIFrame
*& aStartFrame
,
255 nsIFrame
*& aEndFrame
,
258 static nsresult
GetPageRangeForSelection(nsIPresShell
* aPresShell
,
259 nsPresContext
* aPresContext
,
260 nsIRenderingContext
& aRC
,
261 nsISelection
* aSelection
,
262 nsIPageSequenceFrame
* aPageSeqFrame
,
263 nsIFrame
** aStartFrame
,
264 PRInt32
& aStartPageNum
,
266 nsIFrame
** aEndFrame
,
267 PRInt32
& aEndPageNum
,
270 static void MapContentForPO(nsPrintObject
* aPO
, nsIContent
* aContent
);
272 static void MapContentToWebShells(nsPrintObject
* aRootPO
, nsPrintObject
* aPO
);
274 static void SetPrintAsIs(nsPrintObject
* aPO
, PRBool aAsIs
= PR_TRUE
);
276 // Static member variables
277 PRPackedBool mIsCreatingPrintPreview
;
278 PRPackedBool mIsDoingPrinting
;
279 PRPackedBool mIsDoingPrintPreview
; // per DocumentViewer
280 PRPackedBool mProgressDialogIsShown
;
282 nsCOMPtr
<nsIDocumentViewerPrint
> mDocViewerPrint
;
283 nsISupports
* mContainer
; // [WEAK] it owns me!
287 nsPagePrintTimer
* mPagePrintTimer
;
288 nsIPageSequenceFrame
* mPageSeqFrame
;
291 nsPrintData
* mPrtPreview
;
292 nsPrintData
* mOldPrtPreview
;
294 nsCOMPtr
<nsIDocument
> mDocument
;
299 nsPrintEngine
& operator=(const nsPrintEngine
& aOther
); // not implemented
303 #endif /* nsPrintEngine_h___ */