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

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

Issue 862403006: extensions: fix focus management for all dialogs (not just options). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@classList-fix
Patch Set: kalman@ review 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
« no previous file with comments | « chrome/browser/resources/extensions/extensions.html ('k') | ui/webui/resources/js/cr/ui/node_utils.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/extensions/extensions.js
diff --git a/chrome/browser/resources/extensions/extensions.js b/chrome/browser/resources/extensions/extensions.js
index 9c3bc1d9322e76ad1a05106d87fe7c22a3398f45..fcfdd61d256d9eb27e19f19504f8695bb65ead99 100644
--- a/chrome/browser/resources/extensions/extensions.js
+++ b/chrome/browser/resources/extensions/extensions.js
@@ -374,18 +374,13 @@ cr.define('extensions', function() {
/**
* Sets the given overlay to show. This hides whatever overlay is currently
* showing, if any.
- * @param {HTMLElement} node The overlay page to show. If falsey, all overlays
+ * @param {HTMLElement} node The overlay page to show. If null, all overlays
* are hidden.
*/
ExtensionSettings.showOverlay = function(node) {
var pageDiv = $('extension-settings');
- if (node) {
- pageDiv.style.width = window.getComputedStyle(pageDiv).width;
- document.body.classList.add('no-scroll');
- } else {
- document.body.classList.remove('no-scroll');
- pageDiv.style.width = '';
- }
+ pageDiv.style.width = node ? window.getComputedStyle(pageDiv).width : '';
+ document.body.classList.toggle('no-scroll', node);
var currentlyShowingOverlay = ExtensionSettings.getCurrentOverlay();
if (currentlyShowingOverlay) {
@@ -394,8 +389,11 @@ cr.define('extensions', function() {
}
if (node) {
- if (document.activeElement != document.body)
- document.activeElement.blur();
+ var lastFocused = document.activeElement;
+ $('overlay').addEventListener('cancelOverlay', function f() {
+ lastFocused.focus();
+ $('overlay').removeEventListener('cancelOverlay', f);
+ });
node.classList.add('showing');
}
@@ -405,10 +403,27 @@ cr.define('extensions', function() {
}
$('overlay').hidden = !node;
+
+ if (node)
+ ExtensionSettings.focusOverlay();
+
uber.invokeMethodOnParent(node ? 'beginInterceptingEvents' :
'stopInterceptingEvents');
};
+ ExtensionSettings.focusOverlay = function() {
+ var currentlyShowingOverlay = ExtensionSettings.getCurrentOverlay();
+ assert(currentlyShowingOverlay);
+
+ if (cr.ui.FocusOutlineManager.forDocument(document).visible)
+ cr.ui.setInitialFocus(currentlyShowingOverlay);
+
+ if (!currentlyShowingOverlay.contains(document.activeElement)) {
+ // Make sure focus isn't stuck behind the overlay.
+ document.activeElement.blur();
+ }
+ };
+
/**
* Utility function to find the width of various UI strings and synchronize
* the width of relevant spans. This is crucial for making sure the
« no previous file with comments | « chrome/browser/resources/extensions/extensions.html ('k') | ui/webui/resources/js/cr/ui/node_utils.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698