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 var Manager = Polymer({ | 6 var Manager = Polymer({ |
| 7 is: 'downloads-manager', | 7 is: 'downloads-manager', |
| 8 | 8 |
| 9 created: function() { | 9 created: function() { |
| 10 /** @private {!downloads.ActionService} */ | 10 /** @private {!downloads.ActionService} */ |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 /** @private */ | 75 /** @private */ |
| 76 onResize_: function() { | 76 onResize_: function() { |
| 77 // TODO(dbeam): expose <paper-header-panel>'s #mainContainer in Polymer. | 77 // TODO(dbeam): expose <paper-header-panel>'s #mainContainer in Polymer. |
| 78 var container = this.$.panel.$.mainContainer; | 78 var container = this.$.panel.$.mainContainer; |
| 79 var scrollbarWidth = container.offsetWidth - container.clientWidth; | 79 var scrollbarWidth = container.offsetWidth - container.clientWidth; |
| 80 this.items_.forEach(function(item) { | 80 this.items_.forEach(function(item) { |
| 81 item.scrollbarWidth = scrollbarWidth; | 81 item.scrollbarWidth = scrollbarWidth; |
| 82 }); | 82 }); |
| 83 }, | 83 }, |
| 84 | 84 |
| 85 /** @private */ | |
| 86 rebuildFocusGrid_: function() { | |
| 87 var activeElement = this.shadowRoot.activeElement; | |
| 88 | |
| 89 var activeItem; | |
| 90 if (activeElement && activeElement.tagName == 'download-item') | |
| 91 activeItem = activeElement; | |
| 92 | |
| 93 var activeControl = activeItem && activeItem.shadowRoot.activeElement; | |
| 94 | |
| 95 /** @private {!cr.ui.FocusGrid} */ | |
| 96 this.focusGrid_ = this.focusGrid_ || new cr.ui.FocusGrid; | |
| 97 this.focusGrid_.destroy(); | |
| 98 | |
| 99 var boundary = this.$['downloads-list']; | |
| 100 | |
| 101 this.items_.forEach(function(item) { | |
| 102 var focusRow = new downloads.FocusRow(item.content, boundary); | |
| 103 this.focusGrid_.addRow(focusRow); | |
| 104 | |
| 105 if (item == activeItem && !cr.ui.FocusRow.isFocusable(activeControl)) | |
|
hcarmona
2015/08/24 21:00:37
When would you get an active control that isn't fo
Dan Beam
2015/08/24 22:59:30
enter on "Pause" hides and "Resume" is shown
hcarmona
2015/08/24 23:49:19
Acknowledged.
| |
| 106 focusRow.getEquivalentElement(activeControl).focus(); | |
| 107 }, this); | |
| 108 | |
| 109 this.focusGrid_.ensureRowActive(); | |
| 110 }, | |
| 111 | |
| 85 /** | 112 /** |
| 86 * @return {number} The number of downloads shown on the page. | 113 * @return {number} The number of downloads shown on the page. |
| 87 * @private | 114 * @private |
| 88 */ | 115 */ |
| 89 size_: function() { | 116 size_: function() { |
| 90 return this.items_.length; | 117 return this.items_.length; |
| 91 }, | 118 }, |
| 92 | 119 |
| 93 /** | 120 /** |
| 94 * Called when all items need to be updated. | 121 * Called when all items need to be updated. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 this.$['downloads-list'].insertBefore(item, before); | 181 this.$['downloads-list'].insertBefore(item, before); |
| 155 } | 182 } |
| 156 | 183 |
| 157 this.hasDownloads_ = this.size_() > 0; | 184 this.hasDownloads_ = this.size_() > 0; |
| 158 | 185 |
| 159 if (loadTimeData.getBoolean('allowDeletingHistory')) | 186 if (loadTimeData.getBoolean('allowDeletingHistory')) |
| 160 this.$.toolbar.downloadsShowing = this.hasDownloads_; | 187 this.$.toolbar.downloadsShowing = this.hasDownloads_; |
| 161 | 188 |
| 162 this.onResize_(); | 189 this.onResize_(); |
| 163 this.$.panel.classList.remove('loading'); | 190 this.$.panel.classList.remove('loading'); |
| 191 | |
| 192 var allReady = this.items_.map(function(i) { return i.readyPromise; }); | |
| 193 Promise.all(allReady).then(this.rebuildFocusGrid_.bind(this)); | |
|
hcarmona
2015/08/24 21:00:37
Is it possible to update the row rather than rebui
Dan Beam
2015/08/24 22:59:30
yes, but until there's a reason to, it just compli
hcarmona
2015/08/24 23:49:19
One problem from the extensions page was that focu
Dan Beam
2015/08/25 03:22:29
I know, I fixed these issues recently ;)
| |
| 164 }, | 194 }, |
| 165 | 195 |
| 166 /** | 196 /** |
| 167 * @param {!downloads.Data} data | 197 * @param {!downloads.Data} data |
| 168 * @private | 198 * @private |
| 169 */ | 199 */ |
| 170 updateItem_: function(data) { | 200 updateItem_: function(data) { |
| 171 this.idMap_[data.id].update(data); | 201 var item = this.idMap_[data.id]; |
| 202 | |
| 203 var activeControl = this.shadowRoot.activeElement == item ? | |
| 204 item.shadowRoot.activeElement : null; | |
| 205 | |
| 206 item.update(data); | |
| 207 | |
| 208 if (activeControl && !cr.ui.FocusRow.isFocusable(activeControl)) { | |
| 209 var focusRow = this.focusGrid_.getRowForRoot(item.content); | |
| 210 focusRow.getEquivalentElement(activeControl).focus(); | |
| 211 } | |
| 212 | |
| 172 this.onResize_(); | 213 this.onResize_(); |
| 173 }, | 214 }, |
| 174 }); | 215 }); |
| 175 | 216 |
| 176 Manager.size = function() { | 217 Manager.size = function() { |
| 177 return document.querySelector('downloads-manager').size_(); | 218 return document.querySelector('downloads-manager').size_(); |
| 178 }; | 219 }; |
| 179 | 220 |
| 180 Manager.updateAll = function(list) { | 221 Manager.updateAll = function(list) { |
| 181 document.querySelector('downloads-manager').updateAll_(list); | 222 document.querySelector('downloads-manager').updateAll_(list); |
| 182 }; | 223 }; |
| 183 | 224 |
| 184 Manager.updateItem = function(item) { | 225 Manager.updateItem = function(item) { |
| 185 document.querySelector('downloads-manager').updateItem_(item); | 226 document.querySelector('downloads-manager').updateItem_(item); |
| 186 }; | 227 }; |
| 187 | 228 |
| 188 Manager.onLoad = function() { | 229 Manager.onLoad = function() { |
| 189 document.querySelector('downloads-manager').onLoad_(); | 230 document.querySelector('downloads-manager').onLoad_(); |
| 190 }; | 231 }; |
| 191 | 232 |
| 192 return {Manager: Manager}; | 233 return {Manager: Manager}; |
| 193 }); | 234 }); |
| 194 | 235 |
| 195 window.addEventListener('load', downloads.Manager.onLoad); | 236 window.addEventListener('load', downloads.Manager.onLoad); |
| OLD | NEW |