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-term'].value && this.downloadsShowing;
39 var term = this.$['search-term'];
40 term.addEventListener('input', this.onSearchTermInput_.bind(this));
41 term.addEventListener('keydown', this.onSearchTermKeydown_.bind(this));
45 onClearAllClick_: function() {
46 assert(this.canClearAll());
47 this.actionService_.clearAll();
51 onDownloadsShowingChange_: function() {
52 this.updateClearAll_();
56 onSearchTermInput_: function() {
57 this.actionService_.search(this.$['search-term'].value);
58 this.updateClearAll_();
62 onSearchTermKeydown_: function(e) {
63 assert(this.showingSearch_);
64 if (e.keyIdentifier == 'U+001B') // Escape.
65 this.toggleShowingSearch_();
69 onOpenDownloadsFolderClick_: function() {
70 this.actionService_.openDownloadsFolder();
74 toggleShowingSearch_: function() {
75 this.showingSearch_ = !this.showingSearch_;
77 if (this.showingSearch_) {
78 this.$['search-term'].focus();
80 this.$['search-term'].value = '';
81 this.onSearchTermInput_();
86 updateClearAll_: function() {
87 this.$['clear-all'].hidden = !this.canClearAll();
91 return {Toolbar: Toolbar};