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
3 // found in the LICENSE file.
5 cr
.define('downloads', function() {
6 var Toolbar
= Polymer({
7 is
: 'downloads-toolbar',
9 /** @param {!downloads.ActionService} actionService */
10 setActionService: function(actionService
) {
11 /** @private {!downloads.ActionService} */
12 this.actionService_
= actionService
;
19 observer
: 'onDownloadsShowingChange_',
28 /** @return {boolean} Whether removal can be undone. */
30 return !this.$['search-term'].shadowRoot
.activeElement
;
33 /** @return {boolean} Whether "Clear all" should be allowed. */
34 canClearAll: function() {
35 return !this.$['search-input'].value
&& this.downloadsShowing
;
39 onClearAllClick_: function() {
40 assert(this.canClearAll());
41 this.actionService_
.clearAll();
45 onDownloadsShowingChange_: function() {
46 this.updateClearAll_();
50 onSearchTermSearch_: function() {
51 this.actionService_
.search(this.$['search-input'].value
);
52 this.updateClearAll_();
56 onSearchTermKeydown_: function(e
) {
57 assert(this.showingSearch_
);
58 if (e
.keyIdentifier
== 'U+001B') // Escape.
59 this.toggleShowingSearch_();
63 onOpenDownloadsFolderClick_: function() {
64 this.actionService_
.openDownloadsFolder();
68 toggleShowingSearch_: function() {
69 this.showingSearch_
= !this.showingSearch_
;
71 if (this.showingSearch_
) {
72 this.$['search-input'].focus();
74 this.$['search-input'].value
= '';
75 this.onSearchTermSearch_();
80 updateClearAll_: function() {
81 this.$$('#actions .clear-all').hidden
= !this.canClearAll();
82 this.$$('paper-menu .clear-all').hidden
= !this.canClearAll();
86 return {Toolbar
: Toolbar
};
89 // TODO(dbeam): https://github.com/PolymerElements/iron-dropdown/pull/16/files
90 /** @suppress {checkTypes} */
92 Polymer
.IronDropdownScrollManager
.pushScrollLock = function() {};