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..81e02c3a6626948916d24f6c0ff22f6ec9ce79c9 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,8 @@ WebInspector.Widget = function(isWebComponent) |
| this._hideOnDetach = false; |
| this._notificationDepth = 0; |
| this._invalidationsSuspended = 0; |
| + this._boundWasFocused = this.wasFocused.bind(this); |
| + this._lastFocusedChild = null; |
| } |
| WebInspector.Widget.prototype = { |
| @@ -238,6 +240,9 @@ WebInspector.Widget.prototype = { |
| this.detach(); |
| this._parentWidget = parentWidget; |
| this._parentWidget._children.push(this); |
| + if (!this._parentWidget._lastFocusedChild) |
| + this._parentWidget._lastFocusedChild = this; |
| + this._updateDefaultFocusedElementListener(); |
| this._isRoot = false; |
| }, |
| @@ -332,9 +337,12 @@ 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; |
| + this._updateDefaultFocusedElementListener(); |
| } else { |
| WebInspector.Widget.__assert(this._isRoot, "Removing non-root widget from DOM"); |
| } |
| @@ -425,7 +433,22 @@ WebInspector.Widget.prototype = { |
| */ |
| setDefaultFocusedElement: function(element) |
| { |
| + if (this._defaultFocusedElement) |
| + this._defaultFocusedElement.removeEventListener("focus", this._boundWasFocused); |
| this._defaultFocusedElement = element; |
| + this._updateDefaultFocusedElementListener(); |
| + if (this._defaultFocusedElement.ownerDocument.activeElement.isSelfOrDescendant(this._defaultFocusedElement)) |
| + this.wasFocused(); |
| + }, |
| + |
| + _updateDefaultFocusedElementListener: function() |
| + { |
| + if (!this._defaultFocusedElement) |
| + return; |
| + if (this._parentWidget) |
| + this._defaultFocusedElement.addEventListener("focus", this._boundWasFocused, true); |
| + else |
| + this._defaultFocusedElement.removeEventListener("focus", this._boundWasFocused); |
|
luoe
2016/09/08 20:48:56
Should this and L437 also get useCapture == true,
einbinder
2016/09/09 01:32:16
This was removed in the next patch.
|
| }, |
| focus: function() |
| @@ -433,11 +456,24 @@ WebInspector.Widget.prototype = { |
| var element = this._defaultFocusedElement; |
| if (element && !element.isAncestor(this.element.ownerDocument.activeElement)) { |
| WebInspector.setCurrentFocusElement(element); |
| + this.wasFocused(); |
| return; |
| } |
| - if (this._children.length) |
| - this._children[0].focus(); |
| + if (this._lastFocusedChild) |
| + this._lastFocusedChild.focus(); |
| + }, |
| + |
| + /** |
| + * @final |
| + */ |
| + wasFocused: function() |
| + { |
| + var widget = this; |
| + while (widget._parentWidget) { |
| + widget._parentWidget._lastFocusedChild = widget; |
| + widget = widget._parentWidget; |
| + } |
| }, |
| /** |