Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / resources / md_downloads / toolbar.js
blob36d6cf42a26bd6d5ad99941ed69a47f50a484608
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;
13     },
15     properties: {
16       downloadsShowing: {
17         reflectToAttribute: true,
18         type: Boolean,
19         value: false,
20         observer: 'onDownloadsShowingChange_',
21       },
23       showingSearch_: {
24         type: Boolean,
25         value: false,
26       },
27     },
29     /** @return {boolean} Whether removal can be undone. */
30     canUndo: function() {
31       return this.$['search-input'] != this.shadowRoot.activeElement;
32     },
34     /** @return {boolean} Whether "Clear all" should be allowed. */
35     canClearAll: function() {
36       return !this.$['search-input'].value && this.downloadsShowing;
37     },
39     /** @private */
40     onClearAllClick_: function() {
41       assert(this.canClearAll());
42       this.actionService_.clearAll();
43     },
45     /** @private */
46     onDownloadsShowingChange_: function() {
47       this.updateClearAll_();
48     },
50     /** @private */
51     onSearchTermSearch_: function() {
52       this.actionService_.search(this.$['search-input'].value);
53       this.updateClearAll_();
54     },
56     /** @private */
57     onSearchTermKeydown_: function(e) {
58       assert(this.showingSearch_);
59       if (e.keyIdentifier == 'U+001B')  // Escape.
60         this.toggleShowingSearch_();
61     },
63     /** @private */
64     onOpenDownloadsFolderClick_: function() {
65       this.actionService_.openDownloadsFolder();
66     },
68     /** @private */
69     toggleShowingSearch_: function() {
70       this.showingSearch_ = !this.showingSearch_;
72       if (this.showingSearch_) {
73         this.$['search-input'].focus();
74       } else {
75         this.$['search-input'].value = '';
76         this.onSearchTermSearch_();
77       }
78     },
80     /** @private */
81     updateClearAll_: function() {
82       this.$$('#actions .clear-all').hidden = !this.canClearAll();
83       this.$$('paper-menu .clear-all').hidden = !this.canClearAll();
84     },
85   });
87   return {Toolbar: Toolbar};
88 });
90 // TODO(dbeam): https://github.com/PolymerElements/iron-dropdown/pull/16/files
91 /** @suppress {checkTypes} */
92 (function() {
93 Polymer.IronDropdownScrollManager.pushScrollLock = function() {};
94 })();