Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: chrome/browser/resources/extensions/extension_list.js

Issue 1138973005: [Extensions Page] Fix focus when an extension is removed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: getRequiredElement Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 this.removeNode_(getRequiredElement(eventData.item_id));
285 childNode.parentNode.removeChild(childNode);
286 this.focusGrid_.removeRow(assertInstanceof(childNode,
287 ExtensionFocusRow));
288 this.focusGrid_.ensureRowActive();
289 break; 285 break;
290 default: 286 default:
291 assertNotReached(); 287 assertNotReached();
292 } 288 }
293 289
294 if (eventData.event_type == EventType.UNLOADED) 290 if (eventData.event_type == EventType.UNLOADED)
295 this.hideEmbeddedExtensionOptions_(eventData.item_id); 291 this.hideEmbeddedExtensionOptions_(eventData.item_id);
296 292
297 if (eventData.event_type == EventType.INSTALLED || 293 if (eventData.event_type == EventType.INSTALLED ||
298 eventData.event_type == EventType.UNINSTALLED) { 294 eventData.event_type == EventType.UNINSTALLED) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 395
400 // Iterate over the extension data and add each item to the list. 396 // Iterate over the extension data and add each item to the list.
401 this.extensions_.forEach(function(extension) { 397 this.extensions_.forEach(function(extension) {
402 seenIds.push(extension.id); 398 seenIds.push(extension.id);
403 this.updateExtension_(extension); 399 this.updateExtension_(extension);
404 }, this); 400 }, this);
405 this.focusGrid_.ensureRowActive(); 401 this.focusGrid_.ensureRowActive();
406 402
407 // Remove extensions that are no longer installed. 403 // Remove extensions that are no longer installed.
408 var nodes = document.querySelectorAll('.extension-list-item-wrapper[id]'); 404 var nodes = document.querySelectorAll('.extension-list-item-wrapper[id]');
409 for (var i = 0; i < nodes.length; ++i) { 405 Array.prototype.forEach.call(nodes, function(node) {
410 var node = nodes[i]; 406 if (seenIds.indexOf(node.id) < 0)
411 if (seenIds.indexOf(node.id) < 0) { 407 this.removeNode_(node);
412 if (node.contains(document.activeElement)) { 408 }, 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 }, 409 },
426 410
427 /** Updates each row's focusable elements without rebuilding the grid. */ 411 /** Updates each row's focusable elements without rebuilding the grid. */
428 updateFocusableElements: function() { 412 updateFocusableElements: function() {
429 var rows = document.querySelectorAll('.extension-list-item-wrapper[id]'); 413 var rows = document.querySelectorAll('.extension-list-item-wrapper[id]');
430 for (var i = 0; i < rows.length; ++i) { 414 for (var i = 0; i < rows.length; ++i) {
431 assertInstanceof(rows[i], ExtensionFocusRow).updateFocusableElements(); 415 assertInstanceof(rows[i], ExtensionFocusRow).updateFocusableElements();
432 } 416 }
433 }, 417 },
434 418
435 /** 419 /**
420 * Removes the node from the DOM, and updates the focused element if needed.
421 * @param {!HTMLElement} node
422 * @private
423 */
424 removeNode_: function(node) {
425 if (node.contains(document.activeElement)) {
426 var nodes =
427 document.querySelectorAll('.extension-list-item-wrapper[id]');
428 var index = Array.prototype.indexOf.call(nodes, node);
429 assert(index != -1);
430 var focusableNode = nodes[index + 1] || nodes[index - 1];
431 if (focusableNode)
432 focusableNode.getEquivalentElement(document.activeElement).focus();
433 }
434 node.parentNode.removeChild(node);
435 this.focusGrid_.removeRow(assertInstanceof(node, ExtensionFocusRow));
436
437 // Unregister the removed node from events.
438 assertInstanceof(node, ExtensionFocusRow).destroy();
439
440 this.focusGrid_.ensureRowActive();
441 },
442
443 /**
436 * Scrolls the page down to the extension node with the given id. 444 * Scrolls the page down to the extension node with the given id.
437 * @param {string} extensionId The id of the extension to scroll to. 445 * @param {string} extensionId The id of the extension to scroll to.
438 * @private 446 * @private
439 */ 447 */
440 scrollToNode_: function(extensionId) { 448 scrollToNode_: function(extensionId) {
441 // Scroll offset should be calculated slightly higher than the actual 449 // 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 450 // 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 451 // the way at the top. That way it is clear that there are more elements
444 // above the element being scrolled to. 452 // above the element being scrolled to.
445 var scrollFudge = 1.2; 453 var scrollFudge = 1.2;
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
1162 this.createNode_(extension, nextExt ? $(nextExt.id) : null); 1170 this.createNode_(extension, nextExt ? $(nextExt.id) : null);
1163 } 1171 }
1164 } 1172 }
1165 }; 1173 };
1166 1174
1167 return { 1175 return {
1168 ExtensionList: ExtensionList, 1176 ExtensionList: ExtensionList,
1169 ExtensionListDelegate: ExtensionListDelegate 1177 ExtensionListDelegate: ExtensionListDelegate
1170 }; 1178 };
1171 }); 1179 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698