michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #ifndef nsPrintEngine_h___ michael@0: #define nsPrintEngine_h___ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: #include "nsCOMPtr.h" michael@0: michael@0: #include "nsPrintObject.h" michael@0: #include "nsPrintData.h" michael@0: #include "nsFrameList.h" michael@0: #include "mozilla/Attributes.h" michael@0: #include "nsIWebProgress.h" michael@0: #include "mozilla/dom/HTMLCanvasElement.h" michael@0: #include "nsIWebProgressListener.h" michael@0: #include "nsWeakReference.h" michael@0: michael@0: // Interfaces michael@0: #include "nsIDOMWindow.h" michael@0: #include "nsIObserver.h" michael@0: michael@0: // Classes michael@0: class nsPagePrintTimer; michael@0: class nsIDocShell; michael@0: class nsDeviceContext; michael@0: class nsIDocument; michael@0: class nsIDocumentViewerPrint; michael@0: class nsPrintObject; michael@0: class nsIDocShell; michael@0: class nsIPageSequenceFrame; michael@0: class nsIWeakReference; michael@0: michael@0: //------------------------------------------------------------------------ michael@0: // nsPrintEngine Class michael@0: // michael@0: //------------------------------------------------------------------------ michael@0: class nsPrintEngine MOZ_FINAL : public nsIObserver, michael@0: public nsIWebProgressListener, michael@0: public nsSupportsWeakReference michael@0: { michael@0: public: michael@0: // nsISupports interface... michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: // nsIObserver michael@0: NS_DECL_NSIOBSERVER michael@0: michael@0: NS_DECL_NSIWEBPROGRESSLISTENER michael@0: michael@0: // Old nsIWebBrowserPrint methods; not cleaned up yet michael@0: NS_IMETHOD Print(nsIPrintSettings* aPrintSettings, michael@0: nsIWebProgressListener* aWebProgressListener); michael@0: NS_IMETHOD PrintPreview(nsIPrintSettings* aPrintSettings, michael@0: nsIDOMWindow *aChildDOMWin, michael@0: nsIWebProgressListener* aWebProgressListener); michael@0: NS_IMETHOD GetIsFramesetDocument(bool *aIsFramesetDocument); michael@0: NS_IMETHOD GetIsIFrameSelected(bool *aIsIFrameSelected); michael@0: NS_IMETHOD GetIsRangeSelection(bool *aIsRangeSelection); michael@0: NS_IMETHOD GetIsFramesetFrameSelected(bool *aIsFramesetFrameSelected); michael@0: NS_IMETHOD GetPrintPreviewNumPages(int32_t *aPrintPreviewNumPages); michael@0: NS_IMETHOD EnumerateDocumentNames(uint32_t* aCount, char16_t*** aResult); michael@0: static nsresult GetGlobalPrintSettings(nsIPrintSettings** aPrintSettings); michael@0: NS_IMETHOD GetDoingPrint(bool *aDoingPrint); michael@0: NS_IMETHOD GetDoingPrintPreview(bool *aDoingPrintPreview); michael@0: NS_IMETHOD GetCurrentPrintSettings(nsIPrintSettings **aCurrentPrintSettings); michael@0: michael@0: michael@0: // This enum tells indicates what the default should be for the title michael@0: // if the title from the document is null michael@0: enum eDocTitleDefault { michael@0: eDocTitleDefBlank, michael@0: eDocTitleDefURLDoc michael@0: }; michael@0: michael@0: nsPrintEngine(); michael@0: ~nsPrintEngine(); michael@0: michael@0: void Destroy(); michael@0: void DestroyPrintingData(); michael@0: michael@0: nsresult Initialize(nsIDocumentViewerPrint* aDocViewerPrint, michael@0: nsIDocShell* aContainer, michael@0: nsIDocument* aDocument, michael@0: float aScreenDPI, michael@0: FILE* aDebugFile); michael@0: michael@0: nsresult GetSeqFrameAndCountPages(nsIFrame*& aSeqFrame, int32_t& aCount); michael@0: michael@0: // michael@0: // The following three methods are used for printing... michael@0: // michael@0: nsresult DocumentReadyForPrinting(); michael@0: nsresult GetSelectionDocument(nsIDeviceContextSpec * aDevSpec, michael@0: nsIDocument ** aNewDoc); michael@0: michael@0: nsresult SetupToPrintContent(); michael@0: nsresult EnablePOsForPrinting(); michael@0: nsPrintObject* FindSmallestSTF(); michael@0: michael@0: bool PrintDocContent(nsPrintObject* aPO, nsresult& aStatus); michael@0: nsresult DoPrint(nsPrintObject * aPO); michael@0: michael@0: void SetPrintPO(nsPrintObject* aPO, bool aPrint); michael@0: michael@0: void TurnScriptingOn(bool aDoTurnOn); michael@0: bool CheckDocumentForPPCaching(); michael@0: void InstallPrintPreviewListener(); michael@0: michael@0: // nsIDocumentViewerPrint Printing Methods michael@0: bool HasPrintCallbackCanvas(); michael@0: bool PrePrintPage(); michael@0: bool PrintPage(nsPrintObject* aPOect, bool& aInRange); michael@0: bool DonePrintingPages(nsPrintObject* aPO, nsresult aResult); michael@0: michael@0: //--------------------------------------------------------------------- michael@0: void BuildDocTree(nsIDocShell * aParentNode, michael@0: nsTArray * aDocList, michael@0: nsPrintObject * aPO); michael@0: nsresult ReflowDocList(nsPrintObject * aPO, bool aSetPixelScale); michael@0: michael@0: nsresult ReflowPrintObject(nsPrintObject * aPO); michael@0: michael@0: void CheckForChildFrameSets(nsPrintObject* aPO); michael@0: michael@0: void CalcNumPrintablePages(int32_t& aNumPages); michael@0: void ShowPrintProgress(bool aIsForPrinting, bool& aDoNotify); michael@0: nsresult CleanupOnFailure(nsresult aResult, bool aIsPrinting); michael@0: // If FinishPrintPreview() fails, caller may need to reset the state of the michael@0: // object, for example by calling CleanupOnFailure(). michael@0: nsresult FinishPrintPreview(); michael@0: static void CloseProgressDialog(nsIWebProgressListener* aWebProgressListener); michael@0: void SetDocAndURLIntoProgress(nsPrintObject* aPO, michael@0: nsIPrintProgressParams* aParams); michael@0: void EllipseLongString(nsAString& aStr, const uint32_t aLen, bool aDoFront); michael@0: nsresult CheckForPrinters(nsIPrintSettings* aPrintSettings); michael@0: void CleanupDocTitleArray(char16_t**& aArray, int32_t& aCount); michael@0: michael@0: bool IsThereARangeSelection(nsIDOMWindow * aDOMWin); michael@0: michael@0: //--------------------------------------------------------------------- michael@0: michael@0: michael@0: // Timer Methods michael@0: nsresult StartPagePrintTimer(nsPrintObject* aPO); michael@0: michael@0: bool IsWindowsInOurSubTree(nsPIDOMWindow * aDOMWindow); michael@0: static bool IsParentAFrameSet(nsIDocShell * aParent); michael@0: bool IsThereAnIFrameSelected(nsIDocShell* aDocShell, michael@0: nsIDOMWindow* aDOMWin, michael@0: bool& aIsParentFrameSet); michael@0: michael@0: static nsPrintObject* FindPrintObjectByDOMWin(nsPrintObject* aParentObject, michael@0: nsIDOMWindow* aDOMWin); michael@0: michael@0: // get the currently infocus frame for the document viewer michael@0: already_AddRefed FindFocusedDOMWindow(); michael@0: michael@0: //--------------------------------------------------------------------- michael@0: // Static Methods michael@0: //--------------------------------------------------------------------- michael@0: static void GetDocumentTitleAndURL(nsIDocument* aDoc, michael@0: nsAString& aTitle, michael@0: nsAString& aURLStr); michael@0: void GetDisplayTitleAndURL(nsPrintObject* aPO, michael@0: nsAString& aTitle, michael@0: nsAString& aURLStr, michael@0: eDocTitleDefault aDefType); michael@0: static void ShowPrintErrorDialog(nsresult printerror, michael@0: bool aIsPrinting = true); michael@0: michael@0: static bool HasFramesetChild(nsIContent* aContent); michael@0: michael@0: bool CheckBeforeDestroy(); michael@0: nsresult Cancelled(); michael@0: michael@0: nsIPresShell* GetPrintPreviewPresShell() {return mPrtPreview->mPrintObject->mPresShell;} michael@0: michael@0: float GetPrintPreviewScale() { return mPrtPreview->mPrintObject-> michael@0: mPresContext->GetPrintPreviewScale(); } michael@0: michael@0: static nsIPresShell* GetPresShellFor(nsIDocShell* aDocShell); michael@0: michael@0: // These calls also update the DocViewer michael@0: void SetIsPrinting(bool aIsPrinting); michael@0: bool GetIsPrinting() michael@0: { michael@0: return mIsDoingPrinting; michael@0: } michael@0: void SetIsPrintPreview(bool aIsPrintPreview); michael@0: bool GetIsPrintPreview() michael@0: { michael@0: return mIsDoingPrintPreview; michael@0: } michael@0: void SetIsCreatingPrintPreview(bool aIsCreatingPrintPreview) michael@0: { michael@0: mIsCreatingPrintPreview = aIsCreatingPrintPreview; michael@0: } michael@0: bool GetIsCreatingPrintPreview() michael@0: { michael@0: return mIsCreatingPrintPreview; michael@0: } michael@0: michael@0: void SetDisallowSelectionPrint(bool aDisallowSelectionPrint) michael@0: { michael@0: mDisallowSelectionPrint = aDisallowSelectionPrint; michael@0: } michael@0: michael@0: void SetNoMarginBoxes(bool aNoMarginBoxes) { michael@0: mNoMarginBoxes = aNoMarginBoxes; michael@0: } michael@0: michael@0: protected: michael@0: michael@0: nsresult CommonPrint(bool aIsPrintPreview, nsIPrintSettings* aPrintSettings, michael@0: nsIWebProgressListener* aWebProgressListener, michael@0: nsIDOMDocument* aDoc); michael@0: michael@0: nsresult DoCommonPrint(bool aIsPrintPreview, nsIPrintSettings* aPrintSettings, michael@0: nsIWebProgressListener* aWebProgressListener, michael@0: nsIDOMDocument* aDoc); michael@0: michael@0: void FirePrintCompletionEvent(); michael@0: static nsresult GetSeqFrameAndCountPagesInternal(nsPrintObject* aPO, michael@0: nsIFrame*& aSeqFrame, michael@0: int32_t& aCount); michael@0: michael@0: static nsresult FindSelectionBoundsWithList(nsPresContext* aPresContext, michael@0: nsRenderingContext& aRC, michael@0: nsFrameList::Enumerator& aChildFrames, michael@0: nsIFrame * aParentFrame, michael@0: nsRect& aRect, michael@0: nsIFrame *& aStartFrame, michael@0: nsRect& aStartRect, michael@0: nsIFrame *& aEndFrame, michael@0: nsRect& aEndRect); michael@0: michael@0: static nsresult FindSelectionBounds(nsPresContext* aPresContext, michael@0: nsRenderingContext& aRC, michael@0: nsIFrame * aParentFrame, michael@0: nsRect& aRect, michael@0: nsIFrame *& aStartFrame, michael@0: nsRect& aStartRect, michael@0: nsIFrame *& aEndFrame, michael@0: nsRect& aEndRect); michael@0: michael@0: static nsresult GetPageRangeForSelection(nsIPresShell * aPresShell, michael@0: nsPresContext* aPresContext, michael@0: nsRenderingContext& aRC, michael@0: nsISelection* aSelection, michael@0: nsIPageSequenceFrame* aPageSeqFrame, michael@0: nsIFrame** aStartFrame, michael@0: int32_t& aStartPageNum, michael@0: nsRect& aStartRect, michael@0: nsIFrame** aEndFrame, michael@0: int32_t& aEndPageNum, michael@0: nsRect& aEndRect); michael@0: michael@0: static void MapContentForPO(nsPrintObject* aPO, nsIContent* aContent); michael@0: michael@0: static void MapContentToWebShells(nsPrintObject* aRootPO, nsPrintObject* aPO); michael@0: michael@0: static void SetPrintAsIs(nsPrintObject* aPO, bool aAsIs = true); michael@0: michael@0: // Static member variables michael@0: bool mIsCreatingPrintPreview; michael@0: bool mIsDoingPrinting; michael@0: bool mIsDoingPrintPreview; // per DocumentViewer michael@0: bool mProgressDialogIsShown; michael@0: michael@0: nsCOMPtr mDocViewerPrint; michael@0: nsWeakPtr mContainer; michael@0: float mScreenDPI; michael@0: michael@0: nsPrintData* mPrt; michael@0: nsPagePrintTimer* mPagePrintTimer; michael@0: nsIPageSequenceFrame* mPageSeqFrame; michael@0: michael@0: // Print Preview michael@0: nsPrintData* mPrtPreview; michael@0: nsPrintData* mOldPrtPreview; michael@0: michael@0: nsCOMPtr mDocument; michael@0: michael@0: FILE* mDebugFile; michael@0: michael@0: int32_t mLoadCounter; michael@0: bool mDidLoadDataForPrinting; michael@0: bool mIsDestroying; michael@0: bool mDisallowSelectionPrint; michael@0: bool mNoMarginBoxes; michael@0: michael@0: nsresult AfterNetworkPrint(bool aHandleError); michael@0: michael@0: nsresult SetRootView(nsPrintObject* aPO, michael@0: bool& aDoReturn, michael@0: bool& aDocumentIsTopLevel, michael@0: nsSize& aAdjSize); michael@0: nsView* GetParentViewForRoot(); michael@0: bool DoSetPixelScale(); michael@0: void UpdateZoomRatio(nsPrintObject* aPO, bool aSetPixelScale); michael@0: nsresult ReconstructAndReflow(bool aDoSetPixelScale); michael@0: nsresult UpdateSelectionAndShrinkPrintObject(nsPrintObject* aPO, michael@0: bool aDocumentIsTopLevel); michael@0: nsresult InitPrintDocConstruction(bool aHandleError); michael@0: void FirePrintPreviewUpdateEvent(); michael@0: private: michael@0: nsPrintEngine& operator=(const nsPrintEngine& aOther) MOZ_DELETE; michael@0: }; michael@0: michael@0: #endif /* nsPrintEngine_h___ */