Chromium Code Reviews| 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 8b6954c319136932f2d025684b4620f57949ca4d..d24128eb1d44ce070eb82c4b6096878cbea30a38 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/ui/Widget.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/ui/Widget.js |
| @@ -48,6 +48,7 @@ WebInspector.Widget = function(isWebComponent) |
| this._hideOnDetach = false; |
| this._notificationDepth = 0; |
| this._invalidationsSuspended = 0; |
| + this._lastFocusedChild = null; |
| } |
| WebInspector.Widget.prototype = { |
| @@ -238,6 +239,8 @@ WebInspector.Widget.prototype = { |
| this.detach(); |
| this._parentWidget = parentWidget; |
| this._parentWidget._children.push(this); |
| + if (!this._parentWidget._lastFocusedChild) |
| + this._parentWidget._lastFocusedChild = this; |
| this._isRoot = false; |
| }, |
| @@ -332,6 +335,8 @@ WebInspector.Widget.prototype = { |
| var childIndex = this._parentWidget._children.indexOf(this); |
| WebInspector.Widget.__assert(childIndex >= 0, "Attempt to remove non-child widget"); |
| this._parentWidget._children.splice(childIndex, 1); |
| + if (this._parentWidget._lastFocusedChild === this) |
| + this._parentWidget._lastFocusedChild = this._parentWidget._children[0] || null; |
| this._parentWidget.childWasDetached(this); |
| var parent = this._parentWidget; |
| this._parentWidget = null; |
| @@ -428,6 +433,12 @@ WebInspector.Widget.prototype = { |
| this._defaultFocusedElement = element; |
| }, |
| + makeDefaultFocused: function() |
|
pfeldman
2016/09/08 00:53:50
I'd rather have it on the parent.
|
| + { |
| + if (this._parentWidget) |
| + this._parentWidget._lastFocusedChild = this; |
|
pfeldman
2016/09/08 00:53:50
You should now call it defaultFocusChild...
|
| + }, |
| + |
| focus: function() |
| { |
| var element = this._defaultFocusedElement; |
| @@ -436,8 +447,17 @@ WebInspector.Widget.prototype = { |
| return; |
| } |
| - if (this._children.length) |
| - this._children[0].focus(); |
| + if (this._lastFocusedChild) |
| + this._lastFocusedChild.focus(); |
| + }, |
| + |
| + _wasFocused: function() |
| + { |
| + var widget = this; |
| + while (widget._parentWidget) { |
| + widget._parentWidget._lastFocusedChild = widget; |
| + widget = widget._parentWidget; |
| + } |
| }, |
| /** |
| @@ -596,6 +616,20 @@ WebInspector.Widget.__assert = function(condition, message) |
| } |
| /** |
| + * @param {?Node} node |
| + */ |
| +WebInspector.Widget.focusWidgetForNode = function(node) |
| +{ |
| + while (node) { |
| + if (node.__widget) { |
| + node.__widget._wasFocused(); |
| + return; |
| + } |
| + node = node.parentNodeOrShadowHost(); |
| + } |
| +} |
| + |
| +/** |
| * @constructor |
| * @extends {WebInspector.Widget} |
| * @param {boolean=} isWebComponent |