layout/printing/nsPrintData.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/printing/nsPrintData.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,137 @@
     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 +
     1.9 +#include "nsPrintData.h"
    1.10 +
    1.11 +#include "nsIStringBundle.h"
    1.12 +#include "nsIServiceManager.h"
    1.13 +#include "nsPrintObject.h"
    1.14 +#include "nsPrintPreviewListener.h"
    1.15 +#include "nsIWebProgressListener.h"
    1.16 +#include "mozilla/Services.h"
    1.17 +
    1.18 +//-----------------------------------------------------
    1.19 +// PR LOGGING
    1.20 +#ifdef MOZ_LOGGING
    1.21 +#define FORCE_PR_LOG /* Allow logging in the release build */
    1.22 +#endif
    1.23 +
    1.24 +#include "prlog.h"
    1.25 +
    1.26 +#ifdef PR_LOGGING
    1.27 +#define DUMP_LAYOUT_LEVEL 9 // this turns on the dumping of each doucment's layout info
    1.28 +static PRLogModuleInfo *
    1.29 +GetPrintingLog()
    1.30 +{
    1.31 +  static PRLogModuleInfo *sLog;
    1.32 +  if (!sLog)
    1.33 +    sLog = PR_NewLogModule("printing");
    1.34 +  return sLog;
    1.35 +}
    1.36 +#define PR_PL(_p1)  PR_LOG(GetPrintingLog(), PR_LOG_DEBUG, _p1);
    1.37 +#else
    1.38 +#define PRT_YESNO(_p)
    1.39 +#define PR_PL(_p1)
    1.40 +#endif
    1.41 +
    1.42 +//---------------------------------------------------
    1.43 +//-- nsPrintData Class Impl
    1.44 +//---------------------------------------------------
    1.45 +nsPrintData::nsPrintData(ePrintDataType aType) :
    1.46 +  mType(aType), mDebugFilePtr(nullptr), mPrintObject(nullptr), mSelectedPO(nullptr),
    1.47 +  mPrintDocList(0), mIsIFrameSelected(false),
    1.48 +  mIsParentAFrameSet(false), mOnStartSent(false),
    1.49 +  mIsAborted(false), mPreparingForPrint(false), mDocWasToBeDestroyed(false),
    1.50 +  mShrinkToFit(false), mPrintFrameType(nsIPrintSettings::kFramesAsIs), 
    1.51 +  mNumPrintablePages(0), mNumPagesPrinted(0),
    1.52 +  mShrinkRatio(1.0), mOrigDCScale(1.0), mPPEventListeners(nullptr), 
    1.53 +  mBrandName(nullptr)
    1.54 +{
    1.55 +  MOZ_COUNT_CTOR(nsPrintData);
    1.56 +  nsCOMPtr<nsIStringBundle> brandBundle;
    1.57 +  nsCOMPtr<nsIStringBundleService> svc =
    1.58 +    mozilla::services::GetStringBundleService();
    1.59 +  if (svc) {
    1.60 +    svc->CreateBundle( "chrome://branding/locale/brand.properties", getter_AddRefs( brandBundle ) );
    1.61 +    if (brandBundle) {
    1.62 +      brandBundle->GetStringFromName(MOZ_UTF16("brandShortName"), &mBrandName );
    1.63 +    }
    1.64 +  }
    1.65 +
    1.66 +  if (!mBrandName) {
    1.67 +    mBrandName = ToNewUnicode(NS_LITERAL_STRING("Mozilla Document"));
    1.68 +  }
    1.69 +
    1.70 +}
    1.71 +
    1.72 +nsPrintData::~nsPrintData()
    1.73 +{
    1.74 +  MOZ_COUNT_DTOR(nsPrintData);
    1.75 +  // remove the event listeners
    1.76 +  if (mPPEventListeners) {
    1.77 +    mPPEventListeners->RemoveListeners();
    1.78 +    NS_RELEASE(mPPEventListeners);
    1.79 +  }
    1.80 +
    1.81 +  // Only Send an OnEndPrinting if we have started printing
    1.82 +  if (mOnStartSent && mType != eIsPrintPreview) {
    1.83 +    OnEndPrinting();
    1.84 +  }
    1.85 +
    1.86 +  if (mPrintDC && !mDebugFilePtr) {
    1.87 +    PR_PL(("****************** End Document ************************\n"));
    1.88 +    PR_PL(("\n"));
    1.89 +    bool isCancelled = false;
    1.90 +    mPrintSettings->GetIsCancelled(&isCancelled);
    1.91 +
    1.92 +    nsresult rv = NS_OK;
    1.93 +    if (mType == eIsPrinting) {
    1.94 +      if (!isCancelled && !mIsAborted) {
    1.95 +        rv = mPrintDC->EndDocument();
    1.96 +      } else {
    1.97 +        rv = mPrintDC->AbortDocument();  
    1.98 +      }
    1.99 +      if (NS_FAILED(rv)) {
   1.100 +        // XXX nsPrintData::ShowPrintErrorDialog(rv);
   1.101 +      }
   1.102 +    }
   1.103 +  }
   1.104 +
   1.105 +  delete mPrintObject;
   1.106 +
   1.107 +  if (mBrandName) {
   1.108 +    NS_Free(mBrandName);
   1.109 +  }
   1.110 +}
   1.111 +
   1.112 +void nsPrintData::OnStartPrinting()
   1.113 +{
   1.114 +  if (!mOnStartSent) {
   1.115 +    DoOnProgressChange(0, 0, true, nsIWebProgressListener::STATE_START|nsIWebProgressListener::STATE_IS_DOCUMENT|nsIWebProgressListener::STATE_IS_NETWORK);
   1.116 +    mOnStartSent = true;
   1.117 +  }
   1.118 +}
   1.119 +
   1.120 +void nsPrintData::OnEndPrinting()
   1.121 +{
   1.122 +  DoOnProgressChange(100, 100, true, nsIWebProgressListener::STATE_STOP|nsIWebProgressListener::STATE_IS_DOCUMENT);
   1.123 +  DoOnProgressChange(100, 100, true, nsIWebProgressListener::STATE_STOP|nsIWebProgressListener::STATE_IS_NETWORK);
   1.124 +}
   1.125 +
   1.126 +void
   1.127 +nsPrintData::DoOnProgressChange(int32_t      aProgress,
   1.128 +                                int32_t      aMaxProgress,
   1.129 +                                bool         aDoStartStop,
   1.130 +                                int32_t      aFlag)
   1.131 +{
   1.132 +  for (int32_t i=0;i<mPrintProgressListeners.Count();i++) {
   1.133 +    nsIWebProgressListener* wpl = mPrintProgressListeners.ObjectAt(i);
   1.134 +    wpl->OnProgressChange(nullptr, nullptr, aProgress, aMaxProgress, aProgress, aMaxProgress);
   1.135 +    if (aDoStartStop) {
   1.136 +      wpl->OnStateChange(nullptr, nullptr, aFlag, NS_OK);
   1.137 +    }
   1.138 +  }
   1.139 +}
   1.140 +

mercurial