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

Unified Diff: third_party/WebKit/Source/devtools/front_end/ui/Widget.js

Issue 2377193004: [DevTools] Rework some focus code. (Closed)
Patch Set: FocusRestorer Created 4 years, 3 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 | « third_party/WebKit/Source/devtools/front_end/ui/View.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/devtools/front_end/ui/Widget.js
diff --git a/third_party/WebKit/Source/devtools/front_end/ui/Widget.js b/third_party/WebKit/Source/devtools/front_end/ui/Widget.js
index e01fd5b4fbe56db95b7ddd284983b98bc457d374..6322a817ff52051ca91540e7e343ee607df60114 100644
--- a/third_party/WebKit/Source/devtools/front_end/ui/Widget.js
+++ b/third_party/WebKit/Source/devtools/front_end/ui/Widget.js
@@ -437,7 +437,7 @@ WebInspector.Widget.prototype = {
},
/**
- * @param {!Element} element
+ * @param {?Element} element
*/
setDefaultFocusedElement: function(element)
{
@@ -455,9 +455,13 @@ WebInspector.Widget.prototype = {
focus: function()
{
+ if (!this.isShowing())
+ return;
+
var element = this._defaultFocusedElement;
- if (element && !element.isAncestor(this.element.ownerDocument.activeElement)) {
- WebInspector.setCurrentFocusElement(element);
+ if (element) {
+ if (!element.hasFocus())
+ element.focus();
return;
}
@@ -479,8 +483,7 @@ WebInspector.Widget.prototype = {
*/
hasFocus: function()
{
- var activeElement = this.element.ownerDocument.activeElement;
- return activeElement && activeElement.isSelfOrDescendant(this.element);
+ return this.element.hasFocus();
},
/**
@@ -746,6 +749,29 @@ WebInspector.VBoxWithResizeCallback.prototype = {
}
/**
+ * @param {!WebInspector.Widget} widget
+ * @constructor
+ */
+WebInspector.WidgetFocusRestorer = function(widget)
+{
+ this._widget = widget;
+ this._previous = widget.element.ownerDocument.deepActiveElement();
+ widget.focus();
+}
+
+WebInspector.WidgetFocusRestorer.prototype = {
+ restore: function()
+ {
+ if (!this._widget)
+ return;
+ if (this._widget.hasFocus() && this._previous)
+ this._previous.focus();
+ this._previous = null;
+ this._widget = null;
+ }
+}
+
+/**
* @override
* @param {?Node} child
* @return {?Node}
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/ui/View.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698