layout/printing/nsPrintEngine.h

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5 #ifndef nsPrintEngine_h___
michael@0 6 #define nsPrintEngine_h___
michael@0 7
michael@0 8 #include "mozilla/Attributes.h"
michael@0 9
michael@0 10 #include "nsCOMPtr.h"
michael@0 11
michael@0 12 #include "nsPrintObject.h"
michael@0 13 #include "nsPrintData.h"
michael@0 14 #include "nsFrameList.h"
michael@0 15 #include "mozilla/Attributes.h"
michael@0 16 #include "nsIWebProgress.h"
michael@0 17 #include "mozilla/dom/HTMLCanvasElement.h"
michael@0 18 #include "nsIWebProgressListener.h"
michael@0 19 #include "nsWeakReference.h"
michael@0 20
michael@0 21 // Interfaces
michael@0 22 #include "nsIDOMWindow.h"
michael@0 23 #include "nsIObserver.h"
michael@0 24
michael@0 25 // Classes
michael@0 26 class nsPagePrintTimer;
michael@0 27 class nsIDocShell;
michael@0 28 class nsDeviceContext;
michael@0 29 class nsIDocument;
michael@0 30 class nsIDocumentViewerPrint;
michael@0 31 class nsPrintObject;
michael@0 32 class nsIDocShell;
michael@0 33 class nsIPageSequenceFrame;
michael@0 34 class nsIWeakReference;
michael@0 35
michael@0 36 //------------------------------------------------------------------------
michael@0 37 // nsPrintEngine Class
michael@0 38 //
michael@0 39 //------------------------------------------------------------------------
michael@0 40 class nsPrintEngine MOZ_FINAL : public nsIObserver,
michael@0 41 public nsIWebProgressListener,
michael@0 42 public nsSupportsWeakReference
michael@0 43 {
michael@0 44 public:
michael@0 45 // nsISupports interface...
michael@0 46 NS_DECL_ISUPPORTS
michael@0 47
michael@0 48 // nsIObserver
michael@0 49 NS_DECL_NSIOBSERVER
michael@0 50
michael@0 51 NS_DECL_NSIWEBPROGRESSLISTENER
michael@0 52
michael@0 53 // Old nsIWebBrowserPrint methods; not cleaned up yet
michael@0 54 NS_IMETHOD Print(nsIPrintSettings* aPrintSettings,
michael@0 55 nsIWebProgressListener* aWebProgressListener);
michael@0 56 NS_IMETHOD PrintPreview(nsIPrintSettings* aPrintSettings,
michael@0 57 nsIDOMWindow *aChildDOMWin,
michael@0 58 nsIWebProgressListener* aWebProgressListener);
michael@0 59 NS_IMETHOD GetIsFramesetDocument(bool *aIsFramesetDocument);
michael@0 60 NS_IMETHOD GetIsIFrameSelected(bool *aIsIFrameSelected);
michael@0 61 NS_IMETHOD GetIsRangeSelection(bool *aIsRangeSelection);
michael@0 62 NS_IMETHOD GetIsFramesetFrameSelected(bool *aIsFramesetFrameSelected);
michael@0 63 NS_IMETHOD GetPrintPreviewNumPages(int32_t *aPrintPreviewNumPages);
michael@0 64 NS_IMETHOD EnumerateDocumentNames(uint32_t* aCount, char16_t*** aResult);
michael@0 65 static nsresult GetGlobalPrintSettings(nsIPrintSettings** aPrintSettings);
michael@0 66 NS_IMETHOD GetDoingPrint(bool *aDoingPrint);
michael@0 67 NS_IMETHOD GetDoingPrintPreview(bool *aDoingPrintPreview);
michael@0 68 NS_IMETHOD GetCurrentPrintSettings(nsIPrintSettings **aCurrentPrintSettings);
michael@0 69
michael@0 70
michael@0 71 // This enum tells indicates what the default should be for the title
michael@0 72 // if the title from the document is null
michael@0 73 enum eDocTitleDefault {
michael@0 74 eDocTitleDefBlank,
michael@0 75 eDocTitleDefURLDoc
michael@0 76 };
michael@0 77
michael@0 78 nsPrintEngine();
michael@0 79 ~nsPrintEngine();
michael@0 80
michael@0 81 void Destroy();
michael@0 82 void DestroyPrintingData();
michael@0 83
michael@0 84 nsresult Initialize(nsIDocumentViewerPrint* aDocViewerPrint,
michael@0 85 nsIDocShell* aContainer,
michael@0 86 nsIDocument* aDocument,
michael@0 87 float aScreenDPI,
michael@0 88 FILE* aDebugFile);
michael@0 89
michael@0 90 nsresult GetSeqFrameAndCountPages(nsIFrame*& aSeqFrame, int32_t& aCount);
michael@0 91
michael@0 92 //
michael@0 93 // The following three methods are used for printing...
michael@0 94 //
michael@0 95 nsresult DocumentReadyForPrinting();
michael@0 96 nsresult GetSelectionDocument(nsIDeviceContextSpec * aDevSpec,
michael@0 97 nsIDocument ** aNewDoc);
michael@0 98
michael@0 99 nsresult SetupToPrintContent();
michael@0 100 nsresult EnablePOsForPrinting();
michael@0 101 nsPrintObject* FindSmallestSTF();
michael@0 102
michael@0 103 bool PrintDocContent(nsPrintObject* aPO, nsresult& aStatus);
michael@0 104 nsresult DoPrint(nsPrintObject * aPO);
michael@0 105
michael@0 106 void SetPrintPO(nsPrintObject* aPO, bool aPrint);
michael@0 107
michael@0 108 void TurnScriptingOn(bool aDoTurnOn);
michael@0 109 bool CheckDocumentForPPCaching();
michael@0 110 void InstallPrintPreviewListener();
michael@0 111
michael@0 112 // nsIDocumentViewerPrint Printing Methods
michael@0 113 bool HasPrintCallbackCanvas();
michael@0 114 bool PrePrintPage();
michael@0 115 bool PrintPage(nsPrintObject* aPOect, bool& aInRange);
michael@0 116 bool DonePrintingPages(nsPrintObject* aPO, nsresult aResult);
michael@0 117
michael@0 118 //---------------------------------------------------------------------
michael@0 119 void BuildDocTree(nsIDocShell * aParentNode,
michael@0 120 nsTArray<nsPrintObject*> * aDocList,
michael@0 121 nsPrintObject * aPO);
michael@0 122 nsresult ReflowDocList(nsPrintObject * aPO, bool aSetPixelScale);
michael@0 123
michael@0 124 nsresult ReflowPrintObject(nsPrintObject * aPO);
michael@0 125
michael@0 126 void CheckForChildFrameSets(nsPrintObject* aPO);
michael@0 127
michael@0 128 void CalcNumPrintablePages(int32_t& aNumPages);
michael@0 129 void ShowPrintProgress(bool aIsForPrinting, bool& aDoNotify);
michael@0 130 nsresult CleanupOnFailure(nsresult aResult, bool aIsPrinting);
michael@0 131 // If FinishPrintPreview() fails, caller may need to reset the state of the
michael@0 132 // object, for example by calling CleanupOnFailure().
michael@0 133 nsresult FinishPrintPreview();
michael@0 134 static void CloseProgressDialog(nsIWebProgressListener* aWebProgressListener);
michael@0 135 void SetDocAndURLIntoProgress(nsPrintObject* aPO,
michael@0 136 nsIPrintProgressParams* aParams);
michael@0 137 void EllipseLongString(nsAString& aStr, const uint32_t aLen, bool aDoFront);
michael@0 138 nsresult CheckForPrinters(nsIPrintSettings* aPrintSettings);
michael@0 139 void CleanupDocTitleArray(char16_t**& aArray, int32_t& aCount);
michael@0 140
michael@0 141 bool IsThereARangeSelection(nsIDOMWindow * aDOMWin);
michael@0 142
michael@0 143 //---------------------------------------------------------------------
michael@0 144
michael@0 145
michael@0 146 // Timer Methods
michael@0 147 nsresult StartPagePrintTimer(nsPrintObject* aPO);
michael@0 148
michael@0 149 bool IsWindowsInOurSubTree(nsPIDOMWindow * aDOMWindow);
michael@0 150 static bool IsParentAFrameSet(nsIDocShell * aParent);
michael@0 151 bool IsThereAnIFrameSelected(nsIDocShell* aDocShell,
michael@0 152 nsIDOMWindow* aDOMWin,
michael@0 153 bool& aIsParentFrameSet);
michael@0 154
michael@0 155 static nsPrintObject* FindPrintObjectByDOMWin(nsPrintObject* aParentObject,
michael@0 156 nsIDOMWindow* aDOMWin);
michael@0 157
michael@0 158 // get the currently infocus frame for the document viewer
michael@0 159 already_AddRefed<nsIDOMWindow> FindFocusedDOMWindow();
michael@0 160
michael@0 161 //---------------------------------------------------------------------
michael@0 162 // Static Methods
michael@0 163 //---------------------------------------------------------------------
michael@0 164 static void GetDocumentTitleAndURL(nsIDocument* aDoc,
michael@0 165 nsAString& aTitle,
michael@0 166 nsAString& aURLStr);
michael@0 167 void GetDisplayTitleAndURL(nsPrintObject* aPO,
michael@0 168 nsAString& aTitle,
michael@0 169 nsAString& aURLStr,
michael@0 170 eDocTitleDefault aDefType);
michael@0 171 static void ShowPrintErrorDialog(nsresult printerror,
michael@0 172 bool aIsPrinting = true);
michael@0 173
michael@0 174 static bool HasFramesetChild(nsIContent* aContent);
michael@0 175
michael@0 176 bool CheckBeforeDestroy();
michael@0 177 nsresult Cancelled();
michael@0 178
michael@0 179 nsIPresShell* GetPrintPreviewPresShell() {return mPrtPreview->mPrintObject->mPresShell;}
michael@0 180
michael@0 181 float GetPrintPreviewScale() { return mPrtPreview->mPrintObject->
michael@0 182 mPresContext->GetPrintPreviewScale(); }
michael@0 183
michael@0 184 static nsIPresShell* GetPresShellFor(nsIDocShell* aDocShell);
michael@0 185
michael@0 186 // These calls also update the DocViewer
michael@0 187 void SetIsPrinting(bool aIsPrinting);
michael@0 188 bool GetIsPrinting()
michael@0 189 {
michael@0 190 return mIsDoingPrinting;
michael@0 191 }
michael@0 192 void SetIsPrintPreview(bool aIsPrintPreview);
michael@0 193 bool GetIsPrintPreview()
michael@0 194 {
michael@0 195 return mIsDoingPrintPreview;
michael@0 196 }
michael@0 197 void SetIsCreatingPrintPreview(bool aIsCreatingPrintPreview)
michael@0 198 {
michael@0 199 mIsCreatingPrintPreview = aIsCreatingPrintPreview;
michael@0 200 }
michael@0 201 bool GetIsCreatingPrintPreview()
michael@0 202 {
michael@0 203 return mIsCreatingPrintPreview;
michael@0 204 }
michael@0 205
michael@0 206 void SetDisallowSelectionPrint(bool aDisallowSelectionPrint)
michael@0 207 {
michael@0 208 mDisallowSelectionPrint = aDisallowSelectionPrint;
michael@0 209 }
michael@0 210
michael@0 211 void SetNoMarginBoxes(bool aNoMarginBoxes) {
michael@0 212 mNoMarginBoxes = aNoMarginBoxes;
michael@0 213 }
michael@0 214
michael@0 215 protected:
michael@0 216
michael@0 217 nsresult CommonPrint(bool aIsPrintPreview, nsIPrintSettings* aPrintSettings,
michael@0 218 nsIWebProgressListener* aWebProgressListener,
michael@0 219 nsIDOMDocument* aDoc);
michael@0 220
michael@0 221 nsresult DoCommonPrint(bool aIsPrintPreview, nsIPrintSettings* aPrintSettings,
michael@0 222 nsIWebProgressListener* aWebProgressListener,
michael@0 223 nsIDOMDocument* aDoc);
michael@0 224
michael@0 225 void FirePrintCompletionEvent();
michael@0 226 static nsresult GetSeqFrameAndCountPagesInternal(nsPrintObject* aPO,
michael@0 227 nsIFrame*& aSeqFrame,
michael@0 228 int32_t& aCount);
michael@0 229
michael@0 230 static nsresult FindSelectionBoundsWithList(nsPresContext* aPresContext,
michael@0 231 nsRenderingContext& aRC,
michael@0 232 nsFrameList::Enumerator& aChildFrames,
michael@0 233 nsIFrame * aParentFrame,
michael@0 234 nsRect& aRect,
michael@0 235 nsIFrame *& aStartFrame,
michael@0 236 nsRect& aStartRect,
michael@0 237 nsIFrame *& aEndFrame,
michael@0 238 nsRect& aEndRect);
michael@0 239
michael@0 240 static nsresult FindSelectionBounds(nsPresContext* aPresContext,
michael@0 241 nsRenderingContext& aRC,
michael@0 242 nsIFrame * aParentFrame,
michael@0 243 nsRect& aRect,
michael@0 244 nsIFrame *& aStartFrame,
michael@0 245 nsRect& aStartRect,
michael@0 246 nsIFrame *& aEndFrame,
michael@0 247 nsRect& aEndRect);
michael@0 248
michael@0 249 static nsresult GetPageRangeForSelection(nsIPresShell * aPresShell,
michael@0 250 nsPresContext* aPresContext,
michael@0 251 nsRenderingContext& aRC,
michael@0 252 nsISelection* aSelection,
michael@0 253 nsIPageSequenceFrame* aPageSeqFrame,
michael@0 254 nsIFrame** aStartFrame,
michael@0 255 int32_t& aStartPageNum,
michael@0 256 nsRect& aStartRect,
michael@0 257 nsIFrame** aEndFrame,
michael@0 258 int32_t& aEndPageNum,
michael@0 259 nsRect& aEndRect);
michael@0 260
michael@0 261 static void MapContentForPO(nsPrintObject* aPO, nsIContent* aContent);
michael@0 262
michael@0 263 static void MapContentToWebShells(nsPrintObject* aRootPO, nsPrintObject* aPO);
michael@0 264
michael@0 265 static void SetPrintAsIs(nsPrintObject* aPO, bool aAsIs = true);
michael@0 266
michael@0 267 // Static member variables
michael@0 268 bool mIsCreatingPrintPreview;
michael@0 269 bool mIsDoingPrinting;
michael@0 270 bool mIsDoingPrintPreview; // per DocumentViewer
michael@0 271 bool mProgressDialogIsShown;
michael@0 272
michael@0 273 nsCOMPtr<nsIDocumentViewerPrint> mDocViewerPrint;
michael@0 274 nsWeakPtr mContainer;
michael@0 275 float mScreenDPI;
michael@0 276
michael@0 277 nsPrintData* mPrt;
michael@0 278 nsPagePrintTimer* mPagePrintTimer;
michael@0 279 nsIPageSequenceFrame* mPageSeqFrame;
michael@0 280
michael@0 281 // Print Preview
michael@0 282 nsPrintData* mPrtPreview;
michael@0 283 nsPrintData* mOldPrtPreview;
michael@0 284
michael@0 285 nsCOMPtr<nsIDocument> mDocument;
michael@0 286
michael@0 287 FILE* mDebugFile;
michael@0 288
michael@0 289 int32_t mLoadCounter;
michael@0 290 bool mDidLoadDataForPrinting;
michael@0 291 bool mIsDestroying;
michael@0 292 bool mDisallowSelectionPrint;
michael@0 293 bool mNoMarginBoxes;
michael@0 294
michael@0 295 nsresult AfterNetworkPrint(bool aHandleError);
michael@0 296
michael@0 297 nsresult SetRootView(nsPrintObject* aPO,
michael@0 298 bool& aDoReturn,
michael@0 299 bool& aDocumentIsTopLevel,
michael@0 300 nsSize& aAdjSize);
michael@0 301 nsView* GetParentViewForRoot();
michael@0 302 bool DoSetPixelScale();
michael@0 303 void UpdateZoomRatio(nsPrintObject* aPO, bool aSetPixelScale);
michael@0 304 nsresult ReconstructAndReflow(bool aDoSetPixelScale);
michael@0 305 nsresult UpdateSelectionAndShrinkPrintObject(nsPrintObject* aPO,
michael@0 306 bool aDocumentIsTopLevel);
michael@0 307 nsresult InitPrintDocConstruction(bool aHandleError);
michael@0 308 void FirePrintPreviewUpdateEvent();
michael@0 309 private:
michael@0 310 nsPrintEngine& operator=(const nsPrintEngine& aOther) MOZ_DELETE;
michael@0 311 };
michael@0 312
michael@0 313 #endif /* nsPrintEngine_h___ */

mercurial