/src/mozilla-central/layout/printing/nsPrintJob.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | #ifndef nsPrintJob_h |
7 | | #define nsPrintJob_h |
8 | | |
9 | | #include "mozilla/Attributes.h" |
10 | | #include "mozilla/UniquePtr.h" |
11 | | |
12 | | #include "nsCOMPtr.h" |
13 | | |
14 | | #include "nsPrintObject.h" |
15 | | #include "nsPrintData.h" |
16 | | #include "nsFrameList.h" |
17 | | #include "nsIFrame.h" |
18 | | #include "nsIWebProgress.h" |
19 | | #include "mozilla/dom/HTMLCanvasElement.h" |
20 | | #include "nsIWebProgressListener.h" |
21 | | #include "nsWeakReference.h" |
22 | | |
23 | | // Interfaces |
24 | | #include "nsIObserver.h" |
25 | | |
26 | | // Classes |
27 | | class nsPagePrintTimer; |
28 | | class nsIDocShell; |
29 | | class nsIDocument; |
30 | | class nsIDocumentViewerPrint; |
31 | | class nsPrintObject; |
32 | | class nsIDocShell; |
33 | | class nsIPageSequenceFrame; |
34 | | |
35 | | /** |
36 | | * A print job may be instantiated either for printing to an actual physical |
37 | | * printer, or for creating a print preview. |
38 | | */ |
39 | | class nsPrintJob final : public nsIObserver |
40 | | , public nsIWebProgressListener |
41 | | , public nsSupportsWeakReference |
42 | | { |
43 | | public: |
44 | | static nsresult GetGlobalPrintSettings(nsIPrintSettings** aPrintSettings); |
45 | | static void CloseProgressDialog(nsIWebProgressListener* aWebProgressListener); |
46 | | |
47 | 0 | nsPrintJob() = default; |
48 | | |
49 | | // nsISupports interface... |
50 | | NS_DECL_ISUPPORTS |
51 | | |
52 | | // nsIObserver |
53 | | NS_DECL_NSIOBSERVER |
54 | | |
55 | | NS_DECL_NSIWEBPROGRESSLISTENER |
56 | | |
57 | | // Old nsIWebBrowserPrint methods; not cleaned up yet |
58 | | NS_IMETHOD Print(nsIPrintSettings* aPrintSettings, |
59 | | nsIWebProgressListener* aWebProgressListener); |
60 | | NS_IMETHOD PrintPreview(nsIPrintSettings* aPrintSettings, |
61 | | mozIDOMWindowProxy* aChildDOMWin, |
62 | | nsIWebProgressListener* aWebProgressListener); |
63 | | NS_IMETHOD GetIsFramesetDocument(bool *aIsFramesetDocument); |
64 | | NS_IMETHOD GetIsIFrameSelected(bool *aIsIFrameSelected); |
65 | | NS_IMETHOD GetIsRangeSelection(bool *aIsRangeSelection); |
66 | | NS_IMETHOD GetIsFramesetFrameSelected(bool *aIsFramesetFrameSelected); |
67 | | NS_IMETHOD GetPrintPreviewNumPages(int32_t *aPrintPreviewNumPages); |
68 | | NS_IMETHOD EnumerateDocumentNames(uint32_t* aCount, char16_t*** aResult); |
69 | | NS_IMETHOD GetDoingPrint(bool *aDoingPrint); |
70 | | NS_IMETHOD GetDoingPrintPreview(bool *aDoingPrintPreview); |
71 | | NS_IMETHOD GetCurrentPrintSettings(nsIPrintSettings **aCurrentPrintSettings); |
72 | | |
73 | | |
74 | | // This enum tells indicates what the default should be for the title |
75 | | // if the title from the document is null |
76 | | enum eDocTitleDefault { |
77 | | eDocTitleDefBlank, |
78 | | eDocTitleDefURLDoc |
79 | | }; |
80 | | |
81 | | void Destroy(); |
82 | | void DestroyPrintingData(); |
83 | | |
84 | | nsresult Initialize(nsIDocumentViewerPrint* aDocViewerPrint, |
85 | | nsIDocShell* aContainer, |
86 | | nsIDocument* aDocument, |
87 | | float aScreenDPI); |
88 | | |
89 | | nsresult GetSeqFrameAndCountPages(nsIFrame*& aSeqFrame, int32_t& aCount); |
90 | | |
91 | | // |
92 | | // The following three methods are used for printing... |
93 | | // |
94 | | nsresult DocumentReadyForPrinting(); |
95 | | nsresult GetSelectionDocument(nsIDeviceContextSpec * aDevSpec, |
96 | | nsIDocument ** aNewDoc); |
97 | | |
98 | | nsresult SetupToPrintContent(); |
99 | | nsresult EnablePOsForPrinting(); |
100 | | nsPrintObject* FindSmallestSTF(); |
101 | | |
102 | | bool PrintDocContent(const mozilla::UniquePtr<nsPrintObject>& aPO, |
103 | | nsresult& aStatus); |
104 | | nsresult DoPrint(const mozilla::UniquePtr<nsPrintObject>& aPO); |
105 | | |
106 | | void SetPrintPO(nsPrintObject* aPO, bool aPrint); |
107 | | |
108 | | void TurnScriptingOn(bool aDoTurnOn); |
109 | | bool CheckDocumentForPPCaching(); |
110 | | void InstallPrintPreviewListener(); |
111 | | |
112 | | // nsIDocumentViewerPrint Printing Methods |
113 | | bool HasPrintCallbackCanvas(); |
114 | | bool PrePrintPage(); |
115 | | bool PrintPage(nsPrintObject* aPOect, bool& aInRange); |
116 | | bool DonePrintingPages(nsPrintObject* aPO, nsresult aResult); |
117 | | |
118 | | //--------------------------------------------------------------------- |
119 | | void BuildDocTree(nsIDocShell * aParentNode, |
120 | | nsTArray<nsPrintObject*> * aDocList, |
121 | | const mozilla::UniquePtr<nsPrintObject>& aPO); |
122 | | nsresult ReflowDocList(const mozilla::UniquePtr<nsPrintObject>& aPO, |
123 | | bool aSetPixelScale); |
124 | | |
125 | | nsresult ReflowPrintObject(const mozilla::UniquePtr<nsPrintObject>& aPO); |
126 | | |
127 | | void CheckForChildFrameSets(const mozilla::UniquePtr<nsPrintObject>& aPO); |
128 | | |
129 | | void CalcNumPrintablePages(int32_t& aNumPages); |
130 | | void ShowPrintProgress(bool aIsForPrinting, bool& aDoNotify); |
131 | | nsresult CleanupOnFailure(nsresult aResult, bool aIsPrinting); |
132 | | // If FinishPrintPreview() fails, caller may need to reset the state of the |
133 | | // object, for example by calling CleanupOnFailure(). |
134 | | nsresult FinishPrintPreview(); |
135 | | void SetDocAndURLIntoProgress(const mozilla::UniquePtr<nsPrintObject>& aPO, |
136 | | nsIPrintProgressParams* aParams); |
137 | | void EllipseLongString(nsAString& aStr, const uint32_t aLen, bool aDoFront); |
138 | | nsresult CheckForPrinters(nsIPrintSettings* aPrintSettings); |
139 | | void CleanupDocTitleArray(char16_t**& aArray, int32_t& aCount); |
140 | | |
141 | | bool IsThereARangeSelection(nsPIDOMWindowOuter* aDOMWin); |
142 | | |
143 | | void FirePrintingErrorEvent(nsresult aPrintError); |
144 | | //--------------------------------------------------------------------- |
145 | | |
146 | | |
147 | | // Timer Methods |
148 | | nsresult StartPagePrintTimer(const mozilla::UniquePtr<nsPrintObject>& aPO); |
149 | | |
150 | | bool IsWindowsInOurSubTree(nsPIDOMWindowOuter* aDOMWindow); |
151 | | bool IsThereAnIFrameSelected(nsIDocShell* aDocShell, |
152 | | nsPIDOMWindowOuter* aDOMWin, |
153 | | bool& aIsParentFrameSet); |
154 | | |
155 | | // get the currently infocus frame for the document viewer |
156 | | already_AddRefed<nsPIDOMWindowOuter> FindFocusedDOMWindow(); |
157 | | |
158 | | void GetDisplayTitleAndURL(const mozilla::UniquePtr<nsPrintObject>& aPO, |
159 | | nsAString& aTitle, |
160 | | nsAString& aURLStr, |
161 | | eDocTitleDefault aDefType); |
162 | | |
163 | | bool CheckBeforeDestroy(); |
164 | | nsresult Cancelled(); |
165 | | |
166 | 0 | nsIPresShell* GetPrintPreviewPresShell() {return mPrtPreview->mPrintObject->mPresShell;} |
167 | | |
168 | 0 | float GetPrintPreviewScale() { return mPrtPreview->mPrintObject-> |
169 | 0 | mPresContext->GetPrintPreviewScale(); } |
170 | | |
171 | | // These calls also update the DocViewer |
172 | | void SetIsPrinting(bool aIsPrinting); |
173 | | bool GetIsPrinting() |
174 | 0 | { |
175 | 0 | return mIsDoingPrinting; |
176 | 0 | } |
177 | | void SetIsPrintPreview(bool aIsPrintPreview); |
178 | | bool GetIsPrintPreview() |
179 | 0 | { |
180 | 0 | return mIsDoingPrintPreview; |
181 | 0 | } |
182 | | bool GetIsCreatingPrintPreview() |
183 | 0 | { |
184 | 0 | return mIsCreatingPrintPreview; |
185 | 0 | } |
186 | | |
187 | | void SetDisallowSelectionPrint(bool aDisallowSelectionPrint) |
188 | 0 | { |
189 | 0 | mDisallowSelectionPrint = aDisallowSelectionPrint; |
190 | 0 | } |
191 | | |
192 | | private: |
193 | | nsPrintJob& operator=(const nsPrintJob& aOther) = delete; |
194 | | |
195 | | ~nsPrintJob(); |
196 | | |
197 | | nsresult CommonPrint(bool aIsPrintPreview, nsIPrintSettings* aPrintSettings, |
198 | | nsIWebProgressListener* aWebProgressListener, |
199 | | nsIDocument* aDoc); |
200 | | |
201 | | nsresult DoCommonPrint(bool aIsPrintPreview, nsIPrintSettings* aPrintSettings, |
202 | | nsIWebProgressListener* aWebProgressListener, |
203 | | nsIDocument* aDoc); |
204 | | |
205 | | void FirePrintCompletionEvent(); |
206 | | |
207 | | void DisconnectPagePrintTimer(); |
208 | | |
209 | | nsresult AfterNetworkPrint(bool aHandleError); |
210 | | |
211 | | nsresult SetRootView(nsPrintObject* aPO, |
212 | | bool& aDoReturn, |
213 | | bool& aDocumentIsTopLevel, |
214 | | nsSize& aAdjSize); |
215 | | nsView* GetParentViewForRoot(); |
216 | | bool DoSetPixelScale(); |
217 | | void UpdateZoomRatio(nsPrintObject* aPO, bool aSetPixelScale); |
218 | | nsresult ReconstructAndReflow(bool aDoSetPixelScale); |
219 | | nsresult UpdateSelectionAndShrinkPrintObject(nsPrintObject* aPO, |
220 | | bool aDocumentIsTopLevel); |
221 | | nsresult InitPrintDocConstruction(bool aHandleError); |
222 | | void FirePrintPreviewUpdateEvent(); |
223 | | |
224 | | void PageDone(nsresult aResult); |
225 | | |
226 | | |
227 | | nsCOMPtr<nsIDocument> mDocument; |
228 | | nsCOMPtr<nsIDocumentViewerPrint> mDocViewerPrint; |
229 | | |
230 | | nsWeakPtr mContainer; |
231 | | WeakFrame mPageSeqFrame; |
232 | | |
233 | | // We are the primary owner of our nsPrintData member vars. These vars |
234 | | // are refcounted so that functions (e.g. nsPrintData methods) can create |
235 | | // temporary owning references when they need to fire a callback that |
236 | | // could conceivably destroy this nsPrintJob owner object and all its |
237 | | // member-data. |
238 | | RefPtr<nsPrintData> mPrt; |
239 | | |
240 | | // Print Preview |
241 | | RefPtr<nsPrintData> mPrtPreview; |
242 | | RefPtr<nsPrintData> mOldPrtPreview; |
243 | | |
244 | | nsPagePrintTimer* mPagePrintTimer = nullptr; |
245 | | |
246 | | float mScreenDPI = 115.0f; |
247 | | int32_t mLoadCounter = 0; |
248 | | |
249 | | bool mIsCreatingPrintPreview = false; |
250 | | bool mIsDoingPrinting = false; |
251 | | bool mIsDoingPrintPreview = false; |
252 | | bool mProgressDialogIsShown = false; |
253 | | bool mDidLoadDataForPrinting = false; |
254 | | bool mIsDestroying = false; |
255 | | bool mDisallowSelectionPrint = false; |
256 | | }; |
257 | | |
258 | | #endif // nsPrintJob_h |
259 | | |