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

Unified Diff: chrome/browser/resources/md_downloads/crisper.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
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 49a250bcb188dbd7d5067557fd3422590f8622d2..e28a22144dee9e93ba3ea82774121dc2d9fa7cc4 100644
--- a/chrome/browser/resources/md_downloads/crisper.js
+++ b/chrome/browser/resources/md_downloads/crisper.js
@@ -16878,21 +16878,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 */
@@ -16903,23 +16929,28 @@ 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() {
this.showingSearch_ = !this.showingSearch_;
- this.async(function() {
- var searchInput = this.$$('#search-input');
- if (this.showingSearch_) {
- searchInput.focus();
- } else {
- searchInput.value = '';
- this.onSearchTermSearch_();
- }
- });
},
});
// Copyright 2015 The Chromium Authors. All rights reserved.
@@ -16944,7 +16975,7 @@ cr.define('downloads', function() {
reflectToAttribute: true,
type: Boolean,
value: false,
- observer: 'onDownloadsShowingChange_',
+ observer: 'downloadsShowingChanged_',
},
overflowAlign_: {
@@ -16963,6 +16994,10 @@ cr.define('downloads', function() {
return !this.$['search-input'].getValue() && this.downloadsShowing;
},
+ onFindCommand: function() {
+ this.$['search-input'].showAndFocus();
+ },
+
/** @private */
onClearAllTap_: function() {
assert(this.canClearAll());
@@ -16970,7 +17005,7 @@ cr.define('downloads', function() {
},
/** @private */
- onDownloadsShowingChange_: function() {
+ downloadsShowingChanged_: function() {
this.updateClearAll_();
},
@@ -17099,6 +17134,9 @@ cr.define('downloads', function() {
case 'clear-all-command':
e.canExecute = this.$.toolbar.canClearAll();
break;
+ case 'find-command':
+ e.canExecute = true;
+ break;
}
},
@@ -17111,6 +17149,8 @@ cr.define('downloads', function() {
downloads.ActionService.getInstance().clearAll();
else if (e.command.id == 'undo-command')
downloads.ActionService.getInstance().undo();
+ else if (e.command.id == 'find-command')
+ this.$.toolbar.onFindCommand();
},
/** @private */

Powered by Google App Engine
This is Rietveld 408576698