Bug 1770025 [wpt PR 34116] - Update wpt metadata, a=testonly
[gecko.git] / widget / nsIPrintSettings.idl
blobc2da8f122c4c0d52b5da8fcc678f2d3e37c14507
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"
8 %{ C++
9 #include "nsMargin.h"
10 #include "nsTArray.h"
12 namespace mozilla {
13 struct PrintSettingsInitializer;
17 /**
18 * Native types
20 native nsNativeIntMargin(nsIntMargin);
21 [ref] native nsNativeIntMarginRef(nsIntMargin);
23 interface nsIOutputStream;
25 /**
26 * Simplified graphics interface for JS rendering.
28 [scriptable, builtinclass, uuid(ecc5cbad-57fc-4731-b0bd-09e865bd62ad)]
29 interface nsIPrintSettings : nsISupports
31 /**
32 * PrintSettings to be Saved Navigation Constants
34 /* Flag 0x00000001 is unused */
35 const unsigned long kInitSaveHeaderLeft = 0x00000002;
36 const unsigned long kInitSaveHeaderCenter = 0x00000004;
37 const unsigned long kInitSaveHeaderRight = 0x00000008;
38 const unsigned long kInitSaveFooterLeft = 0x00000010;
39 const unsigned long kInitSaveFooterCenter = 0x00000020;
40 const unsigned long kInitSaveFooterRight = 0x00000040;
41 const unsigned long kInitSaveBGColors = 0x00000080;
42 const unsigned long kInitSaveBGImages = 0x00000100;
43 const unsigned long kInitSavePaperSize = 0x00000200;
44 /* Flag 0x00000400 is unused */
45 const unsigned long kInitSaveDuplex = 0x00000800;
46 /* Flag 0x00001000 is unused */
47 /* Flag 0x00002000 is unused */
48 const unsigned long kInitSaveUnwriteableMargins = 0x00004000;
49 const unsigned long kInitSaveEdges = 0x00008000;
51 const unsigned long kInitSaveReversed = 0x00010000;
52 const unsigned long kInitSaveInColor = 0x00020000;
53 const unsigned long kInitSaveOrientation = 0x00040000;
55 const unsigned long kInitSavePrinterName = 0x00100000;
56 const unsigned long kInitSavePrintToFile = 0x00200000;
57 const unsigned long kInitSaveToFileName = 0x00400000;
58 const unsigned long kInitSavePageDelay = 0x00800000;
59 const unsigned long kInitSaveMargins = 0x01000000;
60 const unsigned long kInitSaveNativeData = 0x02000000;
62 const unsigned long kInitSaveShrinkToFit = 0x08000000;
63 const unsigned long kInitSaveScaling = 0x10000000;
65 const unsigned long kInitSaveAll = 0xFFFFFFFF;
67 // These settings should be read from global prefs. Other settings should be
68 // read only from printer-specific prefs.
69 const unsigned long kGlobalSettings =
70 kInitSaveHeaderLeft | kInitSaveHeaderCenter | kInitSaveHeaderRight |
71 kInitSaveFooterLeft | kInitSaveFooterCenter | kInitSaveFooterRight |
72 kInitSaveEdges | kInitSaveReversed | kInitSaveInColor |
73 kInitSaveBGColors | kInitSaveBGImages | kInitSaveShrinkToFit;
75 /* Justification Enums */
76 const long kJustLeft = 0;
77 const long kJustCenter = 1;
78 const long kJustRight = 2;
80 /** Page Size Unit Constants */
81 const short kPaperSizeInches = 0;
82 const short kPaperSizeMillimeters = 1;
84 /** Orientation Constants */
85 const short kPortraitOrientation = 0;
86 const short kLandscapeOrientation = 1;
88 /** Output file format */
89 const short kOutputFormatNative = 0;
90 const short kOutputFormatPDF = 2;
92 /** Output destination */
93 cenum OutputDestinationType : 8 {
94 kOutputDestinationPrinter = 0,
95 kOutputDestinationFile = 1,
96 kOutputDestinationStream = 2,
99 /**
100 * Duplex printing options.
102 * Note that other libraries refer to equivalent duplex settings using
103 * various sets of terminology. This can be confusing and inconsistent both
104 * with other libraries, and with the behavior that these terms intend to describe.
106 * kDuplexNone is equivalent to Simplex. Thankfully, both of these terms are
107 * consistent with the behavior that they describe, which is to have single-sided
108 * printing per sheet.
110 * kDuplexFlipOnLongEdge is equivalent to the following platform-specific constants:
111 * CUPS/macOS: NoTumble
112 * Windows: DMDUP_VERTICAL
113 * GTK: GTK_PRINT_DUPLEX_HORIZONTAL
115 * kDuplexFlipOnShortEdge is equivalent to the following platform-specific constants:
116 * CUPS/macOS: Tumble
117 * Windows: DMDUP_HORIZONTAL
118 * GTK: GTK_PRINT_DUPLEX_VERTICAL
121 * Notice that the GTK and Windows constants have opposite meanings for
122 * VERTICAL and HORIZONTAL.
124 * To make matters more confusing, these platform-specific terms describe different
125 * behavior (from the user's perspective) depending on whether the sheet is in
126 * portrait vs. landscape orientation.
128 * For example, the generic term "tumble" describes behavior where a sheet flips over
129 * a binding on the top edge (like a calendar). This requires that the back side of
130 * the sheet is printed upside down with respect to the front side of the sheet,
131 * so that its content appears upright to the reader when they tumble-flip the
132 * sheet over the top-edge binding.
134 * However, the CUPS/macOS Tumble setting only inverts the back side of the
135 * sheet in portrait orientation. When you switch to landscape orientation, the
136 * Tumble setting behaves like a book-like sheet flip, where the front and back
137 * sides of the sheet are both printed upright with respect to each other.
139 * This is why it is more consistent and more clear to think of these terms
140 * with regard to sheets being bound on the long edge or the short edge.
142 * kDuplexFlipOnLongEdge + Portrait = book-like flip (front/back same direction)
143 * kDuplexFlipOnLongEdge + Landscape = calendar-like flip (front/back inverted)
145 * kDuplexFlipOnShortEdge + Portrait = calendar-like flip (front/back inverted)
146 * kDuplexFlipOnShortEdge + Landscape = book-like flip (front/back same direction)
148 * The long-edge and short-edge terminology unfortunately breaks down when printing
149 * with square sheet dimensions. Thankfully this edge case (hah) is quite uncommon,
150 * since most standard printing paper dimensions are not square. Such a paper size
151 * would even break the uniformly used portrait and landscape terminology.
153 const short kDuplexNone = 0;
154 const short kDuplexFlipOnLongEdge = 1;
155 const short kDuplexFlipOnShortEdge = 2;
158 * Get the page size in twips, considering the
159 * orientation (portrait or landscape).
161 void GetEffectivePageSize(out double aWidth, out double aHeight);
164 * Get the printed sheet size in twips, considering both the user-specified
165 * orientation (portrait or landscape) *as well as* the fact that we might be
166 * inverting the orientation to account for 2 or 6 pages-per-sheet.
168 * This API will usually behave the same (& return the same thing) as
169 * GetEffectivePageSize, *except for* when we are printing with 2 or 6
170 * pages-per-sheet, in which case the return values (aWidth & aHeight) will
171 * be swapped with respect to what GetEffectivePageSize would return.
173 * Callers should use this method rather than GetEffectivePageSize when they
174 * really do want the size of the sheet of paper to be printed, rather than
175 * the possibly-"virtualized"-via-pages-per-sheet page size.
177 [noscript, notxpcom, nostdcall] void GetEffectiveSheetSize(out double aWidth,
178 out double aHeight);
181 * Get the orientation of a printed sheet. This is usually the same as the
182 * 'orientation' attribute (which is the orientation of individual pages),
183 * except when we're printing with 2 or 6 pages-per-sheet, in which case
184 * it'll be the opposite value.
186 * Note that this value is not independently settable. Its value is fully
187 * determined by the 'orientation' and 'numPagesPerSheet' attributes.
189 [noscript, notxpcom, nostdcall] long GetSheetOrientation();
192 * Convenience getter, which returns true IFF the sheet orientation and the
193 * page orientation are orthogonal. (In other words, returns true IFF we
194 * are printing with 2 or 6 pages-per-sheet.)
196 [noscript, notxpcom, nostdcall] bool HasOrthogonalSheetsAndPages();
199 * Makes a new copy
201 nsIPrintSettings clone();
204 * Assigns the internal values from the "in" arg to the current object
206 void assign(in nsIPrintSettings aPS);
209 * Returns true if the settings will result in an equivalent preview and
210 * therefore print. The printer name is ignored and it allows for a small
211 * delta in sizes to allow for rounding differences.
213 bool equivalentTo(in nsIPrintSettings aPrintSettings);
216 * The edge measurements define the positioning of the headers
217 * and footers on the page. They're treated as an offset from the edges of
218 * the page, but are forced to be at least the "unwriteable margin"
219 * (described below).
221 attribute double edgeTop; /* these are in inches */
222 attribute double edgeLeft;
223 attribute double edgeBottom;
224 attribute double edgeRight;
227 * The margins define the positioning of the content on the page.
228 * and footers on the page. They're treated as an offset from the edges of
229 * the page, but are forced to be at least the "unwriteable margin"
230 * (described below).
232 attribute double marginTop; /* these are in inches */
233 attribute double marginLeft;
234 attribute double marginBottom;
235 attribute double marginRight;
237 * The unwriteable margin defines the printable region of the paper.
239 attribute double unwriteableMarginTop; /* these are in inches */
240 attribute double unwriteableMarginLeft;
241 attribute double unwriteableMarginBottom;
242 attribute double unwriteableMarginRight;
244 attribute double scaling; /* values 0.0 - 1.0 */
245 [infallible] attribute boolean printBGColors; /* Print Background Colors */
246 [infallible] attribute boolean printBGImages; /* Print Background Images */
248 /** Whether @page rule margins should be honored or not. */
249 [infallible] attribute boolean honorPageRuleMargins;
251 /** Whether to draw guidelines showing the margin settings */
252 [infallible] attribute boolean showMarginGuides;
254 /** Whether to only print the selected nodes */
255 [infallible] attribute boolean printSelectionOnly;
257 attribute AString title;
258 attribute AString docURL;
260 attribute AString headerStrLeft;
261 attribute AString headerStrCenter;
262 attribute AString headerStrRight;
264 attribute AString footerStrLeft;
265 attribute AString footerStrCenter;
266 attribute AString footerStrRight;
268 attribute boolean printSilent; /* print without putting up the dialog */
269 [infallible] attribute boolean shrinkToFit; /* shrinks content to fit on page */
271 /* Additional XP Related */
272 attribute AString paperId; /* identifier of paper (not display name) */
273 attribute double paperWidth; /* width of the paper in inches or mm */
274 attribute double paperHeight; /* height of the paper in inches or mm */
275 attribute short paperSizeUnit; /* paper is in inches or mm */
277 attribute boolean printReversed;
278 [infallible] attribute boolean printInColor; /* a false means grayscale */
279 attribute long orientation; /* see orientation consts */
280 attribute long numCopies;
283 * For numPagesPerSheet, we support these values: 1, 2, 4, 6, 9, 16.
285 * Unsupported values will be treated internally as 1 page per sheet, and
286 * will trigger assertion failures in debug builds.
288 attribute long numPagesPerSheet;
290 /** Output device information */
291 [infallible] attribute nsIPrintSettings_OutputDestinationType outputDestination;
292 [infallible] attribute short outputFormat;
295 * If outputDestination==kOutputDestinationPrinter, this is set to the name
296 * of the printer that the print output should be saved to, but only in the
297 * parent process (we don't want to leak printer names to potentially
298 * compromised content processes).
300 attribute AString printerName;
303 * If outputDestination==kOutputDestinationFile, this is set to the path
304 * of the file that the print output should be saved to, but only in the
305 * parent process (we don't want to leak system paths to potentially
306 * compromised content processes).
308 attribute AString toFileName;
310 attribute nsIOutputStream outputStream; /* for kOutputDestinationPrinter */
312 [infallible] attribute long printPageDelay; /* in milliseconds */
314 [infallible] attribute long resolution; /* print resolution (dpi) */
316 [infallible] attribute long duplex; /* duplex mode */
318 /* initialize helpers */
320 * This attribute tracks whether the PS has been initialized
321 * from a printer specified by the "printerName" attr.
322 * If a different name is set into the "printerName"
323 * attribute than the one it was initialized with the PS
324 * will then get initialized from that printer.
326 attribute boolean isInitializedFromPrinter;
329 * This attribute tracks whether the PS has been initialized
330 * from prefs. If a different name is set into the "printerName"
331 * attribute than the one it was initialized with the PS
332 * will then get initialized from prefs again.
334 attribute boolean isInitializedFromPrefs;
336 /* C++ Helper Functions */
337 [noscript] void SetMarginInTwips(in nsNativeIntMarginRef aMargin);
338 [noscript] void SetEdgeInTwips(in nsNativeIntMarginRef aEdge);
339 [noscript, notxpcom, nostdcall] nsNativeIntMargin GetMarginInTwips();
340 [noscript, notxpcom, nostdcall] nsNativeIntMargin GetEdgeInTwips();
343 * Sets/Gets the "unwriteable margin" for the page format. This defines
344 * the boundary from which we'll measure the EdgeInTwips and MarginInTwips
345 * attributes, to place the headers and content, respectively.
347 * Note: Implementations of SetUnwriteableMarginInTwips should handle
348 * negative margin values by falling back on the system default for
349 * that margin.
351 [noscript] void SetUnwriteableMarginInTwips(in nsNativeIntMarginRef aEdge);
352 [noscript, notxpcom, nostdcall] nsNativeIntMargin GetUnwriteableMarginInTwips();
355 * Get more accurate print ranges from the superior interval
356 * (startPageRange, endPageRange). The aPages array is populated with a
357 * list of pairs (start, end), where the endpoints are included. The print
358 * ranges (start, end), must not overlap and must be in the
359 * (startPageRange, endPageRange) scope.
361 * If there are no print ranges the aPages array is empty.
363 attribute Array<long> pageRanges;
365 %{C++
367 * Get a PrintSettingsInitializer populated with the relevant current settings.
369 virtual mozilla::PrintSettingsInitializer GetSettingsInitializer() = 0;
371 static bool IsPageSkipped(int32_t aPageNum, const nsTArray<int32_t>& aRanges);
375 %{ C++
376 already_AddRefed<nsIPrintSettings> CreatePlatformPrintSettings(const mozilla::PrintSettingsInitializer&);