| 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 var activeElement = document.activeElement; | 105 var activeElement = document.activeElement; |
| 106 | 106 |
| 107 var item = this.idMap_[data.id]; | 107 var item = this.idMap_[data.id]; |
| 108 item.render(data); | 108 item.render(data); |
| 109 var focusRow = this.decorateItem_(item); | 109 var focusRow = this.decorateItem_(item); |
| 110 | 110 |
| 111 if (activeElement != document.activeElement) | 111 if (focusRow.contains(activeElement) && |
| 112 !downloads.FocusRow.shouldFocus(activeElement)) { |
| 112 focusRow.getEquivalentElement(activeElement).focus(); | 113 focusRow.getEquivalentElement(activeElement).focus(); |
| 114 } |
| 113 }, | 115 }, |
| 114 | 116 |
| 115 /** | 117 /** |
| 116 * Rebuild the focusGrid_ using the elements that each download will have. | 118 * Rebuild the focusGrid_ using the elements that each download will have. |
| 117 * @private | 119 * @private |
| 118 */ | 120 */ |
| 119 rebuildFocusGrid_: function() { | 121 rebuildFocusGrid_: function() { |
| 120 var activeElement = document.activeElement; | 122 var activeElement = document.activeElement; |
| 121 | 123 |
| 122 /** @private {!cr.ui.FocusGrid} */ | 124 /** @private {!cr.ui.FocusGrid} */ |
| 123 this.focusGrid_ = this.focusGrid_ || new cr.ui.FocusGrid(); | 125 this.focusGrid_ = this.focusGrid_ || new cr.ui.FocusGrid(); |
| 124 this.focusGrid_.destroy(); | 126 this.focusGrid_.destroy(); |
| 125 | 127 |
| 126 this.items_.forEach(function(item) { | 128 this.items_.forEach(function(item) { |
| 127 var focusRow = this.decorateItem_(item); | 129 var focusRow = this.decorateItem_(item); |
| 128 this.focusGrid_.addRow(focusRow); | 130 this.focusGrid_.addRow(focusRow); |
| 129 | 131 |
| 130 if (activeElement != document.activeElement && | 132 if (focusRow.contains(activeElement) && |
| 131 focusRow.contains(activeElement)) { | 133 !downloads.FocusRow.shouldFocus(activeElement)) { |
| 132 focusRow.getEquivalentElement(activeElement).focus(); | 134 focusRow.getEquivalentElement(activeElement).focus(); |
| 133 } | 135 } |
| 134 }, this); | 136 }, this); |
| 135 }, | 137 }, |
| 136 | 138 |
| 137 /** | 139 /** |
| 138 * @param {!downloads.Item} item An item to decorate as a FocusRow. | 140 * @param {!downloads.Item} item An item to decorate as a FocusRow. |
| 139 * @return {!downloads.FocusRow} |item| decorated as a FocusRow. | 141 * @return {!downloads.FocusRow} |item| decorated as a FocusRow. |
| 140 */ | 142 */ |
| 141 decorateItem_: function(item) { | 143 decorateItem_: function(item) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 }; | 219 }; |
| 218 | 220 |
| 219 Manager.size = function() { | 221 Manager.size = function() { |
| 220 return Manager.getInstance().size(); | 222 return Manager.getInstance().size(); |
| 221 }; | 223 }; |
| 222 | 224 |
| 223 return {Manager: Manager}; | 225 return {Manager: Manager}; |
| 224 }); | 226 }); |
| 225 | 227 |
| 226 window.addEventListener('DOMContentLoaded', downloads.Manager.onLoad); | 228 window.addEventListener('DOMContentLoaded', downloads.Manager.onLoad); |
| OLD | NEW |