Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Unified Diff: third_party/WebKit/Source/devtools/front_end/ui/Toolbar.js

Issue 2662403002: [DevTools] Merge filter bar with the main toolbar (Closed)
Patch Set: [DevTools] Merge filter bar with the main toolbar Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 121478bf95565792d96d54cff2dc32dceaa4c9c3..726fe5c8c4702cd37e2329a4eef46fe655dc90c3 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,71 @@ 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);
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.setValue('', true));
+ this._input.addEventListener('keydown', event => this._onKeydownCallback(event));
}
/**
* @param {string} value
+ * @param {boolean=} notify
dgozman 2017/02/03 20:54:53 Don't add parameters to public methods if they are
eostroukhov 2017/02/03 22:59:25 Done.
*/
- setValue(value) {
- this._value = value;
- this.element.value = value;
+ setValue(value, notify) {
+ this._input.value = value;
+ if (notify)
+ this._onChangeCallback();
}
/**
* @return {string}
*/
value() {
- return this.element.value;
+ return this._input.value;
+ }
+
+ _onKeydownCallback(event) {
dgozman 2017/02/03 20:54:53 JSDoc please.
eostroukhov 2017/02/03 22:59:25 Done.
+ if (event.code === 'ArrowDown')
+ this.dispatchEventToListeners(UI.ToolbarInput.Event.FocusOnResultsRequested, this);
dgozman 2017/02/03 20:54:53 I don't think this is too generic to be in Toolbar
eostroukhov 2017/02/03 22:59:26 Done.
+ if (event.code !== 'Escape' || !this._input.value)
dgozman 2017/02/03 20:54:53 Escape is good though.
eostroukhov 2017/02/03 22:59:26 Acknowledged.
+ return;
+
+ this.setValue('', 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'),
+ FocusOnResultsRequested: Symbol('FocusOnResultsRequested')
};
/**

Powered by Google App Engine
This is Rietveld 408576698