layout/printing/nsPrintEngine.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/printing/nsPrintEngine.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,313 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +#ifndef nsPrintEngine_h___
     1.9 +#define nsPrintEngine_h___
    1.10 +
    1.11 +#include "mozilla/Attributes.h"
    1.12 +
    1.13 +#include "nsCOMPtr.h"
    1.14 +
    1.15 +#include "nsPrintObject.h"
    1.16 +#include "nsPrintData.h"
    1.17 +#include "nsFrameList.h"
    1.18 +#include "mozilla/Attributes.h"
    1.19 +#include "nsIWebProgress.h"
    1.20 +#include "mozilla/dom/HTMLCanvasElement.h"
    1.21 +#include "nsIWebProgressListener.h"
    1.22 +#include "nsWeakReference.h"
    1.23 +
    1.24 +// Interfaces
    1.25 +#include "nsIDOMWindow.h"
    1.26 +#include "nsIObserver.h"
    1.27 +
    1.28 +// Classes
    1.29 +class nsPagePrintTimer;
    1.30 +class nsIDocShell;
    1.31 +class nsDeviceContext;
    1.32 +class nsIDocument;
    1.33 +class nsIDocumentViewerPrint;
    1.34 +class nsPrintObject;
    1.35 +class nsIDocShell;
    1.36 +class nsIPageSequenceFrame;
    1.37 +class nsIWeakReference;
    1.38 +
    1.39 +//------------------------------------------------------------------------
    1.40 +// nsPrintEngine Class
    1.41 +//
    1.42 +//------------------------------------------------------------------------
    1.43 +class nsPrintEngine MOZ_FINAL : public nsIObserver,
    1.44 +                                public nsIWebProgressListener,
    1.45 +                                public nsSupportsWeakReference
    1.46 +{
    1.47 +public:
    1.48 +  // nsISupports interface...
    1.49 +  NS_DECL_ISUPPORTS
    1.50 +
    1.51 +  // nsIObserver
    1.52 +  NS_DECL_NSIOBSERVER
    1.53 +
    1.54 +  NS_DECL_NSIWEBPROGRESSLISTENER
    1.55 +
    1.56 +  // Old nsIWebBrowserPrint methods; not cleaned up yet
    1.57 +  NS_IMETHOD Print(nsIPrintSettings*       aPrintSettings,
    1.58 +                   nsIWebProgressListener* aWebProgressListener);
    1.59 +  NS_IMETHOD PrintPreview(nsIPrintSettings* aPrintSettings,
    1.60 +                          nsIDOMWindow *aChildDOMWin,
    1.61 +                          nsIWebProgressListener* aWebProgressListener);
    1.62 +  NS_IMETHOD GetIsFramesetDocument(bool *aIsFramesetDocument);
    1.63 +  NS_IMETHOD GetIsIFrameSelected(bool *aIsIFrameSelected);
    1.64 +  NS_IMETHOD GetIsRangeSelection(bool *aIsRangeSelection);
    1.65 +  NS_IMETHOD GetIsFramesetFrameSelected(bool *aIsFramesetFrameSelected);
    1.66 +  NS_IMETHOD GetPrintPreviewNumPages(int32_t *aPrintPreviewNumPages);
    1.67 +  NS_IMETHOD EnumerateDocumentNames(uint32_t* aCount, char16_t*** aResult);
    1.68 +  static nsresult GetGlobalPrintSettings(nsIPrintSettings** aPrintSettings);
    1.69 +  NS_IMETHOD GetDoingPrint(bool *aDoingPrint);
    1.70 +  NS_IMETHOD GetDoingPrintPreview(bool *aDoingPrintPreview);
    1.71 +  NS_IMETHOD GetCurrentPrintSettings(nsIPrintSettings **aCurrentPrintSettings);
    1.72 +
    1.73 +
    1.74 +  // This enum tells indicates what the default should be for the title
    1.75 +  // if the title from the document is null
    1.76 +  enum eDocTitleDefault {
    1.77 +    eDocTitleDefBlank,
    1.78 +    eDocTitleDefURLDoc
    1.79 +  };
    1.80 +
    1.81 +  nsPrintEngine();
    1.82 +  ~nsPrintEngine();
    1.83 +
    1.84 +  void Destroy();
    1.85 +  void DestroyPrintingData();
    1.86 +
    1.87 +  nsresult Initialize(nsIDocumentViewerPrint* aDocViewerPrint, 
    1.88 +                      nsIDocShell*            aContainer,
    1.89 +                      nsIDocument*            aDocument,
    1.90 +                      float                   aScreenDPI,
    1.91 +                      FILE*                   aDebugFile);
    1.92 +
    1.93 +  nsresult GetSeqFrameAndCountPages(nsIFrame*& aSeqFrame, int32_t& aCount);
    1.94 +
    1.95 +  //
    1.96 +  // The following three methods are used for printing...
    1.97 +  //
    1.98 +  nsresult DocumentReadyForPrinting();
    1.99 +  nsresult GetSelectionDocument(nsIDeviceContextSpec * aDevSpec,
   1.100 +                                nsIDocument ** aNewDoc);
   1.101 +
   1.102 +  nsresult SetupToPrintContent();
   1.103 +  nsresult EnablePOsForPrinting();
   1.104 +  nsPrintObject* FindSmallestSTF();
   1.105 +
   1.106 +  bool     PrintDocContent(nsPrintObject* aPO, nsresult& aStatus);
   1.107 +  nsresult DoPrint(nsPrintObject * aPO);
   1.108 +
   1.109 +  void SetPrintPO(nsPrintObject* aPO, bool aPrint);
   1.110 +
   1.111 +  void TurnScriptingOn(bool aDoTurnOn);
   1.112 +  bool CheckDocumentForPPCaching();
   1.113 +  void InstallPrintPreviewListener();
   1.114 +
   1.115 +  // nsIDocumentViewerPrint Printing Methods
   1.116 +  bool     HasPrintCallbackCanvas();
   1.117 +  bool     PrePrintPage();
   1.118 +  bool     PrintPage(nsPrintObject* aPOect, bool& aInRange);
   1.119 +  bool     DonePrintingPages(nsPrintObject* aPO, nsresult aResult);
   1.120 +
   1.121 +  //---------------------------------------------------------------------
   1.122 +  void BuildDocTree(nsIDocShell *      aParentNode,
   1.123 +                    nsTArray<nsPrintObject*> * aDocList,
   1.124 +                    nsPrintObject *            aPO);
   1.125 +  nsresult ReflowDocList(nsPrintObject * aPO, bool aSetPixelScale);
   1.126 +
   1.127 +  nsresult ReflowPrintObject(nsPrintObject * aPO);
   1.128 +
   1.129 +  void CheckForChildFrameSets(nsPrintObject* aPO);
   1.130 +
   1.131 +  void CalcNumPrintablePages(int32_t& aNumPages);
   1.132 +  void ShowPrintProgress(bool aIsForPrinting, bool& aDoNotify);
   1.133 +  nsresult CleanupOnFailure(nsresult aResult, bool aIsPrinting);
   1.134 +  // If FinishPrintPreview() fails, caller may need to reset the state of the
   1.135 +  // object, for example by calling CleanupOnFailure().
   1.136 +  nsresult FinishPrintPreview();
   1.137 +  static void CloseProgressDialog(nsIWebProgressListener* aWebProgressListener);
   1.138 +  void SetDocAndURLIntoProgress(nsPrintObject* aPO,
   1.139 +                                nsIPrintProgressParams* aParams);
   1.140 +  void EllipseLongString(nsAString& aStr, const uint32_t aLen, bool aDoFront);
   1.141 +  nsresult CheckForPrinters(nsIPrintSettings* aPrintSettings);
   1.142 +  void CleanupDocTitleArray(char16_t**& aArray, int32_t& aCount);
   1.143 +
   1.144 +  bool IsThereARangeSelection(nsIDOMWindow * aDOMWin);
   1.145 +
   1.146 +  //---------------------------------------------------------------------
   1.147 +
   1.148 +
   1.149 +  // Timer Methods
   1.150 +  nsresult StartPagePrintTimer(nsPrintObject* aPO);
   1.151 +
   1.152 +  bool IsWindowsInOurSubTree(nsPIDOMWindow * aDOMWindow);
   1.153 +  static bool IsParentAFrameSet(nsIDocShell * aParent);
   1.154 +  bool IsThereAnIFrameSelected(nsIDocShell* aDocShell,
   1.155 +                                 nsIDOMWindow* aDOMWin,
   1.156 +                                 bool& aIsParentFrameSet);
   1.157 +
   1.158 +  static nsPrintObject* FindPrintObjectByDOMWin(nsPrintObject* aParentObject,
   1.159 +                                                nsIDOMWindow* aDOMWin);
   1.160 +
   1.161 +  // get the currently infocus frame for the document viewer
   1.162 +  already_AddRefed<nsIDOMWindow> FindFocusedDOMWindow();
   1.163 +
   1.164 +  //---------------------------------------------------------------------
   1.165 +  // Static Methods
   1.166 +  //---------------------------------------------------------------------
   1.167 +  static void GetDocumentTitleAndURL(nsIDocument* aDoc,
   1.168 +                                     nsAString&   aTitle,
   1.169 +                                     nsAString&   aURLStr);
   1.170 +  void GetDisplayTitleAndURL(nsPrintObject*   aPO,
   1.171 +                             nsAString&       aTitle,
   1.172 +                             nsAString&       aURLStr,
   1.173 +                             eDocTitleDefault aDefType);
   1.174 +  static void ShowPrintErrorDialog(nsresult printerror,
   1.175 +                                   bool aIsPrinting = true);
   1.176 +
   1.177 +  static bool HasFramesetChild(nsIContent* aContent);
   1.178 +
   1.179 +  bool     CheckBeforeDestroy();
   1.180 +  nsresult Cancelled();
   1.181 +
   1.182 +  nsIPresShell* GetPrintPreviewPresShell() {return mPrtPreview->mPrintObject->mPresShell;}
   1.183 +
   1.184 +  float GetPrintPreviewScale() { return mPrtPreview->mPrintObject->
   1.185 +                                        mPresContext->GetPrintPreviewScale(); }
   1.186 +  
   1.187 +  static nsIPresShell* GetPresShellFor(nsIDocShell* aDocShell);
   1.188 +
   1.189 +  // These calls also update the DocViewer
   1.190 +  void SetIsPrinting(bool aIsPrinting);
   1.191 +  bool GetIsPrinting()
   1.192 +  {
   1.193 +    return mIsDoingPrinting;
   1.194 +  }
   1.195 +  void SetIsPrintPreview(bool aIsPrintPreview);
   1.196 +  bool GetIsPrintPreview()
   1.197 +  {
   1.198 +    return mIsDoingPrintPreview;
   1.199 +  }
   1.200 +  void SetIsCreatingPrintPreview(bool aIsCreatingPrintPreview)
   1.201 +  {
   1.202 +    mIsCreatingPrintPreview = aIsCreatingPrintPreview;
   1.203 +  }
   1.204 +  bool GetIsCreatingPrintPreview()
   1.205 +  {
   1.206 +    return mIsCreatingPrintPreview;
   1.207 +  }
   1.208 +
   1.209 +  void SetDisallowSelectionPrint(bool aDisallowSelectionPrint)
   1.210 +  {
   1.211 +    mDisallowSelectionPrint = aDisallowSelectionPrint;
   1.212 +  }
   1.213 +
   1.214 +  void SetNoMarginBoxes(bool aNoMarginBoxes) {
   1.215 +    mNoMarginBoxes = aNoMarginBoxes;
   1.216 +  }
   1.217 +
   1.218 +protected:
   1.219 +
   1.220 +  nsresult CommonPrint(bool aIsPrintPreview, nsIPrintSettings* aPrintSettings,
   1.221 +                       nsIWebProgressListener* aWebProgressListener,
   1.222 +                       nsIDOMDocument* aDoc);
   1.223 +
   1.224 +  nsresult DoCommonPrint(bool aIsPrintPreview, nsIPrintSettings* aPrintSettings,
   1.225 +                         nsIWebProgressListener* aWebProgressListener,
   1.226 +                         nsIDOMDocument* aDoc);
   1.227 +
   1.228 +  void FirePrintCompletionEvent();
   1.229 +  static nsresult GetSeqFrameAndCountPagesInternal(nsPrintObject*  aPO,
   1.230 +                                                   nsIFrame*&      aSeqFrame,
   1.231 +                                                   int32_t&        aCount);
   1.232 +
   1.233 +  static nsresult FindSelectionBoundsWithList(nsPresContext* aPresContext,
   1.234 +                                              nsRenderingContext& aRC,
   1.235 +                                              nsFrameList::Enumerator& aChildFrames,
   1.236 +                                              nsIFrame *      aParentFrame,
   1.237 +                                              nsRect&         aRect,
   1.238 +                                              nsIFrame *&     aStartFrame,
   1.239 +                                              nsRect&         aStartRect,
   1.240 +                                              nsIFrame *&     aEndFrame,
   1.241 +                                              nsRect&         aEndRect);
   1.242 +
   1.243 +  static nsresult FindSelectionBounds(nsPresContext* aPresContext,
   1.244 +                                      nsRenderingContext& aRC,
   1.245 +                                      nsIFrame *      aParentFrame,
   1.246 +                                      nsRect&         aRect,
   1.247 +                                      nsIFrame *&     aStartFrame,
   1.248 +                                      nsRect&         aStartRect,
   1.249 +                                      nsIFrame *&     aEndFrame,
   1.250 +                                      nsRect&         aEndRect);
   1.251 +
   1.252 +  static nsresult GetPageRangeForSelection(nsIPresShell *        aPresShell,
   1.253 +                                           nsPresContext*        aPresContext,
   1.254 +                                           nsRenderingContext&   aRC,
   1.255 +                                           nsISelection*         aSelection,
   1.256 +                                           nsIPageSequenceFrame* aPageSeqFrame,
   1.257 +                                           nsIFrame**            aStartFrame,
   1.258 +                                           int32_t&              aStartPageNum,
   1.259 +                                           nsRect&               aStartRect,
   1.260 +                                           nsIFrame**            aEndFrame,
   1.261 +                                           int32_t&              aEndPageNum,
   1.262 +                                           nsRect&               aEndRect);
   1.263 +
   1.264 +  static void MapContentForPO(nsPrintObject* aPO, nsIContent* aContent);
   1.265 +
   1.266 +  static void MapContentToWebShells(nsPrintObject* aRootPO, nsPrintObject* aPO);
   1.267 +
   1.268 +  static void SetPrintAsIs(nsPrintObject* aPO, bool aAsIs = true);
   1.269 +
   1.270 +  // Static member variables
   1.271 +  bool mIsCreatingPrintPreview;
   1.272 +  bool mIsDoingPrinting;
   1.273 +  bool mIsDoingPrintPreview; // per DocumentViewer
   1.274 +  bool mProgressDialogIsShown;
   1.275 +
   1.276 +  nsCOMPtr<nsIDocumentViewerPrint> mDocViewerPrint;
   1.277 +  nsWeakPtr               mContainer;
   1.278 +  float                   mScreenDPI;
   1.279 +  
   1.280 +  nsPrintData*            mPrt;
   1.281 +  nsPagePrintTimer*       mPagePrintTimer;
   1.282 +  nsIPageSequenceFrame*   mPageSeqFrame;
   1.283 +
   1.284 +  // Print Preview
   1.285 +  nsPrintData*            mPrtPreview;
   1.286 +  nsPrintData*            mOldPrtPreview;
   1.287 +
   1.288 +  nsCOMPtr<nsIDocument>   mDocument;
   1.289 +
   1.290 +  FILE* mDebugFile;
   1.291 +
   1.292 +  int32_t mLoadCounter;
   1.293 +  bool mDidLoadDataForPrinting;
   1.294 +  bool mIsDestroying;
   1.295 +  bool mDisallowSelectionPrint;
   1.296 +  bool mNoMarginBoxes;
   1.297 +
   1.298 +  nsresult AfterNetworkPrint(bool aHandleError);
   1.299 +
   1.300 +  nsresult SetRootView(nsPrintObject* aPO,
   1.301 +                       bool& aDoReturn,
   1.302 +                       bool& aDocumentIsTopLevel,
   1.303 +                       nsSize& aAdjSize);
   1.304 +  nsView* GetParentViewForRoot();
   1.305 +  bool DoSetPixelScale();
   1.306 +  void UpdateZoomRatio(nsPrintObject* aPO, bool aSetPixelScale);
   1.307 +  nsresult ReconstructAndReflow(bool aDoSetPixelScale);
   1.308 +  nsresult UpdateSelectionAndShrinkPrintObject(nsPrintObject* aPO,
   1.309 +                                               bool aDocumentIsTopLevel);
   1.310 +  nsresult InitPrintDocConstruction(bool aHandleError);
   1.311 +  void FirePrintPreviewUpdateEvent();
   1.312 +private:
   1.313 +  nsPrintEngine& operator=(const nsPrintEngine& aOther) MOZ_DELETE;
   1.314 +};
   1.315 +
   1.316 +#endif /* nsPrintEngine_h___ */

mercurial