| 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 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 }, | 576 }, |
| 577 | 577 |
| 578 /** | 578 /** |
| 579 * Called when a destination is selected. Clears the search and hides the | 579 * Called when a destination is selected. Clears the search and hides the |
| 580 * widget. If The destination is provisional, it runs provisional | 580 * widget. If The destination is provisional, it runs provisional |
| 581 * destination resolver first. | 581 * destination resolver first. |
| 582 * @param {!print_preview.Destination} destination The selected destination. | 582 * @param {!print_preview.Destination} destination The selected destination. |
| 583 * @private | 583 * @private |
| 584 */ | 584 */ |
| 585 handleOnDestinationSelect_: function(destination) { | 585 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 |
| 586 if (destination.isProvisional) { | 615 if (destination.isProvisional) { |
| 587 assert(!this.provisionalDestinationResolver_, | 616 assert(!this.provisionalDestinationResolver_, |
| 588 'Provisional destination resolver already exists.'); | 617 'Provisional destination resolver already exists.'); |
| 589 this.provisionalDestinationResolver_ = | 618 this.provisionalDestinationResolver_ = |
| 590 print_preview.ProvisionalDestinationResolver.create( | 619 print_preview.ProvisionalDestinationResolver.create( |
| 591 this.destinationStore_, destination); | 620 this.destinationStore_, destination); |
| 592 assert(!!this.provisionalDestinationResolver_, | 621 assert(!!this.provisionalDestinationResolver_, |
| 593 'Unable to create provisional destination resolver'); | 622 'Unable to create provisional destination resolver'); |
| 594 | 623 |
| 595 var lastFocusedElement = document.activeElement; | 624 var lastFocusedElement = document.activeElement; |
| 596 this.addChild(this.provisionalDestinationResolver_); | 625 this.addChild(this.provisionalDestinationResolver_); |
| 597 this.provisionalDestinationResolver_.run(this.getElement()) | 626 this.provisionalDestinationResolver_.run(this.getElement()). |
| 598 .then( | 627 then( |
| 599 /** | 628 /** |
| 600 * @param {!print_preview.Destination} resolvedDestination | 629 * @param {!print_preview.Destination} resolvedDestination |
| 601 * Destination to which the provisional destination was | 630 * Destination to which the provisional destination was |
| 602 * resolved. | 631 * resolved. |
| 603 */ | 632 */ |
| 604 function(resolvedDestination) { | 633 function(resolvedDestination) { |
| 605 this.handleOnDestinationSelect_(resolvedDestination); | 634 this.handleOnDestinationSelect_(resolvedDestination); |
| 606 }.bind(this)) | 635 }.bind(this)). |
| 607 .catch( | 636 catch( |
| 608 function() { | 637 function() { |
| 609 console.log('Failed to resolve provisional destination: ' + | 638 console.log('Failed to resolve provisional destination: ' + |
| 610 destination.id); | 639 destination.id); |
| 611 }) | 640 }). |
| 612 .then( | 641 then( |
| 613 function() { | 642 function() { |
| 614 this.removeChild(this.provisionalDestinationResolver_); | 643 this.removeChild(this.provisionalDestinationResolver_); |
| 615 this.provisionalDestinationResolver_ = null; | 644 this.provisionalDestinationResolver_ = null; |
| 616 | 645 |
| 617 // Restore focus to the previosly focused element if it's | 646 // Restore focus to the previosly focused element if it's |
| 618 // still shown in the search. | 647 // still shown in the search. |
| 619 if (lastFocusedElement && | 648 if (lastFocusedElement && |
| 620 this.getIsVisible() && | 649 this.getIsVisible() && |
| 621 getIsVisible(lastFocusedElement) && | 650 getIsVisible(lastFocusedElement) && |
| 622 this.getElement().contains(lastFocusedElement)) { | 651 this.getElement().contains(lastFocusedElement)) { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 onWindowResize_: function() { | 793 onWindowResize_: function() { |
| 765 this.reflowLists_(); | 794 this.reflowLists_(); |
| 766 } | 795 } |
| 767 }; | 796 }; |
| 768 | 797 |
| 769 // Export | 798 // Export |
| 770 return { | 799 return { |
| 771 DestinationSearch: DestinationSearch | 800 DestinationSearch: DestinationSearch |
| 772 }; | 801 }; |
| 773 }); | 802 }); |
| OLD | NEW |