/src/mozilla-central/layout/printing/nsPrintData.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "nsPrintData.h" |
8 | | |
9 | | #include "nsIStringBundle.h" |
10 | | #include "nsIServiceManager.h" |
11 | | #include "nsPrintObject.h" |
12 | | #include "nsPrintPreviewListener.h" |
13 | | #include "nsIWebProgressListener.h" |
14 | | #include "mozilla/Services.h" |
15 | | |
16 | | //----------------------------------------------------- |
17 | | // PR LOGGING |
18 | | #include "mozilla/Logging.h" |
19 | | |
20 | | static mozilla::LazyLogModule gPrintingLog("printing"); |
21 | | |
22 | 0 | #define PR_PL(_p1) MOZ_LOG(gPrintingLog, mozilla::LogLevel::Debug, _p1); |
23 | | |
24 | | //--------------------------------------------------- |
25 | | //-- nsPrintData Class Impl |
26 | | //--------------------------------------------------- |
27 | | nsPrintData::nsPrintData(ePrintDataType aType) |
28 | | : mType(aType) |
29 | | , mPrintDocList(0) |
30 | | , mIsIFrameSelected(false) |
31 | | , mIsParentAFrameSet(false) |
32 | | , mOnStartSent(false) |
33 | | , mIsAborted(false) |
34 | | , mPreparingForPrint(false) |
35 | | , mDocWasToBeDestroyed(false) |
36 | | , mShrinkToFit(false) |
37 | | , mPrintFrameType(nsIPrintSettings::kFramesAsIs) |
38 | | , mNumPrintablePages(0) |
39 | | , mNumPagesPrinted(0) |
40 | | , mShrinkRatio(1.0) |
41 | | , mPPEventListeners(nullptr) |
42 | 0 | { |
43 | 0 | nsCOMPtr<nsIStringBundle> brandBundle; |
44 | 0 | nsCOMPtr<nsIStringBundleService> svc = |
45 | 0 | mozilla::services::GetStringBundleService(); |
46 | 0 | if (svc) { |
47 | 0 | svc->CreateBundle( "chrome://branding/locale/brand.properties", getter_AddRefs( brandBundle ) ); |
48 | 0 | if (brandBundle) { |
49 | 0 | brandBundle->GetStringFromName("brandShortName", mBrandName); |
50 | 0 | } |
51 | 0 | } |
52 | 0 |
|
53 | 0 | if (mBrandName.IsEmpty()) { |
54 | 0 | mBrandName.AssignLiteral(u"Mozilla Document"); |
55 | 0 | } |
56 | 0 | } |
57 | | |
58 | | nsPrintData::~nsPrintData() |
59 | 0 | { |
60 | 0 | // remove the event listeners |
61 | 0 | if (mPPEventListeners) { |
62 | 0 | mPPEventListeners->RemoveListeners(); |
63 | 0 | NS_RELEASE(mPPEventListeners); |
64 | 0 | } |
65 | 0 |
|
66 | 0 | // Only Send an OnEndPrinting if we have started printing |
67 | 0 | if (mOnStartSent && mType != eIsPrintPreview) { |
68 | 0 | OnEndPrinting(); |
69 | 0 | } |
70 | 0 |
|
71 | 0 | if (mPrintDC) { |
72 | 0 | PR_PL(("****************** End Document ************************\n")); |
73 | 0 | PR_PL(("\n")); |
74 | 0 | bool isCancelled = false; |
75 | 0 | mPrintSettings->GetIsCancelled(&isCancelled); |
76 | 0 |
|
77 | 0 | nsresult rv = NS_OK; |
78 | 0 | if (mType == eIsPrinting && |
79 | 0 | mPrintDC->IsCurrentlyPrintingDocument()) { |
80 | 0 | if (!isCancelled && !mIsAborted) { |
81 | 0 | rv = mPrintDC->EndDocument(); |
82 | 0 | } else { |
83 | 0 | rv = mPrintDC->AbortDocument(); |
84 | 0 | } |
85 | 0 | if (NS_FAILED(rv)) { |
86 | 0 | // XXX nsPrintData::ShowPrintErrorDialog(rv); |
87 | 0 | } |
88 | 0 | } |
89 | 0 | } |
90 | 0 | } |
91 | | |
92 | | void nsPrintData::OnStartPrinting() |
93 | 0 | { |
94 | 0 | if (!mOnStartSent) { |
95 | 0 | DoOnProgressChange(0, 0, true, nsIWebProgressListener::STATE_START|nsIWebProgressListener::STATE_IS_DOCUMENT|nsIWebProgressListener::STATE_IS_NETWORK); |
96 | 0 | mOnStartSent = true; |
97 | 0 | } |
98 | 0 | } |
99 | | |
100 | | void nsPrintData::OnEndPrinting() |
101 | 0 | { |
102 | 0 | DoOnProgressChange(100, 100, true, nsIWebProgressListener::STATE_STOP|nsIWebProgressListener::STATE_IS_DOCUMENT); |
103 | 0 | DoOnProgressChange(100, 100, true, nsIWebProgressListener::STATE_STOP|nsIWebProgressListener::STATE_IS_NETWORK); |
104 | 0 | } |
105 | | |
106 | | void |
107 | | nsPrintData::DoOnProgressChange(int32_t aProgress, |
108 | | int32_t aMaxProgress, |
109 | | bool aDoStartStop, |
110 | | int32_t aFlag) |
111 | 0 | { |
112 | 0 | size_t numberOfListeners = mPrintProgressListeners.Length(); |
113 | 0 | for (size_t i = 0; i < numberOfListeners; ++i) { |
114 | 0 | nsCOMPtr<nsIWebProgressListener> listener = |
115 | 0 | mPrintProgressListeners.SafeElementAt(i); |
116 | 0 | if (NS_WARN_IF(!listener)) { |
117 | 0 | continue; |
118 | 0 | } |
119 | 0 | listener->OnProgressChange(nullptr, nullptr, aProgress, aMaxProgress, |
120 | 0 | aProgress, aMaxProgress); |
121 | 0 | if (aDoStartStop) { |
122 | 0 | listener->OnStateChange(nullptr, nullptr, aFlag, NS_OK); |
123 | 0 | } |
124 | 0 | } |
125 | 0 | } |
126 | | |
127 | | void |
128 | | nsPrintData::DoOnStatusChange(nsresult aStatus) |
129 | 0 | { |
130 | 0 | size_t numberOfListeners = mPrintProgressListeners.Length(); |
131 | 0 | for (size_t i = 0; i < numberOfListeners; ++i) { |
132 | 0 | nsCOMPtr<nsIWebProgressListener> listener = |
133 | 0 | mPrintProgressListeners.SafeElementAt(i); |
134 | 0 | if (NS_WARN_IF(!listener)) { |
135 | 0 | continue; |
136 | 0 | } |
137 | 0 | listener->OnStatusChange(nullptr, nullptr, aStatus, nullptr); |
138 | 0 | } |
139 | 0 | } |
140 | | |