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;
17 reflectToAttribute: true,
20 observer: 'onDownloadsShowingChange_',
29 /** @return {boolean} Whether removal can be undone. */
31 return this.$['search-input'] != this.shadowRoot.activeElement;
34 /** @return {boolean} Whether "Clear all" should be allowed. */
35 canClearAll: function() {
36 return !this.$['search-input'].value && this.downloadsShowing;
40 onClearAllClick_: function() {
41 assert(this.canClearAll());
42 this.actionService_.clearAll();
46 onDownloadsShowingChange_: function() {
47 this.updateClearAll_();
51 onSearchTermSearch_: function() {
52 this.actionService_.search(this.$['search-input'].value);
53 this.updateClearAll_();
57 onSearchTermKeydown_: function(e) {
58 assert(this.showingSearch_);
59 if (e.keyIdentifier == 'U+001B') // Escape.
60 this.toggleShowingSearch_();
64 onOpenDownloadsFolderClick_: function() {
65 this.actionService_.openDownloadsFolder();
69 toggleShowingSearch_: function() {
70 this.showingSearch_ = !this.showingSearch_;
72 if (this.showingSearch_) {
73 this.$['search-input'].focus();
75 this.$['search-input'].value = '';
76 this.onSearchTermSearch_();
81 updateClearAll_: function() {
82 this.$$('#actions .clear-all').hidden = !this.canClearAll();
83 this.$$('paper-menu .clear-all').hidden = !this.canClearAll();
87 return {Toolbar: Toolbar};
90 // TODO(dbeam): https://github.com/PolymerElements/iron-dropdown/pull/16/files
91 /** @suppress {checkTypes} */
93 Polymer.IronDropdownScrollManager.pushScrollLock = function() {};