Index: chrome/browser/resources/md_downloads/crisper.js |
diff --git a/chrome/browser/resources/md_downloads/crisper.js b/chrome/browser/resources/md_downloads/crisper.js |
index 8ccb8209d77536f0467408b43a1ac97aba08655b..f40bce70ebd09ee3fb5b817aac3daa86cd6f0fde 100644 |
--- a/chrome/browser/resources/md_downloads/crisper.js |
+++ b/chrome/browser/resources/md_downloads/crisper.js |
@@ -10333,6 +10333,111 @@ Polymer({ |
} |
} |
}); |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+/** @interface */ |
+var SearchFieldDelegate = function() {}; |
+ |
+SearchFieldDelegate.prototype = { |
+ /** |
+ * @param {string} value |
+ */ |
+ onSearchTermSearch: assertNotReached, |
+}; |
+ |
+/** |
+ * Implements an incremental search field which can be shown and hidden. |
+ * Canonical implementation is <cr-search-field>. |
+ * @polymerBehavior |
+ */ |
+var CrSearchFieldBehavior = { |
+ properties: { |
+ label: { |
+ type: String, |
+ value: '', |
+ }, |
+ |
+ clearLabel: { |
+ type: String, |
+ value: '', |
+ }, |
+ |
+ showingSearch: { |
+ type: Boolean, |
+ value: false, |
+ notify: true, |
+ observer: 'showingSearchChanged_', |
+ reflectToAttribute: true |
+ }, |
+ |
+ hasSearchText: Boolean, |
+ }, |
+ |
+ /** |
+ * @return {string} The value of the search field. |
+ */ |
+ getValue: function() { |
+ return this.$.searchInput.value; |
+ }, |
+ |
+ /** |
+ * Sets the value of the search field, if it exists. |
+ * @param {string} value |
+ */ |
+ setValue: function(value) { |
+ // Use bindValue when setting the input value so that changes propagate |
+ // correctly. |
+ this.$.searchInput.bindValue = value; |
+ this.hasSearchText = value != ''; |
+ }, |
+ |
+ /** @param {SearchFieldDelegate} delegate */ |
+ setDelegate: function(delegate) { |
+ this.delegate_ = delegate; |
+ }, |
+ |
+ showAndFocus: function() { |
+ this.showingSearch = true; |
+ this.focus_(); |
+ }, |
+ |
+ /** @private */ |
+ focus_: function() { |
+ this.$.searchInput.focus(); |
+ }, |
+ |
+ /** @private */ |
+ onSearchTermSearch_: function() { |
+ this.hasSearchText = this.getValue() != ''; |
+ if (this.delegate_) |
+ this.delegate_.onSearchTermSearch(this.getValue()); |
+ }, |
+ |
+ /** @private */ |
+ onSearchTermKeydown_: function(e) { |
+ if (e.key == 'Escape') |
+ this.showingSearch = false; |
+ }, |
+ |
+ /** @private */ |
+ showingSearchChanged_: function() { |
+ if (this.showingSearch) { |
+ this.focus_(); |
+ return; |
+ } |
+ |
+ this.setValue(''); |
+ this.$.searchInput.blur(); |
+ this.onSearchTermSearch_(); |
+ }, |
+ |
+ /** @private */ |
+ toggleShowingSearch_: function() { |
+ this.showingSearch = !this.showingSearch; |
+ }, |
+}; |
(function() { |
'use strict'; |
@@ -11098,123 +11203,9 @@ Polymer({ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-/** @interface */ |
-var SearchFieldDelegate = function() {}; |
- |
-SearchFieldDelegate.prototype = { |
- /** |
- * @param {string} value |
- */ |
- onSearchTermSearch: assertNotReached, |
-}; |
- |
var SearchField = Polymer({ |
is: 'cr-search-field', |
- |
- properties: { |
- label: { |
- type: String, |
- value: '', |
- }, |
- |
- clearLabel: { |
- type: String, |
- value: '', |
- }, |
- |
- showingSearch_: { |
- type: Boolean, |
- value: false, |
- observer: 'showingSearchChanged_', |
- }, |
- }, |
- |
- /** |
- * Returns the value of the search field. |
- * @return {string} |
- */ |
- getValue: function() { |
- var searchInput = this.getSearchInput_(); |
- return searchInput ? searchInput.value : ''; |
- }, |
- |
- /** |
- * Sets the value of the search field, if it exists. |
- * @param {string} value |
- */ |
- setValue: function(value) { |
- var searchInput = this.getSearchInput_(); |
- if (searchInput) |
- searchInput.value = value; |
- }, |
- |
- /** @param {SearchFieldDelegate} delegate */ |
- setDelegate: function(delegate) { |
- this.delegate_ = delegate; |
- }, |
- |
- /** @return {Promise<boolean>} */ |
- showAndFocus: function() { |
- this.showingSearch_ = true; |
- return this.focus_(); |
- }, |
- |
- /** |
- * @return {Promise<boolean>} |
- * @private |
- */ |
- focus_: function() { |
- return new Promise(function(resolve) { |
- this.async(function() { |
- if (this.showingSearch_) { |
- var searchInput = this.getSearchInput_(); |
- if (searchInput) |
- searchInput.focus(); |
- } |
- resolve(this.showingSearch_); |
- }); |
- }.bind(this)); |
- }, |
- |
- /** |
- * @return {?Element} |
- * @private |
- */ |
- getSearchInput_: function() { |
- return this.$$('#search-input'); |
- }, |
- |
- /** @private */ |
- onSearchTermSearch_: function() { |
- if (this.delegate_) |
- this.delegate_.onSearchTermSearch(this.getValue()); |
- }, |
- |
- /** @private */ |
- onSearchTermKeydown_: function(e) { |
- if (e.keyIdentifier == 'U+001B') // Escape. |
- this.showingSearch_ = false; |
- }, |
- |
- /** @private */ |
- showingSearchChanged_: function() { |
- if (this.showingSearch_) { |
- this.focus_(); |
- return; |
- } |
- |
- var searchInput = this.getSearchInput_(); |
- if (!searchInput) |
- return; |
- |
- searchInput.value = ''; |
- this.onSearchTermSearch_(); |
- }, |
- |
- /** @private */ |
- toggleShowingSearch_: function() { |
- this.showingSearch_ = !this.showingSearch_; |
- }, |
+ behaviors: [CrSearchFieldBehavior] |
}); |
// Copyright 2015 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |