Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Side by Side Diff: chrome/browser/resources/print_preview/print_preview.js

Issue 10450022: Print Preview Print Destination Search Widget (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Reduces size of search image. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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): Might be a problem where might be in fetching destinations
6 // state, then to file selection state, then cancel, which results in the
7 // fetching destinations state being lost.
8
9 // TODO(rltoscano): Move data/* into print_preview.data namespace 5 // TODO(rltoscano): Move data/* into print_preview.data namespace
10 6
11 // TODO(rltoscano): Handle case where cloud print is initial destination, but 7 var localStrings = new LocalStrings(templateData);
12 // cloud print is not enabled.
13
14 var localStrings = new LocalStrings();
15 8
16 <include src="component.js"/> 9 <include src="component.js"/>
17 10
18 cr.define('print_preview', function() { 11 cr.define('print_preview', function() {
19 'use strict'; 12 'use strict';
20 13
21 /** 14 /**
22 * Container class for Chromium's print preview. 15 * Container class for Chromium's print preview.
23 * @constructor 16 * @constructor
24 * @extends {print_preview.Component} 17 * @extends {print_preview.Component}
25 */ 18 */
26 function PrintPreview() { 19 function PrintPreview() {
27 print_preview.Component.call(this); 20 print_preview.Component.call(this);
28 21
29 /** 22 /**
30 * Used to communicate with Chromium's print system. 23 * Used to communicate with Chromium's print system.
31 * @type {!print_preview.NativeLayer} 24 * @type {!print_preview.NativeLayer}
32 * @private 25 * @private
33 */ 26 */
34 this.nativeLayer_ = new print_preview.NativeLayer(); 27 this.nativeLayer_ = new print_preview.NativeLayer();
35 28
36 /** 29 /**
30 * Event target that contains information about the logged in user.
31 * @type {!print_preview.UserInfo}
32 * @private
33 */
34 this.userInfo_ = new print_preview.UserInfo();
35
36 /**
37 * Data store which holds print destinations. 37 * Data store which holds print destinations.
38 * @type {!print_preview.DestinationStore} 38 * @type {!print_preview.DestinationStore}
39 * @private 39 * @private
40 */ 40 */
41 this.destinationStore_ = new print_preview.DestinationStore(); 41 this.destinationStore_ = new print_preview.DestinationStore(
42 this.nativeLayer_);
42 43
43 /** 44 /**
44 * Storage of the print ticket used to create the print job. 45 * Storage of the print ticket used to create the print job.
45 * @type {!print_preview.PrintTicketStore} 46 * @type {!print_preview.PrintTicketStore}
46 * @private 47 * @private
47 */ 48 */
48 this.printTicketStore_ = new print_preview.PrintTicketStore( 49 this.printTicketStore_ = new print_preview.PrintTicketStore(
49 this.destinationStore_); 50 this.destinationStore_);
50 51
51 /** 52 /**
52 * Holds the print and cancel buttons and renders some document statistics. 53 * Holds the print and cancel buttons and renders some document statistics.
53 * @type {!print_preview.PrintHeader} 54 * @type {!print_preview.PrintHeader}
54 * @private 55 * @private
55 */ 56 */
56 this.printHeader_ = new print_preview.PrintHeader( 57 this.printHeader_ = new print_preview.PrintHeader(
57 this.printTicketStore_, this.destinationStore_); 58 this.printTicketStore_, this.destinationStore_);
58 this.addChild(this.printHeader_); 59 this.addChild(this.printHeader_);
59 60
60 /** 61 /**
62 * Component used to search for print destinations.
63 * @type {!print_preview.DestinationSearch}
64 * @private
65 */
66 this.destinationSearch_ = new print_preview.DestinationSearch(
67 this.destinationStore_, this.userInfo_);
68 this.addChild(this.destinationSearch_);
69
70 /**
61 * Component that renders the print destination. 71 * Component that renders the print destination.
62 * @type {!print_preview.DestinationSettings} 72 * @type {!print_preview.DestinationSettings}
63 * @private 73 * @private
64 */ 74 */
65 this.destinationSettings_ = new print_preview.DestinationSettings( 75 this.destinationSettings_ = new print_preview.DestinationSettings(
66 this.destinationStore_); 76 this.destinationStore_);
67 this.addChild(this.destinationSettings_); 77 this.addChild(this.destinationSettings_);
68 78
69 /** 79 /**
70 * Component that renders UI for entering in page range. 80 * Component that renders UI for entering in page range.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 this.isInKioskAutoPrintMode_ = false; 157 this.isInKioskAutoPrintMode_ = false;
148 158
149 /** 159 /**
150 * State of the print preview UI. 160 * State of the print preview UI.
151 * @type {print_preview.PrintPreview.UiState_} 161 * @type {print_preview.PrintPreview.UiState_}
152 * @private 162 * @private
153 */ 163 */
154 this.uiState_ = PrintPreview.UiState_.INITIALIZING; 164 this.uiState_ = PrintPreview.UiState_.INITIALIZING;
155 165
156 /** 166 /**
157 * Current state of fetching destinations.
158 * @type {print_preview.PrintPreview.FetchState_}
159 * @private
160 */
161 this.fetchState_ = PrintPreview.FetchState_.READY;
162
163 /**
164 * Whether document preview generation is in progress. 167 * Whether document preview generation is in progress.
165 * @type {boolean} 168 * @type {boolean}
166 * @private 169 * @private
167 */ 170 */
168 this.isPreviewGenerationInProgress_ = true; 171 this.isPreviewGenerationInProgress_ = true;
169 172
170 this.tracker.add(window, 'DOMContentLoaded', this.onWindowLoad_.bind(this)); 173 this.tracker.add(window, 'DOMContentLoaded', this.onWindowLoad_.bind(this));
171 }; 174 };
172 175
173 /** 176 /**
174 * States of the print preview. 177 * States of the print preview.
175 * @enum {string} 178 * @enum {string}
176 * @private 179 * @private
177 */ 180 */
178 PrintPreview.UiState_ = { 181 PrintPreview.UiState_ = {
179 INITIALIZING: 'initializing', 182 INITIALIZING: 'initializing',
180 READY: 'ready', 183 READY: 'ready',
181 OPENING_PDF_PREVIEW: 'opening-pdf-preview', 184 OPENING_PDF_PREVIEW: 'opening-pdf-preview',
182 OPENING_NATIVE_PRINT_DIALOG: 'opening-native-print-dialog', 185 OPENING_NATIVE_PRINT_DIALOG: 'opening-native-print-dialog',
183 PRINTING: 'printing', 186 PRINTING: 'printing',
184 FILE_SELECTION: 'file-selection', 187 FILE_SELECTION: 'file-selection',
185 CLOSING: 'closing', 188 CLOSING: 'closing',
186 ERROR: 'error' 189 ERROR: 'error'
187 }; 190 };
188 191
189 /**
190 * Bitfield of the states of fetching destinations.
191 * @enum {number}
192 * @private
193 */
194 PrintPreview.FetchState_ = {
195 READY: 1,
196 LOCAL_DESTINATIONS: 2,
197 RECENT_CLOUD_DESTINATIONS: 4,
198 ALL_CLOUD_DESTINATIONS: 8
199 };
200
201 PrintPreview.prototype = { 192 PrintPreview.prototype = {
202 __proto__: print_preview.Component.prototype, 193 __proto__: print_preview.Component.prototype,
203 194
204 /** @override */ 195 /** @override */
205 decorateInternal: function() { 196 decorateInternal: function() {
206 this.printHeader_.decorate($('print-header')); 197 this.printHeader_.decorate($('print-header'));
198 this.destinationSearch_.decorate($('destination-search'));
207 this.destinationSettings_.decorate($('destination-settings')); 199 this.destinationSettings_.decorate($('destination-settings'));
208 this.pageSettings_.decorate($('page-settings')); 200 this.pageSettings_.decorate($('page-settings'));
209 this.copiesSettings_.decorate($('copies-settings')); 201 this.copiesSettings_.decorate($('copies-settings'));
210 this.layoutSettings_.decorate($('layout-settings')); 202 this.layoutSettings_.decorate($('layout-settings'));
211 this.colorSettings_.decorate($('color-settings')); 203 this.colorSettings_.decorate($('color-settings'));
212 this.marginSettings_.decorate($('margin-settings')); 204 this.marginSettings_.decorate($('margin-settings'));
213 this.otherOptionsSettings_.decorate($('other-options-settings')); 205 this.otherOptionsSettings_.decorate($('other-options-settings'));
214 this.previewArea_.decorate($('preview-area')); 206 this.previewArea_.decorate($('preview-area'));
215 207
216 setIsVisible($('cloud-print-dialog-link'), cr.isChromeOS); 208 setIsVisible($('cloud-print-dialog-link'), cr.isChromeOS);
217 setIsVisible($('system-dialog-link'), !cr.isChromeOS); 209 setIsVisible($('system-dialog-link'), !cr.isChromeOS);
218 setIsVisible($('open-pdf-in-preview-link'), cr.isMac); 210 setIsVisible($('open-pdf-in-preview-link'), cr.isMac);
219 }, 211 },
220 212
221 /** @override */ 213 /** @override */
222 enterDocument: function() { 214 enterDocument: function() {
223 // Native layer events. 215 // Native layer events.
224 this.tracker.add( 216 this.tracker.add(
225 this.nativeLayer_, 217 this.nativeLayer_,
226 print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET, 218 print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET,
227 this.onInitialSettingsSet_.bind(this)); 219 this.onInitialSettingsSet_.bind(this));
228 this.tracker.add( 220 this.tracker.add(
229 this.nativeLayer_, 221 this.nativeLayer_,
230 print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE, 222 print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE,
231 this.onCloudPrintEnable_.bind(this)); 223 this.onCloudPrintEnable_.bind(this));
232 this.tracker.add( 224 this.tracker.add(
233 this.nativeLayer_, 225 this.nativeLayer_,
234 print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET,
235 this.onLocalDestinationsSet_.bind(this));
236 this.tracker.add(
237 this.nativeLayer_,
238 print_preview.NativeLayer.EventType.CAPABILITIES_SET,
239 this.onLocalDestinationCapabilitiesSet_.bind(this));
240 this.tracker.add(
241 this.nativeLayer_,
242 print_preview.NativeLayer.EventType.DESTINATIONS_RELOAD,
243 this.onDestinationsReload_.bind(this));
244 this.tracker.add(
245 this.nativeLayer_,
246 print_preview.NativeLayer.EventType.PRINT_TO_CLOUD, 226 print_preview.NativeLayer.EventType.PRINT_TO_CLOUD,
247 this.onPrintToCloud_.bind(this)); 227 this.onPrintToCloud_.bind(this));
248 this.tracker.add( 228 this.tracker.add(
249 this.nativeLayer_, 229 this.nativeLayer_,
250 print_preview.NativeLayer.EventType.FILE_SELECTION_CANCEL, 230 print_preview.NativeLayer.EventType.FILE_SELECTION_CANCEL,
251 this.onFileSelectionCancel_.bind(this)); 231 this.onFileSelectionCancel_.bind(this));
252 this.tracker.add( 232 this.tracker.add(
253 this.nativeLayer_, 233 this.nativeLayer_,
254 print_preview.NativeLayer.EventType.FILE_SELECTION_COMPLETE, 234 print_preview.NativeLayer.EventType.FILE_SELECTION_COMPLETE,
255 this.onFileSelectionComplete_.bind(this)); 235 this.onFileSelectionComplete_.bind(this));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 this.previewArea_, 267 this.previewArea_,
288 print_preview.PreviewArea.EventType.PREVIEW_GENERATION_FAIL, 268 print_preview.PreviewArea.EventType.PREVIEW_GENERATION_FAIL,
289 this.onPreviewGenerationFail_.bind(this)); 269 this.onPreviewGenerationFail_.bind(this));
290 this.tracker.add( 270 this.tracker.add(
291 this.previewArea_, 271 this.previewArea_,
292 print_preview.PreviewArea.EventType.OPEN_SYSTEM_DIALOG_CLICK, 272 print_preview.PreviewArea.EventType.OPEN_SYSTEM_DIALOG_CLICK,
293 this.openSystemPrintDialog_.bind(this)); 273 this.openSystemPrintDialog_.bind(this));
294 274
295 this.tracker.add( 275 this.tracker.add(
296 this.destinationStore_, 276 this.destinationStore_,
297 print_preview.DestinationStore.EventType.DESTINATION_SELECT, 277 print_preview.DestinationStore.EventType.
298 this.onDestinationSelect_.bind(this)); 278 SELECTED_DESTINATION_CAPABILITIES_READY,
279 this.printIfReady_.bind(this));
299 280
300 this.tracker.add( 281 this.tracker.add(
301 this.printHeader_, 282 this.printHeader_,
302 print_preview.PrintHeader.EventType.PRINT_BUTTON_CLICK, 283 print_preview.PrintHeader.EventType.PRINT_BUTTON_CLICK,
303 this.onPrintButtonClick_.bind(this)); 284 this.onPrintButtonClick_.bind(this));
304 this.tracker.add( 285 this.tracker.add(
305 this.printHeader_, 286 this.printHeader_,
306 print_preview.PrintHeader.EventType.CANCEL_BUTTON_CLICK, 287 print_preview.PrintHeader.EventType.CANCEL_BUTTON_CLICK,
307 this.onCancelButtonClick_.bind(this)); 288 this.onCancelButtonClick_.bind(this));
308 289
290 this.tracker.add(window, 'keydown', this.onKeyDown_.bind(this));
291
309 this.tracker.add( 292 this.tracker.add(
310 this.destinationSettings_, 293 this.destinationSettings_,
311 print_preview.DestinationSettings.EventType.MANAGE_PRINTERS_SELECT, 294 print_preview.DestinationSettings.EventType.CHANGE_BUTTON_ACTIVATE,
312 this.onManagePrinters_.bind(this)); 295 this.onDestinationChangeButtonActivate_.bind(this));
313 296
314 this.tracker.add(window, 'keydown', this.onKeyDown_.bind(this)); 297 this.tracker.add(
298 this.destinationSearch_,
299 print_preview.DestinationSearch.EventType.MANAGE_CLOUD_DESTINATIONS,
300 this.onManageCloudDestinationsActivated_.bind(this));
301 this.tracker.add(
302 this.destinationSearch_,
303 print_preview.DestinationSearch.EventType.MANAGE_LOCAL_DESTINATIONS,
304 this.onManageLocalDestinationsActivated_.bind(this));
305 this.tracker.add(
306 this.destinationSearch_,
307 print_preview.DestinationSearch.EventType.SIGN_IN,
308 this.onCloudPrintSignInActivated_.bind(this));
315 }, 309 },
316 310
317 /** 311 /**
318 * Sets whether the controls in the print preview are enabled. 312 * Sets whether the controls in the print preview are enabled.
319 * @param {boolean} isEnabled Whether the controls in the print preview are 313 * @param {boolean} isEnabled Whether the controls in the print preview are
320 * enabled. 314 * enabled.
321 * @private 315 * @private
322 */ 316 */
323 setIsEnabled_: function(isEnabled) { 317 setIsEnabled_: function(isEnabled) {
324 $('system-dialog-link').disabled = !isEnabled; 318 $('system-dialog-link').disabled = !isEnabled;
325 $('cloud-print-dialog-link').disabled = !isEnabled; 319 $('cloud-print-dialog-link').disabled = !isEnabled;
326 $('open-pdf-in-preview-link').disabled = !isEnabled; 320 $('open-pdf-in-preview-link').disabled = !isEnabled;
327 this.printHeader_.isEnabled = isEnabled; 321 this.printHeader_.isEnabled = isEnabled;
328 this.destinationSettings_.isEnabled = isEnabled; 322 this.destinationSettings_.isEnabled = isEnabled;
329 this.pageSettings_.isEnabled = isEnabled; 323 this.pageSettings_.isEnabled = isEnabled;
330 this.copiesSettings_.isEnabled = isEnabled; 324 this.copiesSettings_.isEnabled = isEnabled;
331 this.layoutSettings_.isEnabled = isEnabled; 325 this.layoutSettings_.isEnabled = isEnabled;
332 this.colorSettings_.isEnabled = isEnabled; 326 this.colorSettings_.isEnabled = isEnabled;
333 this.marginSettings_.isEnabled = isEnabled; 327 this.marginSettings_.isEnabled = isEnabled;
334 this.otherOptionsSettings_.isEnabled = isEnabled; 328 this.otherOptionsSettings_.isEnabled = isEnabled;
335 }, 329 },
336 330
337 /** 331 /**
338 * Creates a local PDF print destination.
339 * @return {!print_preview.Destination} Created print destination.
340 * @private
341 */
342 createLocalPdfPrintDestination_: function() {
343 var dest = new print_preview.Destination(
344 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF,
345 localStrings.getString('printToPDF'),
346 false /*isRecent*/,
347 true /*isLocal*/);
348 dest.capabilities = new print_preview.ChromiumCapabilities(
349 false /*hasCopiesCapability*/,
350 '1' /*defaultCopiesStr*/,
351 false /*hasCollateCapability*/,
352 false /*defaultIsCollateEnabled*/,
353 false /*hasDuplexCapability*/,
354 false /*defaultIsDuplexEnabled*/,
355 true /*hasOrientationCapability*/,
356 false /*defaultIsLandscapeEnabled*/,
357 true /*hasColorCapability*/,
358 true /*defaultIsColorEnabled*/);
359 return dest;
360 },
361
362 /**
363 * Creates a new "Print with Cloud Print" print destination. NOTE: this
364 * destination will appear as "Search for additional printers..." on
365 * Chrome OS.
366 * @return {!print_preview.Destination} Created print destination.
367 * @private
368 */
369 createPrintWithCloudPrintDestination_: function() {
370 var dest = new print_preview.Destination(
371 print_preview.Destination.GooglePromotedId.PRINT_WITH_CLOUD_PRINT,
372 localStrings.getString('printWithCloudPrint'),
373 false /*isRecent*/,
374 false /*isLocal*/);
375 dest.capabilities = new print_preview.ChromiumCapabilities(
376 false /*hasCopiesCapability*/,
377 '1' /*defaultCopiesStr*/,
378 false /*hasCollateCapability*/,
379 false /*defaultIsCollateEnabled*/,
380 false /*hasDuplexCapability*/,
381 false /*defaultIsDuplexEnabled*/,
382 true /*hasOrientationCapability*/,
383 false /*defaultIsLandscapeEnabled*/,
384 true /*hasColorCapability*/,
385 true /*defaultIsColorEnabled*/);
386 return dest;
387 },
388
389 /**
390 * Prints the document or launches a pdf preview on the local system. 332 * Prints the document or launches a pdf preview on the local system.
391 * @param {boolean} isPdfPreview Whether to launch the pdf preview. 333 * @param {boolean} isPdfPreview Whether to launch the pdf preview.
392 * @private 334 * @private
393 */ 335 */
394 printDocumentOrOpenPdfPreview_: function(isPdfPreview) { 336 printDocumentOrOpenPdfPreview_: function(isPdfPreview) {
395 assert(this.uiState_ == PrintPreview.UiState_.READY, 337 assert(this.uiState_ == PrintPreview.UiState_.READY,
396 'Print document request received when not in ready state: ' + 338 'Print document request received when not in ready state: ' +
397 this.uiState_); 339 this.uiState_);
398 if (isPdfPreview) { 340 if (isPdfPreview) {
399 this.uiState_ = PrintPreview.UiState_.OPENING_PDF_PREVIEW; 341 this.uiState_ = PrintPreview.UiState_.OPENING_PDF_PREVIEW;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 * getting the printer list. 414 * getting the printer list.
473 * @private 415 * @private
474 */ 416 */
475 onWindowLoad_: function() { 417 onWindowLoad_: function() {
476 this.decorate($('print-preview')); 418 this.decorate($('print-preview'));
477 i18nTemplate.process(document, templateData); 419 i18nTemplate.process(document, templateData);
478 if (!this.previewArea_.hasCompatiblePlugin) { 420 if (!this.previewArea_.hasCompatiblePlugin) {
479 this.setIsEnabled_(false); 421 this.setIsEnabled_(false);
480 } 422 }
481 this.nativeLayer_.startGetInitialSettings(); 423 this.nativeLayer_.startGetInitialSettings();
482 this.nativeLayer_.startGetLocalDestinations(); 424 this.destinationStore_.startLoadLocalDestinations();
483 }, 425 },
484 426
485 /** 427 /**
486 * Called when the native layer has initial settings to set. Sets the 428 * Called when the native layer has initial settings to set. Sets the
487 * initial settings of the print preview and begins fetching print 429 * initial settings of the print preview and begins fetching print
488 * destinations. 430 * destinations.
489 * @param {cr.Event} event Contains the initial print preview settings 431 * @param {cr.Event} event Contains the initial print preview settings
490 * persisted through the session. 432 * persisted through the session.
491 * @private 433 * @private
492 */ 434 */
(...skipping 19 matching lines...) Expand all
512 }, 454 },
513 455
514 /** 456 /**
515 * Calls when the native layer enables Google Cloud Print integration. 457 * Calls when the native layer enables Google Cloud Print integration.
516 * Fetches the user's cloud printers. 458 * Fetches the user's cloud printers.
517 * @param {cr.Event} event Contains the base URL of the Google Cloud Print 459 * @param {cr.Event} event Contains the base URL of the Google Cloud Print
518 * service. 460 * service.
519 * @private 461 * @private
520 */ 462 */
521 onCloudPrintEnable_: function(event) { 463 onCloudPrintEnable_: function(event) {
522 this.cloudPrintInterface_ = new cloudprint.CloudPrintInterface( 464 this.cloudPrintInterface_ =
523 event.baseCloudPrintUrl); 465 new cloudprint.CloudPrintInterface(event.baseCloudPrintUrl);
524 this.tracker.add(
525 this.cloudPrintInterface_,
526 cloudprint.CloudPrintInterface.EventType.SEARCH_DONE,
527 this.onCloudPrintSearchDone_.bind(this));
528 this.tracker.add(
529 this.cloudPrintInterface_,
530 cloudprint.CloudPrintInterface.EventType.PRINTER_DONE,
531 this.onCloudPrintPrinterDone_.bind(this));
532 this.tracker.add( 466 this.tracker.add(
533 this.cloudPrintInterface_, 467 this.cloudPrintInterface_,
534 cloudprint.CloudPrintInterface.EventType.SUBMIT_DONE, 468 cloudprint.CloudPrintInterface.EventType.SUBMIT_DONE,
535 this.onCloudPrintSubmitDone_.bind(this)); 469 this.onCloudPrintSubmitDone_.bind(this));
536 this.tracker.add( 470 this.tracker.add(
537 this.cloudPrintInterface_, 471 this.cloudPrintInterface_,
538 cloudprint.CloudPrintInterface.EventType.ERROR, 472 cloudprint.CloudPrintInterface.EventType.ERROR,
539 this.onCloudPrintError_.bind(this)); 473 this.onCloudPrintError_.bind(this));
540 474
541 var printWithCloudPrintDest = 475 this.userInfo_.setCloudPrintInterface(this.cloudPrintInterface_);
542 this.createPrintWithCloudPrintDestination_(); 476 this.destinationStore_.setCloudPrintInterface(this.cloudPrintInterface_);
543 this.destinationStore_.insertDestination(printWithCloudPrintDest); 477 this.destinationStore_.startLoadRecentCloudDestinations();
544
545 if (cr.isChromeOS) {
546 this.cloudPrintInterface_.search(true /*isRecent*/);
547 this.fetchState_ |= PrintPreview.FetchState_.RECENT_CLOUD_DESTINATIONS;
548 }
549 }, 478 },
550 479
551 /** 480 /**
552 * Called when the native layer gets local destinations. Adds local
553 * destination objects received from the operating system to the destination
554 * store. Also adds a save-as-pdf printer.
555 * @param {cr.Event} Contains the local destinations to set.
556 * @private
557 */
558 onLocalDestinationsSet_: function(event) {
559 var localDestinations = [];
560 for (var destInfo, i = 0; destInfo = event.destinationInfos[i]; i++) {
561 localDestinations.push(
562 print_preview.LocalDestinationParser.parse(destInfo));
563 }
564 localDestinations.push(this.createLocalPdfPrintDestination_());
565 this.destinationStore_.insertDestinations(localDestinations);
566 this.fetchState_ &= ~PrintPreview.FetchState_.LOCAL_DESTINATIONS;
567 },
568
569 /**
570 * Called when the native layer retrieves the capabilities for the selected
571 * local destination.
572 * @param {cr.Event} event Contains the capabilities of the local print
573 * destination.
574 * @private
575 */
576 onLocalDestinationCapabilitiesSet_: function(event) {
577 // TODO(rltoscano): There may be a race condition here. This method is
578 // assumed to return capabilities for the currently selected printer. But
579 // between the time the local printer was selected and the capabilities
580 // were retrieved, the selected printer can change. One way to address
581 // this is to include the destination ID in the settingsInfo parameter.
582 var selectedDestination = this.destinationStore_.selectedDestination;
583 if (selectedDestination.isLocal) {
584 var capabilities = print_preview.LocalCapabilitiesParser.parse(
585 event.settingsInfo);
586 selectedDestination.capabilities = capabilities;
587 this.printTicketStore_.updateDestinationCapabilities(capabilities);
588 this.printIfReady_();
589 }
590 },
591
592 /**
593 * Called from native layer after the user was requested to sign in, and did
594 * so successfully.
595 * @private
596 */
597 onDestinationsReload_: function() {
598 this.destinationStore_.clear();
599 this.nativeLayer_.startGetLocalDestinations();
600 if (this.cloudPrintInterface_) {
601 // Fetch recent printers.
602 this.cloudPrintInterface_.search(true /*isRecent*/);
603 // Fetch the full printer list.
604 this.cloudPrintInterface_.search(false /*isRecent*/);
605 }
606 this.fetchState_ =
607 PrintPreview.FetchState_.LOCAL_DESTINATIONS |
608 PrintPreview.FetchState_.ALL_CLOUD_DESTINATIONS |
609 PrintPreview.FetchState_.RECENT_CLOUD_DESTINATIONS;
610 },
611
612 /**
613 * Called from the native layer when ready to print to Google Cloud Print. 481 * Called from the native layer when ready to print to Google Cloud Print.
614 * @param {cr.Event} event Contains the body to send in the HTTP request. 482 * @param {cr.Event} event Contains the body to send in the HTTP request.
615 * @private 483 * @private
616 */ 484 */
617 onPrintToCloud_: function(event) { 485 onPrintToCloud_: function(event) {
618 assert(this.uiState_ == PrintPreview.UiState_.PRINTING, 486 assert(this.uiState_ == PrintPreview.UiState_.PRINTING,
619 'Document ready to be sent to the cloud when not in printing ' + 487 'Document ready to be sent to the cloud when not in printing ' +
620 'state: ' + this.uiState_); 488 'state: ' + this.uiState_);
621 assert(this.cloudPrintInterface_ != null, 489 assert(this.cloudPrintInterface_ != null,
622 'Google Cloud Print is not enabled'); 490 'Google Cloud Print is not enabled');
(...skipping 20 matching lines...) Expand all
643 onFileSelectionComplete_: function() { 511 onFileSelectionComplete_: function() {
644 assert(this.uiState_ == PrintPreview.UiState_.FILE_SELECTION, 512 assert(this.uiState_ == PrintPreview.UiState_.FILE_SELECTION,
645 'File selection completed when not in file-selection state: ' + 513 'File selection completed when not in file-selection state: ' +
646 this.uiState_); 514 this.uiState_);
647 this.previewArea_.showCustomMessage( 515 this.previewArea_.showCustomMessage(
648 localStrings.getString('printingToPDFInProgress')); 516 localStrings.getString('printingToPDFInProgress'));
649 this.uiState_ = PrintPreview.UiState_.PRINTING; 517 this.uiState_ = PrintPreview.UiState_.PRINTING;
650 }, 518 },
651 519
652 /** 520 /**
653 * Called when the Google Cloud Print search API call completes. Adds
654 * destinations to the printer store and selects one if it matches the
655 * initial destination.
656 * @param {cr.Event} event Contains the new cloud destinations.
657 * @private
658 */
659 onCloudPrintSearchDone_: function(event) {
660 this.destinationStore_.insertDestinations(event.printers);
661 if (event.isRecent) {
662 this.fetchState_ &= ~PrintPreview.FetchState_.RECENT_CLOUD_DESTINATIONS;
663 } else {
664 this.fetchState_ &= ~PrintPreview.FetchState_.ALL_CLOUD_DESTINATIONS;
665 }
666 },
667
668 /**
669 * Called when the Google Cloud Print printer API call completes. Updates
670 * the UI with the newly received capabilities.
671 * @param {cr.Event} event Contains the destination returned in the printer
672 * API call.
673 */
674 onCloudPrintPrinterDone_: function(event) {
675 var dest = this.destinationStore_.updateDestination(event.printer);
676 if (this.destinationStore_.selectedDestination == dest) {
677 this.printTicketStore_.updateDestinationCapabilities(dest.capabilities);
678 this.printIfReady_();
679 }
680 },
681
682 /**
683 * Called after successfully submitting a job to Google Cloud Print. 521 * Called after successfully submitting a job to Google Cloud Print.
684 * @private 522 * @private
685 */ 523 */
686 onCloudPrintSubmitDone_: function() { 524 onCloudPrintSubmitDone_: function() {
687 assert(this.uiState_ == PrintPreview.UiState_.PRINTING, 525 assert(this.uiState_ == PrintPreview.UiState_.PRINTING,
688 'Submited job to Google Cloud Print but not in printing state ' + 526 'Submited job to Google Cloud Print but not in printing state ' +
689 this.uiState_); 527 this.uiState_);
690 this.close_(); 528 this.close_();
691 }, 529 },
692 530
693 /** 531 /**
694 * Called when there was an error communicating with Google Cloud print. 532 * Called when there was an error communicating with Google Cloud print.
695 * Displays an error message in the print header. 533 * Displays an error message in the print header.
696 * @param {cr.Event} event Contains the error message. 534 * @param {cr.Event} event Contains the error message.
697 * @private 535 * @private
698 */ 536 */
699 onCloudPrintError_: function(event) { 537 onCloudPrintError_: function(event) {
700 if (cr.isChromeOS && event.message == '403') { 538 if (event.message == '403') {
701 this.nativeLayer_.startCloudPrintSignIn(); 539 this.destinationSearch_.showCloudPrintPromo();
702 } else { 540 } else {
703 this.printHeader_.setErrorMessage(event.message); 541 this.printHeader_.setErrorMessage(event.message);
704 } 542 }
705 this.fetchState_ &=
706 ~PrintPreview.FetchState_.RECENT_CLOUD_DESTINATIONS &
707 ~PrintPreview.FetchState_.ALL_CLOUD_DESTINATIONS;
708 }, 543 },
709 544
710 /** 545 /**
711 * Called when a new destination has been selected. Fetches the
712 * destination's capability list.
713 * @private
714 */
715 onDestinationSelect_: function() {
716 var destination = this.destinationStore_.selectedDestination;
717
718 // Fetch destination capabilities if necessary.
719 if (!destination.capabilities) {
720 if (destination.isLocal) {
721 this.nativeLayer_.startGetLocalDestinationCapabilities(
722 destination.id);
723 } else {
724 assert(this.cloudPrintInterface_ != null,
725 'Selected destination is a cloud destination, but Google ' +
726 'Cloud Print is not enabled');
727 this.cloudPrintInterface_.printer(destination.id);
728 }
729 } else {
730 this.printTicketStore_.updateDestinationCapabilities(
731 destination.capabilities);
732 }
733
734 this.printIfReady_();
735 },
736
737 /**
738 * Called when the preview area's preview generation is in progress. 546 * Called when the preview area's preview generation is in progress.
739 * @private 547 * @private
740 */ 548 */
741 onPreviewGenerationInProgress_: function() { 549 onPreviewGenerationInProgress_: function() {
742 this.isPreviewGenerationInProgress_ = true; 550 this.isPreviewGenerationInProgress_ = true;
743 }, 551 },
744 552
745 /** 553 /**
746 * Called when the preview area's preview generation is complete. 554 * Called when the preview area's preview generation is complete.
747 * @private 555 * @private
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 /** 608 /**
801 * Consume escape key presses and ctrl + shift + p. Delegate everything else 609 * Consume escape key presses and ctrl + shift + p. Delegate everything else
802 * to the preview area. 610 * to the preview area.
803 * @param {KeyboardEvent} e The keyboard event. 611 * @param {KeyboardEvent} e The keyboard event.
804 * @private 612 * @private
805 */ 613 */
806 onKeyDown_: function(e) { 614 onKeyDown_: function(e) {
807 // Escape key closes the dialog. 615 // Escape key closes the dialog.
808 if (e.keyCode == 27 && !e.shiftKey && !e.ctrlKey && !e.altKey && 616 if (e.keyCode == 27 && !e.shiftKey && !e.ctrlKey && !e.altKey &&
809 !e.metaKey) { 617 !e.metaKey) {
810 this.close_(); 618 if (this.destinationSearch_.getIsVisible()) {
619 this.destinationSearch_.setIsVisible(false);
620 } else {
621 this.close_();
622 }
811 e.preventDefault(); 623 e.preventDefault();
812 return; 624 return;
813 } 625 }
814 626
815 // Ctrl + Shift + p / Mac equivalent. 627 // Ctrl + Shift + p / Mac equivalent.
816 if (e.keyCode == 80) { 628 if (e.keyCode == 80) {
817 if ((cr.isMac && e.metaKey && e.altKey && !e.shiftKey && !e.ctrlKey) || 629 if ((cr.isMac && e.metaKey && e.altKey && !e.shiftKey && !e.ctrlKey) ||
818 (!cr.isMac && e.shiftKey && e.ctrlKey && !e.altKey && !e.metaKey)) { 630 (!cr.isMac && e.shiftKey && e.ctrlKey && !e.altKey && !e.metaKey)) {
819 this.openSystemPrintDialog_(); 631 this.openSystemPrintDialog_();
820 e.preventDefault(); 632 e.preventDefault();
821 return; 633 return;
822 } 634 }
823 } 635 }
824 636
825 // Pass certain directional keyboard events to the PDF viewer. 637 // Pass certain directional keyboard events to the PDF viewer.
826 this.previewArea_.handleDirectionalKeyEvent(e); 638 this.previewArea_.handleDirectionalKeyEvent(e);
827 }, 639 },
828 640
829 /** 641 /**
830 * Called when native layer receives invalid settings for a print request. 642 * Called when native layer receives invalid settings for a print request.
831 * @private 643 * @private
832 */ 644 */
833 onSettingsInvalid_: function() { 645 onSettingsInvalid_: function() {
834 this.uiState_ = PrintPreview.UiState_.ERROR; 646 this.uiState_ = PrintPreview.UiState_.ERROR;
835 this.previewArea_.showCustomMessage( 647 this.previewArea_.showCustomMessage(
836 localStrings.getString('invalidPrinterSettings')); 648 localStrings.getString('invalidPrinterSettings'));
837 }, 649 },
838 650
839 /** 651 /**
652 * Called when the destination settings' change button is activated.
653 * Displays the destination search component.
654 * @private
655 */
656 onDestinationChangeButtonActivate_: function() {
657 this.destinationSearch_.setIsVisible(true);
658 this.destinationStore_.startLoadAllCloudDestinations();
659 },
660
661 /**
662 * Called when the destination search dispatches manage cloud destinations
663 * event. Calls corresponding native layer method.
664 * @private
665 */
666 onManageCloudDestinationsActivated_: function() {
667 this.nativeLayer_.startManageCloudDestinations();
668 },
669
670 /**
671 * Called when the destination search dispatches manage local destinations
672 * event. Calls corresponding native layer method.
673 * @private
674 */
675 onManageLocalDestinationsActivated_: function() {
676 this.nativeLayer_.startManageLocalDestinations();
677 },
678
679 /**
680 * Called when the user wants to sign in to Google Cloud Print. Calls the
681 * corresponding native layer event.
682 * @private
683 */
684 onCloudPrintSignInActivated_: function() {
685 this.nativeLayer_.startCloudPrintSignIn();
686 },
687
688 /**
840 * Called when the native layer dispatches a DISABLE_SCALING event. Updates 689 * Called when the native layer dispatches a DISABLE_SCALING event. Updates
841 * the print ticket. 690 * the print ticket.
842 * @private 691 * @private
843 */ 692 */
844 onDisableScaling_: function() { 693 onDisableScaling_: function() {
845 this.printTicketStore_.updateFitToPage(false); 694 this.printTicketStore_.updateFitToPage(false);
846 },
847
848 /**
849 * Called when the user selects the "Manage printers..." option in the
850 * destination select.
851 * @private
852 */
853 onManagePrinters_: function() {
854 if (cr.isChromeOS) {
855 this.nativeLayer_.startManageCloudPrinters();
856 } else {
857 this.nativeLayer_.startManageLocalPrinters();
858 }
859 } 695 }
860 }; 696 };
861 697
862 // Export 698 // Export
863 return { 699 return {
864 PrintPreview: PrintPreview 700 PrintPreview: PrintPreview
865 }; 701 };
866 }); 702 });
867 703
868 // Pull in all other scripts in a single shot. 704 // Pull in all other scripts in a single shot.
869 <include src="data/page_number_set.js"/> 705 <include src="data/page_number_set.js"/>
870 <include src="data/destination.js"/> 706 <include src="data/destination.js"/>
871 <include src="data/local_parsers.js"/> 707 <include src="data/local_parsers.js"/>
872 <include src="data/cloud_parsers.js"/> 708 <include src="data/cloud_parsers.js"/>
873 <include src="data/chromium_capabilities.js"/> 709 <include src="data/chromium_capabilities.js"/>
874 <include src="data/cloud_capabilities.js"/> 710 <include src="data/cloud_capabilities.js"/>
875 <include src="data/destination_store.js"/> 711 <include src="data/destination_store.js"/>
876 <include src="data/margins.js"/> 712 <include src="data/margins.js"/>
877 <include src="data/document_info.js"/> 713 <include src="data/document_info.js"/>
878 <include src="data/printable_area.js"/> 714 <include src="data/printable_area.js"/>
879 <include src="data/measurement_system.js"/> 715 <include src="data/measurement_system.js"/>
880 <include src="data/print_ticket_store.js"/> 716 <include src="data/print_ticket_store.js"/>
881 <include src="data/coordinate2d.js"/> 717 <include src="data/coordinate2d.js"/>
882 <include src="data/size.js"/> 718 <include src="data/size.js"/>
883 <include src="data/capabilities_holder.js"/> 719 <include src="data/capabilities_holder.js"/>
720 <include src="data/user_info.js"/>
884 721
885 <include src="data/ticket_items/ticket_item.js"/> 722 <include src="data/ticket_items/ticket_item.js"/>
886 723
887 <include src="data/ticket_items/custom_margins.js"/> 724 <include src="data/ticket_items/custom_margins.js"/>
888 <include src="data/ticket_items/collate.js"/> 725 <include src="data/ticket_items/collate.js"/>
889 <include src="data/ticket_items/color.js"/> 726 <include src="data/ticket_items/color.js"/>
890 <include src="data/ticket_items/copies.js"/> 727 <include src="data/ticket_items/copies.js"/>
891 <include src="data/ticket_items/duplex.js"/> 728 <include src="data/ticket_items/duplex.js"/>
892 <include src="data/ticket_items/header_footer.js"/> 729 <include src="data/ticket_items/header_footer.js"/>
893 <include src="data/ticket_items/landscape.js"/> 730 <include src="data/ticket_items/landscape.js"/>
(...skipping 13 matching lines...) Expand all
907 <include src="settings/color_settings.js"/> 744 <include src="settings/color_settings.js"/>
908 <include src="settings/margin_settings.js"/> 745 <include src="settings/margin_settings.js"/>
909 <include src="settings/destination_settings.js"/> 746 <include src="settings/destination_settings.js"/>
910 <include src="settings/other_options_settings.js"/> 747 <include src="settings/other_options_settings.js"/>
911 748
912 <include src="previewarea/margin_control.js"/> 749 <include src="previewarea/margin_control.js"/>
913 <include src="previewarea/margin_control_container.js"/> 750 <include src="previewarea/margin_control_container.js"/>
914 <include src="previewarea/preview_area.js"/> 751 <include src="previewarea/preview_area.js"/>
915 <include src="preview_generator.js"/> 752 <include src="preview_generator.js"/>
916 753
754 <include src="search/destination_list.js"/>
755 <include src="search/cloud_destination_list.js"/>
756 <include src="search/destination_list_item.js"/>
757 <include src="search/destination_search.js"/>
758 <include src="search/search_box.js"/>
759
917 var printPreview = new print_preview.PrintPreview(); 760 var printPreview = new print_preview.PrintPreview();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698