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.

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

mercurial