| 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 activeElement = document.activeElement; |
| 106 |
| 107 var item = this.idMap_[data.id]; |
| 108 item.render(data); |
| 109 var focusRow = this.decorateItem_(item); |
| 110 |
| 111 if (activeElement != document.activeElement) |
| 112 focusRow.getEquivalentElement(activeElement).focus(); |
| 106 }, | 113 }, |
| 107 | 114 |
| 108 /** | 115 /** |
| 109 * Rebuild the focusGrid_ using the elements that each download will have. | 116 * Rebuild the focusGrid_ using the elements that each download will have. |
| 110 * @private | 117 * @private |
| 111 */ | 118 */ |
| 112 rebuildFocusGrid_: function() { | 119 rebuildFocusGrid_: function() { |
| 113 var activeElement = document.activeElement; | 120 var activeElement = document.activeElement; |
| 114 | 121 |
| 115 /** @private {!cr.ui.FocusGrid} */ | 122 /** @private {!cr.ui.FocusGrid} */ |
| 116 this.focusGrid_ = this.focusGrid_ || new cr.ui.FocusGrid(); | 123 this.focusGrid_ = this.focusGrid_ || new cr.ui.FocusGrid(); |
| 117 this.focusGrid_.destroy(); | 124 this.focusGrid_.destroy(); |
| 118 | 125 |
| 119 this.items_.forEach(function(item) { | 126 this.items_.forEach(function(item) { |
| 120 downloads.FocusRow.decorate(item.view.node, item.view, this.node_); | 127 var focusRow = this.decorateItem_(item); |
| 121 var focusRow = assertInstanceof(item.view.node, downloads.FocusRow); | |
| 122 this.focusGrid_.addRow(focusRow); | 128 this.focusGrid_.addRow(focusRow); |
| 123 | 129 |
| 124 // Focus the equivalent element in the focusRow because the active | 130 if (activeElement != document.activeElement && |
| 125 // element may no longer be visible. | 131 focusRow.contains(activeElement)) { |
| 126 if (focusRow.contains(activeElement)) | |
| 127 focusRow.getEquivalentElement(activeElement).focus(); | 132 focusRow.getEquivalentElement(activeElement).focus(); |
| 133 } |
| 128 }, this); | 134 }, this); |
| 129 }, | 135 }, |
| 130 | 136 |
| 137 /** |
| 138 * @param {!downloads.Item} item An item to decorate as a FocusRow. |
| 139 * @return {!downloads.FocusRow} |item| decorated as a FocusRow. |
| 140 */ |
| 141 decorateItem_: function(item) { |
| 142 downloads.FocusRow.decorate(item.view.node, item.view, this.node_); |
| 143 return assertInstanceof(item.view.node, downloads.FocusRow); |
| 144 }, |
| 145 |
| 131 /** @return {number} The number of downloads shown on the page. */ | 146 /** @return {number} The number of downloads shown on the page. */ |
| 132 size: function() { | 147 size: function() { |
| 133 return this.items_.length; | 148 return this.items_.length; |
| 134 }, | 149 }, |
| 135 | 150 |
| 136 clearAll: function() { | 151 clearAll: function() { |
| 137 if (loadTimeData.getBoolean('allow_deleting_history')) { | 152 if (loadTimeData.getBoolean('allow_deleting_history')) { |
| 138 chrome.send('clearAll'); | 153 chrome.send('clearAll'); |
| 139 this.setSearchText(''); | 154 this.setSearchText(''); |
| 140 } | 155 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 }; | 217 }; |
| 203 | 218 |
| 204 Manager.size = function() { | 219 Manager.size = function() { |
| 205 return Manager.getInstance().size(); | 220 return Manager.getInstance().size(); |
| 206 }; | 221 }; |
| 207 | 222 |
| 208 return {Manager: Manager}; | 223 return {Manager: Manager}; |
| 209 }); | 224 }); |
| 210 | 225 |
| 211 window.addEventListener('DOMContentLoaded', downloads.Manager.onLoad); | 226 window.addEventListener('DOMContentLoaded', downloads.Manager.onLoad); |
| OLD | NEW |