LCOV - code coverage report
Current view: top level - layout/printing - nsPrintData.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 60 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 6 0.0 %
Legend: Lines: hit not hit

          Line data    Source 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             : 
       6             : #include "nsPrintData.h"
       7             : 
       8             : #include "nsIStringBundle.h"
       9             : #include "nsIServiceManager.h"
      10             : #include "nsPrintObject.h"
      11             : #include "nsPrintPreviewListener.h"
      12             : #include "nsIWebProgressListener.h"
      13             : #include "mozilla/Services.h"
      14             : 
      15             : //-----------------------------------------------------
      16             : // PR LOGGING
      17             : #include "mozilla/Logging.h"
      18             : 
      19             : #define DUMP_LAYOUT_LEVEL 9 // this turns on the dumping of each doucment's layout info
      20             : static mozilla::LazyLogModule gPrintingLog("printing");
      21             : 
      22             : #define PR_PL(_p1)  MOZ_LOG(gPrintingLog, mozilla::LogLevel::Debug, _p1);
      23             : 
      24             : //---------------------------------------------------
      25             : //-- nsPrintData Class Impl
      26             : //---------------------------------------------------
      27           0 : nsPrintData::nsPrintData(ePrintDataType aType)
      28             :   : mType(aType)
      29             :   , mDebugFilePtr(nullptr)
      30             :   , mPrintDocList(0)
      31             :   , mIsIFrameSelected(false)
      32             :   , mIsParentAFrameSet(false)
      33             :   , mOnStartSent(false)
      34             :   , mIsAborted(false)
      35             :   , mPreparingForPrint(false)
      36             :   , mDocWasToBeDestroyed(false)
      37             :   , mShrinkToFit(false)
      38             :   , mPrintFrameType(nsIPrintSettings::kFramesAsIs)
      39             :   , mNumPrintablePages(0)
      40             :   , mNumPagesPrinted(0)
      41             :   , mShrinkRatio(1.0)
      42             :   , mOrigDCScale(1.0)
      43             :   , mPPEventListeners(nullptr)
      44           0 :   , mBrandName(nullptr)
      45             : {
      46           0 :   nsCOMPtr<nsIStringBundle> brandBundle;
      47             :   nsCOMPtr<nsIStringBundleService> svc =
      48           0 :     mozilla::services::GetStringBundleService();
      49           0 :   if (svc) {
      50           0 :     svc->CreateBundle( "chrome://branding/locale/brand.properties", getter_AddRefs( brandBundle ) );
      51           0 :     if (brandBundle) {
      52           0 :       brandBundle->GetStringFromName(u"brandShortName", &mBrandName );
      53             :     }
      54             :   }
      55             : 
      56           0 :   if (!mBrandName) {
      57           0 :     mBrandName = ToNewUnicode(NS_LITERAL_STRING("Mozilla Document"));
      58             :   }
      59             : 
      60           0 : }
      61             : 
      62           0 : nsPrintData::~nsPrintData()
      63             : {
      64             :   // remove the event listeners
      65           0 :   if (mPPEventListeners) {
      66           0 :     mPPEventListeners->RemoveListeners();
      67           0 :     NS_RELEASE(mPPEventListeners);
      68             :   }
      69             : 
      70             :   // Only Send an OnEndPrinting if we have started printing
      71           0 :   if (mOnStartSent && mType != eIsPrintPreview) {
      72           0 :     OnEndPrinting();
      73             :   }
      74             : 
      75           0 :   if (mPrintDC && !mDebugFilePtr) {
      76           0 :     PR_PL(("****************** End Document ************************\n"));
      77           0 :     PR_PL(("\n"));
      78           0 :     bool isCancelled = false;
      79           0 :     mPrintSettings->GetIsCancelled(&isCancelled);
      80             : 
      81           0 :     nsresult rv = NS_OK;
      82           0 :     if (mType == eIsPrinting &&
      83           0 :         mPrintDC->IsCurrentlyPrintingDocument()) {
      84           0 :       if (!isCancelled && !mIsAborted) {
      85           0 :         rv = mPrintDC->EndDocument();
      86             :       } else {
      87           0 :         rv = mPrintDC->AbortDocument();
      88             :       }
      89           0 :       if (NS_FAILED(rv)) {
      90             :         // XXX nsPrintData::ShowPrintErrorDialog(rv);
      91             :       }
      92             :     }
      93             :   }
      94             : 
      95           0 :   if (mBrandName) {
      96           0 :     free(mBrandName);
      97             :   }
      98           0 : }
      99             : 
     100           0 : void nsPrintData::OnStartPrinting()
     101             : {
     102           0 :   if (!mOnStartSent) {
     103           0 :     DoOnProgressChange(0, 0, true, nsIWebProgressListener::STATE_START|nsIWebProgressListener::STATE_IS_DOCUMENT|nsIWebProgressListener::STATE_IS_NETWORK);
     104           0 :     mOnStartSent = true;
     105             :   }
     106           0 : }
     107             : 
     108           0 : void nsPrintData::OnEndPrinting()
     109             : {
     110           0 :   DoOnProgressChange(100, 100, true, nsIWebProgressListener::STATE_STOP|nsIWebProgressListener::STATE_IS_DOCUMENT);
     111           0 :   DoOnProgressChange(100, 100, true, nsIWebProgressListener::STATE_STOP|nsIWebProgressListener::STATE_IS_NETWORK);
     112           0 : }
     113             : 
     114             : void
     115           0 : nsPrintData::DoOnProgressChange(int32_t      aProgress,
     116             :                                 int32_t      aMaxProgress,
     117             :                                 bool         aDoStartStop,
     118             :                                 int32_t      aFlag)
     119             : {
     120           0 :   size_t numberOfListeners = mPrintProgressListeners.Length();
     121           0 :   for (size_t i = 0; i < numberOfListeners; ++i) {
     122             :     nsCOMPtr<nsIWebProgressListener> listener =
     123           0 :       mPrintProgressListeners.SafeElementAt(i);
     124           0 :     if (NS_WARN_IF(!listener)) {
     125           0 :       continue;
     126             :     }
     127           0 :     listener->OnProgressChange(nullptr, nullptr, aProgress, aMaxProgress,
     128           0 :                                aProgress, aMaxProgress);
     129           0 :     if (aDoStartStop) {
     130           0 :       listener->OnStateChange(nullptr, nullptr, aFlag, NS_OK);
     131             :     }
     132             :   }
     133           0 : }
     134             : 
     135             : void
     136           0 : nsPrintData::DoOnStatusChange(nsresult aStatus)
     137             : {
     138           0 :   size_t numberOfListeners = mPrintProgressListeners.Length();
     139           0 :   for (size_t i = 0; i < numberOfListeners; ++i) {
     140             :     nsCOMPtr<nsIWebProgressListener> listener =
     141           0 :       mPrintProgressListeners.SafeElementAt(i);
     142           0 :     if (NS_WARN_IF(!listener)) {
     143           0 :       continue;
     144             :     }
     145           0 :     listener->OnStatusChange(nullptr, nullptr, aStatus, nullptr);
     146             :   }
     147           0 : }
     148             : 

Generated by: LCOV version 1.13