Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 cr.define('downloads', function() { | 5 cr.define('downloads', function() { |
| 6 /** | 6 /** |
| 7 * Class to own and manage download items. | 7 * Class to own and manage download items. |
| 8 * @constructor | 8 * @constructor |
| 9 */ | 9 */ |
| 10 function Manager() {} | 10 function Manager() {} |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 noDownloadsOrResults.hidden = hasDownloads; | 95 noDownloadsOrResults.hidden = hasDownloads; |
| 96 | 96 |
| 97 if (loadTimeData.getBoolean('allow_deleting_history')) | 97 if (loadTimeData.getBoolean('allow_deleting_history')) |
| 98 $('clear-all').hidden = !hasDownloads || this.searchText_.length > 0; | 98 $('clear-all').hidden = !hasDownloads || this.searchText_.length > 0; |
| 99 | 99 |
| 100 this.rebuildFocusGrid_(); | 100 this.rebuildFocusGrid_(); |
| 101 }, | 101 }, |
| 102 | 102 |
| 103 /** @param {!downloads.Data} data Info about the item to update. */ | 103 /** @param {!downloads.Data} data Info about the item to update. */ |
| 104 updateItem: function(data) { | 104 updateItem: function(data) { |
| 105 this.idMap_[data.id].render(data); | 105 var item = this.idMap_[data.id]; |
| 106 item.render(data); | |
| 107 this.decorateItem_(item); | |
| 106 }, | 108 }, |
| 107 | 109 |
| 108 /** | 110 /** |
| 109 * Rebuild the focusGrid_ using the elements that each download will have. | 111 * Rebuild the focusGrid_ using the elements that each download will have. |
| 110 * @private | 112 * @private |
| 111 */ | 113 */ |
| 112 rebuildFocusGrid_: function() { | 114 rebuildFocusGrid_: function() { |
| 113 var activeElement = document.activeElement; | |
| 114 | |
| 115 /** @private {!cr.ui.FocusGrid} */ | 115 /** @private {!cr.ui.FocusGrid} */ |
| 116 this.focusGrid_ = this.focusGrid_ || new cr.ui.FocusGrid(); | 116 this.focusGrid_ = this.focusGrid_ || new cr.ui.FocusGrid(); |
| 117 this.focusGrid_.destroy(); | 117 this.focusGrid_.destroy(); |
| 118 this.items_.forEach(this.decorateItem_, this); | |
| 119 }, | |
| 118 | 120 |
| 119 this.items_.forEach(function(item) { | 121 /** |
| 120 downloads.FocusRow.decorate(item.view.node, item.view, this.node_); | 122 * @param {!download.Item} item An item to decorate as a downloads.FocusRow. |
| 121 var focusRow = assertInstanceof(item.view.node, downloads.FocusRow); | 123 */ |
| 124 decorateItem_: function(item) { | |
| 125 var activeElement = document.activeElement; | |
| 126 | |
| 127 downloads.FocusRow.decorate(item.view.node, item.view, this.node_); | |
| 128 var focusRow = assertInstanceof(item.view.node, downloads.FocusRow); | |
| 129 | |
| 130 if (this.focusGrid_.rows.indexOf(focusRow) < 0) | |
| 122 this.focusGrid_.addRow(focusRow); | 131 this.focusGrid_.addRow(focusRow); |
| 123 | 132 |
| 124 // Focus the equivalent element in the focusRow because the active | 133 // Focus the equivalent element in the focusRow because the active |
| 125 // element may no longer be visible. | 134 // element may no longer be visible. |
| 126 if (focusRow.contains(activeElement)) | 135 if (focusRow.focusableElements.indexOf(activeElement) >= 0 && |
|
hcarmona
2015/03/12 19:12:52
This should stay "if (focusRow.contains(activeElem
Dan Beam
2015/03/12 20:19:03
Fixed (differently though, see updated code)
| |
| 127 focusRow.getEquivalentElement(activeElement).focus(); | 136 activeElement != document.activeElement) { |
| 128 }, this); | 137 focusRow.getEquivalentElement(activeElement).focus(); |
| 138 } | |
| 129 }, | 139 }, |
| 130 | 140 |
| 131 /** @return {number} The number of downloads shown on the page. */ | 141 /** @return {number} The number of downloads shown on the page. */ |
| 132 size: function() { | 142 size: function() { |
| 133 return this.items_.length; | 143 return this.items_.length; |
| 134 }, | 144 }, |
| 135 | 145 |
| 136 clearAll: function() { | 146 clearAll: function() { |
| 137 if (loadTimeData.getBoolean('allow_deleting_history')) { | 147 if (loadTimeData.getBoolean('allow_deleting_history')) { |
| 138 chrome.send('clearAll'); | 148 chrome.send('clearAll'); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 }; | 212 }; |
| 203 | 213 |
| 204 Manager.size = function() { | 214 Manager.size = function() { |
| 205 return Manager.getInstance().size(); | 215 return Manager.getInstance().size(); |
| 206 }; | 216 }; |
| 207 | 217 |
| 208 return {Manager: Manager}; | 218 return {Manager: Manager}; |
| 209 }); | 219 }); |
| 210 | 220 |
| 211 window.addEventListener('DOMContentLoaded', downloads.Manager.onLoad); | 221 window.addEventListener('DOMContentLoaded', downloads.Manager.onLoad); |
| OLD | NEW |