Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/ui/Toolbar.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/ui/Toolbar.js b/third_party/WebKit/Source/devtools/front_end/ui/Toolbar.js |
| index 08ef50bbef2df738949cd0d7ce0364edc52155df..a5938de1c1e7fb80df37e6877751a220016bb1df 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/ui/Toolbar.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/ui/Toolbar.js |
| @@ -552,44 +552,80 @@ UI.ToolbarButton.Events = { |
| */ |
| UI.ToolbarInput = class extends UI.ToolbarItem { |
| /** |
| - * @param {string=} placeholder |
| + * @param {string} placeholder |
| * @param {number=} growFactor |
| * @param {number=} shrinkFactor |
| + * @param {boolean=} isSearchField |
| */ |
| - constructor(placeholder, growFactor, shrinkFactor) { |
| - super(createElementWithClass('input', 'toolbar-item')); |
| - this.element.addEventListener('input', this._onChangeCallback.bind(this), false); |
| + constructor(placeholder, growFactor, shrinkFactor, isSearchField) { |
| + super(createElementWithClass('div', 'toolbar-input')); |
| + |
| + this._input = this.element.createChild('input'); |
| + this._input.addEventListener('blur', () => this.element.classList.toggle('focused', false)); |
| + this._input.addEventListener('focus', () => this.element.classList.toggle('focused', true)); |
| + this._input.addEventListener('input', () => this._onChangeCallback(), false); |
| + this._isSearchField = !!isSearchField; |
| if (growFactor) |
| this.element.style.flexGrow = growFactor; |
| if (shrinkFactor) |
| this.element.style.flexShrink = shrinkFactor; |
| if (placeholder) |
| - this.element.setAttribute('placeholder', placeholder); |
| - this._value = ''; |
| + this._input.setAttribute('placeholder', placeholder); |
| + |
| + if (isSearchField) |
| + this._setupSearchControls(); |
| + } |
| + |
| + _setupSearchControls() { |
| + var clearButton = this.element.createChild('div', 'toolbar-input-clear-button'); |
| + clearButton.appendChild(UI.Icon.create('smallicon-clear-input', 'search-cancel-button')); |
| + clearButton.addEventListener('click', () => this._internalSetValue('', true)); |
| + this._input.addEventListener('keydown', event => this._onKeydownCallback(event)); |
| } |
| /** |
| * @param {string} value |
| */ |
| setValue(value) { |
| - this._value = value; |
| - this.element.value = value; |
| + this._internalSetValue(value, false); |
| + } |
| + |
| + /** |
| + * @param {string} value |
| + * @param {boolean} notify |
| + */ |
| + _internalSetValue(value, notify) { |
| + this._input.value = value; |
| + if (notify) |
| + this._onChangeCallback(); |
| } |
| /** |
| * @return {string} |
| */ |
| value() { |
| - return this.element.value; |
| + return this._input.value; |
| + } |
| + |
| + /** |
| + * @param {!Event} event |
| + */ |
| + _onKeydownCallback(event) { |
| + this.dispatchEventToListeners(UI.ToolbarInput.Event.KeyDown, event); |
| + if (this.isSearchField || event.code !== 'Escape' || !this._input.value) |
|
pfeldman
2017/02/06 19:37:42
isEscKey(event)
eostroukhov
2017/02/07 00:24:18
Done.
|
| + return; |
| + this._internalSetValue('', true); |
| + event.consume(true); |
| } |
| _onChangeCallback() { |
| - this.dispatchEventToListeners(UI.ToolbarInput.Event.TextChanged, this.element.value); |
| + this.dispatchEventToListeners(UI.ToolbarInput.Event.TextChanged, this._input.value); |
| } |
| }; |
| UI.ToolbarInput.Event = { |
| - TextChanged: Symbol('TextChanged') |
| + TextChanged: Symbol('TextChanged'), |
| + KeyDown: Symbol('KeyDown') |
|
pfeldman
2017/02/06 19:37:42
Don't expose it - it needs to be a part of travers
eostroukhov
2017/02/07 00:24:18
Done.
(I've exposed the input element so the pane
|
| }; |
| /** |