Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Side by Side Diff: chrome/browser/resources/md_downloads/toolbar.js

Issue 1308893009: [MD Extensions] Move search field out of downloads, use it in extensions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: License + Nit Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 {!SearchFieldDelegate} */
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 /** @param {string} searchTerm */
51 onSearchTermSearch_: function() { 52 onSearchTermSearch: function(searchTerm) {
52 this.actionService_.search(this.$['search-input'].value); 53 this.actionService_.search(searchTerm);
53 this.updateClearAll_(); 54 this.updateClearAll_();
54 }, 55 },
55 56
56 /** @private */ 57 /** @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() { 58 onOpenDownloadsFolderClick_: function() {
65 this.actionService_.openDownloadsFolder(); 59 this.actionService_.openDownloadsFolder();
66 }, 60 },
67 61
68 /** @private */ 62 /** @private */
69 toggleShowingSearch_: function() {
70 this.showingSearch_ = !this.showingSearch_;
71 this.$['search-button'].disabled = this.showingSearch_;
72
73 if (this.showingSearch_) {
74 this.$['search-input'].focus();
75 } else {
76 this.$['search-input'].value = '';
77 this.onSearchTermSearch_();
78 }
79 },
80
81 /** @private */
82 updateClearAll_: function() { 63 updateClearAll_: function() {
83 this.$$('#actions .clear-all').hidden = !this.canClearAll(); 64 this.$$('#actions .clear-all').hidden = !this.canClearAll();
84 this.$$('paper-menu .clear-all').hidden = !this.canClearAll(); 65 this.$$('paper-menu .clear-all').hidden = !this.canClearAll();
85 }, 66 },
86 }); 67 });
87 68
69 /**
70 * @constructor
71 * @implements {SearchFieldDelegate}
72 */
73 // TODO(devlin): This is a bit excessive, and it would be better to just have
74 // Toolbar implement SearchFieldDelegate. But for now, we don't know how to
75 // make that happen with closure compiler.
76 function ToolbarSearchFieldDelegate(toolbar) {
77 this.toolbar_ = toolbar;
78 }
79
80 ToolbarSearchFieldDelegate.prototype = {
81 /** @override */
82 onSearchTermSearch: function(searchTerm) {
83 this.toolbar_.onSearchTermSearch(searchTerm);
84 }
85 };
86
88 return {Toolbar: Toolbar}; 87 return {Toolbar: Toolbar};
89 }); 88 });
90 89
91 // TODO(dbeam): https://github.com/PolymerElements/iron-dropdown/pull/16/files 90 // TODO(dbeam): https://github.com/PolymerElements/iron-dropdown/pull/16/files
92 /** @suppress {checkTypes} */ 91 /** @suppress {checkTypes} */
93 (function() { 92 (function() {
94 Polymer.IronDropdownScrollManager.pushScrollLock = function() {}; 93 Polymer.IronDropdownScrollManager.pushScrollLock = function() {};
95 })(); 94 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698