OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 cr.define('print_preview', function() { | |
6 'use strict'; | |
7 | |
8 /** | |
9 * A print ticket defines how the document should be rendered and printed. | |
10 * | |
dpapad
2012/04/24 01:24:56
Nit: Unnecessary blank line.
Robert Toscano
2012/04/24 22:29:56
Done.
| |
11 * @param {!print_preview.ChromiumCapabilities} capabilities Printing | |
12 * capabilities of the print destination. | |
13 * @constructor | |
14 */ | |
15 function ChromiumPrintTicket(capabilities) { | |
16 /** | |
17 * Printing capabilities of the print destination. Contains default values | |
18 * for each of the print ticket fields. | |
19 * @type {!print_preview.ChromiumCapabilities} | |
20 * @private | |
21 */ | |
22 this.capabilities_ = capabilities; | |
23 | |
24 /** | |
25 * String describing which pages to print. E.g. "1-5,9". {@code null} if the | |
26 * user has not specified a page range string. | |
27 * @type {?string} | |
28 * @private | |
29 */ | |
30 this.pageRangeStr_ = null; | |
31 | |
32 /** | |
33 * String representing the number of copies of the document to print. | |
34 * {@code null} if the user has not specified a copies string. | |
35 * @type {?string} | |
36 * @private | |
37 */ | |
38 this.copiesStr_ = null; | |
39 | |
40 /** | |
41 * Whether the document should be collated when printed. {@code null} if the | |
42 * user has not specified. | |
43 * @type {?boolean} | |
44 * @private | |
45 */ | |
46 this.isCollateEnabled_ = null; | |
47 | |
48 /** | |
49 * Whether the document should be duplexed. {@code null} if not specified. | |
50 * @type {?boolean} | |
51 * @private | |
52 */ | |
53 this.isDuplexEnabled_ = null; | |
54 | |
55 /** | |
56 * Whether the document should be printed in landscape. {@code null} if not | |
57 * specified. | |
58 * @type {?boolean} | |
59 * @private | |
60 */ | |
61 this.isLandscapeEnabled_ = null; | |
62 | |
63 /** | |
64 * Whether the document should be printed in color. {@code null} if not | |
65 * specified. | |
66 * @type {?boolean} | |
67 * @private | |
68 */ | |
69 this.isColorEnabled_ = null; | |
70 | |
71 /** | |
72 * Type of margins of the document. {@code null} if user has not specified. | |
73 * @type {?print_preview.Margins.Type} | |
dpapad
2012/04/24 01:24:56
I think that "?" makes sense only for primitives.
Robert Toscano
2012/04/24 22:29:56
It's not explicitly mentioned in the js doc whethe
dpapad
2012/04/24 22:50:19
Hm, I guess I never think of this as a typedef, bu
Robert Toscano
2012/04/28 01:41:37
I'm pretty sure the closure compiler will treat th
dpapad
2012/04/30 16:19:26
Sg.
| |
74 * @private | |
75 */ | |
76 this.marginsType_ = null; | |
77 | |
78 /** | |
79 * Custom margins of the document. {@code null} if not specified. | |
80 * @type {print_preview.Margins} | |
81 * @private | |
82 */ | |
83 this.customMargins_ = null; | |
84 | |
85 /** | |
86 * Whether a header and footer should be added to the document. {@code null} | |
87 * if not specified. | |
88 * @type {?boolean} | |
89 * @private | |
90 */ | |
91 this.isHeaderFooterEnabled_ = null; | |
92 }; | |
93 | |
94 ChromiumPrintTicket.prototype = { | |
95 /** | |
96 * @param {!print_preview.ChromiumCapabilities} capabilities New print | |
97 * destination capabilities to set. | |
98 */ | |
99 set capabilities(capabilities) { | |
100 this.capabilities_ = capabilities; | |
101 }, | |
102 | |
103 /** @return {string} Page range string specification. */ | |
104 get pageRangeStr() { | |
105 return this.pageRangeStr_ || ''; | |
106 }, | |
107 | |
108 /** @param {string} pageRangeStr Page range string specification to set. */ | |
109 set pageRangeStr(pageRangeStr) { | |
110 this.pageRangeStr_ = pageRangeStr; | |
111 }, | |
112 | |
113 /** @return {string} Number of copies to print in string form. */ | |
114 get copiesStr() { | |
115 return this.getValue_( | |
116 this.capabilities_.hasCopiesCapability, | |
117 this.copiesStr_, | |
118 this.capabilities_.defaultCopiesStr, | |
119 '1'); | |
120 }, | |
121 | |
122 /** @param {string} copiesStr String form of number of copies to print. */ | |
123 set copiesStr(copiesStr) { | |
124 this.copiesStr_ = copiesStr; | |
125 }, | |
126 | |
127 /** @return {boolean} Whether the document should be collated. */ | |
128 get isCollateEnabled() { | |
129 return this.getValue_( | |
130 this.capabilities_.hasCollateCapability, | |
131 this.isCollateEnabled_, | |
132 this.capabilities_.defaultIsCollateEnabled, | |
133 true); | |
134 }, | |
135 | |
136 /** | |
137 * @param {boolean} isCollateEnabled Whether the document should be | |
138 * collated. | |
139 */ | |
140 set isCollateEnabled(isCollateEnabled) { | |
141 this.isCollateEnabled_ = isCollateEnabled; | |
142 }, | |
143 | |
144 /** @return {boolean} Whether the document should be duplexed. */ | |
145 get isDuplexEnabled() { | |
146 return this.getValue_( | |
147 this.capabilities_.hasDuplexCapability, | |
148 this.isDuplexEnabled_, | |
149 this.capabilities_.defaultIsDuplexEnabled, | |
150 true); | |
151 }, | |
152 | |
153 /** | |
154 * @param {boolean} isDuplexEnabled Whether the document should be duplexed. | |
155 */ | |
156 set isDuplexEnabled(isDuplexEnabled) { | |
157 this.isDuplexEnabled_ = isDuplexEnabled; | |
158 }, | |
159 | |
160 /** | |
161 * @return {boolean} Whether the document should be printed in landscape. | |
162 */ | |
163 get isLandscapeEnabled() { | |
164 return this.getValue_( | |
165 this.capabilities_.hasOrientationCapability, | |
166 this.isLandscapeEnabled_, | |
167 this.capabilities_.defaultIsLandscapeEnabled, | |
168 false); | |
169 }, | |
170 | |
171 /** | |
172 * @param {boolean} isLandscapeEnabled Whether the document should be | |
173 * printed in landscape. | |
174 */ | |
175 set isLandscapeEnabled(isLandscapeEnabled) { | |
176 this.isLandscapeEnabled_ = isLandscapeEnabled; | |
177 }, | |
178 | |
179 /** @return {boolean} Whether the document should be printed in color. */ | |
180 get isColorEnabled() { | |
181 return this.getValue_( | |
182 this.capabilities_.hasColorCapability, | |
183 this.isColorEnabled_, | |
184 this.capabilities_.defaultIsColorEnabled, | |
185 false); | |
186 }, | |
187 | |
188 /** | |
189 * @param {boolean} isColorEnabled Whether the document should be printed in | |
190 * color. | |
191 */ | |
192 set isColorEnabled(isColorEnabled) { | |
193 this.isColorEnabled_ = isColorEnabled; | |
194 }, | |
195 | |
196 /** | |
197 * @return {print_preview.Margins.Type} The document's predefined margins | |
198 * type. | |
199 */ | |
200 get marginsType() { | |
201 return this.marginsType_ || print_preview.Margins.Type.DEFAULT; | |
202 }, | |
203 | |
204 /** | |
205 * @param {print_preview.Margins.Type} marginsType The document's predefined | |
206 * margins type. | |
207 */ | |
208 set marginsType(marginsType) { | |
209 this.marginsType_ = marginsType; | |
210 }, | |
211 | |
212 /** | |
213 * @return {print_preview.Margins} Custom margins of the print document. | |
214 */ | |
215 get customMargins() { | |
216 return this.customMargins_; | |
217 }, | |
218 | |
219 /** | |
220 * @param {print_preview.Margins} customMargins Custom margins of the | |
221 * print document. | |
222 */ | |
223 set customMargins(customMargins) { | |
224 this.customMargins_ = customMargins; | |
225 }, | |
226 | |
227 /** | |
228 * @return {boolean} Whether a header footer should be superimposed on the | |
229 * document. | |
230 */ | |
231 get isHeaderFooterEnabled() { | |
232 if (this.isHeaderFooterEnabled_ == null) { | |
233 return true; | |
234 } else { | |
235 return this.isHeaderFooterEnabled_; | |
236 } | |
237 }, | |
238 | |
239 /** | |
240 * @param {boolean} isHeaderFooterEnabled Whether a header footer should be | |
241 * superimposed on the document. | |
242 */ | |
243 set isHeaderFooterEnabled(isHeaderFooterEnabled) { | |
244 this.isHeaderFooterEnabled_ = isHeaderFooterEnabled; | |
245 }, | |
246 | |
247 /** | |
248 * Gets the value of a capability of a renderer or print destination. | |
249 * @param {boolean} hasCap Whether the renderer or print destination has the | |
250 * given capability. | |
251 * @param {Object} userVal Value specified by the user. | |
252 * @param {Object} defaultCapVal Value specified as the default value of the | |
253 * given capability. | |
254 * @param {Object} defaultChromiumVal Value specified if the renderer or | |
255 * print destination does not have the given capability. | |
256 * @return {Object} User value if specified, then default capability value | |
257 * if capability is available, and finally default chromium value if | |
258 * capability not available. | |
259 * @private | |
260 */ | |
261 getValue_: function(hasCap, userVal, defaultCapVal, defaultChromiumVal) { | |
262 if (hasCap && userVal != null) { | |
263 return userVal; | |
264 } else if (hasCap && defaultCapVal != null) { | |
265 return defaultCapVal; | |
266 } else { | |
267 return defaultChromiumVal; | |
268 } | |
269 } | |
270 }; | |
271 | |
272 /** | |
273 * Capabilities of a print destination not including the capabilities of the | |
274 * document renderer. | |
275 * | |
276 * @param {boolean} hasCopiesCapability Whether the print destination has a | |
277 * copies capability. | |
278 * @param {string} defaultCopiesStr Default string representation of the | |
279 * copies value. | |
280 * @param {boolean} hasCollateCapability Whether the print destination has | |
281 * collation capability. | |
282 * @param {boolean} defaultIsCollateEnabled Whether collate is enabled by | |
283 * default. | |
284 * @param {boolean} hasDuplexCapability Whether the print destination has | |
285 * duplexing capability. | |
286 * @param {boolean} defaultIsDuplexEnabled Whether duplexing is enabled by | |
287 * default. | |
288 * @param {boolean} hasOrientationCapability Whether the print destination has | |
289 * orientation capability. | |
290 * @param {boolean} defaultIsLandscapeEnabled Whether the document should be | |
291 * printed in landscape by default. | |
292 * @param {boolean} hasColorCapability Whether the print destination has | |
293 * color printing capability. | |
294 * @param {boolean} defaultIsColorEnabled Whether the document should be | |
295 * printed in color by default. | |
296 * @constructor | |
297 */ | |
298 function ChromiumCapabilities( | |
299 hasCopiesCapability, | |
300 defaultCopiesStr, | |
301 hasCollateCapability, | |
302 defaultIsCollateEnabled, | |
303 hasDuplexCapability, | |
304 defaultIsDuplexEnabled, | |
305 hasOrientationCapability, | |
306 defaultIsLandscapeEnabled, | |
307 hasColorCapability, | |
308 defaultIsColorEnabled) { | |
309 /** | |
310 * Whether the print destination has a copies capability. | |
311 * @type {boolean} | |
312 * @private | |
313 */ | |
314 this.hasCopiesCapability_ = hasCopiesCapability; | |
315 | |
316 /** | |
317 * Default string representation of the copies value. | |
318 * @type {string} | |
319 * @private | |
320 */ | |
321 this.defaultCopiesStr_ = defaultCopiesStr; | |
322 | |
323 /** | |
324 * Whether the print destination has collation capability. | |
325 * @type {boolean} | |
326 * @private | |
327 */ | |
328 this.hasCollateCapability_ = hasCollateCapability; | |
329 | |
330 /** | |
331 * Whether collate is enabled by default. | |
332 * @type {boolean} | |
333 * @private | |
334 */ | |
335 this.defaultIsCollateEnabled_ = defaultIsCollateEnabled; | |
336 | |
337 /** | |
338 * Whether the print destination has duplexing capability. | |
339 * @type {boolean} | |
340 * @private | |
341 */ | |
342 this.hasDuplexCapability_ = hasDuplexCapability; | |
343 | |
344 /** | |
345 * Whether duplex is enabled by default. | |
346 * @type {boolean} | |
347 * @private | |
348 */ | |
349 this.defaultIsDuplexEnabled_ = defaultIsDuplexEnabled; | |
350 | |
351 /** | |
352 * Whether the print destination has orientation capability. | |
353 * @type {boolean} | |
354 * @private | |
355 */ | |
356 this.hasOrientationCapability_ = hasOrientationCapability; | |
357 | |
358 /** | |
359 * Whether the document should be printed in landscape by default. | |
360 * @type {boolean} | |
361 * @private | |
362 */ | |
363 this.defaultIsLandscapeEnabled_ = defaultIsLandscapeEnabled; | |
364 | |
365 /** | |
366 * Whether the print destination has color printing capability. | |
367 * @type {boolean} | |
368 * @private | |
369 */ | |
370 this.hasColorCapability_ = hasColorCapability; | |
371 | |
372 /** | |
373 * Whether the document should be printed in color. | |
374 * @type {boolean} | |
375 * @private | |
376 */ | |
377 this.defaultIsColorEnabled_ = defaultIsColorEnabled; | |
378 }; | |
379 | |
380 ChromiumCapabilities.prototype = { | |
381 /** @return {boolean} Whether the destination has the copies capability. */ | |
382 get hasCopiesCapability() { | |
383 return this.hasCopiesCapability_; | |
384 }, | |
385 | |
386 /** @return {string} Default number of copies in string format. */ | |
387 get defaultCopiesStr() { | |
388 return this.defaultCopiesStr_; | |
389 }, | |
390 | |
391 /** @return {boolean} Whether the destination has collation capability. */ | |
392 get hasCollateCapability() { | |
393 return this.hasCollateCapability_; | |
394 }, | |
395 | |
396 /** @return {boolean} Whether collation is enabled by default. */ | |
397 get defaultIsCollateEnabled() { | |
398 return this.defaultIsCollateEnabled_; | |
399 }, | |
400 | |
401 /** @return {boolean} Whether the destination has the duplex capability. */ | |
402 get hasDuplexCapability() { | |
403 return this.hasDuplexCapability_; | |
404 }, | |
405 | |
406 /** @return {boolean} Whether duplexing is enabled by default. */ | |
407 get defaultIsDuplexEnabled() { | |
408 return this.defaultIsDuplexEnabled_; | |
409 }, | |
410 | |
411 /** | |
412 * @return {boolean} Whether the destination has the orientation capability. | |
413 */ | |
414 get hasOrientationCapability() { | |
415 return this.hasOrientationCapability_; | |
416 }, | |
417 | |
418 /** | |
419 * @return {boolean} Whether document should be printed in landscape by | |
420 * default. | |
421 */ | |
422 get defaultIsLandscapeEnabled() { | |
423 return this.defaultIsLandscapeEnabled_; | |
424 }, | |
425 | |
426 /** | |
427 * @return {boolean} Whether the destination has color printing capability. | |
428 */ | |
429 get hasColorCapability() { | |
430 return this.hasColorCapability_; | |
431 }, | |
432 | |
433 /** | |
434 * @return {boolean} Whether document should be printed in color by default. | |
435 */ | |
436 get defaultIsColorEnabled() { | |
437 return this.defaultIsColorEnabled_; | |
438 } | |
439 }; | |
440 | |
441 // Export | |
442 return { | |
443 ChromiumCapabilities: ChromiumCapabilities, | |
444 ChromiumPrintTicket: ChromiumPrintTicket | |
445 }; | |
446 }); | |
OLD | NEW |