Bug 1715716 [wpt PR 29323] - Use unittest.mock instead of the mock package, a=testonly
[gecko.git] / widget / nsIPrintSettings.idl
blobc3624c1a44991c6db4bb10368a7bda9579fde596
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "nsISupports.idl"
9 %{ C++
10 #include "nsMargin.h"
11 #include "nsTArray.h"
14 /**
15 * Native types
17 native nsNativeIntMargin(nsIntMargin);
18 [ref] native nsNativeIntMarginRef(nsIntMargin);
20 interface nsIPrintSession;
22 /**
23 * Simplified graphics interface for JS rendering.
25 [scriptable, builtinclass, uuid(ecc5cbad-57fc-4731-b0bd-09e865bd62ad)]
26 interface nsIPrintSettings : nsISupports
28 /**
29 * PrintSettings to be Saved Navigation Constants
31 /* Flag 0x00000001 is unused */
32 const unsigned long kInitSaveHeaderLeft = 0x00000002;
33 const unsigned long kInitSaveHeaderCenter = 0x00000004;
34 const unsigned long kInitSaveHeaderRight = 0x00000008;
35 const unsigned long kInitSaveFooterLeft = 0x00000010;
36 const unsigned long kInitSaveFooterCenter = 0x00000020;
37 const unsigned long kInitSaveFooterRight = 0x00000040;
38 const unsigned long kInitSaveBGColors = 0x00000080;
39 const unsigned long kInitSaveBGImages = 0x00000100;
40 const unsigned long kInitSavePaperSize = 0x00000200;
41 const unsigned long kInitSaveResolution = 0x00000400;
42 const unsigned long kInitSaveDuplex = 0x00000800;
43 /* Flag 0x00001000 is unused */
44 /* Flag 0x00002000 is unused */
45 const unsigned long kInitSaveUnwriteableMargins = 0x00004000;
46 const unsigned long kInitSaveEdges = 0x00008000;
48 const unsigned long kInitSaveReversed = 0x00010000;
49 const unsigned long kInitSaveInColor = 0x00020000;
50 const unsigned long kInitSaveOrientation = 0x00040000;
52 const unsigned long kInitSavePrinterName = 0x00100000;
53 const unsigned long kInitSavePrintToFile = 0x00200000;
54 const unsigned long kInitSaveToFileName = 0x00400000;
55 const unsigned long kInitSavePageDelay = 0x00800000;
56 const unsigned long kInitSaveMargins = 0x01000000;
57 const unsigned long kInitSaveNativeData = 0x02000000;
59 const unsigned long kInitSaveShrinkToFit = 0x08000000;
60 const unsigned long kInitSaveScaling = 0x10000000;
62 const unsigned long kInitSaveAll = 0xFFFFFFFF;
64 // These settings should be read from global prefs. Other settings should be
65 // read only from printer-specific prefs.
66 const unsigned long kGlobalSettings =
67 kInitSaveHeaderLeft | kInitSaveHeaderCenter | kInitSaveHeaderRight |
68 kInitSaveFooterLeft | kInitSaveFooterCenter | kInitSaveFooterRight |
69 kInitSaveEdges | kInitSaveReversed | kInitSaveInColor |
70 kInitSaveBGColors | kInitSaveBGImages | kInitSaveShrinkToFit;
72 /* Justification Enums */
73 const long kJustLeft = 0;
74 const long kJustCenter = 1;
75 const long kJustRight = 2;
77 /**
78 * Page Size Unit Constants
80 const short kPaperSizeInches = 0;
81 const short kPaperSizeMillimeters = 1;
83 /**
84 * Orientation Constants
86 const short kPortraitOrientation = 0;
87 const short kLandscapeOrientation = 1;
89 /**
90 * Output file format
92 const short kOutputFormatNative = 0;
93 const short kOutputFormatPS = 1;
94 const short kOutputFormatPDF = 2;
96 /**
97 * Duplex printing options.
99 * Note that other libraries refer to equivalent duplex settings using
100 * various sets of terminology. This can be confusing and inconsistent both
101 * with other libraries, and with the behavior that these terms intend to describe.
103 * kDuplexNone is equivalent to Simplex. Thankfully, both of these terms are
104 * consistent with the behavior that they describe, which is to have single-sided
105 * printing per sheet.
107 * kDuplexFlipOnLongEdge is equivalent to the following platform-specific constants:
108 * CUPS/macOS: NoTumble
109 * Windows: DMDUP_VERTICAL
110 * GTK: GTK_PRINT_DUPLEX_HORIZONTAL
112 * kDuplexFlipOnShortEdge is equivalent to the following platform-specific constants:
113 * CUPS/macOS: Tumble
114 * Windows: DMDUP_HORIZONTAL
115 * GTK: GTK_PRINT_DUPLEX_VERTICAL
118 * Notice that the GTK and Windows constants have opposite meanings for
119 * VERTICAL and HORIZONTAL.
121 * To make matters more confusing, these platform-specific terms describe different
122 * behavior (from the user's perspective) depending on whether the sheet is in
123 * portrait vs. landscape orientation.
125 * For example, the generic term "tumble" describes behavior where a sheet flips over
126 * a binding on the top edge (like a calendar). This requires that the back side of
127 * the sheet is printed upside down with respect to the front side of the sheet,
128 * so that its content appears upright to the reader when they tumble-flip the
129 * sheet over the top-edge binding.
131 * However, the CUPS/macOS Tumble setting only inverts the back side of the
132 * sheet in portrait orientation. When you switch to landscape orientation, the
133 * Tumble setting behaves like a book-like sheet flip, where the front and back
134 * sides of the sheet are both printed upright with respect to each other.
136 * This is why it is more consistent and more clear to think of these terms
137 * with regard to sheets being bound on the long edge or the short edge.
139 * kDuplexFlipOnLongEdge + Portrait = book-like flip (front/back same direction)
140 * kDuplexFlipOnLongEdge + Landscape = calendar-like flip (front/back inverted)
142 * kDuplexFlipOnShortEdge + Portrait = calendar-like flip (front/back inverted)
143 * kDuplexFlipOnShortEdge + Landscape = book-like flip (front/back same direction)
145 * The long-edge and short-edge terminology unfortunately breaks down when printing
146 * with square sheet dimensions. Thankfully this edge case (hah) is quite uncommon,
147 * since most standard printing paper dimensions are not square. Such a paper size
148 * would even break the uniformly used portrait and landscape terminology.
150 const short kDuplexNone = 0;
151 const short kDuplexFlipOnLongEdge = 1;
152 const short kDuplexFlipOnShortEdge = 2;
155 * Get the page size in twips, considering the
156 * orientation (portrait or landscape).
158 void GetEffectivePageSize(out double aWidth, out double aHeight);
161 * Get the printed sheet size in twips, considering both the user-specified
162 * orientation (portrait or landscape) *as well as* the fact that we might be
163 * inverting the orientation to account for 2 or 6 pages-per-sheet.
165 * This API will usually behave the same (& return the same thing) as
166 * GetEffectivePageSize, *except for* when we are printing with 2 or 6
167 * pages-per-sheet, in which case the return values (aWidth & aHeight) will
168 * be swapped with respect to what GetEffectivePageSize would return.
170 * Callers should use this method rather than GetEffectivePageSize when they
171 * really do want the size of the sheet of paper to be printed, rather than
172 * the possibly-"virtualized"-via-pages-per-sheet page size.
174 [noscript, notxpcom, nostdcall] void GetEffectiveSheetSize(out double aWidth,
175 out double aHeight);
178 * Get the orientation of a printed sheet. This is usually the same as the
179 * 'orientation' attribute (which is the orientation of individual pages),
180 * except when we're printing with 2 or 6 pages-per-sheet, in which case
181 * it'll be the opposite value.
183 * Note that this value is not independently settable. Its value is fully
184 * determined by the 'orientation' and 'numPagesPerSheet' attributes.
186 [noscript, notxpcom, nostdcall] long GetSheetOrientation();
189 * Convenience getter, which returns true IFF the sheet orientation and the
190 * page orientation are orthogonal. (In other words, returns true IFF we
191 * are printing with 2 or 6 pages-per-sheet.)
193 [noscript, notxpcom, nostdcall] bool HasOrthogonalSheetsAndPages();
196 * Makes a new copy
198 nsIPrintSettings clone();
201 * Assigns the internal values from the "in" arg to the current object
203 void assign(in nsIPrintSettings aPS);
206 * Data Members
208 [noscript] attribute nsIPrintSession printSession; /* We hold a weak reference */
211 * The edge measurements define the positioning of the headers
212 * and footers on the page. They're treated as an offset from the edges of
213 * the page, but are forced to be at least the "unwriteable margin"
214 * (described below).
216 attribute double edgeTop; /* these are in inches */
217 attribute double edgeLeft;
218 attribute double edgeBottom;
219 attribute double edgeRight;
222 * The margins define the positioning of the content on the page.
223 * and footers on the page. They're treated as an offset from the edges of
224 * the page, but are forced to be at least the "unwriteable margin"
225 * (described below).
227 attribute double marginTop; /* these are in inches */
228 attribute double marginLeft;
229 attribute double marginBottom;
230 attribute double marginRight;
232 * The unwriteable margin defines the printable region of the paper.
234 attribute double unwriteableMarginTop; /* these are in inches */
235 attribute double unwriteableMarginLeft;
236 attribute double unwriteableMarginBottom;
237 attribute double unwriteableMarginRight;
239 attribute double scaling; /* values 0.0 - 1.0 */
240 [infallible] attribute boolean printBGColors; /* Print Background Colors */
241 [infallible] attribute boolean printBGImages; /* Print Background Images */
243 /** Whether @page rule margins should be honored or not. */
244 [infallible] attribute boolean honorPageRuleMargins;
246 /** Whether to draw guidelines showing the margin settings */
247 [infallible] attribute boolean showMarginGuides;
249 /** Whether whether the "print selection" radio button should be enabled
250 * in the UI (i.e. whether there is an active selection) */
251 [infallible] attribute boolean isPrintSelectionRBEnabled;
253 /** Whether to only print the selected nodes */
254 [infallible] attribute boolean printSelectionOnly;
256 attribute AString title;
257 attribute AString docURL;
259 attribute AString headerStrLeft;
260 attribute AString headerStrCenter;
261 attribute AString headerStrRight;
263 attribute AString footerStrLeft;
264 attribute AString footerStrCenter;
265 attribute AString footerStrRight;
267 attribute boolean isCancelled; /* indicates whether the print job has been cancelled */
268 readonly attribute boolean saveOnCancel; /* indicates whether the print settings should be saved after a cancel */
269 attribute boolean printSilent; /* print without putting up the dialog */
270 attribute boolean shrinkToFit; /* shrinks content to fit on page */
271 attribute boolean showPrintProgress; /* indicates whether the progress dialog should be shown */
273 /* Additional XP Related */
274 attribute AString paperId; /* identifier of paper (not display name) */
275 attribute double paperWidth; /* width of the paper in inches or mm */
276 attribute double paperHeight; /* height of the paper in inches or mm */
277 attribute short paperSizeUnit; /* paper is in inches or mm */
279 attribute boolean printReversed;
280 [infallible] attribute boolean printInColor; /* a false means grayscale */
281 attribute long orientation; /* see orientation consts */
282 attribute long numCopies;
285 * For numPagesPerSheet, we support these values: 1, 2, 4, 6, 9, 16.
287 * Unsupported values will be treated internally as 1 page per sheet, and
288 * will trigger assertion failures in debug builds.
290 attribute long numPagesPerSheet;
292 attribute AString printerName; /* name of destination printer */
294 attribute boolean printToFile;
295 attribute AString toFileName;
296 attribute short outputFormat;
298 attribute long printPageDelay; /* in milliseconds */
300 attribute long resolution; /* print resolution (dpi) */
302 attribute long duplex; /* duplex mode */
304 /* initialize helpers */
306 * This attribute tracks whether the PS has been initialized
307 * from a printer specified by the "printerName" attr.
308 * If a different name is set into the "printerName"
309 * attribute than the one it was initialized with the PS
310 * will then get intialized from that printer.
312 attribute boolean isInitializedFromPrinter;
315 * This attribute tracks whether the PS has been initialized
316 * from prefs. If a different name is set into the "printerName"
317 * attribute than the one it was initialized with the PS
318 * will then get intialized from prefs again.
320 attribute boolean isInitializedFromPrefs;
322 /* C++ Helper Functions */
323 [noscript] void SetMarginInTwips(in nsNativeIntMarginRef aMargin);
324 [noscript] void SetEdgeInTwips(in nsNativeIntMarginRef aEdge);
325 [noscript, notxpcom, nostdcall] nsNativeIntMargin GetMarginInTwips();
326 [noscript, notxpcom, nostdcall] nsNativeIntMargin GetEdgeInTwips();
329 * We call this function so that anything that requires a run of the event loop
330 * can do so safely. The print dialog runs the event loop but in silent printing
331 * that doesn't happen.
333 * Either this or ShowPrintDialog (but not both) MUST be called by the print engine
334 * before printing, otherwise printing can fail on some platforms.
336 [noscript] void SetupSilentPrinting();
339 * Sets/Gets the "unwriteable margin" for the page format. This defines
340 * the boundary from which we'll measure the EdgeInTwips and MarginInTwips
341 * attributes, to place the headers and content, respectively.
343 * Note: Implementations of SetUnwriteableMarginInTwips should handle
344 * negative margin values by falling back on the system default for
345 * that margin.
347 [noscript] void SetUnwriteableMarginInTwips(in nsNativeIntMarginRef aEdge);
348 [noscript, notxpcom, nostdcall] nsNativeIntMargin GetUnwriteableMarginInTwips();
351 * Get more accurate print ranges from the superior interval
352 * (startPageRange, endPageRange). The aPages array is populated with a
353 * list of pairs (start, end), where the endpoints are included. The print
354 * ranges (start, end), must not overlap and must be in the
355 * (startPageRange, endPageRange) scope.
357 * If there are no print ranges the aPages array is empty.
359 attribute Array<long> pageRanges;
361 %{C++
362 static bool IsPageSkipped(int32_t aPageNum, const nsTArray<int32_t>& aRanges);
366 %{ C++
367 namespace mozilla {
368 struct PrintSettingsInitializer;
371 already_AddRefed<nsIPrintSettings> CreatePlatformPrintSettings(const mozilla::PrintSettingsInitializer&);