Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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('downloads', function() { | 5 cr.define('downloads', function() { |
| 6 var Toolbar = Polymer({ | 6 var Toolbar = Polymer({ |
| 7 is: 'downloads-toolbar', | 7 is: 'downloads-toolbar', |
| 8 | 8 |
| 9 /** @param {!downloads.ActionService} actionService */ | 9 /** @param {!downloads.ActionService} actionService */ |
| 10 setActionService: function(actionService) { | 10 setActionService: function(actionService) { |
| 11 /** @private {!downloads.ActionService} */ | 11 /** @private {!downloads.ActionService} */ |
| 12 this.actionService_ = actionService; | 12 this.actionService_ = actionService; |
| 13 }, | 13 }, |
| 14 | 14 |
| 15 attached: function() { | |
| 16 /** @private {!cr.ui.SearchField.Delegate} */ | |
| 17 this.searchFieldDelegate_ = new ToolbarSearchFieldDelegate(this); | |
| 18 this.$['search-input'].setDelegate(this.searchFieldDelegate_); | |
| 19 }, | |
| 20 | |
| 15 properties: { | 21 properties: { |
| 16 downloadsShowing: { | 22 downloadsShowing: { |
| 17 reflectToAttribute: true, | 23 reflectToAttribute: true, |
| 18 type: Boolean, | 24 type: Boolean, |
| 19 value: false, | 25 value: false, |
| 20 observer: 'onDownloadsShowingChange_', | 26 observer: 'onDownloadsShowingChange_', |
| 21 }, | 27 }, |
| 22 | |
| 23 showingSearch_: { | |
| 24 type: Boolean, | |
| 25 value: false, | |
| 26 }, | |
| 27 }, | 28 }, |
| 28 | 29 |
| 29 /** @return {boolean} Whether removal can be undone. */ | 30 /** @return {boolean} Whether removal can be undone. */ |
| 30 canUndo: function() { | 31 canUndo: function() { |
| 31 return this.$['search-input'] != this.shadowRoot.activeElement; | 32 return this.$['search-input'] != this.shadowRoot.activeElement; |
| 32 }, | 33 }, |
| 33 | 34 |
| 34 /** @return {boolean} Whether "Clear all" should be allowed. */ | 35 /** @return {boolean} Whether "Clear all" should be allowed. */ |
| 35 canClearAll: function() { | 36 canClearAll: function() { |
| 36 return !this.$['search-input'].value && this.downloadsShowing; | 37 return !this.$['search-input'].getValue() && this.downloadsShowing; |
| 37 }, | 38 }, |
| 38 | 39 |
| 39 /** @private */ | 40 /** @private */ |
| 40 onClearAllClick_: function() { | 41 onClearAllClick_: function() { |
| 41 assert(this.canClearAll()); | 42 assert(this.canClearAll()); |
| 42 this.actionService_.clearAll(); | 43 this.actionService_.clearAll(); |
| 43 }, | 44 }, |
| 44 | 45 |
| 45 /** @private */ | 46 /** @private */ |
| 46 onDownloadsShowingChange_: function() { | 47 onDownloadsShowingChange_: function() { |
| 47 this.updateClearAll_(); | 48 this.updateClearAll_(); |
| 48 }, | 49 }, |
| 49 | 50 |
| 50 /** @private */ | 51 /** |
| 51 onSearchTermSearch_: function() { | 52 * @param {string} value |
| 52 this.actionService_.search(this.$['search-input'].value); | 53 */ |
| 54 onSearchTermSearch: function(value) { | |
| 55 this.actionService_.search(value); | |
| 53 this.updateClearAll_(); | 56 this.updateClearAll_(); |
| 54 }, | 57 }, |
| 55 | 58 |
| 56 /** @private */ | 59 /** @private */ |
| 57 onSearchTermKeydown_: function(e) { | |
| 58 assert(this.showingSearch_); | |
| 59 if (e.keyIdentifier == 'U+001B') // Escape. | |
| 60 this.toggleShowingSearch_(); | |
| 61 }, | |
| 62 | |
| 63 /** @private */ | |
| 64 onOpenDownloadsFolderClick_: function() { | 60 onOpenDownloadsFolderClick_: function() { |
| 65 this.actionService_.openDownloadsFolder(); | 61 this.actionService_.openDownloadsFolder(); |
| 66 }, | 62 }, |
| 67 | 63 |
| 68 /** @private */ | 64 /** @private */ |
| 69 toggleShowingSearch_: function() { | |
| 70 this.showingSearch_ = !this.showingSearch_; | |
| 71 | |
| 72 if (this.showingSearch_) { | |
| 73 this.$['search-input'].focus(); | |
| 74 } else { | |
| 75 this.$['search-input'].value = ''; | |
| 76 this.onSearchTermSearch_(); | |
| 77 } | |
| 78 }, | |
| 79 | |
| 80 /** @private */ | |
| 81 updateClearAll_: function() { | 65 updateClearAll_: function() { |
| 82 this.$$('#actions .clear-all').hidden = !this.canClearAll(); | 66 this.$$('#actions .clear-all').hidden = !this.canClearAll(); |
| 83 this.$$('paper-menu .clear-all').hidden = !this.canClearAll(); | 67 this.$$('paper-menu .clear-all').hidden = !this.canClearAll(); |
| 84 }, | 68 }, |
| 85 }); | 69 }); |
| 86 | 70 |
| 71 /** | |
| 72 * @constructor | |
| 73 * @implements {cr.ui.SearchField.Delegate} | |
| 74 */ | |
| 75 function ToolbarSearchFieldDelegate(toolbar) { | |
| 76 this.toolbar_ = toolbar; | |
| 77 }; | |
|
Dan Beam
2015/09/14 19:22:05
}; -> }
Devlin
2015/09/14 21:47:18
Done.
| |
| 78 | |
| 79 ToolbarSearchFieldDelegate.prototype = { | |
| 80 /** @override */ | |
| 81 onSearchTermSearch: function(value) { | |
| 82 this.toolbar_.onSearchTermSearch(value); | |
| 83 } | |
| 84 }; | |
| 85 | |
| 87 return {Toolbar: Toolbar}; | 86 return {Toolbar: Toolbar}; |
| 88 }); | 87 }); |
| 89 | 88 |
| 90 // TODO(dbeam): https://github.com/PolymerElements/iron-dropdown/pull/16/files | 89 // TODO(dbeam): https://github.com/PolymerElements/iron-dropdown/pull/16/files |
| 91 /** @suppress {checkTypes} */ | 90 /** @suppress {checkTypes} */ |
| 92 (function() { | 91 (function() { |
| 93 Polymer.IronDropdownScrollManager.pushScrollLock = function() {}; | 92 Polymer.IronDropdownScrollManager.pushScrollLock = function() {}; |
| 94 })(); | 93 })(); |
| OLD | NEW |