Bug 1708422: part 16) Rename `mozInlineSpellChecker::SpellCheckerTimeSlice` to `mozIn...
[gecko.git] / widget / nsPrintSettingsImpl.cpp
blob02add9448efb41d992f2b04206c661d175a50457
1 /* -*- Mode: C++; tab-width: 4; 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 "nsPrintSettingsImpl.h"
8 #include "prenv.h"
9 #include "nsCoord.h"
10 #include "nsPaper.h"
11 #include "nsReadableUtils.h"
12 #include "nsIPrintSession.h"
13 #include "mozilla/DebugOnly.h"
14 #include "mozilla/RefPtr.h"
16 #define DEFAULT_MARGIN_WIDTH 0.5
18 NS_IMPL_ISUPPORTS(nsPrintSettings, nsIPrintSettings)
20 nsPrintSettings::nsPrintSettings()
21 : mScaling(1.0),
22 mPrintBGColors(false),
23 mPrintBGImages(false),
24 mIsCancelled(false),
25 mSaveOnCancel(true),
26 mPrintSilent(false),
27 mShrinkToFit(true),
28 mShowPrintProgress(true),
29 mShowMarginGuides(false),
30 mHonorPageRuleMargins(true),
31 mIsPrintSelectionRBEnabled(false),
32 mPrintSelectionOnly(false),
33 mPrintPageDelay(50),
34 mPaperWidth(8.5),
35 mPaperHeight(11.0),
36 mPaperSizeUnit(kPaperSizeInches),
37 mPrintReversed(false),
38 mPrintInColor(true),
39 mOrientation(kPortraitOrientation),
40 mResolution(0),
41 mDuplex(0),
42 mNumCopies(1),
43 mNumPagesPerSheet(1),
44 mPrintToFile(false),
45 mOutputFormat(kOutputFormatNative),
46 mIsInitedFromPrinter(false),
47 mIsInitedFromPrefs(false) {
48 /* member initializers and constructor code */
49 int32_t marginWidth = NS_INCHES_TO_INT_TWIPS(DEFAULT_MARGIN_WIDTH);
50 mMargin.SizeTo(marginWidth, marginWidth, marginWidth, marginWidth);
51 mEdge.SizeTo(0, 0, 0, 0);
52 mUnwriteableMargin.SizeTo(0, 0, 0, 0);
54 mHeaderStrs[0].AssignLiteral("&T");
55 mHeaderStrs[2].AssignLiteral("&U");
57 mFooterStrs[0].AssignLiteral(
58 "&PT"); // Use &P (Page Num Only) or &PT (Page Num of Page Total)
59 mFooterStrs[2].AssignLiteral("&D");
62 void nsPrintSettings::InitWithInitializer(
63 const PrintSettingsInitializer& aSettings) {
64 const double kInchesPerPoint = 1.0 / 72.0;
66 SetPrinterName(aSettings.mPrinter);
67 SetPrintInColor(aSettings.mPrintInColor);
68 SetResolution(aSettings.mResolution);
69 // The paper ID used by nsPrintSettings is the non-localizable identifier
70 // exposed as "id" by the paper, not the potentially localized human-friendly
71 // "name", which could change, e.g. if the user changes their system locale.
72 SetPaperId(aSettings.mPaperInfo.mId);
73 SetPaperWidth(aSettings.mPaperInfo.mSize.Width() * kInchesPerPoint);
74 SetPaperHeight(aSettings.mPaperInfo.mSize.Height() * kInchesPerPoint);
75 SetPaperSizeUnit(nsIPrintSettings::kPaperSizeInches);
77 if (aSettings.mPaperInfo.mUnwriteableMargin) {
78 const auto& margin = aSettings.mPaperInfo.mUnwriteableMargin.value();
79 // Margins are stored internally in TWIPS, but the setters expect inches.
80 SetUnwriteableMarginTop(margin.top * kInchesPerPoint);
81 SetUnwriteableMarginRight(margin.right * kInchesPerPoint);
82 SetUnwriteableMarginBottom(margin.bottom * kInchesPerPoint);
83 SetUnwriteableMarginLeft(margin.left * kInchesPerPoint);
86 // Set this last because other setters may overwrite its value.
87 SetIsInitializedFromPrinter(true);
90 nsPrintSettings::nsPrintSettings(const nsPrintSettings& aPS) { *this = aPS; }
92 nsPrintSettings::~nsPrintSettings() = default;
94 NS_IMETHODIMP nsPrintSettings::GetPrintSession(
95 nsIPrintSession** aPrintSession) {
96 NS_ENSURE_ARG_POINTER(aPrintSession);
97 *aPrintSession = nullptr;
99 nsCOMPtr<nsIPrintSession> session = do_QueryReferent(mSession);
100 if (!session) return NS_ERROR_NOT_INITIALIZED;
101 *aPrintSession = session;
102 NS_ADDREF(*aPrintSession);
103 return NS_OK;
106 NS_IMETHODIMP nsPrintSettings::SetPrintSession(nsIPrintSession* aPrintSession) {
107 // Clearing it by passing nullptr is not allowed. That's why we
108 // use a weak ref so that it doesn't have to be cleared.
109 NS_ENSURE_ARG(aPrintSession);
111 mSession = do_GetWeakReference(aPrintSession);
112 if (!mSession) {
113 // This may happen if the implementation of this object does
114 // not support weak references - programmer error.
115 NS_ERROR("Could not get a weak reference from aPrintSession");
116 return NS_ERROR_FAILURE;
118 return NS_OK;
121 NS_IMETHODIMP nsPrintSettings::GetPrintReversed(bool* aPrintReversed) {
122 *aPrintReversed = mPrintReversed;
123 return NS_OK;
125 NS_IMETHODIMP nsPrintSettings::SetPrintReversed(bool aPrintReversed) {
126 mPrintReversed = aPrintReversed;
127 return NS_OK;
130 NS_IMETHODIMP nsPrintSettings::GetPrintInColor(bool* aPrintInColor) {
131 *aPrintInColor = mPrintInColor;
132 return NS_OK;
134 NS_IMETHODIMP nsPrintSettings::SetPrintInColor(bool aPrintInColor) {
135 mPrintInColor = aPrintInColor;
136 return NS_OK;
139 NS_IMETHODIMP nsPrintSettings::GetOrientation(int32_t* aOrientation) {
140 *aOrientation = mOrientation;
141 return NS_OK;
143 NS_IMETHODIMP nsPrintSettings::SetOrientation(int32_t aOrientation) {
144 mOrientation = aOrientation;
145 return NS_OK;
148 NS_IMETHODIMP nsPrintSettings::GetResolution(int32_t* aResolution) {
149 NS_ENSURE_ARG_POINTER(aResolution);
150 *aResolution = mResolution;
151 return NS_OK;
153 NS_IMETHODIMP nsPrintSettings::SetResolution(const int32_t aResolution) {
154 mResolution = aResolution;
155 return NS_OK;
158 NS_IMETHODIMP nsPrintSettings::GetDuplex(int32_t* aDuplex) {
159 NS_ENSURE_ARG_POINTER(aDuplex);
160 *aDuplex = mDuplex;
161 return NS_OK;
163 NS_IMETHODIMP nsPrintSettings::SetDuplex(const int32_t aDuplex) {
164 mDuplex = aDuplex;
165 return NS_OK;
168 NS_IMETHODIMP nsPrintSettings::GetPrinterName(nsAString& aPrinter) {
169 aPrinter = mPrinter;
170 return NS_OK;
173 NS_IMETHODIMP nsPrintSettings::SetPrinterName(const nsAString& aPrinter) {
174 if (!mPrinter.Equals(aPrinter)) {
175 mIsInitedFromPrinter = false;
176 mIsInitedFromPrefs = false;
179 mPrinter.Assign(aPrinter);
180 return NS_OK;
183 NS_IMETHODIMP nsPrintSettings::GetNumCopies(int32_t* aNumCopies) {
184 NS_ENSURE_ARG_POINTER(aNumCopies);
185 *aNumCopies = mNumCopies;
186 return NS_OK;
188 NS_IMETHODIMP nsPrintSettings::SetNumCopies(int32_t aNumCopies) {
189 mNumCopies = aNumCopies;
190 return NS_OK;
193 NS_IMETHODIMP nsPrintSettings::GetNumPagesPerSheet(int32_t* aNumPagesPerSheet) {
194 NS_ENSURE_ARG_POINTER(aNumPagesPerSheet);
195 *aNumPagesPerSheet = mNumPagesPerSheet;
196 return NS_OK;
198 NS_IMETHODIMP nsPrintSettings::SetNumPagesPerSheet(int32_t aNumPagesPerSheet) {
199 mNumPagesPerSheet = aNumPagesPerSheet;
200 return NS_OK;
203 NS_IMETHODIMP nsPrintSettings::GetPrintToFile(bool* aPrintToFile) {
204 NS_ENSURE_ARG_POINTER(aPrintToFile);
205 *aPrintToFile = mPrintToFile;
206 return NS_OK;
208 NS_IMETHODIMP nsPrintSettings::SetPrintToFile(bool aPrintToFile) {
209 mPrintToFile = aPrintToFile;
210 return NS_OK;
213 NS_IMETHODIMP nsPrintSettings::GetToFileName(nsAString& aToFileName) {
214 aToFileName = mToFileName;
215 return NS_OK;
217 NS_IMETHODIMP nsPrintSettings::SetToFileName(const nsAString& aToFileName) {
218 mToFileName = aToFileName;
219 return NS_OK;
222 NS_IMETHODIMP nsPrintSettings::GetOutputFormat(int16_t* aOutputFormat) {
223 NS_ENSURE_ARG_POINTER(aOutputFormat);
224 *aOutputFormat = mOutputFormat;
225 return NS_OK;
227 NS_IMETHODIMP nsPrintSettings::SetOutputFormat(int16_t aOutputFormat) {
228 mOutputFormat = aOutputFormat;
229 return NS_OK;
232 NS_IMETHODIMP nsPrintSettings::GetPrintPageDelay(int32_t* aPrintPageDelay) {
233 *aPrintPageDelay = mPrintPageDelay;
234 return NS_OK;
236 NS_IMETHODIMP nsPrintSettings::SetPrintPageDelay(int32_t aPrintPageDelay) {
237 mPrintPageDelay = aPrintPageDelay;
238 return NS_OK;
241 NS_IMETHODIMP nsPrintSettings::GetIsInitializedFromPrinter(
242 bool* aIsInitializedFromPrinter) {
243 NS_ENSURE_ARG_POINTER(aIsInitializedFromPrinter);
244 *aIsInitializedFromPrinter = mIsInitedFromPrinter;
245 return NS_OK;
247 NS_IMETHODIMP nsPrintSettings::SetIsInitializedFromPrinter(
248 bool aIsInitializedFromPrinter) {
249 mIsInitedFromPrinter = aIsInitializedFromPrinter;
250 return NS_OK;
253 NS_IMETHODIMP nsPrintSettings::GetIsInitializedFromPrefs(
254 bool* aInitializedFromPrefs) {
255 NS_ENSURE_ARG_POINTER(aInitializedFromPrefs);
256 *aInitializedFromPrefs = mIsInitedFromPrefs;
257 return NS_OK;
259 NS_IMETHODIMP nsPrintSettings::SetIsInitializedFromPrefs(
260 bool aInitializedFromPrefs) {
261 mIsInitedFromPrefs = aInitializedFromPrefs;
262 return NS_OK;
265 NS_IMETHODIMP nsPrintSettings::GetMarginTop(double* aMarginTop) {
266 NS_ENSURE_ARG_POINTER(aMarginTop);
267 *aMarginTop = NS_TWIPS_TO_INCHES(mMargin.top);
268 return NS_OK;
270 NS_IMETHODIMP nsPrintSettings::SetMarginTop(double aMarginTop) {
271 mMargin.top = NS_INCHES_TO_INT_TWIPS(float(aMarginTop));
272 return NS_OK;
275 NS_IMETHODIMP nsPrintSettings::GetMarginLeft(double* aMarginLeft) {
276 NS_ENSURE_ARG_POINTER(aMarginLeft);
277 *aMarginLeft = NS_TWIPS_TO_INCHES(mMargin.left);
278 return NS_OK;
280 NS_IMETHODIMP nsPrintSettings::SetMarginLeft(double aMarginLeft) {
281 mMargin.left = NS_INCHES_TO_INT_TWIPS(float(aMarginLeft));
282 return NS_OK;
285 NS_IMETHODIMP nsPrintSettings::GetMarginBottom(double* aMarginBottom) {
286 NS_ENSURE_ARG_POINTER(aMarginBottom);
287 *aMarginBottom = NS_TWIPS_TO_INCHES(mMargin.bottom);
288 return NS_OK;
290 NS_IMETHODIMP nsPrintSettings::SetMarginBottom(double aMarginBottom) {
291 mMargin.bottom = NS_INCHES_TO_INT_TWIPS(float(aMarginBottom));
292 return NS_OK;
295 NS_IMETHODIMP nsPrintSettings::GetMarginRight(double* aMarginRight) {
296 NS_ENSURE_ARG_POINTER(aMarginRight);
297 *aMarginRight = NS_TWIPS_TO_INCHES(mMargin.right);
298 return NS_OK;
300 NS_IMETHODIMP nsPrintSettings::SetMarginRight(double aMarginRight) {
301 mMargin.right = NS_INCHES_TO_INT_TWIPS(float(aMarginRight));
302 return NS_OK;
305 NS_IMETHODIMP nsPrintSettings::GetEdgeTop(double* aEdgeTop) {
306 NS_ENSURE_ARG_POINTER(aEdgeTop);
307 *aEdgeTop = NS_TWIPS_TO_INCHES(mEdge.top);
308 return NS_OK;
310 NS_IMETHODIMP nsPrintSettings::SetEdgeTop(double aEdgeTop) {
311 mEdge.top = NS_INCHES_TO_INT_TWIPS(float(aEdgeTop));
312 return NS_OK;
315 NS_IMETHODIMP nsPrintSettings::GetEdgeLeft(double* aEdgeLeft) {
316 NS_ENSURE_ARG_POINTER(aEdgeLeft);
317 *aEdgeLeft = NS_TWIPS_TO_INCHES(mEdge.left);
318 return NS_OK;
320 NS_IMETHODIMP nsPrintSettings::SetEdgeLeft(double aEdgeLeft) {
321 mEdge.left = NS_INCHES_TO_INT_TWIPS(float(aEdgeLeft));
322 return NS_OK;
325 NS_IMETHODIMP nsPrintSettings::GetEdgeBottom(double* aEdgeBottom) {
326 NS_ENSURE_ARG_POINTER(aEdgeBottom);
327 *aEdgeBottom = NS_TWIPS_TO_INCHES(mEdge.bottom);
328 return NS_OK;
330 NS_IMETHODIMP nsPrintSettings::SetEdgeBottom(double aEdgeBottom) {
331 mEdge.bottom = NS_INCHES_TO_INT_TWIPS(float(aEdgeBottom));
332 return NS_OK;
335 NS_IMETHODIMP nsPrintSettings::GetEdgeRight(double* aEdgeRight) {
336 NS_ENSURE_ARG_POINTER(aEdgeRight);
337 *aEdgeRight = NS_TWIPS_TO_INCHES(mEdge.right);
338 return NS_OK;
340 NS_IMETHODIMP nsPrintSettings::SetEdgeRight(double aEdgeRight) {
341 mEdge.right = NS_INCHES_TO_INT_TWIPS(float(aEdgeRight));
342 return NS_OK;
345 NS_IMETHODIMP nsPrintSettings::GetUnwriteableMarginTop(
346 double* aUnwriteableMarginTop) {
347 NS_ENSURE_ARG_POINTER(aUnwriteableMarginTop);
348 *aUnwriteableMarginTop = NS_TWIPS_TO_INCHES(mUnwriteableMargin.top);
349 return NS_OK;
351 NS_IMETHODIMP nsPrintSettings::SetUnwriteableMarginTop(
352 double aUnwriteableMarginTop) {
353 if (aUnwriteableMarginTop >= 0.0) {
354 mUnwriteableMargin.top = NS_INCHES_TO_INT_TWIPS(aUnwriteableMarginTop);
356 return NS_OK;
359 NS_IMETHODIMP nsPrintSettings::GetUnwriteableMarginLeft(
360 double* aUnwriteableMarginLeft) {
361 NS_ENSURE_ARG_POINTER(aUnwriteableMarginLeft);
362 *aUnwriteableMarginLeft = NS_TWIPS_TO_INCHES(mUnwriteableMargin.left);
363 return NS_OK;
365 NS_IMETHODIMP nsPrintSettings::SetUnwriteableMarginLeft(
366 double aUnwriteableMarginLeft) {
367 if (aUnwriteableMarginLeft >= 0.0) {
368 mUnwriteableMargin.left = NS_INCHES_TO_INT_TWIPS(aUnwriteableMarginLeft);
370 return NS_OK;
373 NS_IMETHODIMP nsPrintSettings::GetUnwriteableMarginBottom(
374 double* aUnwriteableMarginBottom) {
375 NS_ENSURE_ARG_POINTER(aUnwriteableMarginBottom);
376 *aUnwriteableMarginBottom = NS_TWIPS_TO_INCHES(mUnwriteableMargin.bottom);
377 return NS_OK;
379 NS_IMETHODIMP nsPrintSettings::SetUnwriteableMarginBottom(
380 double aUnwriteableMarginBottom) {
381 if (aUnwriteableMarginBottom >= 0.0) {
382 mUnwriteableMargin.bottom =
383 NS_INCHES_TO_INT_TWIPS(aUnwriteableMarginBottom);
385 return NS_OK;
388 NS_IMETHODIMP nsPrintSettings::GetUnwriteableMarginRight(
389 double* aUnwriteableMarginRight) {
390 NS_ENSURE_ARG_POINTER(aUnwriteableMarginRight);
391 *aUnwriteableMarginRight = NS_TWIPS_TO_INCHES(mUnwriteableMargin.right);
392 return NS_OK;
394 NS_IMETHODIMP nsPrintSettings::SetUnwriteableMarginRight(
395 double aUnwriteableMarginRight) {
396 if (aUnwriteableMarginRight >= 0.0) {
397 mUnwriteableMargin.right = NS_INCHES_TO_INT_TWIPS(aUnwriteableMarginRight);
399 return NS_OK;
402 NS_IMETHODIMP nsPrintSettings::GetScaling(double* aScaling) {
403 NS_ENSURE_ARG_POINTER(aScaling);
404 *aScaling = mScaling;
405 return NS_OK;
408 NS_IMETHODIMP nsPrintSettings::SetScaling(double aScaling) {
409 mScaling = aScaling;
410 return NS_OK;
413 NS_IMETHODIMP nsPrintSettings::GetPrintBGColors(bool* aPrintBGColors) {
414 NS_ENSURE_ARG_POINTER(aPrintBGColors);
415 *aPrintBGColors = mPrintBGColors;
416 return NS_OK;
418 NS_IMETHODIMP nsPrintSettings::SetPrintBGColors(bool aPrintBGColors) {
419 mPrintBGColors = aPrintBGColors;
420 return NS_OK;
423 NS_IMETHODIMP nsPrintSettings::GetPrintBGImages(bool* aPrintBGImages) {
424 NS_ENSURE_ARG_POINTER(aPrintBGImages);
425 *aPrintBGImages = mPrintBGImages;
426 return NS_OK;
428 NS_IMETHODIMP nsPrintSettings::SetPrintBGImages(bool aPrintBGImages) {
429 mPrintBGImages = aPrintBGImages;
430 return NS_OK;
433 NS_IMETHODIMP nsPrintSettings::GetTitle(nsAString& aTitle) {
434 aTitle = mTitle;
435 return NS_OK;
437 NS_IMETHODIMP nsPrintSettings::SetTitle(const nsAString& aTitle) {
438 mTitle = aTitle;
439 return NS_OK;
442 NS_IMETHODIMP nsPrintSettings::GetDocURL(nsAString& aDocURL) {
443 aDocURL = mURL;
444 return NS_OK;
446 NS_IMETHODIMP nsPrintSettings::SetDocURL(const nsAString& aDocURL) {
447 mURL = aDocURL;
448 return NS_OK;
451 NS_IMETHODIMP nsPrintSettings::GetHeaderStrLeft(nsAString& aTitle) {
452 aTitle = mHeaderStrs[0];
453 return NS_OK;
455 NS_IMETHODIMP nsPrintSettings::SetHeaderStrLeft(const nsAString& aTitle) {
456 mHeaderStrs[0] = aTitle;
457 return NS_OK;
460 NS_IMETHODIMP nsPrintSettings::GetHeaderStrCenter(nsAString& aTitle) {
461 aTitle = mHeaderStrs[1];
462 return NS_OK;
464 NS_IMETHODIMP nsPrintSettings::SetHeaderStrCenter(const nsAString& aTitle) {
465 mHeaderStrs[1] = aTitle;
466 return NS_OK;
469 NS_IMETHODIMP nsPrintSettings::GetHeaderStrRight(nsAString& aTitle) {
470 aTitle = mHeaderStrs[2];
471 return NS_OK;
473 NS_IMETHODIMP nsPrintSettings::SetHeaderStrRight(const nsAString& aTitle) {
474 mHeaderStrs[2] = aTitle;
475 return NS_OK;
478 NS_IMETHODIMP nsPrintSettings::GetFooterStrLeft(nsAString& aTitle) {
479 aTitle = mFooterStrs[0];
480 return NS_OK;
482 NS_IMETHODIMP nsPrintSettings::SetFooterStrLeft(const nsAString& aTitle) {
483 mFooterStrs[0] = aTitle;
484 return NS_OK;
487 NS_IMETHODIMP nsPrintSettings::GetFooterStrCenter(nsAString& aTitle) {
488 aTitle = mFooterStrs[1];
489 return NS_OK;
491 NS_IMETHODIMP nsPrintSettings::SetFooterStrCenter(const nsAString& aTitle) {
492 mFooterStrs[1] = aTitle;
493 return NS_OK;
496 NS_IMETHODIMP nsPrintSettings::GetFooterStrRight(nsAString& aTitle) {
497 aTitle = mFooterStrs[2];
498 return NS_OK;
500 NS_IMETHODIMP nsPrintSettings::SetFooterStrRight(const nsAString& aTitle) {
501 mFooterStrs[2] = aTitle;
502 return NS_OK;
505 NS_IMETHODIMP nsPrintSettings::GetPrintSilent(bool* aPrintSilent) {
506 NS_ENSURE_ARG_POINTER(aPrintSilent);
507 *aPrintSilent = mPrintSilent;
508 return NS_OK;
510 NS_IMETHODIMP nsPrintSettings::SetPrintSilent(bool aPrintSilent) {
511 mPrintSilent = aPrintSilent;
512 return NS_OK;
515 NS_IMETHODIMP nsPrintSettings::GetShrinkToFit(bool* aShrinkToFit) {
516 NS_ENSURE_ARG_POINTER(aShrinkToFit);
517 *aShrinkToFit = mShrinkToFit;
518 return NS_OK;
520 NS_IMETHODIMP nsPrintSettings::SetShrinkToFit(bool aShrinkToFit) {
521 mShrinkToFit = aShrinkToFit;
522 return NS_OK;
525 NS_IMETHODIMP nsPrintSettings::GetShowPrintProgress(bool* aShowPrintProgress) {
526 NS_ENSURE_ARG_POINTER(aShowPrintProgress);
527 *aShowPrintProgress = mShowPrintProgress;
528 return NS_OK;
530 NS_IMETHODIMP nsPrintSettings::SetShowPrintProgress(bool aShowPrintProgress) {
531 mShowPrintProgress = aShowPrintProgress;
532 return NS_OK;
535 NS_IMETHODIMP nsPrintSettings::GetShowMarginGuides(bool* aShowMarginGuides) {
536 *aShowMarginGuides = mShowMarginGuides;
537 return NS_OK;
540 NS_IMETHODIMP nsPrintSettings::SetShowMarginGuides(bool aShowMarginGuides) {
541 mShowMarginGuides = aShowMarginGuides;
542 return NS_OK;
545 NS_IMETHODIMP nsPrintSettings::GetHonorPageRuleMargins(bool* aResult) {
546 *aResult = mHonorPageRuleMargins;
547 return NS_OK;
550 NS_IMETHODIMP nsPrintSettings::SetHonorPageRuleMargins(bool aHonor) {
551 mHonorPageRuleMargins = aHonor;
552 return NS_OK;
555 NS_IMETHODIMP nsPrintSettings::GetIsPrintSelectionRBEnabled(
556 bool* aIsPrintSelectionRBEnabled) {
557 *aIsPrintSelectionRBEnabled = mIsPrintSelectionRBEnabled;
558 return NS_OK;
560 NS_IMETHODIMP nsPrintSettings::SetIsPrintSelectionRBEnabled(
561 bool aIsPrintSelectionRBEnabled) {
562 mIsPrintSelectionRBEnabled = aIsPrintSelectionRBEnabled;
563 return NS_OK;
566 NS_IMETHODIMP nsPrintSettings::GetPrintSelectionOnly(bool* aResult) {
567 *aResult = mPrintSelectionOnly;
568 return NS_OK;
571 NS_IMETHODIMP nsPrintSettings::SetPrintSelectionOnly(bool aSelectionOnly) {
572 mPrintSelectionOnly = aSelectionOnly;
573 return NS_OK;
576 NS_IMETHODIMP nsPrintSettings::GetPaperId(nsAString& aPaperId) {
577 aPaperId = mPaperId;
578 return NS_OK;
580 NS_IMETHODIMP nsPrintSettings::SetPaperId(const nsAString& aPaperId) {
581 mPaperId = aPaperId;
582 return NS_OK;
585 NS_IMETHODIMP nsPrintSettings::GetIsCancelled(bool* aIsCancelled) {
586 NS_ENSURE_ARG_POINTER(aIsCancelled);
587 *aIsCancelled = mIsCancelled;
588 return NS_OK;
590 NS_IMETHODIMP nsPrintSettings::SetIsCancelled(bool aIsCancelled) {
591 mIsCancelled = aIsCancelled;
592 return NS_OK;
595 NS_IMETHODIMP nsPrintSettings::GetSaveOnCancel(bool* aSaveOnCancel) {
596 *aSaveOnCancel = mSaveOnCancel;
597 return NS_OK;
600 NS_IMETHODIMP nsPrintSettings::GetPaperWidth(double* aPaperWidth) {
601 NS_ENSURE_ARG_POINTER(aPaperWidth);
602 *aPaperWidth = mPaperWidth;
603 return NS_OK;
605 NS_IMETHODIMP nsPrintSettings::SetPaperWidth(double aPaperWidth) {
606 mPaperWidth = aPaperWidth;
607 return NS_OK;
610 NS_IMETHODIMP nsPrintSettings::GetPaperHeight(double* aPaperHeight) {
611 NS_ENSURE_ARG_POINTER(aPaperHeight);
612 *aPaperHeight = mPaperHeight;
613 return NS_OK;
615 NS_IMETHODIMP nsPrintSettings::SetPaperHeight(double aPaperHeight) {
616 mPaperHeight = aPaperHeight;
617 return NS_OK;
620 NS_IMETHODIMP nsPrintSettings::GetPaperSizeUnit(int16_t* aPaperSizeUnit) {
621 NS_ENSURE_ARG_POINTER(aPaperSizeUnit);
622 *aPaperSizeUnit = mPaperSizeUnit;
623 return NS_OK;
625 NS_IMETHODIMP nsPrintSettings::SetPaperSizeUnit(int16_t aPaperSizeUnit) {
626 mPaperSizeUnit = aPaperSizeUnit;
627 return NS_OK;
630 /** ---------------------------------------------------
631 * See documentation in nsPrintSettingsService.h
632 * @update 6/21/00 dwc
633 * @update 1/12/01 rods
635 NS_IMETHODIMP
636 nsPrintSettings::SetMarginInTwips(nsIntMargin& aMargin) {
637 mMargin = aMargin;
638 return NS_OK;
641 NS_IMETHODIMP
642 nsPrintSettings::SetEdgeInTwips(nsIntMargin& aEdge) {
643 mEdge = aEdge;
644 return NS_OK;
647 // NOTE: Any subclass implementation of this function should make sure
648 // to check for negative margin values in aUnwriteableMargin (which
649 // would indicate that we should use the system default unwriteable margin.)
650 NS_IMETHODIMP
651 nsPrintSettings::SetUnwriteableMarginInTwips(nsIntMargin& aUnwriteableMargin) {
652 if (aUnwriteableMargin.top >= 0) {
653 mUnwriteableMargin.top = aUnwriteableMargin.top;
655 if (aUnwriteableMargin.left >= 0) {
656 mUnwriteableMargin.left = aUnwriteableMargin.left;
658 if (aUnwriteableMargin.bottom >= 0) {
659 mUnwriteableMargin.bottom = aUnwriteableMargin.bottom;
661 if (aUnwriteableMargin.right >= 0) {
662 mUnwriteableMargin.right = aUnwriteableMargin.right;
664 return NS_OK;
667 nsIntMargin nsPrintSettings::GetMarginInTwips() { return mMargin; }
669 nsIntMargin nsPrintSettings::GetEdgeInTwips() { return mEdge; }
671 nsIntMargin nsPrintSettings::GetUnwriteableMarginInTwips() {
672 return mUnwriteableMargin;
675 /** ---------------------------------------------------
676 * Stub - platform-specific implementations can use this function.
678 NS_IMETHODIMP
679 nsPrintSettings::SetupSilentPrinting() { return NS_OK; }
681 /** ---------------------------------------------------
682 * See documentation in nsPrintSettingsService.h
684 NS_IMETHODIMP
685 nsPrintSettings::GetEffectivePageSize(double* aWidth, double* aHeight) {
686 if (mPaperSizeUnit == kPaperSizeInches) {
687 *aWidth = NS_INCHES_TO_TWIPS(float(mPaperWidth));
688 *aHeight = NS_INCHES_TO_TWIPS(float(mPaperHeight));
689 } else {
690 MOZ_ASSERT(mPaperSizeUnit == kPaperSizeMillimeters,
691 "unexpected paper size unit");
692 *aWidth = NS_MILLIMETERS_TO_TWIPS(float(mPaperWidth));
693 *aHeight = NS_MILLIMETERS_TO_TWIPS(float(mPaperHeight));
695 if (kLandscapeOrientation == mOrientation) {
696 double temp = *aWidth;
697 *aWidth = *aHeight;
698 *aHeight = temp;
700 return NS_OK;
703 bool nsPrintSettings::HasOrthogonalSheetsAndPages() {
704 return mNumPagesPerSheet == 2 || mNumPagesPerSheet == 6;
707 void nsPrintSettings::GetEffectiveSheetSize(double* aWidth, double* aHeight) {
708 mozilla::DebugOnly<nsresult> rv = GetEffectivePageSize(aWidth, aHeight);
710 // Our GetEffectivePageSize impls only return NS_OK, so this should hold:
711 MOZ_ASSERT(NS_SUCCEEDED(rv), "Uh oh, GetEffectivePageSize failed");
713 if (HasOrthogonalSheetsAndPages()) {
714 std::swap(*aWidth, *aHeight);
718 int32_t nsPrintSettings::GetSheetOrientation() {
719 if (HasOrthogonalSheetsAndPages()) {
720 // Sheet orientation is rotated with respect to the page orientation.
721 return kLandscapeOrientation == mOrientation ? kPortraitOrientation
722 : kLandscapeOrientation;
725 // Sheet orientation is the same as the page orientation.
726 return mOrientation;
729 NS_IMETHODIMP
730 nsPrintSettings::SetPageRanges(const nsTArray<int32_t>& aPages) {
731 // Needs to be a set of (start, end) pairs.
732 if (aPages.Length() % 2 != 0) {
733 return NS_ERROR_FAILURE;
735 mPageRanges = aPages.Clone();
736 return NS_OK;
739 NS_IMETHODIMP
740 nsPrintSettings::GetPageRanges(nsTArray<int32_t>& aPages) {
741 aPages = mPageRanges.Clone();
742 return NS_OK;
745 bool nsIPrintSettings::IsPageSkipped(int32_t aPageNum,
746 const nsTArray<int32_t>& aRanges) {
747 MOZ_RELEASE_ASSERT(aRanges.Length() % 2 == 0);
748 if (aRanges.IsEmpty()) {
749 return false;
751 for (size_t i = 0; i < aRanges.Length(); i += 2) {
752 if (aRanges[i] <= aPageNum && aPageNum <= aRanges[i + 1]) {
753 // The page is included in this piece of the custom range,
754 // so it's not skipped.
755 return false;
758 return true;
761 nsresult nsPrintSettings::_Clone(nsIPrintSettings** _retval) {
762 RefPtr<nsPrintSettings> printSettings = new nsPrintSettings(*this);
763 printSettings.forget(_retval);
764 return NS_OK;
767 NS_IMETHODIMP
768 nsPrintSettings::Clone(nsIPrintSettings** _retval) {
769 NS_ENSURE_ARG_POINTER(_retval);
770 return _Clone(_retval);
773 nsresult nsPrintSettings::_Assign(nsIPrintSettings* aPS) {
774 nsPrintSettings* ps = static_cast<nsPrintSettings*>(aPS);
775 *this = *ps;
776 return NS_OK;
779 NS_IMETHODIMP
780 nsPrintSettings::Assign(nsIPrintSettings* aPS) {
781 NS_ENSURE_ARG(aPS);
782 return _Assign(aPS);
785 //-------------------------------------------
786 nsPrintSettings& nsPrintSettings::operator=(const nsPrintSettings& rhs) {
787 if (this == &rhs) {
788 return *this;
791 mPageRanges = rhs.mPageRanges.Clone();
792 mMargin = rhs.mMargin;
793 mEdge = rhs.mEdge;
794 mUnwriteableMargin = rhs.mUnwriteableMargin;
795 mScaling = rhs.mScaling;
796 mPrintBGColors = rhs.mPrintBGColors;
797 mPrintBGImages = rhs.mPrintBGImages;
798 mTitle = rhs.mTitle;
799 mURL = rhs.mURL;
800 mIsCancelled = rhs.mIsCancelled;
801 mSaveOnCancel = rhs.mSaveOnCancel;
802 mPrintSilent = rhs.mPrintSilent;
803 mShrinkToFit = rhs.mShrinkToFit;
804 mShowPrintProgress = rhs.mShowPrintProgress;
805 mShowMarginGuides = rhs.mShowMarginGuides;
806 mHonorPageRuleMargins = rhs.mHonorPageRuleMargins;
807 mIsPrintSelectionRBEnabled = rhs.mIsPrintSelectionRBEnabled;
808 mPrintSelectionOnly = rhs.mPrintSelectionOnly;
809 mPaperId = rhs.mPaperId;
810 mPaperWidth = rhs.mPaperWidth;
811 mPaperHeight = rhs.mPaperHeight;
812 mPaperSizeUnit = rhs.mPaperSizeUnit;
813 mPrintReversed = rhs.mPrintReversed;
814 mPrintInColor = rhs.mPrintInColor;
815 mOrientation = rhs.mOrientation;
816 mResolution = rhs.mResolution;
817 mDuplex = rhs.mDuplex;
818 mNumCopies = rhs.mNumCopies;
819 mNumPagesPerSheet = rhs.mNumPagesPerSheet;
820 mPrinter = rhs.mPrinter;
821 mPrintToFile = rhs.mPrintToFile;
822 mToFileName = rhs.mToFileName;
823 mOutputFormat = rhs.mOutputFormat;
824 mIsInitedFromPrinter = rhs.mIsInitedFromPrinter;
825 mIsInitedFromPrefs = rhs.mIsInitedFromPrefs;
826 mPrintPageDelay = rhs.mPrintPageDelay;
828 for (int32_t i = 0; i < NUM_HEAD_FOOT; i++) {
829 mHeaderStrs[i] = rhs.mHeaderStrs[i];
830 mFooterStrs[i] = rhs.mFooterStrs[i];
833 return *this;
836 void nsPrintSettings::SetDefaultFileName() {
837 nsAutoString filename;
838 nsresult rv = GetToFileName(filename);
839 if (NS_FAILED(rv) || filename.IsEmpty()) {
840 const char* path = PR_GetEnv("PWD");
841 if (!path) {
842 path = PR_GetEnv("HOME");
845 if (path) {
846 CopyUTF8toUTF16(mozilla::MakeStringSpan(path), filename);
847 filename.AppendLiteral("/mozilla.pdf");
848 } else {
849 filename.AssignLiteral("mozilla.pdf");
852 SetToFileName(filename);