LCOV - app.info - layout/printing/nsPrintData.cpp

LCOV - code coverage report
| Current view: | directory - layout/printing - nsPrintData.cpp (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 51 | 2 | 3.9 %
| Date: | 2012-07-07 | Functions: | 8 | 2 | 25.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                 :
          38                 : #include "nsPrintData.h"
          39                 :
          40                 : #include "nsIStringBundle.h"
          41                 : #include "nsIServiceManager.h"
          42                 : #include "nsPrintObject.h"
          43                 : #include "nsPrintPreviewListener.h"
          44                 : #include "nsIWebProgressListener.h"
          45                 : #include "mozilla/Services.h"
          46                 :
          47                 : //-----------------------------------------------------
          48                 : // PR LOGGING
          49                 : #ifdef MOZ_LOGGING
          50                 : #define FORCE_PR_LOG /* Allow logging in the release build */
          51                 : #endif
          52                 :
          53                 : #include "prlog.h"
          54                 :
          55                 : #ifdef PR_LOGGING
          56                 : #define DUMP_LAYOUT_LEVEL 9 // this turns on the dumping of each doucment's layout info
          57            1464 : static PRLogModuleInfo * kPrintingLogMod = PR_NewLogModule("printing");
          58                 : #define PR_PL(_p1)  PR_LOG(kPrintingLogMod, PR_LOG_DEBUG, _p1);
          59                 : #else
          60                 : #define PRT_YESNO(_p)
          61                 : #define PR_PL(_p1)
          62                 : #endif
          63                 :
          64                 : //---------------------------------------------------
          65                 : //-- nsPrintData Class Impl
          66                 : //---------------------------------------------------
          67               0 : nsPrintData::nsPrintData(ePrintDataType aType) :
          68                 :   mType(aType), mDebugFilePtr(nsnull), mPrintObject(nsnull), mSelectedPO(nsnull),
          69                 :   mPrintDocList(nsnull), mIsIFrameSelected(false),
          70                 :   mIsParentAFrameSet(false), mOnStartSent(false),
          71                 :   mIsAborted(false), mPreparingForPrint(false), mDocWasToBeDestroyed(false),
          72                 :   mShrinkToFit(false), mPrintFrameType(nsIPrintSettings::kFramesAsIs),
          73                 :   mNumPrintablePages(0), mNumPagesPrinted(0),
          74                 :   mShrinkRatio(1.0), mOrigDCScale(1.0), mPPEventListeners(NULL),
          75               0 :   mBrandName(nsnull)
          76                 : {
          77               0 :   MOZ_COUNT_CTOR(nsPrintData);
          78               0 :   nsCOMPtr<nsIStringBundle> brandBundle;
          79                 :   nsCOMPtr<nsIStringBundleService> svc =
          80               0 :     mozilla::services::GetStringBundleService();
          81               0 :   if (svc) {
          82               0 :     svc->CreateBundle( "chrome://branding/locale/brand.properties", getter_AddRefs( brandBundle ) );
          83               0 :     if (brandBundle) {
          84               0 :       brandBundle->GetStringFromName(NS_LITERAL_STRING("brandShortName").get(), &mBrandName );
          85                 :     }
          86                 :   }
          87                 :
          88               0 :   if (!mBrandName) {
          89               0 :     mBrandName = ToNewUnicode(NS_LITERAL_STRING("Mozilla Document"));
          90                 :   }
          91                 :
          92               0 : }
          93                 :
          94               0 : nsPrintData::~nsPrintData()
          95                 : {
          96               0 :   MOZ_COUNT_DTOR(nsPrintData);
          97                 :   // remove the event listeners
          98               0 :   if (mPPEventListeners) {
          99               0 :     mPPEventListeners->RemoveListeners();
         100               0 :     NS_RELEASE(mPPEventListeners);
         101                 :   }
         102                 :
         103                 :   // Only Send an OnEndPrinting if we have started printing
         104               0 :   if (mOnStartSent && mType != eIsPrintPreview) {
         105               0 :     OnEndPrinting();
         106                 :   }
         107                 :
         108               0 :   if (mPrintDC && !mDebugFilePtr) {
         109               0 :     PR_PL(("****************** End Document ************************\n"));
         110               0 :     PR_PL(("\n"));
         111               0 :     bool isCancelled = false;
         112               0 :     mPrintSettings->GetIsCancelled(&isCancelled);
         113                 :
         114               0 :     nsresult rv = NS_OK;
         115               0 :     if (mType == eIsPrinting) {
         116               0 :       if (!isCancelled && !mIsAborted) {
         117               0 :         rv = mPrintDC->EndDocument();
         118                 :       } else {
         119               0 :         rv = mPrintDC->AbortDocument();
         120                 :       }
         121               0 :       if (NS_FAILED(rv)) {
         122                 :         // XXX nsPrintData::ShowPrintErrorDialog(rv);
         123                 :       }
         124                 :     }
         125                 :   }
         126                 :
         127               0 :   delete mPrintObject;
         128                 :
         129               0 :   if (mBrandName) {
         130               0 :     NS_Free(mBrandName);
         131                 :   }
         132               0 : }
         133                 :
         134               0 : void nsPrintData::OnStartPrinting()
         135                 : {
         136               0 :   if (!mOnStartSent) {
         137               0 :     DoOnProgressChange(0, 0, true, nsIWebProgressListener::STATE_START|nsIWebProgressListener::STATE_IS_DOCUMENT|nsIWebProgressListener::STATE_IS_NETWORK);
         138               0 :     mOnStartSent = true;
         139                 :   }
         140               0 : }
         141                 :
         142               0 : void nsPrintData::OnEndPrinting()
         143                 : {
         144               0 :   DoOnProgressChange(100, 100, true, nsIWebProgressListener::STATE_STOP|nsIWebProgressListener::STATE_IS_DOCUMENT);
         145               0 :   DoOnProgressChange(100, 100, true, nsIWebProgressListener::STATE_STOP|nsIWebProgressListener::STATE_IS_NETWORK);
         146               0 : }
         147                 :
         148                 : void
         149               0 : nsPrintData::DoOnProgressChange(PRInt32      aProgress,
         150                 :                                 PRInt32      aMaxProgress,
         151                 :                                 bool         aDoStartStop,
         152                 :                                 PRInt32      aFlag)
         153                 : {
         154               0 :   for (PRInt32 i=0;i<mPrintProgressListeners.Count();i++) {
         155               0 :     nsIWebProgressListener* wpl = mPrintProgressListeners.ObjectAt(i);
         156               0 :     wpl->OnProgressChange(nsnull, nsnull, aProgress, aMaxProgress, aProgress, aMaxProgress);
         157               0 :     if (aDoStartStop) {
         158               0 :       wpl->OnStateChange(nsnull, nsnull, aFlag, 0);
         159                 :     }
         160                 :   }
         161            4392 : }
         162                 :

Generated by: LCOV version 1.7