LCOV - code coverage report
Current view: directory - layout/printing - nsPrintEngine.h (source / functions) Found Hit Coverage
Test: app.info Lines: 12 0 0.0 %
Date: 2012-06-02 Functions: 6 0 0.0 %

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

Generated by: LCOV version 1.7