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..54117b47317d14a48c6c13cd932385b832f58eaf 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) |
|
dgozman
2016/09/12 18:24:54
I think we can now remove this one, as we iterate
einbinder
2016/09/12 18:37:12
Done.
|
| + 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; |
|
dgozman
2016/09/12 18:24:54
Just set to null here?
einbinder
2016/09/12 18:37:12
Done.
|
| this._parentWidget.childWasDetached(this); |
| var parent = this._parentWidget; |
| this._parentWidget = null; |
| @@ -428,6 +433,15 @@ WebInspector.Widget.prototype = { |
| this._defaultFocusedElement = element; |
| }, |
| + /** |
| + * @param {!WebInspector.Widget} child |
| + */ |
| + setDefaultFocusedChild: function(child) |
| + { |
| + WebInspector.Widget.__assert(child._parentWidget === this, "Attempt to set non-child widget as default focused."); |
| + this._defaultFocusedChild = child; |
| + }, |
| + |
| focus: function() |
| { |
| var element = this._defaultFocusedElement; |
| @@ -436,8 +450,18 @@ WebInspector.Widget.prototype = { |
| return; |
| } |
| - if (this._children.length) |
| - this._children[0].focus(); |
| + if (this._defaultFocusedChild && this._defaultFocusedChild._visible) { |
| + this._defaultFocusedChild.focus(); |
| + } |
| + else { |
|
dgozman
2016/09/12 18:24:54
style: else on the same line as }
einbinder
2016/09/12 18:37:12
Done.
|
| + for (var child of this._children) { |
| + if (child._visible) { |
| + child.focus(); |
| + break; |
| + } |
| + } |
| + } |
| + |
| }, |
| /** |
| @@ -596,6 +620,24 @@ WebInspector.Widget.__assert = function(condition, message) |
| } |
| /** |
| + * @param {?Node} node |
| + */ |
| +WebInspector.Widget.focusWidgetForNode = function(node) |
| +{ |
| + while (node) { |
|
dgozman
2016/09/12 18:24:54
nit: I'd split this into two loops:
while (node &
einbinder
2016/09/12 18:37:12
Done.
|
| + if (node.__widget) { |
| + var widget = node.__widget; |
| + while (widget._parentWidget) { |
| + widget._parentWidget._defaultFocusedChild = widget; |
| + widget = widget._parentWidget; |
| + } |
| + return; |
| + } |
| + node = node.parentNodeOrShadowHost(); |
| + } |
| +} |
| + |
| +/** |
| * @constructor |
| * @extends {WebInspector.Widget} |
| * @param {boolean=} isWebComponent |