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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/md_downloads/toolbar.js
diff --git a/chrome/browser/resources/md_downloads/toolbar.js b/chrome/browser/resources/md_downloads/toolbar.js
index 0611152c87c03b7b99a9dea2ed223176651808ee..3cab91fb7047d8e9309973e6c8bb4d904347d8a7 100644
--- a/chrome/browser/resources/md_downloads/toolbar.js
+++ b/chrome/browser/resources/md_downloads/toolbar.js
@@ -12,6 +12,12 @@ cr.define('downloads', function() {
this.actionService_ = actionService;
},
+ attached: function() {
+ /** @private {!SearchFieldDelegate} */
+ this.searchFieldDelegate_ = new ToolbarSearchFieldDelegate(this);
+ this.$['search-input'].setDelegate(this.searchFieldDelegate_);
+ },
+
properties: {
downloadsShowing: {
reflectToAttribute: true,
@@ -19,11 +25,6 @@ cr.define('downloads', function() {
value: false,
observer: 'onDownloadsShowingChange_',
},
-
- showingSearch_: {
- type: Boolean,
- value: false,
- },
},
/** @return {boolean} Whether removal can be undone. */
@@ -33,7 +34,7 @@ cr.define('downloads', function() {
/** @return {boolean} Whether "Clear all" should be allowed. */
canClearAll: function() {
- return !this.$['search-input'].value && this.downloadsShowing;
+ return !this.$['search-input'].getValue() && this.downloadsShowing;
},
/** @private */
@@ -47,44 +48,42 @@ cr.define('downloads', function() {
this.updateClearAll_();
},
- /** @private */
- onSearchTermSearch_: function() {
- this.actionService_.search(this.$['search-input'].value);
+ /** @param {string} searchTerm */
+ onSearchTermSearch: function(searchTerm) {
+ this.actionService_.search(searchTerm);
this.updateClearAll_();
},
/** @private */
- onSearchTermKeydown_: function(e) {
- assert(this.showingSearch_);
- if (e.keyIdentifier == 'U+001B') // Escape.
- this.toggleShowingSearch_();
- },
-
- /** @private */
onOpenDownloadsFolderClick_: function() {
this.actionService_.openDownloadsFolder();
},
/** @private */
- toggleShowingSearch_: function() {
- this.showingSearch_ = !this.showingSearch_;
- this.$['search-button'].disabled = this.showingSearch_;
-
- if (this.showingSearch_) {
- this.$['search-input'].focus();
- } else {
- this.$['search-input'].value = '';
- this.onSearchTermSearch_();
- }
- },
-
- /** @private */
updateClearAll_: function() {
this.$$('#actions .clear-all').hidden = !this.canClearAll();
this.$$('paper-menu .clear-all').hidden = !this.canClearAll();
},
});
+ /**
+ * @constructor
+ * @implements {SearchFieldDelegate}
+ */
+ // TODO(devlin): This is a bit excessive, and it would be better to just have
+ // Toolbar implement SearchFieldDelegate. But for now, we don't know how to
+ // make that happen with closure compiler.
+ function ToolbarSearchFieldDelegate(toolbar) {
+ this.toolbar_ = toolbar;
+ }
+
+ ToolbarSearchFieldDelegate.prototype = {
+ /** @override */
+ onSearchTermSearch: function(searchTerm) {
+ this.toolbar_.onSearchTermSearch(searchTerm);
+ }
+ };
+
return {Toolbar: Toolbar};
});

Powered by Google App Engine
This is Rietveld 408576698