Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <include src="extension_error.js"> | 5 <include src="extension_error.js"> |
| 6 | 6 |
| 7 /////////////////////////////////////////////////////////////////////////////// | 7 /////////////////////////////////////////////////////////////////////////////// |
| 8 // ExtensionFocusRow: | 8 // ExtensionFocusRow: |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 case EventType.ERRORS_REMOVED: | 274 case EventType.ERRORS_REMOVED: |
| 275 case EventType.PREFS_CHANGED: | 275 case EventType.PREFS_CHANGED: |
| 276 if (eventData.extensionInfo) { | 276 if (eventData.extensionInfo) { |
| 277 this.updateExtension_(eventData.extensionInfo); | 277 this.updateExtension_(eventData.extensionInfo); |
| 278 this.focusGrid_.ensureRowActive(); | 278 this.focusGrid_.ensureRowActive(); |
| 279 } | 279 } |
| 280 break; | 280 break; |
| 281 case EventType.UNINSTALLED: | 281 case EventType.UNINSTALLED: |
| 282 var index = this.getIndexOfExtension_(eventData.item_id); | 282 var index = this.getIndexOfExtension_(eventData.item_id); |
| 283 this.extensions_.splice(index, 1); | 283 this.extensions_.splice(index, 1); |
| 284 var childNode = $(eventData.item_id); | 284 var node = $(eventData.item_id); |
| 285 childNode.parentNode.removeChild(childNode); | 285 assert(node != null); |
| 286 this.focusGrid_.removeRow(assertInstanceof(childNode, | 286 this.removeNode_(node); |
|
Devlin
2015/05/15 23:29:43
I thought there was something like assertNotNull s
Dan Beam
2015/05/15 23:47:45
this.removeNode_(getRequiredElement(eventData.item
Devlin
2015/05/19 16:29:50
I like getRequiredElement. Gives us compile error
Dan Beam
2015/05/19 21:09:33
compile-time type filtering + runtime errors. ass
Devlin
2015/05/19 21:36:39
(For my own edification)
Hmm... If I make the par
Dan Beam
2015/05/19 21:44:22
this.removeNode_(assert(node));
| |
| 287 ExtensionFocusRow)); | |
| 288 this.focusGrid_.ensureRowActive(); | |
| 289 break; | 287 break; |
| 290 default: | 288 default: |
| 291 assertNotReached(); | 289 assertNotReached(); |
| 292 } | 290 } |
| 293 | 291 |
| 294 if (eventData.event_type == EventType.UNLOADED) | 292 if (eventData.event_type == EventType.UNLOADED) |
| 295 this.hideEmbeddedExtensionOptions_(eventData.item_id); | 293 this.hideEmbeddedExtensionOptions_(eventData.item_id); |
| 296 | 294 |
| 297 if (eventData.event_type == EventType.INSTALLED || | 295 if (eventData.event_type == EventType.INSTALLED || |
| 298 eventData.event_type == EventType.UNINSTALLED) { | 296 eventData.event_type == EventType.UNINSTALLED) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 399 | 397 |
| 400 // Iterate over the extension data and add each item to the list. | 398 // Iterate over the extension data and add each item to the list. |
| 401 this.extensions_.forEach(function(extension) { | 399 this.extensions_.forEach(function(extension) { |
| 402 seenIds.push(extension.id); | 400 seenIds.push(extension.id); |
| 403 this.updateExtension_(extension); | 401 this.updateExtension_(extension); |
| 404 }, this); | 402 }, this); |
| 405 this.focusGrid_.ensureRowActive(); | 403 this.focusGrid_.ensureRowActive(); |
| 406 | 404 |
| 407 // Remove extensions that are no longer installed. | 405 // Remove extensions that are no longer installed. |
| 408 var nodes = document.querySelectorAll('.extension-list-item-wrapper[id]'); | 406 var nodes = document.querySelectorAll('.extension-list-item-wrapper[id]'); |
| 409 for (var i = 0; i < nodes.length; ++i) { | 407 Array.prototype.forEach.call(nodes, function(node) { |
| 410 var node = nodes[i]; | 408 if (seenIds.indexOf(node.id) < 0) |
| 411 if (seenIds.indexOf(node.id) < 0) { | 409 this.removeNode_(node); |
| 412 if (node.contains(document.activeElement)) { | 410 }, this); |
| 413 var focusableNode = nodes[i + 1] || nodes[i - 1]; | |
| 414 if (focusableNode) { | |
| 415 focusableNode.getEquivalentElement( | |
| 416 document.activeElement).focus(); | |
| 417 } | |
| 418 } | |
| 419 | |
| 420 node.parentElement.removeChild(node); | |
| 421 // Unregister the removed node from events. | |
| 422 assertInstanceof(node, ExtensionFocusRow).destroy(); | |
| 423 } | |
| 424 } | |
| 425 }, | 411 }, |
| 426 | 412 |
| 427 /** Updates each row's focusable elements without rebuilding the grid. */ | 413 /** Updates each row's focusable elements without rebuilding the grid. */ |
| 428 updateFocusableElements: function() { | 414 updateFocusableElements: function() { |
| 429 var rows = document.querySelectorAll('.extension-list-item-wrapper[id]'); | 415 var rows = document.querySelectorAll('.extension-list-item-wrapper[id]'); |
| 430 for (var i = 0; i < rows.length; ++i) { | 416 for (var i = 0; i < rows.length; ++i) { |
| 431 assertInstanceof(rows[i], ExtensionFocusRow).updateFocusableElements(); | 417 assertInstanceof(rows[i], ExtensionFocusRow).updateFocusableElements(); |
| 432 } | 418 } |
| 433 }, | 419 }, |
| 434 | 420 |
| 435 /** | 421 /** |
| 422 * Removes the node from the DOM, and updates the focused element if needed. | |
| 423 * @param {!HTMLElement} node | |
| 424 * @private | |
| 425 */ | |
| 426 removeNode_: function(node) { | |
| 427 if (node.contains(document.activeElement)) { | |
| 428 var nodes = | |
| 429 document.querySelectorAll('.extension-list-item-wrapper[id]'); | |
| 430 var index = Array.prototype.indexOf.call(nodes, node); | |
| 431 assert(index != -1); | |
| 432 var focusableNode = nodes[index + 1] || nodes[index - 1]; | |
| 433 if (focusableNode) | |
| 434 focusableNode.getEquivalentElement(document.activeElement).focus(); | |
| 435 } | |
| 436 node.parentNode.removeChild(node); | |
| 437 this.focusGrid_.removeRow(assertInstanceof(node, ExtensionFocusRow)); | |
| 438 | |
| 439 // Unregister the removed node from events. | |
| 440 assertInstanceof(node, ExtensionFocusRow).destroy(); | |
| 441 | |
| 442 this.focusGrid_.ensureRowActive(); | |
| 443 }, | |
| 444 | |
| 445 /** | |
| 436 * Scrolls the page down to the extension node with the given id. | 446 * Scrolls the page down to the extension node with the given id. |
| 437 * @param {string} extensionId The id of the extension to scroll to. | 447 * @param {string} extensionId The id of the extension to scroll to. |
| 438 * @private | 448 * @private |
| 439 */ | 449 */ |
| 440 scrollToNode_: function(extensionId) { | 450 scrollToNode_: function(extensionId) { |
| 441 // Scroll offset should be calculated slightly higher than the actual | 451 // Scroll offset should be calculated slightly higher than the actual |
| 442 // offset of the element being scrolled to, so that it ends up not all | 452 // offset of the element being scrolled to, so that it ends up not all |
| 443 // the way at the top. That way it is clear that there are more elements | 453 // the way at the top. That way it is clear that there are more elements |
| 444 // above the element being scrolled to. | 454 // above the element being scrolled to. |
| 445 var scrollFudge = 1.2; | 455 var scrollFudge = 1.2; |
| (...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1162 this.createNode_(extension, nextExt ? $(nextExt.id) : null); | 1172 this.createNode_(extension, nextExt ? $(nextExt.id) : null); |
| 1163 } | 1173 } |
| 1164 } | 1174 } |
| 1165 }; | 1175 }; |
| 1166 | 1176 |
| 1167 return { | 1177 return { |
| 1168 ExtensionList: ExtensionList, | 1178 ExtensionList: ExtensionList, |
| 1169 ExtensionListDelegate: ExtensionListDelegate | 1179 ExtensionListDelegate: ExtensionListDelegate |
| 1170 }; | 1180 }; |
| 1171 }); | 1181 }); |
| OLD | NEW |