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

Unified Diff: chrome/browser/resources/extensions/extension_error.js

Issue 916243002: Enable keyboard shortcuts for chrome://extensions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Attempt to fix trybots Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/extensions/extension_error.js
diff --git a/chrome/browser/resources/extensions/extension_error.js b/chrome/browser/resources/extensions/extension_error.js
index 2452b12f8aaa2cade0966ddc34310b4bad681033..2848097953175b1fe6cce26d9eac4e28c2be1596 100644
--- a/chrome/browser/resources/extensions/extension_error.js
+++ b/chrome/browser/resources/extensions/extension_error.js
@@ -28,24 +28,35 @@ cr.define('extensions', function() {
/**
* Creates a new ExtensionError HTMLElement; this is used to show a
* notification to the user when an error is caused by an extension.
- * @param {Object} error The error the element should represent.
+ * @param {RuntimeError} error The error the element should represent.
+ * @param {Element} boundary The boundary for the focus grid.
* @constructor
- * @extends {HTMLDivElement}
+ * @extends {cr.ui.FocusRow}
*/
- function ExtensionError(error) {
+ function ExtensionError(error, boundary) {
var div = cloneTemplate('extension-error-metadata');
div.__proto__ = ExtensionError.prototype;
- div.decorate(error);
+ div.decorate(error, boundary);
return div;
}
ExtensionError.prototype = {
- __proto__: HTMLDivElement.prototype,
+ __proto__: cr.ui.FocusRow.prototype,
+
+ /** @override */
+ getEquivalentElement: function(element) {
+ return assertInstanceof(
+ this.querySelector('.extension-error-view-details'), Element);
Dan Beam 2015/02/24 00:55:37 nit: querySelector only returns Element|null, so j
hcarmona 2015/02/24 02:49:44 Done.
+ },
/**
- * @param {RuntimeError} error
+ * @param {RuntimeError} error The error the element should represent
+ * @param {Element} boundary The boundary for the FocusGrid.
+ * @override
*/
- decorate: function(error) {
+ decorate: function(error, boundary) {
+ cr.ui.FocusRow.prototype.decorate.call(this, boundary);
+
// Add an additional class for the severity level.
if (error.level == 0)
this.classList.add('extension-error-severity-info');
@@ -56,6 +67,7 @@ cr.define('extensions', function() {
var iconNode = document.createElement('img');
iconNode.className = 'extension-error-icon';
+ iconNode.alt = '';
Dan Beam 2015/02/24 00:55:37 nit: add TODO to fix
hcarmona 2015/02/24 02:49:44 Done.
this.insertBefore(iconNode, this.firstChild);
var messageSpan = this.querySelector('.extension-error-message');
@@ -79,6 +91,8 @@ cr.define('extensions', function() {
extensions.ExtensionErrorOverlay.getInstance().setErrorAndShowOverlay(
error, extensionUrl);
});
+
+ this.addFocusableElement(viewDetailsLink);
}
},
};
@@ -109,20 +123,75 @@ cr.define('extensions', function() {
__proto__: HTMLDivElement.prototype,
decorate: function() {
- this.contents_ = this.querySelector('.extension-error-list-contents');
+ this.focusGrid_ = new cr.ui.FocusGrid();
+ this.gridBoundary_ = this.querySelector('.extension-error-list-contents');
+ this.gridBoundary_.addEventListener('focus', this.onFocus_.bind(this));
+ this.gridBoundary_.addEventListener('focusin',
+ this.onFocusin_.bind(this));
this.errors_.forEach(function(error) {
if (idIsValid(error.extensionId)) {
- this.contents_.appendChild(document.createElement('li')).appendChild(
- new ExtensionError(error));
+ var focusRow = new ExtensionError(error, this.gridBoundary_);
+ this.gridBoundary_.appendChild(
+ document.createElement('li')).appendChild(focusRow);
+ this.focusGrid_.addRow(focusRow);
}
}, this);
- var numShowing = this.contents_.children.length;
+ var numShowing = this.focusGrid_.rows.length;
if (numShowing > ExtensionErrorList.MAX_ERRORS_TO_SHOW_)
this.initShowMoreLink_();
},
/**
+ * @return {?Element} The element that toggles between show more and show
+ * less, or null if it's hidden. Button will be hidden if there are less
+ * errors than |MAX_ERRORS_TO_SHOW_|.
+ */
+ getToggleElement: function() {
+ return this.querySelector(
+ '.extension-error-list-show-more [is="action-link"]:not([hidden])');
+ },
+
+ /** @return {!Element} The element containing the list of errors. */
+ getErrorListElement: function() {
+ return this.gridBoundary_;
+ },
+
+ /**
+ * The grid should not be focusable once it or an element inside it is
+ * focused. This is necessary to allow tabbing out of the grid in reverse.
+ * @private
+ */
+ onFocusin_: function() {
+ this.gridBoundary_.tabIndex = -1;
+ },
+
+ /**
+ * Focus the first focusable row when tabbing into the grid for the
+ * first time.
+ * @private
+ */
+ onFocus_: function() {
+ var activeRow = this.gridBoundary_.querySelector('.focus-row-active');
+ var toggleButton = this.getToggleElement();
+
+ if (!toggleButton || toggleButton.isShowingAll) {
Dan Beam 2015/02/24 00:55:37 i think this if is easier to read reversed as i
hcarmona 2015/02/24 02:49:44 I agree with this change. Done.
+ activeRow = activeRow || this.focusGrid_.rows[0];
+ activeRow.getEquivalentElement(null).focus();
+ } else {
+ var rows = this.focusGrid_.rows;
+
+ var firstVisible = rows.length - ExtensionErrorList.MAX_ERRORS_TO_SHOW_;
Dan Beam 2015/02/24 00:55:37 what if rows.length == 0 or less than MAX_ERRORS_T
hcarmona 2015/02/24 02:49:43 toggleButton == null if rows.length < MAX_ERRORS_T
Dan Beam 2015/02/24 18:16:46 i assume you mean <=
hcarmona 2015/02/24 18:41:09 Yes
+ var focusedIndex = rows.indexOf(activeRow);
+
+ if (focusedIndex < firstVisible)
+ activeRow = rows[firstVisible];
+
+ activeRow.getEquivalentElement(null).focus();
+ }
Dan Beam 2015/02/24 00:55:37 activeRow.getEquivalentElement(null).focus(); is
hcarmona 2015/02/24 02:49:44 Done.
+ },
+
+ /**
* Initialize the "Show More" link for the error list. If there are more
* than |MAX_ERRORS_TO_SHOW_| errors in the list.
* @private
@@ -144,6 +213,9 @@ cr.define('extensions', function() {
});
link.addEventListener('click', function(e) {
+ // Needs to be enabled in case the focused row is now hidden.
+ this.gridBoundary_.tabIndex = 0;
+
link.isShowingAll = !link.isShowingAll;
var message = link.isShowingAll ? 'extensionErrorsShowFewer' :

Powered by Google App Engine
This is Rietveld 408576698