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