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

Unified Diff: ui/webui/resources/cr_elements/cr_search_field/cr_search_field.js

Issue 1613233003: MD Downloads: make Ctrl+f invoke in-page search (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dl-vulcanize
Patch Set: rework, revulc Created 4 years, 11 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
« no previous file with comments | « chrome/browser/resources/md_downloads/vulcanized.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/webui/resources/cr_elements/cr_search_field/cr_search_field.js
diff --git a/ui/webui/resources/cr_elements/cr_search_field/cr_search_field.js b/ui/webui/resources/cr_elements/cr_search_field/cr_search_field.js
index e24e30935380f9a1d3e6f04475e3f6b031e046cc..2b39c58a431afbfb7924f5f69c57f28380833e6a 100644
--- a/ui/webui/resources/cr_elements/cr_search_field/cr_search_field.js
+++ b/ui/webui/resources/cr_elements/cr_search_field/cr_search_field.js
@@ -29,21 +29,47 @@ var SearchField = Polymer({
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 : '';
+ },
+
/** @param {SearchFieldDelegate} delegate */
setDelegate: function(delegate) {
this.delegate_ = delegate;
},
+ showAndFocus: function() {
+ this.showingSearch_ = true;
+ this.focus_();
+ },
+
+ /** @private */
+ focus_: function() {
+ this.async(function() {
+ if (!this.showingSearch_)
+ return;
+
+ var searchInput = this.getSearchInput_();
+ if (searchInput)
+ searchInput.focus();
+ });
+ },
+
/**
- * Returns the value of the search field.
- * @return {string}
+ * @return {?HTMLElement}
+ * @private
*/
- getValue: function() {
- var searchInput = this.$$('#search-input');
- return searchInput ? searchInput.value : '';
+ getSearchInput_: function() {
+ return this.$$('#search-input');
},
/** @private */
@@ -54,22 +80,27 @@ var SearchField = Polymer({
/** @private */
onSearchTermKeydown_: function(e) {
- assert(this.showingSearch_);
if (e.keyIdentifier == 'U+001B') // Escape.
- this.toggleShowingSearch_();
+ 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() {
michaelpg 2016/01/21 23:43:35 unused now?
Dan Beam 2016/01/21 23:54:23 nope, in html
this.showingSearch_ = !this.showingSearch_;
- this.async(function() {
- var searchInput = this.$$('#search-input');
- if (this.showingSearch_) {
- searchInput.focus();
- } else {
- searchInput.value = '';
- this.onSearchTermSearch_();
- }
- });
},
});
« no previous file with comments | « chrome/browser/resources/md_downloads/vulcanized.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698