Bug 458160 - Enable downloadable .otf fonts under Windows. r=roc, sr=vlad.
[wine-gecko.git] / layout / printing / nsPrintEngine.h
blob3fc5f39e77b60a91f695e04e9037be1312be1755
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
13 * License.
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.
22 * Contributor(s):
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___
40 #include "nsCOMPtr.h"
42 #include "nsPrintObject.h"
43 #include "nsPrintData.h"
45 // Interfaces
46 #include "nsIDocument.h"
47 #include "nsIDOMWindow.h"
48 #include "nsIObserver.h"
50 // Classes
51 class nsPagePrintTimer;
52 class nsIDocShellTreeNode;
53 class nsIDeviceContext;
54 class nsIDocumentViewerPrint;
55 class nsPrintObject;
56 class nsIDocShell;
57 class nsIPageSequenceFrame;
59 //------------------------------------------------------------------------
60 // nsPrintEngine Class
62 //------------------------------------------------------------------------
63 class nsPrintEngine : public nsIObserver
65 public:
66 // nsISupports interface...
67 NS_DECL_ISUPPORTS
69 // nsIObserver
70 NS_DECL_NSIOBSERVER
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 {
93 eDocTitleDefNone,
94 eDocTitleDefBlank,
95 eDocTitleDefURLDoc
98 nsPrintEngine();
99 ~nsPrintEngine();
101 void Destroy();
102 void DestroyPrintingData();
104 nsresult Initialize(nsIDocumentViewerPrint* aDocViewerPrint,
105 nsISupports* aContainer,
106 nsIDocument* aDocument,
107 nsIDeviceContext* aDevContext,
108 nsIWidget* aParentWidget,
109 FILE* aDebugFile);
111 nsresult GetSeqFrameAndCountPages(nsIFrame*& aSeqFrame, PRInt32& aCount);
114 // The following three methods are used for printing...
116 nsresult DocumentReadyForPrinting();
117 nsresult GetSelectionDocument(nsIDeviceContextSpec * aDevSpec,
118 nsIDocument ** aNewDoc);
120 nsresult SetupToPrintContent();
121 nsresult EnablePOsForPrinting();
122 nsPrintObject* FindSmallestSTF();
124 PRBool PrintDocContent(nsPrintObject* aPO, nsresult& aStatus);
125 nsresult DoPrint(nsPrintObject * aPO);
127 void SetPrintPO(nsPrintObject* aPO, PRBool aPrint);
129 void TurnScriptingOn(PRBool aDoTurnOn);
130 PRBool CheckDocumentForPPCaching();
131 void InstallPrintPreviewListener();
133 // nsIDocumentViewerPrint Printing Methods
134 PRBool PrintPage(nsPrintObject* aPOect, PRBool& aInRange);
135 PRBool DonePrintingPages(nsPrintObject* aPO, nsresult aResult);
137 //---------------------------------------------------------------------
138 void BuildDocTree(nsIDocShellTreeNode * aParentNode,
139 nsVoidArray * aDocList,
140 nsPrintObject * aPO);
141 nsresult ReflowDocList(nsPrintObject * aPO, PRBool aSetPixelScale);
143 nsresult ReflowPrintObject(nsPrintObject * aPO);
145 void CheckForChildFrameSets(nsPrintObject* aPO);
147 void CalcNumPrintablePages(PRInt32& aNumPages);
148 void ShowPrintProgress(PRBool aIsForPrinting, PRBool& aDoNotify);
149 nsresult CleanupOnFailure(nsresult aResult, PRBool aIsPrinting);
150 // If FinishPrintPreview() fails, caller may need to reset the state of the
151 // object, for example by calling CleanupOnFailure().
152 nsresult FinishPrintPreview();
153 static void CloseProgressDialog(nsIWebProgressListener* aWebProgressListener);
154 void SetDocAndURLIntoProgress(nsPrintObject* aPO,
155 nsIPrintProgressParams* aParams);
156 void ElipseLongString(PRUnichar *& aStr, const PRUint32 aLen, PRBool aDoFront);
157 nsresult CheckForPrinters(nsIPrintSettings* aPrintSettings);
158 void CleanupDocTitleArray(PRUnichar**& aArray, PRInt32& aCount);
160 PRBool IsThereARangeSelection(nsIDOMWindow * aDOMWin);
162 //---------------------------------------------------------------------
165 // Timer Methods
166 nsresult StartPagePrintTimer(nsPrintObject* aPO);
168 PRBool IsWindowsInOurSubTree(nsIDOMWindow * aDOMWindow);
169 static PRBool IsParentAFrameSet(nsIDocShell * aParent);
170 PRBool IsThereAnIFrameSelected(nsIDocShell* aDocShell,
171 nsIDOMWindow* aDOMWin,
172 PRPackedBool& aIsParentFrameSet);
174 static nsPrintObject* FindPrintObjectByDOMWin(nsPrintObject* aParentObject,
175 nsIDOMWindow* aDOMWin);
177 // get the currently infocus frame for the document viewer
178 already_AddRefed<nsIDOMWindow> FindFocusedDOMWindow();
180 //---------------------------------------------------------------------
181 // Static Methods
182 //---------------------------------------------------------------------
183 static void GetDocumentTitleAndURL(nsIDocument* aDoc,
184 PRUnichar** aTitle,
185 PRUnichar** aURLStr);
186 void GetDisplayTitleAndURL(nsPrintObject* aPO,
187 PRUnichar** aTitle,
188 PRUnichar** aURLStr,
189 eDocTitleDefault aDefType);
190 static void ShowPrintErrorDialog(nsresult printerror,
191 PRBool aIsPrinting = PR_TRUE);
193 static PRBool HasFramesetChild(nsIContent* aContent);
195 PRBool CheckBeforeDestroy();
196 nsresult Cancelled();
198 nsIWidget* GetPrintPreviewWindow() {return mPrtPreview->mPrintObject->mWindow;}
200 nsIViewManager* GetPrintPreviewViewManager() {return mPrtPreview->mPrintObject->mViewManager;}
202 float GetPrintPreviewScale() { return mPrtPreview->mPrintObject->
203 mPresContext->GetPrintPreviewScale(); }
205 static nsIPresShell* GetPresShellFor(nsIDocShell* aDocShell);
207 // These calls also update the DocViewer
208 void SetIsPrinting(PRBool aIsPrinting);
209 PRBool GetIsPrinting()
211 return mIsDoingPrinting;
213 void SetIsPrintPreview(PRBool aIsPrintPreview);
214 PRBool GetIsPrintPreview()
216 return mIsDoingPrintPreview;
218 void SetIsCreatingPrintPreview(PRBool aIsCreatingPrintPreview)
220 mIsCreatingPrintPreview = aIsCreatingPrintPreview;
222 PRBool GetIsCreatingPrintPreview()
224 return mIsCreatingPrintPreview;
227 protected:
229 nsresult CommonPrint(PRBool aIsPrintPreview, nsIPrintSettings* aPrintSettings,
230 nsIWebProgressListener* aWebProgressListener);
232 nsresult DoCommonPrint(PRBool aIsPrintPreview, nsIPrintSettings* aPrintSettings,
233 nsIWebProgressListener* aWebProgressListener);
235 void FirePrintCompletionEvent();
236 static nsresult GetSeqFrameAndCountPagesInternal(nsPrintObject* aPO,
237 nsIFrame*& aSeqFrame,
238 PRInt32& aCount);
240 static nsresult FindSelectionBoundsWithList(nsPresContext* aPresContext,
241 nsIRenderingContext& aRC,
242 nsIAtom* aList,
243 nsIFrame * aParentFrame,
244 nsRect& aRect,
245 nsIFrame *& aStartFrame,
246 nsRect& aStartRect,
247 nsIFrame *& aEndFrame,
248 nsRect& aEndRect);
250 static nsresult FindSelectionBounds(nsPresContext* aPresContext,
251 nsIRenderingContext& aRC,
252 nsIFrame * aParentFrame,
253 nsRect& aRect,
254 nsIFrame *& aStartFrame,
255 nsRect& aStartRect,
256 nsIFrame *& aEndFrame,
257 nsRect& aEndRect);
259 static nsresult GetPageRangeForSelection(nsIPresShell * aPresShell,
260 nsPresContext* aPresContext,
261 nsIRenderingContext& aRC,
262 nsISelection* aSelection,
263 nsIPageSequenceFrame* aPageSeqFrame,
264 nsIFrame** aStartFrame,
265 PRInt32& aStartPageNum,
266 nsRect& aStartRect,
267 nsIFrame** aEndFrame,
268 PRInt32& aEndPageNum,
269 nsRect& aEndRect);
271 static void MapContentForPO(nsPrintObject* aPO, nsIContent* aContent);
273 static void MapContentToWebShells(nsPrintObject* aRootPO, nsPrintObject* aPO);
275 static void SetPrintAsIs(nsPrintObject* aPO, PRBool aAsIs = PR_TRUE);
277 // Static member variables
278 PRPackedBool mIsCreatingPrintPreview;
279 PRPackedBool mIsDoingPrinting;
280 PRPackedBool mIsDoingPrintPreview; // per DocumentViewer
281 PRPackedBool mProgressDialogIsShown;
283 nsCOMPtr<nsIDocumentViewerPrint> mDocViewerPrint;
284 nsISupports* mContainer; // [WEAK] it owns me!
285 nsIDeviceContext* mDeviceContext; // not ref counted
287 nsPrintData* mPrt;
288 nsPagePrintTimer* mPagePrintTimer;
289 nsIPageSequenceFrame* mPageSeqFrame;
291 // Print Preview
292 nsCOMPtr<nsIWidget> mParentWidget;
293 nsPrintData* mPrtPreview;
294 nsPrintData* mOldPrtPreview;
296 nsCOMPtr<nsIDocument> mDocument;
298 FILE* mDebugFile;
300 private:
301 nsPrintEngine& operator=(const nsPrintEngine& aOther); // not implemented
305 #endif /* nsPrintEngine_h___ */