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

Side by Side Diff: chrome/browser/resources/downloads/downloads.js

Issue 807593005: Make downloads list keyboard shortcuts more consistent. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Apply feedback Created 5 years, 10 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // TODO(jhawkins): Use hidden instead of showInline* and display:none. 5 // TODO(jhawkins): Use hidden instead of showInline* and display:none.
6 // TODO(hcarmona): This file is big: it may be good to split it up.
6 7
7 /** 8 /**
8 * The type of the download object. The definition is based on 9 * The type of the download object. The definition is based on
9 * chrome/browser/ui/webui/downloads_dom_handler.cc:CreateDownloadItemValue() 10 * chrome/browser/ui/webui/downloads_dom_handler.cc:CreateDownloadItemValue()
10 * @typedef {{by_ext_id: (string|undefined), 11 * @typedef {{by_ext_id: (string|undefined),
11 * by_ext_name: (string|undefined), 12 * by_ext_name: (string|undefined),
12 * danger_type: (string|undefined), 13 * danger_type: (string|undefined),
13 * date_string: string, 14 * date_string: string,
14 * file_externally_removed: boolean, 15 * file_externally_removed: boolean,
15 * file_name: string, 16 * file_name: string,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 */ 71 */
71 function createButton(onclick, value) { 72 function createButton(onclick, value) {
72 var button = document.createElement('input'); 73 var button = document.createElement('input');
73 button.type = 'button'; 74 button.type = 'button';
74 button.value = value; 75 button.value = value;
75 button.onclick = onclick; 76 button.onclick = onclick;
76 return button; 77 return button;
77 } 78 }
78 79
79 /////////////////////////////////////////////////////////////////////////////// 80 ///////////////////////////////////////////////////////////////////////////////
81 // DownloadFocusRow:
82
83 /**
84 * Provides an implementation for a single column grid.
85 * @constructor
86 * @extends {cr.ui.FocusRow}
87 */
88 function DownloadFocusRow() {}
89
90 /**
91 * Decorates |focusRow| so that it can be treated as a DownloadFocusRow.
92 * @param {Element} focusRow The element that has all the columns represented
93 * by |download|.
94 * @param {Download} download The Download representing this row.
95 * @param {Node} boundary Focus events are ignored outside of this node.
96 */
97 DownloadFocusRow.decorate = function(focusRow, download, boundary) {
98 focusRow.__proto__ = DownloadFocusRow.prototype;
99 focusRow.decorate(boundary);
100
101 // Add all clickable elements as a row into the grid.
102 focusRow.addElementIfFocusable_(download.nodeFileLink_, 'name');
103 focusRow.addElementIfFocusable_(download.nodeURL_, 'url');
104 focusRow.addElementIfFocusable_(download.controlShow_, 'show');
105 focusRow.addElementIfFocusable_(download.controlRetry_, 'retry');
106 focusRow.addElementIfFocusable_(download.controlPause_, 'pause');
107 focusRow.addElementIfFocusable_(download.controlResume_, 'resume');
108 focusRow.addElementIfFocusable_(download.controlRemove_, 'remove');
109 focusRow.addElementIfFocusable_(download.controlCancel_, 'cancel');
110 focusRow.addElementIfFocusable_(download.malwareSave_, 'save');
111 focusRow.addElementIfFocusable_(download.dangerSave_, 'save');
112 focusRow.addElementIfFocusable_(download.malwareDiscard_, 'discard');
113 focusRow.addElementIfFocusable_(download.dangerDiscard_, 'discard');
114 focusRow.addElementIfFocusable_(download.controlByExtensionLink_,
115 'extension');
116 };
117
118 DownloadFocusRow.prototype = {
119 __proto__: cr.ui.FocusRow.prototype,
120
121 /** @override */
122 getEquivalentElement: function(element) {
123 if (this.contains(element))
124 return element;
125
126 // All elements default to another element with the same type.
127 var columnType = element.getAttribute('column-type');
128 var equivalent = this.querySelector('[column-type=' + columnType + ']');
129
130 if (!equivalent) {
131 var equivalentTypes =
132 ['show', 'retry', 'pause', 'resume', 'remove', 'cancel'];
133 if (equivalentTypes.indexOf(columnType) != -1) {
134 var allTypes = equivalentTypes.map(function(type) {
135 return '[column-type=' + type + ']';
136 }).join(', ');
137 equivalent = this.querySelector(allTypes);
138 }
139 }
140
141 // Return the first focusable element if no equivalent type is found.
142 return equivalent || this.focusableElements[0];
143 },
144
145 /**
146 * @param {Element} element The element that should be added.
147 * @param {string} type The column type to use for the element.
148 * @private
149 */
150 addElementIfFocusable_: function(element, type) {
151 if (this.shouldFocus_(element)) {
152 this.addFocusableElement(element);
153 element.setAttribute('column-type', type);
154 }
155 },
156
157 /**
158 * Determines if element should be focusable.
159 * @param {!Element} element
160 * @return {boolean}
161 * @private
162 */
163 shouldFocus_: function(element) {
164 if (!element)
165 return false;
166
167 // Hidden elements are not focusable.
168 var style = window.getComputedStyle(element);
169 if (style.visibility == 'hidden' || style.display == 'none')
170 return false;
171
172 // Verify all ancestors are focusable.
173 return !element.parentElement || this.shouldFocus_(element.parentElement);
174 },
175 };
176
177 ///////////////////////////////////////////////////////////////////////////////
80 // Downloads 178 // Downloads
81 /** 179 /**
82 * Class to hold all the information about the visible downloads. 180 * Class to hold all the information about the visible downloads.
83 * @constructor 181 * @constructor
84 */ 182 */
85 function Downloads() { 183 function Downloads() {
86 /** 184 /**
87 * @type {!Object.<string, Download>} 185 * @type {!Object.<string, Download>}
88 * @private 186 * @private
89 */ 187 */
90 this.downloads_ = {}; 188 this.downloads_ = {};
91 this.node_ = $('downloads-display'); 189 this.node_ = $('downloads-display');
92 this.summary_ = $('downloads-summary-text'); 190 this.summary_ = $('downloads-summary-text');
93 this.searchText_ = ''; 191 this.searchText_ = '';
192 this.focusGrid_ = new cr.ui.FocusGrid();
94 193
95 // Keep track of the dates of the newest and oldest downloads so that we 194 // Keep track of the dates of the newest and oldest downloads so that we
96 // know where to insert them. 195 // know where to insert them.
97 this.newestTime_ = -1; 196 this.newestTime_ = -1;
98 197
99 // Icon load request queue. 198 // Icon load request queue.
100 this.iconLoadQueue_ = []; 199 this.iconLoadQueue_ = [];
101 this.isIconLoading_ = false; 200 this.isIconLoading_ = false;
102 201
103 this.progressForeground1_ = new Image(); 202 this.progressForeground1_ = new Image();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 var noDownloadsOrResults = $('no-downloads-or-results'); 268 var noDownloadsOrResults = $('no-downloads-or-results');
170 noDownloadsOrResults.textContent = loadTimeData.getString( 269 noDownloadsOrResults.textContent = loadTimeData.getString(
171 this.searchText_ ? 'no_search_results' : 'no_downloads'); 270 this.searchText_ ? 'no_search_results' : 'no_downloads');
172 271
173 var hasDownloads = this.size() > 0; 272 var hasDownloads = this.size() > 0;
174 this.node_.hidden = !hasDownloads; 273 this.node_.hidden = !hasDownloads;
175 noDownloadsOrResults.hidden = hasDownloads; 274 noDownloadsOrResults.hidden = hasDownloads;
176 275
177 if (loadTimeData.getBoolean('allow_deleting_history')) 276 if (loadTimeData.getBoolean('allow_deleting_history'))
178 $('clear-all').hidden = !hasDownloads || this.searchText_.length > 0; 277 $('clear-all').hidden = !hasDownloads || this.searchText_.length > 0;
278
279 this.rebuildFocusGrid_();
179 }; 280 };
180 281
181 /** 282 /**
283 * Rebuild the focusGrid_ using the elements that each download will have.
284 * @private
285 */
286 Downloads.prototype.rebuildFocusGrid_ = function() {
287 this.focusGrid_.destroy();
288
289 var keys = Object.keys(this.downloads_);
290 for (var i = 0; i < keys.length; ++i) {
291 var download = this.downloads_[keys[i]];
292 DownloadFocusRow.decorate(download.node, download, this.node_);
293 }
294
295 // The ordering of the keys is not guaranteed, and downloads should be added
296 // to the FocusGrid in the order they will be in the UI.
297 var downloads = document.querySelectorAll('.download');
298 for (var i = 0; i < downloads.length; ++i) {
299 this.focusGrid_.addRow(downloads[i]);
300 }
301 };
302
303 /**
182 * Returns the number of downloads in the model. Used by tests. 304 * Returns the number of downloads in the model. Used by tests.
183 * @return {number} Returns the number of downloads shown on the page. 305 * @return {number} Returns the number of downloads shown on the page.
184 */ 306 */
185 Downloads.prototype.size = function() { 307 Downloads.prototype.size = function() {
186 return Object.keys(this.downloads_).length; 308 return Object.keys(this.downloads_).length;
187 }; 309 };
188 310
189 /** 311 /**
190 * Called whenever the downloads lists items have changed (either by being 312 * Called whenever the downloads lists items have changed (either by being
191 * updated, added, or removed). 313 * updated, added, or removed).
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 if (Date.now() - start > 50) { 1100 if (Date.now() - start > 50) {
979 clearTimeout(resultsTimeout); 1101 clearTimeout(resultsTimeout);
980 resultsTimeout = setTimeout(tryDownloadUpdatedPeriodically, 5); 1102 resultsTimeout = setTimeout(tryDownloadUpdatedPeriodically, 5);
981 break; 1103 break;
982 } 1104 }
983 } 1105 }
984 } 1106 }
985 1107
986 // Add handlers to HTML elements. 1108 // Add handlers to HTML elements.
987 window.addEventListener('DOMContentLoaded', load); 1109 window.addEventListener('DOMContentLoaded', load);
OLDNEW
« no previous file with comments | « chrome/browser/resources/downloads/downloads.html ('k') | chrome/browser/resources/history/history.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698