Chromium Code Reviews| 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 cr.define('print_preview', function() { | 5 cr.define('print_preview', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Component used for searching for a print destination. | 9 * Component used for searching for a print destination. |
| 10 * This is a modal dialog that allows the user to search and select a | 10 * This is a modal dialog that allows the user to search and select a |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 | 67 |
| 68 /** | 68 /** |
| 69 * Child overlay used for resolving a provisional destination. The overlay | 69 * Child overlay used for resolving a provisional destination. The overlay |
| 70 * is shown when the user attempts to select a provisional destination. | 70 * is shown when the user attempts to select a provisional destination. |
| 71 * Set only when a destination is being resolved. | 71 * Set only when a destination is being resolved. |
| 72 * @private {?print_preview.ProvisionalDestinationResolver} | 72 * @private {?print_preview.ProvisionalDestinationResolver} |
| 73 */ | 73 */ |
| 74 this.provisionalDestinationResolver_ = null; | 74 this.provisionalDestinationResolver_ = null; |
| 75 | 75 |
| 76 /** | 76 /** |
| 77 * The destination that is currently in configuration. | |
| 78 * @private {?print_preview.Destination} | |
| 79 */ | |
| 80 this.destinationInConfiguring_ = null; | |
| 81 | |
| 82 /** | |
| 77 * Search box used to search through the destination lists. | 83 * Search box used to search through the destination lists. |
| 78 * @type {!print_preview.SearchBox} | 84 * @type {!print_preview.SearchBox} |
| 79 * @private | 85 * @private |
| 80 */ | 86 */ |
| 81 this.searchBox_ = new print_preview.SearchBox( | 87 this.searchBox_ = new print_preview.SearchBox( |
| 82 loadTimeData.getString('searchBoxPlaceholder')); | 88 loadTimeData.getString('searchBoxPlaceholder')); |
| 83 this.addChild(this.searchBox_); | 89 this.addChild(this.searchBox_); |
| 84 | 90 |
| 85 /** | 91 /** |
| 86 * Destination list containing recent destinations. | 92 * Destination list containing recent destinations. |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 this.tracker.add( | 222 this.tracker.add( |
| 217 this.getChildElement('.cloudprint-promo > .close-button'), | 223 this.getChildElement('.cloudprint-promo > .close-button'), |
| 218 'click', | 224 'click', |
| 219 this.onCloudprintPromoCloseButtonClick_.bind(this)); | 225 this.onCloudprintPromoCloseButtonClick_.bind(this)); |
| 220 this.tracker.add( | 226 this.tracker.add( |
| 221 this.searchBox_, | 227 this.searchBox_, |
| 222 print_preview.SearchBox.EventType.SEARCH, | 228 print_preview.SearchBox.EventType.SEARCH, |
| 223 this.onSearch_.bind(this)); | 229 this.onSearch_.bind(this)); |
| 224 this.tracker.add( | 230 this.tracker.add( |
| 225 this, | 231 this, |
| 232 print_preview.DestinationListItem.EventType.CONFIGURE_REQUEST, | |
| 233 this.onDestinationConfigureRequest_.bind(this)); | |
| 234 this.tracker.add( | |
| 235 this, | |
| 226 print_preview.DestinationListItem.EventType.SELECT, | 236 print_preview.DestinationListItem.EventType.SELECT, |
| 227 this.onDestinationSelect_.bind(this)); | 237 this.onDestinationSelect_.bind(this)); |
| 228 this.tracker.add( | 238 this.tracker.add( |
| 229 this, | 239 this, |
| 230 print_preview.DestinationListItem.EventType.REGISTER_PROMO_CLICKED, | 240 print_preview.DestinationListItem.EventType.REGISTER_PROMO_CLICKED, |
| 231 function() { | 241 function() { |
| 232 this.metrics_.record(print_preview.Metrics.DestinationSearchBucket. | 242 this.metrics_.record(print_preview.Metrics.DestinationSearchBucket. |
| 233 REGISTER_PROMO_SELECTED); | 243 REGISTER_PROMO_SELECTED); |
| 234 }.bind(this)); | 244 }.bind(this)); |
| 235 | 245 |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 559 * Called when a destination search should be executed. Filters the | 569 * Called when a destination search should be executed. Filters the |
| 560 * destination lists with the given query. | 570 * destination lists with the given query. |
| 561 * @param {Event} evt Contains the search query. | 571 * @param {Event} evt Contains the search query. |
| 562 * @private | 572 * @private |
| 563 */ | 573 */ |
| 564 onSearch_: function(evt) { | 574 onSearch_: function(evt) { |
| 565 this.filterLists_(evt.queryRegExp); | 575 this.filterLists_(evt.queryRegExp); |
| 566 }, | 576 }, |
| 567 | 577 |
| 568 /** | 578 /** |
| 579 * Handler for {@code print_preview.DestinationListItem.EventType. | |
| 580 * CONFIGURE_REQUEST} event, which is called to check a destination list | |
| 581 * item needs to be setup on Chrome OS before being selected. Note we do not | |
| 582 * allow configuring more than one destination at the same time. | |
| 583 * @param {Event} evt Contains the destination needs to be setup. | |
|
dpapad
2017/03/30 20:56:23
!Event
xdai1
2017/03/30 23:18:43
Done.
| |
| 584 * @private | |
| 585 */ | |
| 586 onDestinationConfigureRequest_: function(evt) { | |
|
dpapad
2017/03/30 20:56:23
|evt| is not an established abbreviation. Can you
xdai1
2017/03/30 23:18:43
Sure. Renamed it to event.
| |
| 587 var destinationItem = evt.destination.isLocal | |
| 588 ? this.localList_.getDestinationItem(evt.destination.id) | |
|
dpapad
2017/03/30 20:56:24
It is way more common to put the binary operator i
xdai1
2017/03/30 23:18:43
Done.
| |
| 589 : this.cloudList_.getDestinationItem(evt.destination.id); | |
| 590 if (!destinationItem) | |
|
dpapad
2017/03/30 20:56:24
When can this happen? Please add a comment to expl
xdai1
2017/03/30 23:18:44
I don't think it can happen. Modified to an assert
| |
| 591 return; | |
| 592 | |
| 593 // Another printer setup is in process or the printer doesn't need to be | |
| 594 // set up. Reject the setup request directly. | |
| 595 if (this.destinationInConfiguring_ != null || | |
| 596 evt.destination.origin != print_preview.Destination.Origin.CROS || | |
| 597 evt.destination.capabilities != null) { | |
| 598 destinationItem.onConfigureRequestRejected( | |
| 599 this.destinationInConfiguring_ != null); | |
| 600 } else { | |
| 601 destinationItem.onConfigureRequestAccepted(); | |
| 602 this.handleConfigureDestination_(evt.destination); | |
| 603 } | |
| 604 }, | |
| 605 | |
| 606 /** | |
| 607 * Called When a destination needs to be setup. | |
| 608 * @param {!print_preview.Destination} destination The destination needs to | |
| 609 * be setup. | |
| 610 * @private | |
| 611 */ | |
| 612 handleConfigureDestination_: function(destination) { | |
| 613 assert(destination.origin == print_preview.Destination.Origin.CROS, | |
| 614 'Only local printer on Chrome OS requires setup.'); | |
| 615 this.destinationInConfiguring_ = destination; | |
| 616 this.destinationStore_.resolveCrosDestination(destination).then( | |
| 617 /** | |
| 618 * Called when the Promise is fulfilled. | |
| 619 * @param {!print_preview.PrinterSetupResponse} response. | |
| 620 */ | |
| 621 function(response) { | |
| 622 this.localList_.getDestinationItem(destination.id) | |
| 623 .onConfigureResolved(response); | |
| 624 this.destinationInConfiguring_ = null; | |
| 625 }.bind(this), | |
| 626 /** | |
| 627 * Called when the Promise is rejected. | |
|
dpapad
2017/03/30 20:56:24
Nit: Maybe remove this comment? Does not add much
xdai1
2017/03/30 23:18:44
I would prefer to preserve this comment if the abo
dpapad
2017/03/31 00:37:52
I would prefer trimming the 1st comment to
/** @pa
| |
| 628 */ | |
| 629 function() { | |
| 630 this.localList_.getDestinationItem(destination.id) | |
| 631 .onConfigureResolved({printerId: destination.id, success: false}); | |
| 632 this.destinationInConfiguring_ = null; | |
| 633 }.bind(this)); | |
| 634 }, | |
| 635 | |
| 636 /** | |
| 569 * Handler for {@code print_preview.DestinationListItem.EventType.SELECT} | 637 * Handler for {@code print_preview.DestinationListItem.EventType.SELECT} |
| 570 * event, which is called when a destinationi list item is selected. | 638 * event, which is called when a destination list item is selected. |
| 571 * @param {Event} evt Contains the selected destination. | 639 * @param {Event} evt Contains the selected destination. |
| 572 * @private | 640 * @private |
| 573 */ | 641 */ |
| 574 onDestinationSelect_: function(evt) { | 642 onDestinationSelect_: function(evt) { |
| 575 this.handleOnDestinationSelect_(evt.destination); | 643 this.handleOnDestinationSelect_(evt.destination); |
| 576 }, | 644 }, |
| 577 | 645 |
| 578 /** | 646 /** |
| 579 * Called when a destination is selected. Clears the search and hides the | 647 * Called when a destination is selected. Clears the search and hides the |
| 580 * widget. If The destination is provisional, it runs provisional | 648 * widget. If The destination is provisional, it runs provisional |
| 581 * destination resolver first. | 649 * destination resolver first. |
| 582 * @param {!print_preview.Destination} destination The selected destination. | 650 * @param {!print_preview.Destination} destination The selected destination. |
| 583 * @private | 651 * @private |
| 584 */ | 652 */ |
| 585 handleOnDestinationSelect_: function(destination) { | 653 handleOnDestinationSelect_: function(destination) { |
| 586 if (destination.origin == print_preview.Destination.Origin.CROS && | |
| 587 !destination.capabilities) { | |
| 588 // local printers on CrOS require setup. | |
| 589 assert(!this.printerConfigurer_); | |
| 590 this.printerConfigurer_ = new print_preview.CrosDestinationResolver( | |
| 591 this.destinationStore_, destination); | |
| 592 this.addChild(this.printerConfigurer_); | |
| 593 this.printerConfigurer_.run(this.getElement()). | |
| 594 then( | |
| 595 /** | |
| 596 * @param {!print_preview.PrinterSetupResponse} result | |
| 597 * An object containing the printerId and capabilities. | |
| 598 */ | |
| 599 function(result) { | |
| 600 assert(result.printerId == destination.id); | |
| 601 destination.capabilities = result.capabilities; | |
| 602 this.handleOnDestinationSelect_(destination); | |
| 603 }.bind(this), | |
| 604 function() { | |
| 605 console.warn( | |
| 606 'Failed to setup destination: ' + destination.id); | |
| 607 }). | |
| 608 then(function() { | |
| 609 this.removeChild(this.printerConfigurer_); | |
| 610 this.printerConfigurer_ = null; | |
| 611 }.bind(this)); | |
| 612 return; | |
| 613 } | |
| 614 | |
| 615 if (destination.isProvisional) { | 654 if (destination.isProvisional) { |
| 616 assert(!this.provisionalDestinationResolver_, | 655 assert(!this.provisionalDestinationResolver_, |
| 617 'Provisional destination resolver already exists.'); | 656 'Provisional destination resolver already exists.'); |
| 618 this.provisionalDestinationResolver_ = | 657 this.provisionalDestinationResolver_ = |
| 619 print_preview.ProvisionalDestinationResolver.create( | 658 print_preview.ProvisionalDestinationResolver.create( |
| 620 this.destinationStore_, destination); | 659 this.destinationStore_, destination); |
| 621 assert(!!this.provisionalDestinationResolver_, | 660 assert(!!this.provisionalDestinationResolver_, |
| 622 'Unable to create provisional destination resolver'); | 661 'Unable to create provisional destination resolver'); |
| 623 | 662 |
| 624 var lastFocusedElement = document.activeElement; | 663 var lastFocusedElement = document.activeElement; |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 793 onWindowResize_: function() { | 832 onWindowResize_: function() { |
| 794 this.reflowLists_(); | 833 this.reflowLists_(); |
| 795 } | 834 } |
| 796 }; | 835 }; |
| 797 | 836 |
| 798 // Export | 837 // Export |
| 799 return { | 838 return { |
| 800 DestinationSearch: DestinationSearch | 839 DestinationSearch: DestinationSearch |
| 801 }; | 840 }; |
| 802 }); | 841 }); |
| OLD | NEW |