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 * An interface to the native Chromium printing system layer. | |
10 * @constructor | |
11 * @extends {cr.EventTarget} | |
12 */ | |
13 function NativeLayer() { | |
14 cr.EventTarget.call(this); | |
15 | |
16 // Bind global handlers | |
17 global['setInitialSettings'] = this.onSetInitialSettings_.bind(this); | |
18 global['setUseCloudPrint'] = this.onSetUseCloudPrint_.bind(this); | |
19 global['setPrinters'] = this.onSetPrinters_.bind(this); | |
20 global['updateWithPrinterCapabilities'] = | |
21 this.onUpdateWithPrinterCapabilities_.bind(this); | |
22 global['reloadPrintersList'] = this.onReloadPrintersList_.bind(this); | |
23 global['printToCloud'] = this.onPrintToCloud_.bind(this); | |
24 global['fileSelectionCancelled'] = | |
25 this.onFileSelectionCancelled_.bind(this); | |
26 global['fileSelectionCompleted'] = | |
27 this.onFileSelectionCompleted_.bind(this); | |
28 global['printPreviewFailed'] = this.onPrintPreviewFailed_.bind(this); | |
29 global['invalidPrinterSettings'] = | |
30 this.onInvalidPrinterSettings_.bind(this); | |
31 global['onDidGetDefaultPageLayout'] = | |
32 this.onDidGetDefaultPageLayout_.bind(this); | |
33 global['onDidGetPreviewPageCount'] = | |
34 this.onDidGetPreviewPageCount_.bind(this); | |
35 global['reloadPreviewPages'] = this.onReloadPreviewPages_.bind(this); | |
36 global['onDidPreviewPage'] = this.onDidPreviewPage_.bind(this); | |
37 global['updatePrintPreview'] = this.onUpdatePrintPreview_.bind(this); | |
38 }; | |
39 | |
40 /** | |
41 * Event types dispatched from the Chromium native layer. | |
42 * @enum {string} | |
43 * @const | |
44 */ | |
45 NativeLayer.EventType = { | |
46 CAPABILITIES_SET: 'print_preview.NativeLayer.CAPABILITIES_SET', | |
47 CLOUD_PRINT_ENABLE: 'print_preview.NativeLayer.CLOUD_PRINT_ENABLE', | |
48 DESTINATIONS_RELOAD: 'print_preview.NativeLayer.DESTINATIONS_RELOAD', | |
49 FILE_SELECTION_CANCEL: 'print_preview.NativeLayer.FILE_SELECTION_CANCEL', | |
50 FILE_SELECTION_COMPLETE: | |
51 'print_preview.NativeLayer.FILE_SELECTION_COMPLETE', | |
52 INITIAL_SETTINGS_SET: 'print_preview.NativeLayer.INITIAL_SETTINGS_SET', | |
53 LOCAL_DESTINATIONS_SET: 'print_preview.NativeLayer.LOCAL_DESTINATIONS_SET', | |
54 PAGE_COUNT_READY: 'print_preview.NativeLayer.PAGE_COUNT_READY', | |
55 PAGE_LAYOUT_READY: 'print_preview.NativeLayer.PAGE_LAYOUT_READY', | |
56 PAGE_PREVIEW_READY: 'print_preview.NativeLayer.PAGE_PREVIEW_READY', | |
57 PREVIEW_GENERATION_DONE: | |
58 'print_preview.NativeLayer.PREVIEW_GENERATION_DONE', | |
59 PREVIEW_GENERATION_FAIL: | |
60 'print_preview.NativeLayer.PREVIEW_GENERATION_FAIL', | |
61 PREVIEW_RELOAD: 'print_preview.NativeLayer.PREVIEW_RELOAD', | |
62 PRINT_TO_CLOUD: 'print_preview.NativeLayer.PRINT_TO_CLOUD', | |
63 SETTINGS_INVALID: 'print_preview.NativeLayer.SETTINGS_INVALID' | |
64 }; | |
65 | |
66 /** | |
67 * Constant values matching printing::DuplexMode enum. | |
68 * @enum {number} | |
69 */ | |
70 NativeLayer.DuplexMode = { | |
71 SIMPLEX: 0, | |
72 LONG_EDGE: 1, | |
73 UNKNOWN_DUPLEX_MODE: -1 | |
74 }; | |
75 | |
76 /** | |
77 * Enumeration of color modes used by Chromium. | |
78 * @enum {number} | |
79 * @private | |
80 */ | |
81 NativeLayer.ColorMode_ = { | |
82 GRAY: 1, | |
83 COLOR: 2 | |
84 }; | |
85 | |
86 NativeLayer.prototype = { | |
87 __proto__: cr.EventTarget.prototype, | |
88 | |
89 /** Gets the initial settings to initialize the print preview with. */ | |
90 startGetInitialSettings: function() { | |
91 chrome.send('getInitialSettings'); | |
92 }, | |
93 | |
94 /** | |
95 * Requests the system's local print destinations. A LOCAL_DESTINATIONS_SET | |
96 * event will be dispatched in response. | |
97 */ | |
98 startGetLocalDestinations: function() { | |
99 chrome.send('getPrinters'); | |
100 }, | |
101 | |
102 /** | |
103 * Requests the destination's printing capabilities. A CAPABILITIES_SET | |
104 * event will be dispatched in response. | |
105 * @param {string} destinationId ID of the destination. | |
106 */ | |
107 startGetLocalDestinationCapabilities: function(destinationId) { | |
108 chrome.send('getPrinterCapabilities', [destinationId]); | |
109 }, | |
110 | |
111 /** | |
112 * Requests that a preview be generated. The following events may be | |
113 * dispatched in response: | |
114 * - PAGE_COUNT_READY | |
115 * - PAGE_LAYOUT_READY | |
116 * - PAGE_PREVIEW_READY | |
117 * - PREVIEW_GENERATION_DONE | |
118 * - PREVIEW_GENERATION_FAIL | |
119 * - PREVIEW_RELOAD | |
120 * @param {print_preview.Destination} destination Destination to print to. | |
121 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the | |
122 * state of the print ticket. | |
123 * @param {number} ID of the preview request. | |
124 */ | |
125 startGetPreview: function(destination, printTicketStore, requestId) { | |
126 if (!printTicketStore.isTicketValid()) { | |
127 throw Error('Trying to generate preview when ticket is not valid'); | |
128 } | |
129 | |
130 var pageRanges = []; | |
131 if (requestId > 0 && | |
132 !printTicketStore.isDocumentModifiable && | |
133 printTicketStore.hasPageRangeCapability()) { | |
134 pageRanges = printTicketStore.getPageNumberSet().getPageRanges(); | |
135 } | |
136 | |
137 var ticket = { | |
138 'pageRange': pageRanges, // pageRanges, | |
139 'landscape': printTicketStore.isLandscapeEnabled(), | |
140 'color': printTicketStore.isColorEnabled() ? | |
141 NativeLayer.ColorMode_.COLOR : NativeLayer.ColorMode_.GRAY, | |
142 'headerFooterEnabled': printTicketStore.isHeaderFooterEnabled(), | |
143 'marginsType': printTicketStore.getMarginsType(), | |
144 'isFirstRequest': requestId == 0, | |
145 'requestID': requestId, | |
146 'previewModifiable': printTicketStore.isDocumentModifiable, | |
147 'printToPDF': destination != null && destination.isPrintToPdf, | |
148 'printWithCloudPrint': destination != null && !destination.isLocal, | |
149 'deviceName': destination == null ? 'foo' : destination.id, | |
150 'cloudPrintID': destination == null ? 'foo' : destination.id, | |
151 'generateDraftData': printTicketStore.isDocumentModifiable, | |
152 | |
153 // NOTE: Even though the following fields don't directly relate to the | |
154 // preview, they still need to be included. | |
155 'duplex': printTicketStore.isDuplexEnabled() ? | |
156 NativeLayer.DuplexMode.LONG_EDGE : NativeLayer.DuplexMode.SIMPLEX, | |
157 'copies': printTicketStore.getCopies(), | |
158 'collate': printTicketStore.isCollateEnabled() | |
159 }; | |
160 | |
161 if (printTicketStore.hasMarginsCapability() && | |
162 printTicketStore.getMarginsType() == | |
163 print_preview.ticket_items.MarginsType.Value.CUSTOM) { | |
164 var customMarginsInPts = printTicketStore.getCustomMarginsInPts(); | |
165 var orientationEnum = | |
166 print_preview.ticket_items.CustomMargins.Orientation; | |
167 ticket['marginsCustom'] = { | |
168 'marginTop': customMarginsInPts.get(orientationEnum.TOP), | |
169 'marginRight': customMarginsInPts.get(orientationEnum.RIGHT), | |
170 'marginBottom': customMarginsInPts.get(orientationEnum.BOTTOM), | |
171 'marginLeft': customMarginsInPts.get(orientationEnum.LEFT) | |
172 }; | |
173 } | |
174 | |
175 chrome.send( | |
176 'getPreview', | |
177 [JSON.stringify(ticket), -1, printTicketStore.isDocumentModifiable]); | |
178 }, | |
179 | |
180 /** | |
181 * Persists the selected destination and print ticket for the next print | |
182 * session. | |
183 * @param {!print_preview.Destination} destination Destination to save. | |
184 * @param {!print_preview.PrintTicketStore} printTicketStore Used for | |
185 * generating the serialized print ticket to persist. | |
186 */ | |
187 startSaveDestinationAndTicket: function(destination, printTicketStore) { | |
188 chrome.send('saveLastPrinter', [destination.id, '' /*TODO*/); | |
dpapad
2012/05/10 02:15:03
Closing bracket missing, causing uncaught js error
Robert Toscano
2012/05/10 03:37:41
Done.
dpapad
2012/05/10 15:49:27
Does not seem fixed. Is the latest patch uploaded
| |
189 }, | |
190 | |
191 /** | |
192 * Requests that the document be printed. | |
193 * @param {!print_preview.Destination} destination Destination to print to. | |
194 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the | |
195 * state of the print ticket. | |
196 * @param {print_preview.CloudPrintInterface} cloudPrintInterface Interface | |
197 * to Google Cloud Print. | |
198 */ | |
199 startPrint: function(destination, printTicketStore, cloudPrintInterface) { | |
200 if (!printTicketStore.isTicketValid()) { | |
201 throw Error( | |
202 'Requesting ticket for preview generator when ticket is not valid'); | |
203 } | |
204 | |
205 var ticket = { | |
206 'pageRange': printTicketStore.hasPageRangeCapability() ? | |
207 printTicketStore.getPageNumberSet().getPageRanges() : [], | |
208 'landscape': printTicketStore.isLandscapeEnabled(), | |
209 'color': printTicketStore.isColorEnabled() ? | |
210 NativeLayer.ColorMode_.COLOR : NativeLayer.ColorMode_.GRAY, | |
211 'headerFooterEnabled': printTicketStore.isHeaderFooterEnabled(), | |
212 'marginsType': printTicketStore.getMarginsType(), | |
213 'generateDraftData': true, // TODO What should this value be? | |
214 'duplex': printTicketStore.isDuplexEnabled() ? | |
215 NativeLayer.DuplexMode.LONG_EDGE : NativeLayer.DuplexMode.SIMPLEX, | |
216 'copies': printTicketStore.getCopies(), | |
217 'collate': printTicketStore.isCollateEnabled(), | |
218 'previewModifiable': printTicketStore.isDocumentModifiable, | |
219 'printToPDF': destination.isPrintToPdf, | |
220 'printWithCloudPrint': !destination.isLocal, | |
221 'deviceName': destination.id, | |
222 'isFirstRequest': false, | |
223 'requestID': -1 | |
224 }; | |
225 | |
226 if (!destination.isLocal && !destination.isPrintWithCloudPrint) { | |
227 // We can't set cloudPrintID if the destination is "Print with Cloud | |
228 // Print" because the native system will try to print to Google Cloud | |
229 // Print with this ID instead of opening a Google Cloud Print dialog. | |
230 ticket['cloudPrintID'] = destination.id; | |
231 } | |
232 | |
233 if (printTicketStore.hasMarginsCapability() && | |
234 printTicketStore.getMarginsType() == | |
235 print_preview.ticket_items.MarginsType.Value.CUSTOM) { | |
236 var customMarginsInPts = printTicketStore.getCustomMargins(); | |
237 var orientationEnum = | |
238 print_preview.ticket_items.CustomMargins.Orientation; | |
239 ticket['marginsCustom'] = { | |
240 'marginTop': customMarginsInPts.get(orientationEnum.TOP), | |
241 'marginRight': customMarginsInPts.get(orientationEnum.RIGHT), | |
242 'marginBottom': customMarginsInPts.get(orientationEnum.BOTTOM), | |
243 'marginLeft': customMarginsInPts.get(orientationEnum.LEFT) | |
244 }; | |
245 } | |
246 | |
247 var cloudTicket = null; | |
248 if (!destination.isLocal) { | |
249 if (!cloudPrintInterface) { | |
250 throw Error( | |
251 'Trying to print to a cloud destination but Google Cloud Print ' + | |
252 'integration is disabled'); | |
253 } | |
254 cloudTicket = cloudPrintInterface.createPrintTicket( | |
255 destination, printTicketStore); | |
256 cloudTicket = JSON.stringify(cloudTicket); | |
257 } | |
258 | |
259 chrome.send('print', [JSON.stringify(ticket), cloudTicket]); | |
260 }, | |
261 | |
262 /** Requests that the current pending print request be cancelled. */ | |
263 startCancelPendingPrint: function() { | |
264 chrome.send('cancelPendingPrintRequest'); | |
265 }, | |
266 | |
267 /** Shows the system's native printing dialog. */ | |
268 startShowSystemDialog: function() { | |
269 chrome.send('showSystemDialog'); | |
270 }, | |
271 | |
272 /** Closes the print preview dialog. */ | |
273 startCloseDialog: function() { | |
274 chrome.send('closePrintPreviewTab'); | |
275 chrome.send('DialogClose'); | |
276 }, | |
277 | |
278 /** Hide the print preview dialog and allow the native layer to close it. */ | |
279 startHideDialog: function() { | |
280 chrome.send('hidePreview'); | |
281 }, | |
282 | |
283 /** | |
284 * Opens the Google Cloud Print sign-in dialog. The DESTINATIONS_RELOAD | |
285 * event will be dispatched in response. | |
286 */ | |
287 startCloudPrintSignIn: function() { | |
288 chrome.send('signIn'); | |
289 }, | |
290 | |
291 /** Navigates the user to the system printer settings interface. */ | |
292 startManageLocalPrinters: function() { | |
293 chrome.send('manageLocalPrinters'); | |
294 }, | |
295 | |
296 /** Navigates the user to the Google Cloud Print management page. */ | |
297 startManageCloudPrinters: function() { | |
298 chrome.send('manageCloudPrinters'); | |
299 }, | |
300 | |
301 /** | |
302 * @param {object} initialSettings Object containing all initial settings. | |
303 */ | |
304 onSetInitialSettings_: function(initialSettings) { | |
305 // Not using initialSettings['initiatorTabTitle'] since the print preview | |
306 // no longer opens in a new tab. And because of this, | |
307 // localStrings.getStringF('printPreviewTitleFormat', initiatorTabTitle) | |
308 // is also not used. | |
309 // TODO Remove those unused local strings. | |
310 | |
311 // TODO Use initialSettings['cloudPrintData'] to prepopulate destination | |
312 // and initial print ticket. | |
313 var numberFormatSymbols = | |
314 print_preview.MeasurementSystem.parseNumberFormat( | |
315 initialSettings['numberFormat']); | |
316 var unitType = print_preview.MeasurementSystem.UnitType.IMPERIAL; | |
317 if (initialSettings['measurementSystem'] != null) { | |
318 unitType = initialSettings['measurementSystem']; | |
319 } | |
320 var measurementSystem = new print_preview.MeasurementSystem( | |
321 numberFormatSymbols[0], | |
322 numberFormatSymbols[1], | |
323 unitType); | |
324 | |
325 var customMargins = null; | |
326 if (initialSettings.hasOwnProperty('marginTop') && | |
327 initialSettings.hasOwnProperty('marginRight') && | |
328 initialSettings.hasOwnProperty('marginBottom') && | |
329 initialSettings.hasOwnProperty('marginLeft')) { | |
330 customMargins = new print_preview.Margins( | |
331 initialSettings['marginTop'] || 0, | |
332 initialSettings['marginRight'] || 0, | |
333 initialSettings['marginBottom'] || 0, | |
334 initialSettings['marginLeft'] || 0); | |
335 } | |
336 | |
337 var marginsType = null; | |
338 if (initialSettings.hasOwnProperty('marginsType')) { | |
339 marginsType = initialSettings['marginsType']; | |
340 } | |
341 | |
342 var nativeInitialSettings = new print_preview.NativeInitialSettings( | |
343 initialSettings['printAutomaticallyInKioskMode'] || false, | |
344 numberFormatSymbols[0] || ',', | |
345 numberFormatSymbols[1] || '.', | |
346 unitType, | |
347 initialSettings['previewModifiable'] || false, | |
348 marginsType, | |
349 customMargins, | |
350 initialSettings['duplex'] || false, | |
351 initialSettings['headerFooterEnabled'] || false, | |
352 initialSettings['printerName'] || null); | |
353 | |
354 var initialSettingsSetEvent = new cr.Event( | |
355 print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); | |
356 initialSettingsSetEvent.initialSettings = nativeInitialSettings; | |
357 this.dispatchEvent(initialSettingsSetEvent); | |
358 }, | |
359 | |
360 /** | |
361 * Turn on the integration of Cloud Print. | |
362 * @param {string} cloudPrintURL The URL to use for cloud print servers. | |
363 * @private | |
364 */ | |
365 onSetUseCloudPrint_: function(cloudPrintURL) { | |
366 var cloudPrintEnableEvent = new cr.Event( | |
367 print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE); | |
368 cloudPrintEnableEvent.baseCloudPrintUrl = cloudPrintURL; | |
369 this.dispatchEvent(cloudPrintEnableEvent); | |
370 }, | |
371 | |
372 /** | |
373 * Updates the print preview with local printers. | |
374 * Called from PrintPreviewHandler::SetupPrinterList(). | |
375 * @param {Array} printers Array of printer info objects. | |
376 * @private | |
377 */ | |
378 onSetPrinters_: function(printers) { | |
379 var localDestsSetEvent = new cr.Event( | |
380 print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); | |
381 localDestsSetEvent.destinationInfos = printers; | |
382 this.dispatchEvent(localDestsSetEvent); | |
383 }, | |
384 | |
385 /** | |
386 * Called when native layer gets settings information for a requested local | |
387 * destination. | |
388 * @param {Object} settingsInfo printer setting information. | |
389 * @private | |
390 */ | |
391 onUpdateWithPrinterCapabilities_: function(settingsInfo) { | |
392 var capsSetEvent = new cr.Event( | |
393 print_preview.NativeLayer.EventType.CAPABILITIES_SET); | |
394 capsSetEvent.settingsInfo = settingsInfo; | |
395 this.dispatchEvent(capsSetEvent); | |
396 }, | |
397 | |
398 /** Reloads the printer list. */ | |
399 onReloadPrintersList_: function() { | |
400 cr.dispatchSimpleEvent( | |
401 this, print_preview.NativeLayer.EventType.DESTINATIONS_RELOAD); | |
402 }, | |
403 | |
404 /** | |
405 * Called from the C++ layer. | |
406 * Take the PDF data handed to us and submit it to the cloud, closing the | |
407 * print preview tab once the upload is successful. | |
408 * @param {string} data Data to send as the print job. | |
409 * @private | |
410 */ | |
411 onPrintToCloud_: function(data) { | |
412 var printToCloudEvent = new cr.Event( | |
413 print_preview.NativeLayer.EventType.PRINT_TO_CLOUD); | |
414 printToCloudEvent.data = data; | |
415 this.dispatchEvent(printToCloudEvent); | |
416 }, | |
417 | |
418 /** | |
419 * Called from PrintPreviewUI::OnFileSelectionCancelled to notify the print | |
420 * preview tab regarding the file selection cancel event. | |
421 * @private | |
422 */ | |
423 onFileSelectionCancelled_: function() { | |
424 cr.dispatchSimpleEvent( | |
425 this, print_preview.NativeLayer.EventType.FILE_SELECTION_CANCEL); | |
426 }, | |
427 | |
428 /** | |
429 * Called from PrintPreviewUI::OnFileSelectionCompleted to notify the print | |
430 * preview tab regarding the file selection completed event. | |
431 * @private | |
432 */ | |
433 onFileSelectionCompleted_: function() { | |
434 // If the file selection is completed and the tab is not already closed it | |
435 // means that a pending print to pdf request exists. | |
436 cr.dispatchSimpleEvent( | |
437 this, print_preview.NativeLayer.EventType.FILE_SELECTION_COMPLETE); | |
438 }, | |
439 | |
440 /** | |
441 * Display an error message when print preview fails. | |
442 * Called from PrintPreviewMessageHandler::OnPrintPreviewFailed(). | |
443 * @private | |
444 */ | |
445 onPrintPreviewFailed_: function() { | |
446 cr.dispatchSimpleEvent( | |
447 this, print_preview.NativeLayer.EventType.PREVIEW_GENERATION_FAIL); | |
448 }, | |
449 | |
450 /** | |
451 * Display an error message when encountered invalid printer settings. | |
452 * Called from PrintPreviewMessageHandler::OnInvalidPrinterSettings(). | |
453 * @private | |
454 */ | |
455 onInvalidPrinterSettings_: function() { | |
456 cr.dispatchSimpleEvent( | |
457 this, print_preview.NativeLayer.EventType.SETTINGS_INVALID); | |
458 }, | |
459 | |
460 /** | |
461 * @param {{contentWidth: number, contentHeight: number, marginLeft: number, | |
462 * marginRight: number, marginTop: number, marginBottom: number, | |
463 * printableAreaX: number, printableAreaY: number, | |
464 * printableAreaWidth: number, printableAreaHeight: number}} | |
465 * pageLayout Specifies default page layout details in points. | |
466 * @param {boolean} hasCustomPageSizeStyle Indicates whether the previewed | |
467 * document has a custom page size style. | |
468 * @private | |
469 */ | |
470 onDidGetDefaultPageLayout_: function(pageLayout, hasCustomPageSizeStyle) { | |
471 var pageLayoutChangeEvent = new cr.Event( | |
472 print_preview.NativeLayer.EventType.PAGE_LAYOUT_READY); | |
473 pageLayoutChangeEvent.pageLayout = pageLayout; | |
474 pageLayoutChangeEvent.hasCustomPageSizeStyle = hasCustomPageSizeStyle; | |
475 this.dispatchEvent(pageLayoutChangeEvent); | |
476 }, | |
477 | |
478 /** | |
479 * Update the page count and check the page range. | |
480 * Called from PrintPreviewUI::OnDidGetPreviewPageCount(). | |
481 * @param {number} pageCount The number of pages. | |
482 * @param {number} previewResponseId The preview request id that resulted in | |
483 * this response. | |
484 * @private | |
485 */ | |
486 onDidGetPreviewPageCount_: function(pageCount, previewResponseId) { | |
487 var pageCountChangeEvent = new cr.Event( | |
488 print_preview.NativeLayer.EventType.PAGE_COUNT_READY); | |
489 pageCountChangeEvent.pageCount = pageCount; | |
490 pageCountChangeEvent.previewResponseId = previewResponseId; | |
491 this.dispatchEvent(pageCountChangeEvent); | |
492 }, | |
493 | |
494 /** | |
495 * Called when no pipelining previewed pages. | |
496 * @param {string} previewUid Preview unique identifier. | |
497 * @param {number} previewResponseId The preview request id that resulted in | |
498 * this response. | |
499 * @private | |
500 */ | |
501 onReloadPreviewPages_: function(previewUid, previewResponseId) { | |
502 var previewReloadEvent = new cr.Event( | |
503 print_preview.NativeLayer.EventType.PREVIEW_RELOAD); | |
504 previewReloadEvent.previewUid = previewUid; | |
505 previewReloadEvent.previewResponseId = previewResponseId; | |
506 this.dispatchEvent(previewReloadEvent); | |
507 }, | |
508 | |
509 /** | |
510 * Notification that a print preview page has been rendered. | |
511 * Check if the settings have changed and request a regeneration if needed. | |
512 * Called from PrintPreviewUI::OnDidPreviewPage(). | |
513 * @param {number} pageNumber The page number, 0-based. | |
514 * @param {string} previewUid Preview unique identifier. | |
515 * @param {number} previewResponseId The preview request id that resulted in | |
516 * this response. | |
517 * @private | |
518 */ | |
519 onDidPreviewPage_: function(pageNumber, previewUid, previewResponseId) { | |
520 var pagePreviewGenEvent = new cr.Event( | |
521 print_preview.NativeLayer.EventType.PAGE_PREVIEW_READY); | |
522 pagePreviewGenEvent.pageIndex = pageNumber; | |
523 pagePreviewGenEvent.previewUid = previewUid; | |
524 pagePreviewGenEvent.previewResponseId = previewResponseId; | |
525 this.dispatchEvent(pagePreviewGenEvent); | |
526 }, | |
527 | |
528 /** | |
529 * Update the print preview when new preview data is available. | |
530 * Create the PDF plugin as needed. | |
531 * Called from PrintPreviewUI::PreviewDataIsAvailable(). | |
532 * @param {string} previewUid Preview unique identifier. | |
533 * @param {number} previewResponseId The preview request id that resulted in | |
534 * this response. | |
535 * @private | |
536 */ | |
537 onUpdatePrintPreview_: function(previewUid, previewResponseId) { | |
538 var previewGenDoneEvent = new cr.Event( | |
539 print_preview.NativeLayer.EventType.PREVIEW_GENERATION_DONE); | |
540 previewGenDoneEvent.previewUid = previewUid; | |
541 previewGenDoneEvent.previewResponseId = previewResponseId; | |
542 this.dispatchEvent(previewGenDoneEvent); | |
543 } | |
544 }; | |
545 | |
546 /** | |
547 * Initial settings retrieved from the native layer. | |
548 * @param {boolean} isInKioskAutoPrintMode Whether the print preview should be | |
549 * in auto-print mode. | |
550 * @param {string} thousandsDelimeter Character delimeter of thousands digits. | |
551 * @param {string} decimalDelimeter Character delimeter of the decimal point. | |
552 * @param {print_preview.MeasurementSystem.UnitType} unitType Unit type of | |
553 * local machine's measurement system. | |
554 * @param {boolean} isDocumentModifiable Whether the document to print is | |
555 * modifiable. | |
556 * @param {?print_preview.ticket_items.MarginsType.Value} marginsType Initial | |
557 * margins type. | |
558 * @param {print_preview.Margins} customMargins Initial custom margins. | |
559 * @param {boolean} isDuplexEnabled Whether duplexing is initially enabled. | |
560 * @param {boolean} isHeaderFooterEnabled Whether the header-footer is | |
561 * initially enabled. | |
562 * @param {?string} initialDestinationId ID of the destination to initially | |
563 * select. | |
564 * @constructor | |
565 */ | |
566 function NativeInitialSettings( | |
567 isInKioskAutoPrintMode, | |
568 thousandsDelimeter, | |
569 decimalDelimeter, | |
570 unitType, | |
571 isDocumentModifiable, | |
572 marginsType, | |
573 customMargins, | |
574 isDuplexEnabled, | |
575 isHeaderFooterEnabled, | |
576 initialDestinationId) { | |
577 | |
578 /** | |
579 * Whether the print preview should be in auto-print mode. | |
580 * @type {boolean} | |
581 * @private | |
582 */ | |
583 this.isInKioskAutoPrintMode_ = isInKioskAutoPrintMode; | |
584 | |
585 /** | |
586 * Character delimeter of thousands digits. | |
587 * @type {string} | |
588 * @private | |
589 */ | |
590 this.thousandsDelimeter_ = thousandsDelimeter; | |
591 | |
592 /** | |
593 * Character delimeter of the decimal point. | |
594 * @type {string} | |
595 * @private | |
596 */ | |
597 this.decimalDelimeter_ = decimalDelimeter; | |
598 | |
599 /** | |
600 * Unit type of local machine's measurement system. | |
601 * @type {string} | |
602 * @private | |
603 */ | |
604 this.unitType_ = unitType; | |
605 | |
606 /** | |
607 * Whether the document to print is modifiable. | |
608 * @type {boolean} | |
609 * @private | |
610 */ | |
611 this.isDocumentModifiable_ = isDocumentModifiable; | |
612 | |
613 /** | |
614 * Initial margins type. | |
615 * @type {?print_preview.ticket_items.MarginsType.Value} | |
616 * @private | |
617 */ | |
618 this.marginsType_ = marginsType; | |
619 | |
620 /** | |
621 * Initial custom margins. | |
622 * @type {print_preview.Margins} | |
623 * @private | |
624 */ | |
625 this.customMargins_ = customMargins; | |
626 | |
627 /** | |
628 * Whether duplexing is initially enabled. | |
629 * @type {boolean} | |
630 * @private | |
631 */ | |
632 this.isDuplexEnabled_ = isDuplexEnabled; | |
633 | |
634 /** | |
635 * Whether the header-footer is initially enabled. | |
636 * @type {boolean} | |
637 * @private | |
638 */ | |
639 this.isHeaderFooterEnabled_ = isHeaderFooterEnabled; | |
640 | |
641 /** | |
642 * ID of the initially selected destination. | |
643 * @type {?string} | |
644 * @private | |
645 */ | |
646 this.initialDestinationId_ = initialDestinationId; | |
647 }; | |
648 | |
649 NativeInitialSettings.prototype = { | |
650 /** | |
651 * @return {boolean} Whether the print preview should be in auto-print mode. | |
652 */ | |
653 get isInKioskAutoPrintMode() { | |
654 return this.isInKioskAutoPrintMode_; | |
655 }, | |
656 | |
657 /** @return {string} Character delimeter of thousands digits. */ | |
658 get thousandsDelimeter() { | |
659 return this.thousandsDelimeter_; | |
660 }, | |
661 | |
662 /** @return {string} Character delimeter of the decimal point. */ | |
663 get decimalDelimeter() { | |
664 return this.decimalDelimeter_; | |
665 }, | |
666 | |
667 /** | |
668 * @return {print_preview.MeasurementSystem.UnitType} Unit type of local | |
669 * machine's measurement system. | |
670 */ | |
671 get unitType() { | |
672 return this.unitType_; | |
673 }, | |
674 | |
675 /** @return {boolean} Whether the document to print is modifiable. */ | |
676 get isDocumentModifiable() { | |
677 return this.isDocumentModifiable_; | |
678 }, | |
679 | |
680 /** | |
681 * @return {?print_preview.ticket_items.MarginsType.Value} Initial margins | |
682 * type or {@code null} if not initially set. | |
683 */ | |
684 get marginsType() { | |
685 return this.marginsType_; | |
686 }, | |
687 | |
688 /** @return {print_preview.Margins} Initial custom margins. */ | |
689 get customMargins() { | |
690 return this.customMargins_; | |
691 }, | |
692 | |
693 /** @return {boolean} Whether duplexing is initially enabled. */ | |
694 get isDuplexEnabled() { | |
695 return this.isDuplexEnabled_; | |
696 }, | |
697 | |
698 /** @return {boolean} Whether the header-footer is initially enabled. */ | |
699 get isHeaderFooterEnabled() { | |
700 this.isHeaderFooterEnabled_; | |
701 }, | |
702 | |
703 /** @return {?string} ID of the initially selected destination. */ | |
704 get initialDestinationId() { | |
705 return this.initialDestinationId_; | |
706 } | |
707 }; | |
708 | |
709 // Export | |
710 return { | |
711 NativeInitialSettings: NativeInitialSettings, | |
712 NativeLayer: NativeLayer | |
713 }; | |
714 }); | |
OLD | NEW |