Commit 0da16bda authored by rdevlin.cronin's avatar rdevlin.cronin Committed by Commit bot

[Extensions Page] Fix focus when an extension is removed

When an extension is removed, if an element was focused, the analogous element
on the previous/next extension should be focused.

BUG=479092

Review URL: https://codereview.chromium.org/1138973005

Cr-Commit-Position: refs/heads/master@{#330547}
parent 0aecfd86
......@@ -281,11 +281,7 @@ cr.define('extensions', function() {
case EventType.UNINSTALLED:
var index = this.getIndexOfExtension_(eventData.item_id);
this.extensions_.splice(index, 1);
var childNode = $(eventData.item_id);
childNode.parentNode.removeChild(childNode);
this.focusGrid_.removeRow(assertInstanceof(childNode,
ExtensionFocusRow));
this.focusGrid_.ensureRowActive();
this.removeNode_(getRequiredElement(eventData.item_id));
break;
default:
assertNotReached();
......@@ -406,22 +402,10 @@ cr.define('extensions', function() {
// Remove extensions that are no longer installed.
var nodes = document.querySelectorAll('.extension-list-item-wrapper[id]');
for (var i = 0; i < nodes.length; ++i) {
var node = nodes[i];
if (seenIds.indexOf(node.id) < 0) {
if (node.contains(document.activeElement)) {
var focusableNode = nodes[i + 1] || nodes[i - 1];
if (focusableNode) {
focusableNode.getEquivalentElement(
document.activeElement).focus();
}
}
node.parentElement.removeChild(node);
// Unregister the removed node from events.
assertInstanceof(node, ExtensionFocusRow).destroy();
}
}
Array.prototype.forEach.call(nodes, function(node) {
if (seenIds.indexOf(node.id) < 0)
this.removeNode_(node);
}, this);
},
/** Updates each row's focusable elements without rebuilding the grid. */
......@@ -432,6 +416,30 @@ cr.define('extensions', function() {
}
},
/**
* Removes the node from the DOM, and updates the focused element if needed.
* @param {!HTMLElement} node
* @private
*/
removeNode_: function(node) {
if (node.contains(document.activeElement)) {
var nodes =
document.querySelectorAll('.extension-list-item-wrapper[id]');
var index = Array.prototype.indexOf.call(nodes, node);
assert(index != -1);
var focusableNode = nodes[index + 1] || nodes[index - 1];
if (focusableNode)
focusableNode.getEquivalentElement(document.activeElement).focus();
}
node.parentNode.removeChild(node);
this.focusGrid_.removeRow(assertInstanceof(node, ExtensionFocusRow));
// Unregister the removed node from events.
assertInstanceof(node, ExtensionFocusRow).destroy();
this.focusGrid_.ensureRowActive();
},
/**
* Scrolls the page down to the extension node with the given id.
* @param {string} extensionId The id of the extension to scroll to.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment