OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // TODO(rltoscano): Move data/* into print_preview.data namespace | 5 // TODO(rltoscano): Move data/* into print_preview.data namespace |
6 | 6 |
7 // <include src="component.js"> | 7 // <include src="component.js"> |
8 // <include src="print_preview_focus_manager.js"> | 8 // <include src="print_preview_focus_manager.js"> |
9 // | 9 // |
10 | 10 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 */ | 117 */ |
118 this.destinationSearch_ = new print_preview.DestinationSearch( | 118 this.destinationSearch_ = new print_preview.DestinationSearch( |
119 this.destinationStore_, this.invitationStore_, this.userInfo_); | 119 this.destinationStore_, this.invitationStore_, this.userInfo_); |
120 this.addChild(this.destinationSearch_); | 120 this.addChild(this.destinationSearch_); |
121 | 121 |
122 /** | 122 /** |
123 * Component that renders the print destination. | 123 * Component that renders the print destination. |
124 * @type {!print_preview.DestinationSettings} | 124 * @type {!print_preview.DestinationSettings} |
125 * @private | 125 * @private |
126 */ | 126 */ |
127 this.destinationSettings_ = new print_preview.DestinationSettings( | 127 this.destinationSettings_ = |
128 this.destinationStore_); | 128 new print_preview.DestinationSettings(this.destinationStore_); |
129 this.addChild(this.destinationSettings_); | 129 this.addChild(this.destinationSettings_); |
130 | 130 |
131 /** | 131 /** |
132 * Component that renders UI for entering in page range. | 132 * Component that renders UI for entering in page range. |
133 * @type {!print_preview.PageSettings} | 133 * @type {!print_preview.PageSettings} |
134 * @private | 134 * @private |
135 */ | 135 */ |
136 this.pageSettings_ = new print_preview.PageSettings( | 136 this.pageSettings_ = |
137 this.printTicketStore_.pageRange); | 137 new print_preview.PageSettings(this.printTicketStore_.pageRange); |
138 this.addChild(this.pageSettings_); | 138 this.addChild(this.pageSettings_); |
139 | 139 |
140 /** | 140 /** |
141 * Component that renders the copies settings. | 141 * Component that renders the copies settings. |
142 * @type {!print_preview.CopiesSettings} | 142 * @type {!print_preview.CopiesSettings} |
143 * @private | 143 * @private |
144 */ | 144 */ |
145 this.copiesSettings_ = new print_preview.CopiesSettings( | 145 this.copiesSettings_ = new print_preview.CopiesSettings( |
146 this.printTicketStore_.copies, this.printTicketStore_.collate); | 146 this.printTicketStore_.copies, this.printTicketStore_.collate); |
147 this.addChild(this.copiesSettings_); | 147 this.addChild(this.copiesSettings_); |
148 | 148 |
149 /** | 149 /** |
150 * Component that renders the layout settings. | 150 * Component that renders the layout settings. |
151 * @type {!print_preview.LayoutSettings} | 151 * @type {!print_preview.LayoutSettings} |
152 * @private | 152 * @private |
153 */ | 153 */ |
154 this.layoutSettings_ = | 154 this.layoutSettings_ = |
155 new print_preview.LayoutSettings(this.printTicketStore_.landscape); | 155 new print_preview.LayoutSettings(this.printTicketStore_.landscape); |
156 this.addChild(this.layoutSettings_); | 156 this.addChild(this.layoutSettings_); |
157 | 157 |
158 /** | 158 /** |
159 * Component that renders the color options. | 159 * Component that renders the color options. |
160 * @type {!print_preview.ColorSettings} | 160 * @type {!print_preview.ColorSettings} |
161 * @private | 161 * @private |
162 */ | 162 */ |
163 this.colorSettings_ = | 163 this.colorSettings_ = |
164 new print_preview.ColorSettings(this.printTicketStore_.color); | 164 new print_preview.ColorSettings(this.printTicketStore_.color); |
165 this.addChild(this.colorSettings_); | 165 this.addChild(this.colorSettings_); |
166 | 166 |
167 /** | 167 /** |
168 * Component that renders the media size settings. | 168 * Component that renders the media size settings. |
169 * @type {!print_preview.MediaSizeSettings} | 169 * @type {!print_preview.MediaSizeSettings} |
170 * @private | 170 * @private |
171 */ | 171 */ |
172 this.mediaSizeSettings_ = | 172 this.mediaSizeSettings_ = |
173 new print_preview.MediaSizeSettings(this.printTicketStore_.mediaSize); | 173 new print_preview.MediaSizeSettings(this.printTicketStore_.mediaSize); |
174 this.addChild(this.mediaSizeSettings_); | 174 this.addChild(this.mediaSizeSettings_); |
175 | 175 |
176 /** | 176 /** |
177 * Component that renders a select box for choosing margin settings. | 177 * Component that renders a select box for choosing margin settings. |
(...skipping 11 matching lines...) Expand all Loading... |
189 */ | 189 */ |
190 this.dpiSettings_ = | 190 this.dpiSettings_ = |
191 new print_preview.DpiSettings(this.printTicketStore_.dpi); | 191 new print_preview.DpiSettings(this.printTicketStore_.dpi); |
192 this.addChild(this.dpiSettings_); | 192 this.addChild(this.dpiSettings_); |
193 | 193 |
194 /** | 194 /** |
195 * Component that renders the scaling settings. | 195 * Component that renders the scaling settings. |
196 * @type {!print_preview.ScalingSettings} | 196 * @type {!print_preview.ScalingSettings} |
197 * @private | 197 * @private |
198 */ | 198 */ |
199 this.scalingSettings_ = | 199 this.scalingSettings_ = new print_preview.ScalingSettings( |
200 new print_preview.ScalingSettings(this.printTicketStore_.scaling, | 200 this.printTicketStore_.scaling, this.printTicketStore_.fitToPage); |
201 this.printTicketStore_.fitToPage); | |
202 this.addChild(this.scalingSettings_); | 201 this.addChild(this.scalingSettings_); |
203 | 202 |
204 /** | 203 /** |
205 * Component that renders miscellaneous print options. | 204 * Component that renders miscellaneous print options. |
206 * @type {!print_preview.OtherOptionsSettings} | 205 * @type {!print_preview.OtherOptionsSettings} |
207 * @private | 206 * @private |
208 */ | 207 */ |
209 this.otherOptionsSettings_ = new print_preview.OtherOptionsSettings( | 208 this.otherOptionsSettings_ = new print_preview.OtherOptionsSettings( |
210 this.printTicketStore_.duplex, | 209 this.printTicketStore_.duplex, this.printTicketStore_.fitToPage, |
211 this.printTicketStore_.fitToPage, | |
212 this.printTicketStore_.cssBackground, | 210 this.printTicketStore_.cssBackground, |
213 this.printTicketStore_.selectionOnly, | 211 this.printTicketStore_.selectionOnly, |
214 this.printTicketStore_.headerFooter, | 212 this.printTicketStore_.headerFooter, this.printTicketStore_.rasterize); |
215 this.printTicketStore_.rasterize); | |
216 this.addChild(this.otherOptionsSettings_); | 213 this.addChild(this.otherOptionsSettings_); |
217 | 214 |
218 /** | 215 /** |
219 * Component that renders the advanced options button. | 216 * Component that renders the advanced options button. |
220 * @type {!print_preview.AdvancedOptionsSettings} | 217 * @type {!print_preview.AdvancedOptionsSettings} |
221 * @private | 218 * @private |
222 */ | 219 */ |
223 this.advancedOptionsSettings_ = new print_preview.AdvancedOptionsSettings( | 220 this.advancedOptionsSettings_ = new print_preview.AdvancedOptionsSettings( |
224 this.printTicketStore_.vendorItems, this.destinationStore_); | 221 this.printTicketStore_.vendorItems, this.destinationStore_); |
225 this.addChild(this.advancedOptionsSettings_); | 222 this.addChild(this.advancedOptionsSettings_); |
226 | 223 |
227 /** | 224 /** |
228 * Component used to search for print destinations. | 225 * Component used to search for print destinations. |
229 * @type {!print_preview.AdvancedSettings} | 226 * @type {!print_preview.AdvancedSettings} |
230 * @private | 227 * @private |
231 */ | 228 */ |
232 this.advancedSettings_ = new print_preview.AdvancedSettings( | 229 this.advancedSettings_ = |
233 this.printTicketStore_); | 230 new print_preview.AdvancedSettings(this.printTicketStore_); |
234 this.addChild(this.advancedSettings_); | 231 this.addChild(this.advancedSettings_); |
235 | 232 |
236 var settingsSections = [ | 233 var settingsSections = [ |
237 this.destinationSettings_, | 234 this.destinationSettings_, this.pageSettings_, this.copiesSettings_, |
238 this.pageSettings_, | 235 this.mediaSizeSettings_, this.layoutSettings_, this.marginSettings_, |
239 this.copiesSettings_, | 236 this.colorSettings_, this.dpiSettings_, this.scalingSettings_, |
240 this.mediaSizeSettings_, | 237 this.otherOptionsSettings_, this.advancedOptionsSettings_ |
241 this.layoutSettings_, | 238 ]; |
242 this.marginSettings_, | |
243 this.colorSettings_, | |
244 this.dpiSettings_, | |
245 this.scalingSettings_, | |
246 this.otherOptionsSettings_, | |
247 this.advancedOptionsSettings_]; | |
248 | 239 |
249 /** | 240 /** |
250 * Component representing more/less settings button. | 241 * Component representing more/less settings button. |
251 * @type {!print_preview.MoreSettings} | 242 * @type {!print_preview.MoreSettings} |
252 * @private | 243 * @private |
253 */ | 244 */ |
254 this.moreSettings_ = new print_preview.MoreSettings( | 245 this.moreSettings_ = new print_preview.MoreSettings( |
255 this.destinationStore_, settingsSections); | 246 this.destinationStore_, settingsSections); |
256 this.addChild(this.moreSettings_); | 247 this.addChild(this.moreSettings_); |
257 | 248 |
258 /** | 249 /** |
259 * Area of the UI that holds the print preview. | 250 * Area of the UI that holds the print preview. |
260 * @type {!print_preview.PreviewArea} | 251 * @type {!print_preview.PreviewArea} |
261 * @private | 252 * @private |
262 */ | 253 */ |
263 this.previewArea_ = new print_preview.PreviewArea(this.destinationStore_, | 254 this.previewArea_ = new print_preview.PreviewArea( |
264 this.printTicketStore_, | 255 this.destinationStore_, this.printTicketStore_, this.nativeLayer_, |
265 this.nativeLayer_, | 256 this.documentInfo_); |
266 this.documentInfo_); | |
267 this.addChild(this.previewArea_); | 257 this.addChild(this.previewArea_); |
268 | 258 |
269 /** | 259 /** |
270 * Interface to the Google Cloud Print API. Null if Google Cloud Print | 260 * Interface to the Google Cloud Print API. Null if Google Cloud Print |
271 * integration is disabled. | 261 * integration is disabled. |
272 * @type {cloudprint.CloudPrintInterface} | 262 * @type {cloudprint.CloudPrintInterface} |
273 * @private | 263 * @private |
274 */ | 264 */ |
275 this.cloudPrintInterface_ = null; | 265 this.cloudPrintInterface_ = null; |
276 | 266 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 /** Sets up the page and print preview by getting the printer list. */ | 324 /** Sets up the page and print preview by getting the printer list. */ |
335 initialize: function() { | 325 initialize: function() { |
336 this.decorate($('print-preview')); | 326 this.decorate($('print-preview')); |
337 if (!this.previewArea_.hasCompatiblePlugin) { | 327 if (!this.previewArea_.hasCompatiblePlugin) { |
338 this.setIsEnabled_(false); | 328 this.setIsEnabled_(false); |
339 } | 329 } |
340 this.nativeLayer_.getInitialSettings().then( | 330 this.nativeLayer_.getInitialSettings().then( |
341 this.onInitialSettingsSet_.bind(this)); | 331 this.onInitialSettingsSet_.bind(this)); |
342 print_preview.PrintPreviewFocusManager.getInstance().initialize(); | 332 print_preview.PrintPreviewFocusManager.getInstance().initialize(); |
343 cr.ui.FocusOutlineManager.forDocument(document); | 333 cr.ui.FocusOutlineManager.forDocument(document); |
344 this.listenerTracker.add('print-failed', | 334 this.listenerTracker.add('print-failed', this.onPrintFailed_.bind(this)); |
345 this.onPrintFailed_.bind(this)); | 335 this.listenerTracker.add( |
346 this.listenerTracker.add('privet-printer-added', | 336 'privet-printer-added', |
347 this.destinationStore_.onPrivetPrinterAdded_.bind( | 337 this.destinationStore_.onPrivetPrinterAdded_.bind( |
348 this.destinationStore_)); | 338 this.destinationStore_)); |
349 this.listenerTracker.add('extension-printers-added', | 339 this.listenerTracker.add( |
| 340 'extension-printers-added', |
350 this.destinationStore_.onExtensionPrintersAdded_.bind( | 341 this.destinationStore_.onExtensionPrintersAdded_.bind( |
351 this.destinationStore_)); | 342 this.destinationStore_)); |
352 }, | 343 }, |
353 | 344 |
354 /** @override */ | 345 /** @override */ |
355 enterDocument: function() { | 346 enterDocument: function() { |
356 // Native layer events. | 347 // Native layer events. |
357 var nativeLayerEventTarget = this.nativeLayer_.getEventTarget(); | 348 var nativeLayerEventTarget = this.nativeLayer_.getEventTarget(); |
358 this.tracker.add( | 349 this.tracker.add( |
359 nativeLayerEventTarget, | 350 nativeLayerEventTarget, |
(...skipping 23 matching lines...) Expand all Loading... |
383 nativeLayerEventTarget, | 374 nativeLayerEventTarget, |
384 print_preview.NativeLayer.EventType.PAGE_COUNT_READY, | 375 print_preview.NativeLayer.EventType.PAGE_COUNT_READY, |
385 this.onPageCountReady_.bind(this)); | 376 this.onPageCountReady_.bind(this)); |
386 this.tracker.add( | 377 this.tracker.add( |
387 nativeLayerEventTarget, | 378 nativeLayerEventTarget, |
388 print_preview.NativeLayer.EventType.MANIPULATE_SETTINGS_FOR_TEST, | 379 print_preview.NativeLayer.EventType.MANIPULATE_SETTINGS_FOR_TEST, |
389 this.onManipulateSettingsForTest_.bind(this)); | 380 this.onManipulateSettingsForTest_.bind(this)); |
390 | 381 |
391 if ($('system-dialog-link')) { | 382 if ($('system-dialog-link')) { |
392 this.tracker.add( | 383 this.tracker.add( |
393 getRequiredElement('system-dialog-link'), | 384 getRequiredElement('system-dialog-link'), 'click', |
394 'click', | |
395 this.openSystemPrintDialog_.bind(this)); | 385 this.openSystemPrintDialog_.bind(this)); |
396 } | 386 } |
397 if ($('open-pdf-in-preview-link')) { | 387 if ($('open-pdf-in-preview-link')) { |
398 this.tracker.add( | 388 this.tracker.add( |
399 getRequiredElement('open-pdf-in-preview-link'), | 389 getRequiredElement('open-pdf-in-preview-link'), 'click', |
400 'click', | |
401 this.onOpenPdfInPreviewLinkClick_.bind(this)); | 390 this.onOpenPdfInPreviewLinkClick_.bind(this)); |
402 } | 391 } |
403 | 392 |
404 this.tracker.add( | 393 this.tracker.add( |
405 this.previewArea_, | 394 this.previewArea_, |
406 print_preview.PreviewArea.EventType.PREVIEW_GENERATION_IN_PROGRESS, | 395 print_preview.PreviewArea.EventType.PREVIEW_GENERATION_IN_PROGRESS, |
407 this.onPreviewGenerationInProgress_.bind(this)); | 396 this.onPreviewGenerationInProgress_.bind(this)); |
408 this.tracker.add( | 397 this.tracker.add( |
409 this.previewArea_, | 398 this.previewArea_, |
410 print_preview.PreviewArea.EventType.PREVIEW_GENERATION_DONE, | 399 print_preview.PreviewArea.EventType.PREVIEW_GENERATION_DONE, |
411 this.onPreviewGenerationDone_.bind(this)); | 400 this.onPreviewGenerationDone_.bind(this)); |
412 this.tracker.add( | 401 this.tracker.add( |
413 this.previewArea_, | 402 this.previewArea_, |
414 print_preview.PreviewArea.EventType.PREVIEW_GENERATION_FAIL, | 403 print_preview.PreviewArea.EventType.PREVIEW_GENERATION_FAIL, |
415 this.onPreviewGenerationFail_.bind(this)); | 404 this.onPreviewGenerationFail_.bind(this)); |
416 this.tracker.add( | 405 this.tracker.add( |
417 this.previewArea_, | 406 this.previewArea_, |
418 print_preview.PreviewArea.EventType.OPEN_SYSTEM_DIALOG_CLICK, | 407 print_preview.PreviewArea.EventType.OPEN_SYSTEM_DIALOG_CLICK, |
419 this.openSystemPrintDialog_.bind(this)); | 408 this.openSystemPrintDialog_.bind(this)); |
420 | 409 |
421 this.tracker.add( | 410 this.tracker.add( |
422 this.destinationStore_, | 411 this.destinationStore_, |
423 print_preview.DestinationStore.EventType. | 412 print_preview.DestinationStore.EventType |
424 SELECTED_DESTINATION_CAPABILITIES_READY, | 413 .SELECTED_DESTINATION_CAPABILITIES_READY, |
425 this.printIfReady_.bind(this)); | 414 this.printIfReady_.bind(this)); |
426 this.tracker.add( | 415 this.tracker.add( |
427 this.destinationStore_, | 416 this.destinationStore_, |
428 print_preview.DestinationStore.EventType.DESTINATION_SELECT, | 417 print_preview.DestinationStore.EventType.DESTINATION_SELECT, |
429 this.onDestinationSelect_.bind(this)); | 418 this.onDestinationSelect_.bind(this)); |
430 this.tracker.add( | 419 this.tracker.add( |
431 this.destinationStore_, | 420 this.destinationStore_, |
432 print_preview.DestinationStore.EventType.DESTINATION_SEARCH_DONE, | 421 print_preview.DestinationStore.EventType.DESTINATION_SEARCH_DONE, |
433 this.onDestinationSearchDone_.bind(this)); | 422 this.onDestinationSearchDone_.bind(this)); |
434 | 423 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 this.onCloudPrintRegisterPromoClick_.bind(this)); | 460 this.onCloudPrintRegisterPromoClick_.bind(this)); |
472 | 461 |
473 this.tracker.add( | 462 this.tracker.add( |
474 this.advancedOptionsSettings_, | 463 this.advancedOptionsSettings_, |
475 print_preview.AdvancedOptionsSettings.EventType.BUTTON_ACTIVATED, | 464 print_preview.AdvancedOptionsSettings.EventType.BUTTON_ACTIVATED, |
476 this.onAdvancedOptionsButtonActivated_.bind(this)); | 465 this.onAdvancedOptionsButtonActivated_.bind(this)); |
477 | 466 |
478 // TODO(rltoscano): Move no-destinations-promo into its own component | 467 // TODO(rltoscano): Move no-destinations-promo into its own component |
479 // instead being part of PrintPreview. | 468 // instead being part of PrintPreview. |
480 this.tracker.add( | 469 this.tracker.add( |
481 this.getChildElement('#no-destinations-promo .close-button'), | 470 this.getChildElement('#no-destinations-promo .close-button'), 'click', |
482 'click', | |
483 this.onNoDestinationsPromoClose_.bind(this)); | 471 this.onNoDestinationsPromoClose_.bind(this)); |
484 this.tracker.add( | 472 this.tracker.add( |
485 this.getChildElement('#no-destinations-promo .not-now-button'), | 473 this.getChildElement('#no-destinations-promo .not-now-button'), |
486 'click', | 474 'click', this.onNoDestinationsPromoClose_.bind(this)); |
487 this.onNoDestinationsPromoClose_.bind(this)); | |
488 this.tracker.add( | 475 this.tracker.add( |
489 this.getChildElement('#no-destinations-promo .add-printer-button'), | 476 this.getChildElement('#no-destinations-promo .add-printer-button'), |
490 'click', | 477 'click', this.onNoDestinationsPromoClick_.bind(this)); |
491 this.onNoDestinationsPromoClick_.bind(this)); | |
492 }, | 478 }, |
493 | 479 |
494 /** @override */ | 480 /** @override */ |
495 decorateInternal: function() { | 481 decorateInternal: function() { |
496 this.printHeader_.decorate($('print-header')); | 482 this.printHeader_.decorate($('print-header')); |
497 this.destinationSearch_.decorate($('destination-search')); | 483 this.destinationSearch_.decorate($('destination-search')); |
498 this.destinationSettings_.decorate($('destination-settings')); | 484 this.destinationSettings_.decorate($('destination-settings')); |
499 this.pageSettings_.decorate($('page-settings')); | 485 this.pageSettings_.decorate($('page-settings')); |
500 this.copiesSettings_.decorate($('copies-settings')); | 486 this.copiesSettings_.decorate($('copies-settings')); |
501 this.layoutSettings_.decorate($('layout-settings')); | 487 this.layoutSettings_.decorate($('layout-settings')); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 this.otherOptionsSettings_.isEnabled = isEnabled; | 521 this.otherOptionsSettings_.isEnabled = isEnabled; |
536 this.advancedOptionsSettings_.isEnabled = isEnabled; | 522 this.advancedOptionsSettings_.isEnabled = isEnabled; |
537 }, | 523 }, |
538 | 524 |
539 /** | 525 /** |
540 * Prints the document or launches a pdf preview on the local system. | 526 * Prints the document or launches a pdf preview on the local system. |
541 * @param {boolean} isPdfPreview Whether to launch the pdf preview. | 527 * @param {boolean} isPdfPreview Whether to launch the pdf preview. |
542 * @private | 528 * @private |
543 */ | 529 */ |
544 printDocumentOrOpenPdfPreview_: function(isPdfPreview) { | 530 printDocumentOrOpenPdfPreview_: function(isPdfPreview) { |
545 assert(this.uiState_ == PrintPreviewUiState_.READY, | 531 assert( |
546 'Print document request received when not in ready state: ' + | 532 this.uiState_ == PrintPreviewUiState_.READY, |
547 this.uiState_); | 533 'Print document request received when not in ready state: ' + |
| 534 this.uiState_); |
548 if (isPdfPreview) { | 535 if (isPdfPreview) { |
549 this.uiState_ = PrintPreviewUiState_.OPENING_PDF_PREVIEW; | 536 this.uiState_ = PrintPreviewUiState_.OPENING_PDF_PREVIEW; |
550 } else if (this.destinationStore_.selectedDestination.id == | 537 } else if ( |
| 538 this.destinationStore_.selectedDestination.id == |
551 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { | 539 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { |
552 this.uiState_ = PrintPreviewUiState_.FILE_SELECTION; | 540 this.uiState_ = PrintPreviewUiState_.FILE_SELECTION; |
553 } else { | 541 } else { |
554 this.uiState_ = PrintPreviewUiState_.PRINTING; | 542 this.uiState_ = PrintPreviewUiState_.PRINTING; |
555 } | 543 } |
556 this.setIsEnabled_(false); | 544 this.setIsEnabled_(false); |
557 this.printHeader_.isCancelButtonEnabled = true; | 545 this.printHeader_.isCancelButtonEnabled = true; |
558 var printAttemptResult = this.printIfReady_(); | 546 var printAttemptResult = this.printIfReady_(); |
559 if (printAttemptResult == print_preview.PrintAttemptResult_.PRINTED || | 547 if (printAttemptResult == print_preview.PrintAttemptResult_.PRINTED || |
560 printAttemptResult == | 548 printAttemptResult == |
561 print_preview.PrintAttemptResult_.READY_WAITING_FOR_PREVIEW) { | 549 print_preview.PrintAttemptResult_.READY_WAITING_FOR_PREVIEW) { |
562 if ((this.destinationStore_.selectedDestination.isLocal && | 550 if ((this.destinationStore_.selectedDestination.isLocal && |
563 !this.destinationStore_.selectedDestination.isPrivet && | 551 !this.destinationStore_.selectedDestination.isPrivet && |
564 !this.destinationStore_.selectedDestination.isExtension && | 552 !this.destinationStore_.selectedDestination.isExtension && |
565 this.destinationStore_.selectedDestination.id != | 553 this.destinationStore_.selectedDestination.id != |
566 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) || | 554 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) || |
567 this.uiState_ == PrintPreviewUiState_.OPENING_PDF_PREVIEW) { | 555 this.uiState_ == PrintPreviewUiState_.OPENING_PDF_PREVIEW) { |
568 // Hide the dialog for now. The actual print command will be issued | 556 // Hide the dialog for now. The actual print command will be issued |
569 // when the preview generation is done. | 557 // when the preview generation is done. |
570 this.nativeLayer_.startHideDialog(); | 558 this.nativeLayer_.startHideDialog(); |
571 } | 559 } |
572 } | 560 } |
573 }, | 561 }, |
574 | 562 |
575 /** | 563 /** |
576 * Attempts to print if needed and if ready. | 564 * Attempts to print if needed and if ready. |
577 * @return {print_preview.PrintAttemptResult_} Attempt result. | 565 * @return {print_preview.PrintAttemptResult_} Attempt result. |
578 * @private | 566 * @private |
579 */ | 567 */ |
580 printIfReady_: function() { | 568 printIfReady_: function() { |
581 var okToPrint = | 569 var okToPrint = |
582 (this.uiState_ == PrintPreviewUiState_.PRINTING || | 570 (this.uiState_ == PrintPreviewUiState_.PRINTING || |
583 this.uiState_ == PrintPreviewUiState_.OPENING_PDF_PREVIEW || | 571 this.uiState_ == PrintPreviewUiState_.OPENING_PDF_PREVIEW || |
584 this.uiState_ == PrintPreviewUiState_.FILE_SELECTION || | 572 this.uiState_ == PrintPreviewUiState_.FILE_SELECTION || |
585 this.isInKioskAutoPrintMode_) && | 573 this.isInKioskAutoPrintMode_) && |
586 this.destinationStore_.selectedDestination && | 574 this.destinationStore_.selectedDestination && |
587 this.destinationStore_.selectedDestination.capabilities; | 575 this.destinationStore_.selectedDestination.capabilities; |
588 if (!okToPrint) { | 576 if (!okToPrint) { |
589 return print_preview.PrintAttemptResult_.NOT_READY; | 577 return print_preview.PrintAttemptResult_.NOT_READY; |
590 } | 578 } |
591 if (this.isPreviewGenerationInProgress_) { | 579 if (this.isPreviewGenerationInProgress_) { |
592 return print_preview.PrintAttemptResult_.READY_WAITING_FOR_PREVIEW; | 580 return print_preview.PrintAttemptResult_.READY_WAITING_FOR_PREVIEW; |
593 } | 581 } |
594 assert(this.printTicketStore_.isTicketValid(), | 582 assert( |
| 583 this.printTicketStore_.isTicketValid(), |
595 'Trying to print with invalid ticket'); | 584 'Trying to print with invalid ticket'); |
596 if (getIsVisible(this.moreSettings_.getElement())) { | 585 if (getIsVisible(this.moreSettings_.getElement())) { |
597 new print_preview.PrintSettingsUiMetricsContext().record( | 586 new print_preview.PrintSettingsUiMetricsContext().record( |
598 this.moreSettings_.isExpanded ? | 587 this.moreSettings_.isExpanded ? |
599 print_preview.Metrics.PrintSettingsUiBucket. | 588 print_preview.Metrics.PrintSettingsUiBucket |
600 PRINT_WITH_SETTINGS_EXPANDED : | 589 .PRINT_WITH_SETTINGS_EXPANDED : |
601 print_preview.Metrics.PrintSettingsUiBucket. | 590 print_preview.Metrics.PrintSettingsUiBucket |
602 PRINT_WITH_SETTINGS_COLLAPSED); | 591 .PRINT_WITH_SETTINGS_COLLAPSED); |
603 } | 592 } |
604 this.nativeLayer_.startPrint( | 593 this.nativeLayer_.startPrint( |
605 assert(this.destinationStore_.selectedDestination), | 594 assert(this.destinationStore_.selectedDestination), |
606 this.printTicketStore_, | 595 this.printTicketStore_, this.cloudPrintInterface_, this.documentInfo_, |
607 this.cloudPrintInterface_, | |
608 this.documentInfo_, | |
609 this.uiState_ == PrintPreviewUiState_.OPENING_PDF_PREVIEW, | 596 this.uiState_ == PrintPreviewUiState_.OPENING_PDF_PREVIEW, |
610 this.showSystemDialogBeforeNextPrint_); | 597 this.showSystemDialogBeforeNextPrint_); |
611 this.showSystemDialogBeforeNextPrint_ = false; | 598 this.showSystemDialogBeforeNextPrint_ = false; |
612 return print_preview.PrintAttemptResult_.PRINTED; | 599 return print_preview.PrintAttemptResult_.PRINTED; |
613 }, | 600 }, |
614 | 601 |
615 /** | 602 /** |
616 * Closes the print preview. | 603 * Closes the print preview. |
617 * @private | 604 * @private |
618 */ | 605 */ |
(...skipping 25 matching lines...) Expand all Loading... |
644 | 631 |
645 /** | 632 /** |
646 * Called when the native layer has initial settings to set. Sets the | 633 * Called when the native layer has initial settings to set. Sets the |
647 * initial settings of the print preview and begins fetching print | 634 * initial settings of the print preview and begins fetching print |
648 * destinations. | 635 * destinations. |
649 * @param {!print_preview.NativeInitialSettings} settings The initial print | 636 * @param {!print_preview.NativeInitialSettings} settings The initial print |
650 * preview settings persisted through the session. | 637 * preview settings persisted through the session. |
651 * @private | 638 * @private |
652 */ | 639 */ |
653 onInitialSettingsSet_: function(settings) { | 640 onInitialSettingsSet_: function(settings) { |
654 assert(this.uiState_ == PrintPreviewUiState_.INITIALIZING, | 641 assert( |
655 'Updating initial settings when not in initializing state: ' + | 642 this.uiState_ == PrintPreviewUiState_.INITIALIZING, |
656 this.uiState_); | 643 'Updating initial settings when not in initializing state: ' + |
| 644 this.uiState_); |
657 this.uiState_ = PrintPreviewUiState_.READY; | 645 this.uiState_ = PrintPreviewUiState_.READY; |
658 | 646 |
659 this.isInKioskAutoPrintMode_ = settings.isInKioskAutoPrintMode; | 647 this.isInKioskAutoPrintMode_ = settings.isInKioskAutoPrintMode; |
660 this.isInAppKioskMode_ = settings.isInAppKioskMode; | 648 this.isInAppKioskMode_ = settings.isInAppKioskMode; |
661 | 649 |
662 // The following components must be initialized in this order. | 650 // The following components must be initialized in this order. |
663 this.appState_.init(settings.serializedAppStateStr); | 651 this.appState_.init(settings.serializedAppStateStr); |
664 this.documentInfo_.init( | 652 this.documentInfo_.init( |
665 settings.isDocumentModifiable, | 653 settings.isDocumentModifiable, settings.documentTitle, |
666 settings.documentTitle, | |
667 settings.documentHasSelection); | 654 settings.documentHasSelection); |
668 this.printTicketStore_.init( | 655 this.printTicketStore_.init( |
669 settings.thousandsDelimeter, | 656 settings.thousandsDelimeter, settings.decimalDelimeter, |
670 settings.decimalDelimeter, | 657 settings.unitType, settings.selectionOnly); |
671 settings.unitType, | |
672 settings.selectionOnly); | |
673 this.destinationStore_.init( | 658 this.destinationStore_.init( |
674 settings.isInAppKioskMode, | 659 settings.isInAppKioskMode, settings.systemDefaultDestinationId, |
675 settings.systemDefaultDestinationId, | |
676 settings.serializedDefaultDestinationSelectionRulesStr); | 660 settings.serializedDefaultDestinationSelectionRulesStr); |
677 this.appState_.setInitialized(); | 661 this.appState_.setInitialized(); |
678 | 662 |
679 $('document-title').innerText = settings.documentTitle; | 663 $('document-title').innerText = settings.documentTitle; |
680 this.hideSystemDialogLink_ = settings.isInAppKioskMode; | 664 this.hideSystemDialogLink_ = settings.isInAppKioskMode; |
681 if ($('system-dialog-link')) { | 665 if ($('system-dialog-link')) { |
682 setIsVisible(getRequiredElement('system-dialog-link'), | 666 setIsVisible( |
683 this.shouldShowSystemDialogLink_()); | 667 getRequiredElement('system-dialog-link'), |
| 668 this.shouldShowSystemDialogLink_()); |
684 } | 669 } |
685 }, | 670 }, |
686 | 671 |
687 /** | 672 /** |
688 * Calls when the native layer enables Google Cloud Print integration. | 673 * Calls when the native layer enables Google Cloud Print integration. |
689 * Fetches the user's cloud printers. | 674 * Fetches the user's cloud printers. |
690 * @param {Event} event Contains the base URL of the Google Cloud Print | 675 * @param {Event} event Contains the base URL of the Google Cloud Print |
691 * service. | 676 * service. |
692 * @private | 677 * @private |
693 */ | 678 */ |
694 onCloudPrintEnable_: function(event) { | 679 onCloudPrintEnable_: function(event) { |
695 this.cloudPrintInterface_ = new cloudprint.CloudPrintInterface( | 680 this.cloudPrintInterface_ = new cloudprint.CloudPrintInterface( |
696 event.baseCloudPrintUrl, | 681 event.baseCloudPrintUrl, this.nativeLayer_, this.userInfo_, |
697 this.nativeLayer_, | |
698 this.userInfo_, | |
699 event.appKioskMode); | 682 event.appKioskMode); |
700 this.tracker.add( | 683 this.tracker.add( |
701 this.cloudPrintInterface_, | 684 this.cloudPrintInterface_, |
702 cloudprint.CloudPrintInterfaceEventType.SUBMIT_DONE, | 685 cloudprint.CloudPrintInterfaceEventType.SUBMIT_DONE, |
703 this.onCloudPrintSubmitDone_.bind(this)); | 686 this.onCloudPrintSubmitDone_.bind(this)); |
704 this.tracker.add( | 687 this.tracker.add( |
705 this.cloudPrintInterface_, | 688 this.cloudPrintInterface_, |
706 cloudprint.CloudPrintInterfaceEventType.SEARCH_FAILED, | 689 cloudprint.CloudPrintInterfaceEventType.SEARCH_FAILED, |
707 this.onCloudPrintError_.bind(this)); | 690 this.onCloudPrintError_.bind(this)); |
708 this.tracker.add( | 691 this.tracker.add( |
(...skipping 12 matching lines...) Expand all Loading... |
721 this.invitationStore_.startLoadingInvitations(); | 704 this.invitationStore_.startLoadingInvitations(); |
722 } | 705 } |
723 }, | 706 }, |
724 | 707 |
725 /** | 708 /** |
726 * Called from the native layer when ready to print to Google Cloud Print. | 709 * Called from the native layer when ready to print to Google Cloud Print. |
727 * @param {Event} event Contains the body to send in the HTTP request. | 710 * @param {Event} event Contains the body to send in the HTTP request. |
728 * @private | 711 * @private |
729 */ | 712 */ |
730 onPrintToCloud_: function(event) { | 713 onPrintToCloud_: function(event) { |
731 assert(this.uiState_ == PrintPreviewUiState_.PRINTING, | 714 assert( |
732 'Document ready to be sent to the cloud when not in printing ' + | 715 this.uiState_ == PrintPreviewUiState_.PRINTING, |
733 'state: ' + this.uiState_); | 716 'Document ready to be sent to the cloud when not in printing ' + |
734 assert(this.cloudPrintInterface_ != null, | 717 'state: ' + this.uiState_); |
735 'Google Cloud Print is not enabled'); | 718 assert( |
| 719 this.cloudPrintInterface_ != null, |
| 720 'Google Cloud Print is not enabled'); |
736 assert(this.destinationStore_.selectedDestination != null); | 721 assert(this.destinationStore_.selectedDestination != null); |
737 this.cloudPrintInterface_.submit( | 722 this.cloudPrintInterface_.submit( |
738 this.destinationStore_.selectedDestination, | 723 this.destinationStore_.selectedDestination, this.printTicketStore_, |
739 this.printTicketStore_, | 724 this.documentInfo_, event.data); |
740 this.documentInfo_, | |
741 event.data); | |
742 }, | 725 }, |
743 | 726 |
744 /** | 727 /** |
745 * Called from the native layer when the user cancels the save-to-pdf file | 728 * Called from the native layer when the user cancels the save-to-pdf file |
746 * selection dialog. | 729 * selection dialog. |
747 * @private | 730 * @private |
748 */ | 731 */ |
749 onFileSelectionCancel_: function() { | 732 onFileSelectionCancel_: function() { |
750 assert(this.uiState_ == PrintPreviewUiState_.FILE_SELECTION, | 733 assert( |
751 'File selection cancelled when not in file-selection state: ' + | 734 this.uiState_ == PrintPreviewUiState_.FILE_SELECTION, |
752 this.uiState_); | 735 'File selection cancelled when not in file-selection state: ' + |
| 736 this.uiState_); |
753 this.setIsEnabled_(true); | 737 this.setIsEnabled_(true); |
754 this.uiState_ = PrintPreviewUiState_.READY; | 738 this.uiState_ = PrintPreviewUiState_.READY; |
755 }, | 739 }, |
756 | 740 |
757 /** | 741 /** |
758 * Called from the native layer when save-to-pdf file selection is complete. | 742 * Called from the native layer when save-to-pdf file selection is complete. |
759 * @private | 743 * @private |
760 */ | 744 */ |
761 onFileSelectionComplete_: function() { | 745 onFileSelectionComplete_: function() { |
762 assert(this.uiState_ == PrintPreviewUiState_.FILE_SELECTION, | 746 assert( |
763 'File selection completed when not in file-selection state: ' + | 747 this.uiState_ == PrintPreviewUiState_.FILE_SELECTION, |
764 this.uiState_); | 748 'File selection completed when not in file-selection state: ' + |
| 749 this.uiState_); |
765 this.previewArea_.showCustomMessage( | 750 this.previewArea_.showCustomMessage( |
766 loadTimeData.getString('printingToPDFInProgress')); | 751 loadTimeData.getString('printingToPDFInProgress')); |
767 this.uiState_ = PrintPreviewUiState_.PRINTING; | 752 this.uiState_ = PrintPreviewUiState_.PRINTING; |
768 }, | 753 }, |
769 | 754 |
770 /** | 755 /** |
771 * Called after successfully submitting a job to Google Cloud Print. | 756 * Called after successfully submitting a job to Google Cloud Print. |
772 * @param {!Event} event Contains the ID of the submitted print job. | 757 * @param {!Event} event Contains the ID of the submitted print job. |
773 * @private | 758 * @private |
774 */ | 759 */ |
775 onCloudPrintSubmitDone_: function(event) { | 760 onCloudPrintSubmitDone_: function(event) { |
776 assert(this.uiState_ == PrintPreviewUiState_.PRINTING, | 761 assert( |
777 'Submited job to Google Cloud Print but not in printing state ' + | 762 this.uiState_ == PrintPreviewUiState_.PRINTING, |
778 this.uiState_); | 763 'Submited job to Google Cloud Print but not in printing state ' + |
| 764 this.uiState_); |
779 this.close_(); | 765 this.close_(); |
780 }, | 766 }, |
781 | 767 |
782 /** | 768 /** |
783 * Called when there was an error communicating with Google Cloud print. | 769 * Called when there was an error communicating with Google Cloud print. |
784 * Displays an error message in the print header. | 770 * Displays an error message in the print header. |
785 * @param {!Event} event Contains the error message. | 771 * @param {!Event} event Contains the error message. |
786 * @private | 772 * @private |
787 */ | 773 */ |
788 onCloudPrintError_: function(event) { | 774 onCloudPrintError_: function(event) { |
789 if (event.status == 0) { | 775 if (event.status == 0) { |
790 return; // Ignore, the system does not have internet connectivity. | 776 return; // Ignore, the system does not have internet connectivity. |
791 } | 777 } |
792 if (event.status == 403) { | 778 if (event.status == 403) { |
793 if (!this.isInAppKioskMode_) { | 779 if (!this.isInAppKioskMode_) { |
794 this.destinationSearch_.showCloudPrintPromo(); | 780 this.destinationSearch_.showCloudPrintPromo(); |
795 } | 781 } |
796 } else { | 782 } else { |
797 this.printHeader_.setErrorMessage(event.message); | 783 this.printHeader_.setErrorMessage(event.message); |
798 } | 784 } |
799 if (event.status == 200) { | 785 if (event.status == 200) { |
800 console.error('Google Cloud Print Error: (' + event.errorCode + ') ' + | 786 console.error( |
801 event.message); | 787 'Google Cloud Print Error: (' + event.errorCode + ') ' + |
| 788 event.message); |
802 } else { | 789 } else { |
803 console.error('Google Cloud Print Error: HTTP status ' + event.status); | 790 console.error('Google Cloud Print Error: HTTP status ' + event.status); |
804 } | 791 } |
805 }, | 792 }, |
806 | 793 |
807 /** | 794 /** |
808 * Called when the preview area's preview generation is in progress. | 795 * Called when the preview area's preview generation is in progress. |
809 * @private | 796 * @private |
810 */ | 797 */ |
811 onPreviewGenerationInProgress_: function() { | 798 onPreviewGenerationInProgress_: function() { |
(...skipping 23 matching lines...) Expand all Loading... |
835 }, | 822 }, |
836 | 823 |
837 /** | 824 /** |
838 * Called when the 'Open pdf in preview' link is clicked. Launches the pdf | 825 * Called when the 'Open pdf in preview' link is clicked. Launches the pdf |
839 * preview app. | 826 * preview app. |
840 * @private | 827 * @private |
841 */ | 828 */ |
842 onOpenPdfInPreviewLinkClick_: function() { | 829 onOpenPdfInPreviewLinkClick_: function() { |
843 if ($('open-pdf-in-preview-link').classList.contains('disabled')) | 830 if ($('open-pdf-in-preview-link').classList.contains('disabled')) |
844 return; | 831 return; |
845 assert(this.uiState_ == PrintPreviewUiState_.READY, | 832 assert( |
846 'Trying to open pdf in preview when not in ready state: ' + | 833 this.uiState_ == PrintPreviewUiState_.READY, |
847 this.uiState_); | 834 'Trying to open pdf in preview when not in ready state: ' + |
| 835 this.uiState_); |
848 setIsVisible(getRequiredElement('open-preview-app-throbber'), true); | 836 setIsVisible(getRequiredElement('open-preview-app-throbber'), true); |
849 this.previewArea_.showCustomMessage( | 837 this.previewArea_.showCustomMessage( |
850 loadTimeData.getString('openingPDFInPreview')); | 838 loadTimeData.getString('openingPDFInPreview')); |
851 this.printDocumentOrOpenPdfPreview_(true /*isPdfPreview*/); | 839 this.printDocumentOrOpenPdfPreview_(true /*isPdfPreview*/); |
852 }, | 840 }, |
853 | 841 |
854 /** | 842 /** |
855 * Called when the print header's print button is clicked. Prints the | 843 * Called when the print header's print button is clicked. Prints the |
856 * document. | 844 * document. |
857 * @private | 845 * @private |
858 */ | 846 */ |
859 onPrintButtonClick_: function() { | 847 onPrintButtonClick_: function() { |
860 assert(this.uiState_ == PrintPreviewUiState_.READY, | 848 assert( |
861 'Trying to print when not in ready state: ' + this.uiState_); | 849 this.uiState_ == PrintPreviewUiState_.READY, |
| 850 'Trying to print when not in ready state: ' + this.uiState_); |
862 this.printDocumentOrOpenPdfPreview_(false /*isPdfPreview*/); | 851 this.printDocumentOrOpenPdfPreview_(false /*isPdfPreview*/); |
863 }, | 852 }, |
864 | 853 |
865 /** | 854 /** |
866 * Called when the print header's cancel button is clicked. Closes the | 855 * Called when the print header's cancel button is clicked. Closes the |
867 * print dialog. | 856 * print dialog. |
868 * @private | 857 * @private |
869 */ | 858 */ |
870 onCancelButtonClick_: function() { | 859 onCancelButtonClick_: function() { |
871 this.close_(); | 860 this.close_(); |
872 }, | 861 }, |
873 | 862 |
874 /** | 863 /** |
875 * Called when the register promo for Cloud Print is clicked. | 864 * Called when the register promo for Cloud Print is clicked. |
876 * @private | 865 * @private |
877 */ | 866 */ |
878 onCloudPrintRegisterPromoClick_: function(e) { | 867 onCloudPrintRegisterPromoClick_: function(e) { |
879 var devicesUrl = 'chrome://devices/register?id=' + e.destination.id; | 868 var devicesUrl = 'chrome://devices/register?id=' + e.destination.id; |
880 this.nativeLayer_.startForceOpenNewTab(devicesUrl); | 869 this.nativeLayer_.startForceOpenNewTab(devicesUrl); |
881 this.destinationStore_.waitForRegister(e.destination.id); | 870 this.destinationStore_.waitForRegister(e.destination.id); |
882 }, | 871 }, |
883 | 872 |
884 /** | 873 /** |
885 * Consume escape key presses and ctrl + shift + p. Delegate everything else | 874 * Consume escape key presses and ctrl + shift + p. Delegate everything else |
886 * to the preview area. | 875 * to the preview area. |
887 * @param {KeyboardEvent} e The keyboard event. | 876 * @param {KeyboardEvent} e The keyboard event. |
888 * @private | 877 * @private |
889 * @suppress {uselessCode} | 878 * @suppress {uselessCode} |
890 * Current compiler preprocessor leaves all the code inside all the <if>s, | 879 * Current compiler preprocessor leaves all the code inside all the <if>s, |
891 * so the compiler claims that code after first return is unreachable. | 880 * so the compiler claims that code after first return is unreachable. |
892 */ | 881 */ |
(...skipping 24 matching lines...) Expand all Loading... |
917 e.preventDefault(); | 906 e.preventDefault(); |
918 return; | 907 return; |
919 } | 908 } |
920 } | 909 } |
921 | 910 |
922 if (e.keyCode == 13 /*enter*/ && | 911 if (e.keyCode == 13 /*enter*/ && |
923 !document.querySelector('.overlay:not([hidden])') && | 912 !document.querySelector('.overlay:not([hidden])') && |
924 this.destinationStore_.selectedDestination && | 913 this.destinationStore_.selectedDestination && |
925 this.printTicketStore_.isTicketValid() && | 914 this.printTicketStore_.isTicketValid() && |
926 this.printHeader_.isPrintButtonEnabled) { | 915 this.printHeader_.isPrintButtonEnabled) { |
927 assert(this.uiState_ == PrintPreviewUiState_.READY, | 916 assert( |
| 917 this.uiState_ == PrintPreviewUiState_.READY, |
928 'Trying to print when not in ready state: ' + this.uiState_); | 918 'Trying to print when not in ready state: ' + this.uiState_); |
929 var activeElementTag = document.activeElement.tagName.toUpperCase(); | 919 var activeElementTag = document.activeElement.tagName.toUpperCase(); |
930 if (activeElementTag != 'BUTTON' && activeElementTag != 'SELECT' && | 920 if (activeElementTag != 'BUTTON' && activeElementTag != 'SELECT' && |
931 activeElementTag != 'A') { | 921 activeElementTag != 'A') { |
932 this.printDocumentOrOpenPdfPreview_(false /*isPdfPreview*/); | 922 this.printDocumentOrOpenPdfPreview_(false /*isPdfPreview*/); |
933 e.preventDefault(); | 923 e.preventDefault(); |
934 } | 924 } |
935 return; | 925 return; |
936 } | 926 } |
937 | 927 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1024 | 1014 |
1025 /** | 1015 /** |
1026 * Called when the Page Count Ready message is received to update the fit to | 1016 * Called when the Page Count Ready message is received to update the fit to |
1027 * page scaling value in the scaling settings. | 1017 * page scaling value in the scaling settings. |
1028 * @param {Event} event Event object representing the page count ready | 1018 * @param {Event} event Event object representing the page count ready |
1029 * message | 1019 * message |
1030 * @private | 1020 * @private |
1031 */ | 1021 */ |
1032 onPageCountReady_: function(event) { | 1022 onPageCountReady_: function(event) { |
1033 if (event.fitToPageScaling >= 0) { | 1023 if (event.fitToPageScaling >= 0) { |
1034 this.scalingSettings_.updateFitToPageScaling( | 1024 this.scalingSettings_.updateFitToPageScaling(event.fitToPageScaling); |
1035 event.fitToPageScaling); | |
1036 } | 1025 } |
1037 }, | 1026 }, |
1038 | 1027 |
1039 /** | 1028 /** |
1040 * Called when printing to a privet or extension printer fails. | 1029 * Called when printing to a privet or extension printer fails. |
1041 * @param {number | string} httpError The HTTP error code, or -1 if not an | 1030 * @param {number | string} httpError The HTTP error code, or -1 if not an |
1042 * HTTP error. | 1031 * HTTP error. |
1043 * @private | 1032 * @private |
1044 */ | 1033 */ |
1045 onPrintFailed_: function(httpError) { | 1034 onPrintFailed_: function(httpError) { |
1046 console.error('Privet printing failed with error code ' + httpError); | 1035 console.error('Privet printing failed with error code ' + httpError); |
1047 this.printHeader_.setErrorMessage( | 1036 this.printHeader_.setErrorMessage( |
1048 loadTimeData.getString('couldNotPrint')); | 1037 loadTimeData.getString('couldNotPrint')); |
1049 }, | 1038 }, |
1050 | 1039 |
1051 /** | 1040 /** |
1052 * Called when the print preview settings need to be changed for testing. | 1041 * Called when the print preview settings need to be changed for testing. |
1053 * @param {Event} event Event object that contains the option that is to | 1042 * @param {Event} event Event object that contains the option that is to |
1054 * be changed and what to set that option. | 1043 * be changed and what to set that option. |
1055 * @private | 1044 * @private |
1056 */ | 1045 */ |
1057 onManipulateSettingsForTest_: function(event) { | 1046 onManipulateSettingsForTest_: function(event) { |
1058 var settings = | 1047 var settings = |
1059 /** @type {print_preview.PreviewSettings} */(event.settings); | 1048 /** @type {print_preview.PreviewSettings} */ (event.settings); |
1060 if ('selectSaveAsPdfDestination' in settings) { | 1049 if ('selectSaveAsPdfDestination' in settings) { |
1061 this.saveAsPdfForTest_(); // No parameters. | 1050 this.saveAsPdfForTest_(); // No parameters. |
1062 } else if ('layoutSettings' in settings) { | 1051 } else if ('layoutSettings' in settings) { |
1063 this.setLayoutSettingsForTest_(settings.layoutSettings.portrait); | 1052 this.setLayoutSettingsForTest_(settings.layoutSettings.portrait); |
1064 } else if ('pageRange' in settings) { | 1053 } else if ('pageRange' in settings) { |
1065 this.setPageRangeForTest_(settings.pageRange); | 1054 this.setPageRangeForTest_(settings.pageRange); |
1066 } else if ('headersAndFooters' in settings) { | 1055 } else if ('headersAndFooters' in settings) { |
1067 this.setHeadersAndFootersForTest_(settings.headersAndFooters); | 1056 this.setHeadersAndFootersForTest_(settings.headersAndFooters); |
1068 } else if ('backgroundColorsAndImages' in settings) { | 1057 } else if ('backgroundColorsAndImages' in settings) { |
1069 this.setBackgroundColorsAndImagesForTest_( | 1058 this.setBackgroundColorsAndImagesForTest_( |
1070 settings.backgroundColorsAndImages); | 1059 settings.backgroundColorsAndImages); |
1071 } else if ('margins' in settings) { | 1060 } else if ('margins' in settings) { |
1072 this.setMarginsForTest_(settings.margins); | 1061 this.setMarginsForTest_(settings.margins); |
1073 } | 1062 } |
1074 }, | 1063 }, |
1075 | 1064 |
1076 /** | 1065 /** |
1077 * Called by onManipulateSettingsForTest_(). Sets the print destination | 1066 * Called by onManipulateSettingsForTest_(). Sets the print destination |
1078 * as a pdf. | 1067 * as a pdf. |
1079 * @private | 1068 * @private |
1080 */ | 1069 */ |
1081 saveAsPdfForTest_: function() { | 1070 saveAsPdfForTest_: function() { |
1082 if (this.destinationStore_.selectedDestination && | 1071 if (this.destinationStore_.selectedDestination && |
1083 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF == | 1072 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF == |
1084 this.destinationStore_.selectedDestination.id) { | 1073 this.destinationStore_.selectedDestination.id) { |
1085 this.nativeLayer_.previewReadyForTest(); | 1074 this.nativeLayer_.previewReadyForTest(); |
1086 return; | 1075 return; |
1087 } | 1076 } |
1088 | 1077 |
1089 var destinations = this.destinationStore_.destinations(); | 1078 var destinations = this.destinationStore_.destinations(); |
1090 var pdfDestination = null; | 1079 var pdfDestination = null; |
1091 for (var i = 0; i < destinations.length; i++) { | 1080 for (var i = 0; i < destinations.length; i++) { |
1092 if (destinations[i].id == | 1081 if (destinations[i].id == |
1093 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { | 1082 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { |
1094 pdfDestination = destinations[i]; | 1083 pdfDestination = destinations[i]; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1190 * current destination. | 1179 * current destination. |
1191 * @return {boolean} Returns true if link should be shown. | 1180 * @return {boolean} Returns true if link should be shown. |
1192 */ | 1181 */ |
1193 shouldShowSystemDialogLink_: function() { | 1182 shouldShowSystemDialogLink_: function() { |
1194 if (cr.isChromeOS || this.hideSystemDialogLink_) | 1183 if (cr.isChromeOS || this.hideSystemDialogLink_) |
1195 return false; | 1184 return false; |
1196 if (!cr.isWindows) | 1185 if (!cr.isWindows) |
1197 return true; | 1186 return true; |
1198 var selectedDest = this.destinationStore_.selectedDestination; | 1187 var selectedDest = this.destinationStore_.selectedDestination; |
1199 return !!selectedDest && | 1188 return !!selectedDest && |
1200 selectedDest.origin == print_preview.DestinationOrigin.LOCAL && | 1189 selectedDest.origin == print_preview.DestinationOrigin.LOCAL && |
1201 selectedDest.id != | 1190 selectedDest.id != |
1202 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF; | 1191 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF; |
1203 }, | 1192 }, |
1204 | 1193 |
1205 /** | 1194 /** |
1206 * Called when a print destination is selected. Shows/hides the "Print with | 1195 * Called when a print destination is selected. Shows/hides the "Print with |
1207 * Cloud Print" link in the navbar. | 1196 * Cloud Print" link in the navbar. |
1208 * @private | 1197 * @private |
1209 */ | 1198 */ |
1210 onDestinationSelect_: function() { | 1199 onDestinationSelect_: function() { |
1211 if ($('system-dialog-link')) { | 1200 if ($('system-dialog-link')) { |
1212 setIsVisible(getRequiredElement('system-dialog-link'), | 1201 setIsVisible( |
1213 this.shouldShowSystemDialogLink_()); | 1202 getRequiredElement('system-dialog-link'), |
| 1203 this.shouldShowSystemDialogLink_()); |
1214 } | 1204 } |
1215 // Reset if we had a bad settings fetch since the user selected a new | 1205 // Reset if we had a bad settings fetch since the user selected a new |
1216 // printer. | 1206 // printer. |
1217 if (this.uiState_ == PrintPreviewUiState_.ERROR) | 1207 if (this.uiState_ == PrintPreviewUiState_.ERROR) |
1218 this.uiState_ = PrintPreviewUiState_.READY; | 1208 this.uiState_ = PrintPreviewUiState_.READY; |
1219 if (this.destinationStore_.selectedDestination && | 1209 if (this.destinationStore_.selectedDestination && |
1220 this.isInKioskAutoPrintMode_) { | 1210 this.isInKioskAutoPrintMode_) { |
1221 this.onPrintButtonClick_(); | 1211 this.onPrintButtonClick_(); |
1222 } | 1212 } |
1223 }, | 1213 }, |
1224 | 1214 |
1225 /** | 1215 /** |
1226 * Called when the destination store loads a group of destinations. Shows | 1216 * Called when the destination store loads a group of destinations. Shows |
1227 * a promo on Chrome OS if the user has no print destinations promoting | 1217 * a promo on Chrome OS if the user has no print destinations promoting |
1228 * Google Cloud Print. | 1218 * Google Cloud Print. |
1229 * @private | 1219 * @private |
1230 */ | 1220 */ |
1231 onDestinationSearchDone_: function() { | 1221 onDestinationSearchDone_: function() { |
1232 var isPromoVisible = cr.isChromeOS && | 1222 var isPromoVisible = cr.isChromeOS && this.cloudPrintInterface_ && |
1233 this.cloudPrintInterface_ && | 1223 this.userInfo_.activeUser && !this.appState_.isGcpPromoDismissed && |
1234 this.userInfo_.activeUser && | |
1235 !this.appState_.isGcpPromoDismissed && | |
1236 !this.destinationStore_.isLocalDestinationSearchInProgress && | 1224 !this.destinationStore_.isLocalDestinationSearchInProgress && |
1237 !this.destinationStore_.isCloudDestinationSearchInProgress && | 1225 !this.destinationStore_.isCloudDestinationSearchInProgress && |
1238 this.destinationStore_.hasOnlyDefaultCloudDestinations(); | 1226 this.destinationStore_.hasOnlyDefaultCloudDestinations(); |
1239 setIsVisible(this.getChildElement('#no-destinations-promo'), | 1227 setIsVisible( |
1240 isPromoVisible); | 1228 this.getChildElement('#no-destinations-promo'), isPromoVisible); |
1241 if (isPromoVisible) { | 1229 if (isPromoVisible) { |
1242 new print_preview.GcpPromoMetricsContext().record( | 1230 new print_preview.GcpPromoMetricsContext().record( |
1243 print_preview.Metrics.GcpPromoBucket.PROMO_SHOWN); | 1231 print_preview.Metrics.GcpPromoBucket.PROMO_SHOWN); |
1244 } | 1232 } |
1245 }, | 1233 }, |
1246 | 1234 |
1247 /** | 1235 /** |
1248 * Called when the close button on the no-destinations-promotion is clicked. | 1236 * Called when the close button on the no-destinations-promotion is clicked. |
1249 * Hides the promotion. | 1237 * Hides the promotion. |
1250 * @private | 1238 * @private |
1251 */ | 1239 */ |
1252 onNoDestinationsPromoClose_: function() { | 1240 onNoDestinationsPromoClose_: function() { |
1253 new print_preview.GcpPromoMetricsContext().record( | 1241 new print_preview.GcpPromoMetricsContext().record( |
1254 print_preview.Metrics.GcpPromoBucket.PROMO_CLOSED); | 1242 print_preview.Metrics.GcpPromoBucket.PROMO_CLOSED); |
1255 setIsVisible(this.getChildElement('#no-destinations-promo'), false); | 1243 setIsVisible(this.getChildElement('#no-destinations-promo'), false); |
1256 this.appState_.persistIsGcpPromoDismissed(true); | 1244 this.appState_.persistIsGcpPromoDismissed(true); |
1257 }, | 1245 }, |
1258 | 1246 |
1259 /** | 1247 /** |
1260 * Called when the no-destinations promotion link is clicked. Opens the | 1248 * Called when the no-destinations promotion link is clicked. Opens the |
1261 * Google Cloud Print management page and closes the print preview. | 1249 * Google Cloud Print management page and closes the print preview. |
1262 * @private | 1250 * @private |
1263 */ | 1251 */ |
1264 onNoDestinationsPromoClick_: function() { | 1252 onNoDestinationsPromoClick_: function() { |
1265 new print_preview.GcpPromoMetricsContext().record( | 1253 new print_preview.GcpPromoMetricsContext().record( |
1266 print_preview.Metrics.GcpPromoBucket.PROMO_CLICKED); | 1254 print_preview.Metrics.GcpPromoBucket.PROMO_CLICKED); |
1267 this.appState_.persistIsGcpPromoDismissed(true); | 1255 this.appState_.persistIsGcpPromoDismissed(true); |
1268 window.open(this.cloudPrintInterface_.baseUrl + '?user=' + | 1256 window.open( |
1269 this.userInfo_.activeUser + '#printers'); | 1257 this.cloudPrintInterface_.baseUrl + |
| 1258 '?user=' + this.userInfo_.activeUser + '#printers'); |
1270 this.close_(); | 1259 this.close_(); |
1271 } | 1260 } |
1272 }; | 1261 }; |
1273 | 1262 |
1274 // Export | 1263 // Export |
1275 return { | 1264 return {PrintPreview: PrintPreview}; |
1276 PrintPreview: PrintPreview | |
1277 }; | |
1278 }); | 1265 }); |
1279 | 1266 |
1280 // Pull in all other scripts in a single shot. | 1267 // Pull in all other scripts in a single shot. |
1281 // <include src="common/overlay.js"> | 1268 // <include src="common/overlay.js"> |
1282 // <include src="common/search_box.js"> | 1269 // <include src="common/search_box.js"> |
1283 // <include src="common/search_bubble.js"> | 1270 // <include src="common/search_bubble.js"> |
1284 | 1271 |
1285 // <include src="data/page_number_set.js"> | 1272 // <include src="data/page_number_set.js"> |
1286 // <include src="data/destination.js"> | 1273 // <include src="data/destination.js"> |
1287 // <include src="data/destination_match.js"> | 1274 // <include src="data/destination_match.js"> |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1358 // <include src="search/destination_search.js"> | 1345 // <include src="search/destination_search.js"> |
1359 // <include src="search/provisional_destination_resolver.js"> | 1346 // <include src="search/provisional_destination_resolver.js"> |
1360 | 1347 |
1361 window.addEventListener('DOMContentLoaded', function() { | 1348 window.addEventListener('DOMContentLoaded', function() { |
1362 var previewWindow = /** @type {{isTest: boolean}} */ (window); | 1349 var previewWindow = /** @type {{isTest: boolean}} */ (window); |
1363 if (!previewWindow.isTest) { | 1350 if (!previewWindow.isTest) { |
1364 var printPreview = new print_preview.PrintPreview(); | 1351 var printPreview = new print_preview.PrintPreview(); |
1365 printPreview.initialize(); | 1352 printPreview.initialize(); |
1366 } | 1353 } |
1367 }); | 1354 }); |
OLD | NEW |