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

Side by Side 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: 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 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 if (typeof Polymer == 'undefined') 5 if (typeof Polymer == 'undefined')
6 Polymer = {dom: 'shadow'}; 6 Polymer = {dom: 'shadow'};
7 else 7 else
8 console.error('Polymer is already defined.'); 8 console.error('Polymer is already defined.');
9 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 9 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
10 // Use of this source code is governed by a BSD-style license that can be 10 // Use of this source code is governed by a BSD-style license that can be
(...skipping 16857 matching lines...) Expand 10 before | Expand all | Expand 10 after
16868 label: { 16868 label: {
16869 type: String, 16869 type: String,
16870 value: '', 16870 value: '',
16871 }, 16871 },
16872 16872
16873 clearLabel: { 16873 clearLabel: {
16874 type: String, 16874 type: String,
16875 value: '', 16875 value: '',
16876 }, 16876 },
16877 16877
16878 showingSearch_: { 16878 showingSearch: {
16879 type: Boolean, 16879 type: Boolean,
16880 value: false, 16880 value: false,
16881 observer: 'showingSearchChanged_',
16881 }, 16882 },
16882 }, 16883 },
16883 16884
16884 /** @param {SearchFieldDelegate} delegate */ 16885 focus: function() {
16885 setDelegate: function(delegate) { 16886 this.$$('#search-input').focus();
16886 this.delegate_ = delegate;
16887 }, 16887 },
16888 16888
16889 /** 16889 /**
16890 * Returns the value of the search field. 16890 * Returns the value of the search field.
16891 * @return {string} 16891 * @return {string}
16892 */ 16892 */
16893 getValue: function() { 16893 getValue: function() {
16894 var searchInput = this.$$('#search-input'); 16894 var searchInput = this.$$('#search-input');
16895 return searchInput ? searchInput.value : ''; 16895 return searchInput ? searchInput.value : '';
16896 }, 16896 },
16897 16897
16898 /** @param {SearchFieldDelegate} delegate */
16899 setDelegate: function(delegate) {
16900 this.delegate_ = delegate;
16901 },
16902
16898 /** @private */ 16903 /** @private */
16899 onSearchTermSearch_: function() { 16904 onSearchTermSearch_: function() {
16900 if (this.delegate_) 16905 if (this.delegate_)
16901 this.delegate_.onSearchTermSearch(this.getValue()); 16906 this.delegate_.onSearchTermSearch(this.getValue());
16902 }, 16907 },
16903 16908
16904 /** @private */ 16909 /** @private */
16905 onSearchTermKeydown_: function(e) { 16910 onSearchTermKeydown_: function(e) {
16906 assert(this.showingSearch_);
16907 if (e.keyIdentifier == 'U+001B') // Escape. 16911 if (e.keyIdentifier == 'U+001B') // Escape.
16908 this.toggleShowingSearch_(); 16912 this.showingSearch = false;
16909 }, 16913 },
16910 16914
16911 /** @private */ 16915 /** @private */
16912 toggleShowingSearch_: function() { 16916 showingSearchChanged_: function() {
16913 this.showingSearch_ = !this.showingSearch_;
16914 this.async(function() { 16917 this.async(function() {
16915 var searchInput = this.$$('#search-input'); 16918 var searchInput = this.$$('#search-input');
16916 if (this.showingSearch_) { 16919
16920 if (!searchInput)
16921 return;
16922
16923 if (this.showingSearch) {
16917 searchInput.focus(); 16924 searchInput.focus();
16918 } else { 16925 } else {
16919 searchInput.value = ''; 16926 searchInput.value = '';
16920 this.onSearchTermSearch_(); 16927 this.onSearchTermSearch_();
16921 } 16928 }
16922 }); 16929 });
16923 }, 16930 },
16931
16932 /** @private */
16933 toggleShowingSearch_: function() {
16934 this.showingSearch = !this.showingSearch;
16935 },
16924 }); 16936 });
16925 // Copyright 2015 The Chromium Authors. All rights reserved. 16937 // Copyright 2015 The Chromium Authors. All rights reserved.
16926 // Use of this source code is governed by a BSD-style license that can be 16938 // Use of this source code is governed by a BSD-style license that can be
16927 // found in the LICENSE file. 16939 // found in the LICENSE file.
16928 16940
16929 cr.define('downloads', function() { 16941 cr.define('downloads', function() {
16930 var Toolbar = Polymer({ 16942 var Toolbar = Polymer({
16931 is: 'downloads-toolbar', 16943 is: 'downloads-toolbar',
16932 16944
16933 attached: function() { 16945 attached: function() {
16934 // isRTL() only works after i18n_template.js runs to set <html dir>. 16946 // isRTL() only works after i18n_template.js runs to set <html dir>.
16935 this.overflowAlign_ = isRTL() ? 'left' : 'right'; 16947 this.overflowAlign_ = isRTL() ? 'left' : 'right';
16936 16948
16937 /** @private {!SearchFieldDelegate} */ 16949 /** @private {!SearchFieldDelegate} */
16938 this.searchFieldDelegate_ = new ToolbarSearchFieldDelegate(this); 16950 this.searchFieldDelegate_ = new ToolbarSearchFieldDelegate(this);
16939 this.$['search-input'].setDelegate(this.searchFieldDelegate_); 16951 this.$['search-input'].setDelegate(this.searchFieldDelegate_);
16940 }, 16952 },
16941 16953
16942 properties: { 16954 properties: {
16943 downloadsShowing: { 16955 downloadsShowing: {
16944 reflectToAttribute: true, 16956 reflectToAttribute: true,
16945 type: Boolean, 16957 type: Boolean,
16946 value: false, 16958 value: false,
16947 observer: 'onDownloadsShowingChange_', 16959 observer: 'downloadsShowingChanged_',
16948 }, 16960 },
16949 16961
16950 overflowAlign_: { 16962 overflowAlign_: {
16951 type: String, 16963 type: String,
16952 value: 'right', 16964 value: 'right',
16953 }, 16965 },
16954 }, 16966 },
16955 16967
16956 /** @return {boolean} Whether removal can be undone. */ 16968 /** @return {boolean} Whether removal can be undone. */
16957 canUndo: function() { 16969 canUndo: function() {
16958 return this.$['search-input'] != this.shadowRoot.activeElement; 16970 return this.$['search-input'] != this.shadowRoot.activeElement;
16959 }, 16971 },
16960 16972
16961 /** @return {boolean} Whether "Clear all" should be allowed. */ 16973 /** @return {boolean} Whether "Clear all" should be allowed. */
16962 canClearAll: function() { 16974 canClearAll: function() {
16963 return !this.$['search-input'].getValue() && this.downloadsShowing; 16975 return !this.$['search-input'].getValue() && this.downloadsShowing;
16964 }, 16976 },
16965 16977
16978 onFindCommand: function() {
16979 var searchInput = this.$ && this.$['search-input'];
16980 if (!searchInput)
16981 return;
16982
16983 searchInput.showingSearch = true;
16984 searchInput.focus();
16985 },
16986
16966 /** @private */ 16987 /** @private */
16967 onClearAllTap_: function() { 16988 onClearAllTap_: function() {
16968 assert(this.canClearAll()); 16989 assert(this.canClearAll());
16969 downloads.ActionService.getInstance().clearAll(); 16990 downloads.ActionService.getInstance().clearAll();
16970 }, 16991 },
16971 16992
16972 /** @private */ 16993 /** @private */
16973 onDownloadsShowingChange_: function() { 16994 downloadsShowingChanged_: function() {
16974 this.updateClearAll_(); 16995 this.updateClearAll_();
16975 }, 16996 },
16976 16997
16977 /** @param {string} searchTerm */ 16998 /** @param {string} searchTerm */
16978 onSearchTermSearch: function(searchTerm) { 16999 onSearchTermSearch: function(searchTerm) {
16979 downloads.ActionService.getInstance().search(searchTerm); 17000 downloads.ActionService.getInstance().search(searchTerm);
16980 this.updateClearAll_(); 17001 this.updateClearAll_();
16981 }, 17002 },
16982 17003
16983 /** @private */ 17004 /** @private */
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
17092 */ 17113 */
17093 onCanExecute_: function(e) { 17114 onCanExecute_: function(e) {
17094 e = /** @type {cr.ui.CanExecuteEvent} */(e); 17115 e = /** @type {cr.ui.CanExecuteEvent} */(e);
17095 switch (e.command.id) { 17116 switch (e.command.id) {
17096 case 'undo-command': 17117 case 'undo-command':
17097 e.canExecute = this.$.toolbar.canUndo(); 17118 e.canExecute = this.$.toolbar.canUndo();
17098 break; 17119 break;
17099 case 'clear-all-command': 17120 case 'clear-all-command':
17100 e.canExecute = this.$.toolbar.canClearAll(); 17121 e.canExecute = this.$.toolbar.canClearAll();
17101 break; 17122 break;
17123 case 'find-command':
17124 e.canExecute = true;
17125 break;
17102 } 17126 }
17103 }, 17127 },
17104 17128
17105 /** 17129 /**
17106 * @param {Event} e 17130 * @param {Event} e
17107 * @private 17131 * @private
17108 */ 17132 */
17109 onCommand_: function(e) { 17133 onCommand_: function(e) {
17110 if (e.command.id == 'clear-all-command') 17134 if (e.command.id == 'clear-all-command')
17111 downloads.ActionService.getInstance().clearAll(); 17135 downloads.ActionService.getInstance().clearAll();
17112 else if (e.command.id == 'undo-command') 17136 else if (e.command.id == 'undo-command')
17113 downloads.ActionService.getInstance().undo(); 17137 downloads.ActionService.getInstance().undo();
17138 else if (e.command.id == 'find-command' && this.$ && this.$.toolbar)
17139 this.$.toolbar.onFindCommand();
17114 }, 17140 },
17115 17141
17116 /** @private */ 17142 /** @private */
17117 onListScroll_: function() { 17143 onListScroll_: function() {
17118 var list = this.$['downloads-list']; 17144 var list = this.$['downloads-list'];
17119 if (list.scrollHeight - list.scrollTop - list.offsetHeight <= 100) { 17145 if (list.scrollHeight - list.scrollTop - list.offsetHeight <= 100) {
17120 // Approaching the end of the scrollback. Attempt to load more items. 17146 // Approaching the end of the scrollback. Attempt to load more items.
17121 downloads.ActionService.getInstance().loadMore(); 17147 downloads.ActionService.getInstance().loadMore();
17122 } 17148 }
17123 }, 17149 },
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
17194 Manager.get().updateItem_(index, data); 17220 Manager.get().updateItem_(index, data);
17195 }; 17221 };
17196 17222
17197 return {Manager: Manager}; 17223 return {Manager: Manager};
17198 }); 17224 });
17199 // Copyright 2015 The Chromium Authors. All rights reserved. 17225 // Copyright 2015 The Chromium Authors. All rights reserved.
17200 // Use of this source code is governed by a BSD-style license that can be 17226 // Use of this source code is governed by a BSD-style license that can be
17201 // found in the LICENSE file. 17227 // found in the LICENSE file.
17202 17228
17203 window.addEventListener('load', downloads.Manager.onLoad); 17229 window.addEventListener('load', downloads.Manager.onLoad);
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/md_downloads/downloads.html » ('j') | chrome/browser/resources/md_downloads/toolbar.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698