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..bdac9695215037f062ab06026a9fd6c2b5703895 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._defaultFocusedChild = null; |
| } |
| WebInspector.Widget.prototype = { |
| @@ -238,6 +239,8 @@ WebInspector.Widget.prototype = { |
| this.detach(); |
| this._parentWidget = parentWidget; |
| this._parentWidget._children.push(this); |
| + if (!this._parentWidget._defaultFocusedChild) |
| + this._parentWidget._defaultFocusedChild = 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._defaultFocusedChild === this) |
| + this._parentWidget._defaultFocusedChild = this._parentWidget._children[0] || null; |
| this._parentWidget.childWasDetached(this); |
| var parent = this._parentWidget; |
| this._parentWidget = null; |
| @@ -428,6 +433,16 @@ WebInspector.Widget.prototype = { |
| this._defaultFocusedElement = element; |
| }, |
| + /** |
| + * @param {!WebInspector.Widget} child |
| + */ |
| + setDefaultFocusedChild: function(child) |
| + { |
| + var childIndex = this._children.indexOf(child); |
| + WebInspector.Widget.__assert(childIndex >= 0, "Attempt to set non-child widget as default focused."); |
|
dgozman
2016/09/12 16:50:22
Let's instead check child._parentWidget === this.
einbinder
2016/09/12 18:18:54
Done.
|
| + this._defaultFocusedChild = child; |
| + }, |
| + |
| focus: function() |
| { |
| var element = this._defaultFocusedElement; |
| @@ -436,8 +451,17 @@ WebInspector.Widget.prototype = { |
| return; |
| } |
| - if (this._children.length) |
| - this._children[0].focus(); |
| + if (this._defaultFocusedChild) |
|
dgozman
2016/09/12 16:50:22
Let's go to the first visible children if this is
einbinder
2016/09/12 18:18:54
Done.
|
| + this._defaultFocusedChild.focus(); |
| + }, |
| + |
| + _wasFocused: function() |
|
dgozman
2016/09/12 16:50:22
Let's inline this into focusWidgetForNode.
einbinder
2016/09/12 18:18:54
Done.
|
| + { |
| + var widget = this; |
| + while (widget._parentWidget) { |
| + widget._parentWidget._defaultFocusedChild = widget; |
| + widget = widget._parentWidget; |
| + } |
| }, |
| /** |
| @@ -596,6 +620,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 |