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/. */
6 #include "nsPrintData.h"
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"
15 //-----------------------------------------------------
20 #define DUMP_LAYOUT_LEVEL 9 // this turns on the dumping of each doucment's layout info
21 static PRLogModuleInfo
*
24 static PRLogModuleInfo
*sLog
;
26 sLog
= PR_NewLogModule("printing");
29 #define PR_PL(_p1) PR_LOG(GetPrintingLog(), PR_LOG_DEBUG, _p1);
35 //---------------------------------------------------
36 //-- nsPrintData Class Impl
37 //---------------------------------------------------
38 nsPrintData::nsPrintData(ePrintDataType aType
) :
39 mType(aType
), mDebugFilePtr(nullptr), mPrintObject(nullptr), mSelectedPO(nullptr),
40 mPrintDocList(0), mIsIFrameSelected(false),
41 mIsParentAFrameSet(false), mOnStartSent(false),
42 mIsAborted(false), mPreparingForPrint(false), mDocWasToBeDestroyed(false),
43 mShrinkToFit(false), mPrintFrameType(nsIPrintSettings::kFramesAsIs
),
44 mNumPrintablePages(0), mNumPagesPrinted(0),
45 mShrinkRatio(1.0), mOrigDCScale(1.0), mPPEventListeners(nullptr),
48 MOZ_COUNT_CTOR(nsPrintData
);
49 nsCOMPtr
<nsIStringBundle
> brandBundle
;
50 nsCOMPtr
<nsIStringBundleService
> svc
=
51 mozilla::services::GetStringBundleService();
53 svc
->CreateBundle( "chrome://branding/locale/brand.properties", getter_AddRefs( brandBundle
) );
55 brandBundle
->GetStringFromName(MOZ_UTF16("brandShortName"), &mBrandName
);
60 mBrandName
= ToNewUnicode(NS_LITERAL_STRING("Mozilla Document"));
65 nsPrintData::~nsPrintData()
67 MOZ_COUNT_DTOR(nsPrintData
);
68 // remove the event listeners
69 if (mPPEventListeners
) {
70 mPPEventListeners
->RemoveListeners();
71 NS_RELEASE(mPPEventListeners
);
74 // Only Send an OnEndPrinting if we have started printing
75 if (mOnStartSent
&& mType
!= eIsPrintPreview
) {
79 if (mPrintDC
&& !mDebugFilePtr
) {
80 PR_PL(("****************** End Document ************************\n"));
82 bool isCancelled
= false;
83 mPrintSettings
->GetIsCancelled(&isCancelled
);
86 if (mType
== eIsPrinting
) {
87 if (!isCancelled
&& !mIsAborted
) {
88 rv
= mPrintDC
->EndDocument();
90 rv
= mPrintDC
->AbortDocument();
93 // XXX nsPrintData::ShowPrintErrorDialog(rv);
105 void nsPrintData::OnStartPrinting()
108 DoOnProgressChange(0, 0, true, nsIWebProgressListener::STATE_START
|nsIWebProgressListener::STATE_IS_DOCUMENT
|nsIWebProgressListener::STATE_IS_NETWORK
);
113 void nsPrintData::OnEndPrinting()
115 DoOnProgressChange(100, 100, true, nsIWebProgressListener::STATE_STOP
|nsIWebProgressListener::STATE_IS_DOCUMENT
);
116 DoOnProgressChange(100, 100, true, nsIWebProgressListener::STATE_STOP
|nsIWebProgressListener::STATE_IS_NETWORK
);
120 nsPrintData::DoOnProgressChange(int32_t aProgress
,
121 int32_t aMaxProgress
,
125 for (int32_t i
=0;i
<mPrintProgressListeners
.Count();i
++) {
126 nsIWebProgressListener
* wpl
= mPrintProgressListeners
.ObjectAt(i
);
127 wpl
->OnProgressChange(nullptr, nullptr, aProgress
, aMaxProgress
, aProgress
, aMaxProgress
);
129 wpl
->OnStateChange(nullptr, nullptr, aFlag
, NS_OK
);