Bumping manifests a=b2g-bump
[gecko.git] / layout / printing / nsPrintData.cpp
blobe08e13cbd0ac3e2dbc88c4445767ae95e49c8743
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 //-----------------------------------------------------
16 // PR LOGGING
17 #include "prlog.h"
19 #ifdef PR_LOGGING
20 #define DUMP_LAYOUT_LEVEL 9 // this turns on the dumping of each doucment's layout info
21 static PRLogModuleInfo *
22 GetPrintingLog()
24 static PRLogModuleInfo *sLog;
25 if (!sLog)
26 sLog = PR_NewLogModule("printing");
27 return sLog;
29 #define PR_PL(_p1) PR_LOG(GetPrintingLog(), PR_LOG_DEBUG, _p1);
30 #else
31 #define PRT_YESNO(_p)
32 #define PR_PL(_p1)
33 #endif
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),
46 mBrandName(nullptr)
48 MOZ_COUNT_CTOR(nsPrintData);
49 nsCOMPtr<nsIStringBundle> brandBundle;
50 nsCOMPtr<nsIStringBundleService> svc =
51 mozilla::services::GetStringBundleService();
52 if (svc) {
53 svc->CreateBundle( "chrome://branding/locale/brand.properties", getter_AddRefs( brandBundle ) );
54 if (brandBundle) {
55 brandBundle->GetStringFromName(MOZ_UTF16("brandShortName"), &mBrandName );
59 if (!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) {
76 OnEndPrinting();
79 if (mPrintDC && !mDebugFilePtr) {
80 PR_PL(("****************** End Document ************************\n"));
81 PR_PL(("\n"));
82 bool isCancelled = false;
83 mPrintSettings->GetIsCancelled(&isCancelled);
85 nsresult rv = NS_OK;
86 if (mType == eIsPrinting) {
87 if (!isCancelled && !mIsAborted) {
88 rv = mPrintDC->EndDocument();
89 } else {
90 rv = mPrintDC->AbortDocument();
92 if (NS_FAILED(rv)) {
93 // XXX nsPrintData::ShowPrintErrorDialog(rv);
98 delete mPrintObject;
100 if (mBrandName) {
101 NS_Free(mBrandName);
105 void nsPrintData::OnStartPrinting()
107 if (!mOnStartSent) {
108 DoOnProgressChange(0, 0, true, nsIWebProgressListener::STATE_START|nsIWebProgressListener::STATE_IS_DOCUMENT|nsIWebProgressListener::STATE_IS_NETWORK);
109 mOnStartSent = true;
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);
119 void
120 nsPrintData::DoOnProgressChange(int32_t aProgress,
121 int32_t aMaxProgress,
122 bool aDoStartStop,
123 int32_t aFlag)
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);
128 if (aDoStartStop) {
129 wpl->OnStateChange(nullptr, nullptr, aFlag, NS_OK);