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

Side by Side 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, 10 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 Click: Symbol('Click'), 545 Click: Symbol('Click'),
546 MouseDown: Symbol('MouseDown'), 546 MouseDown: Symbol('MouseDown'),
547 MouseUp: Symbol('MouseUp') 547 MouseUp: Symbol('MouseUp')
548 }; 548 };
549 549
550 /** 550 /**
551 * @unrestricted 551 * @unrestricted
552 */ 552 */
553 UI.ToolbarInput = class extends UI.ToolbarItem { 553 UI.ToolbarInput = class extends UI.ToolbarItem {
554 /** 554 /**
555 * @param {string=} placeholder 555 * @param {string} placeholder
556 * @param {number=} growFactor 556 * @param {number=} growFactor
557 * @param {number=} shrinkFactor 557 * @param {number=} shrinkFactor
558 * @param {boolean=} isSearchField
558 */ 559 */
559 constructor(placeholder, growFactor, shrinkFactor) { 560 constructor(placeholder, growFactor, shrinkFactor, isSearchField) {
560 super(createElementWithClass('input', 'toolbar-item')); 561 super(createElementWithClass('div', 'toolbar-input'));
561 this.element.addEventListener('input', this._onChangeCallback.bind(this), fa lse); 562
563 this._input = this.element.createChild('input');
564 this._input.addEventListener('blur', () => this.element.classList.toggle('fo cused', false));
565 this._input.addEventListener('focus', () => this.element.classList.toggle('f ocused', true));
566 this._input.addEventListener('input', () => this._onChangeCallback(), false) ;
562 if (growFactor) 567 if (growFactor)
563 this.element.style.flexGrow = growFactor; 568 this.element.style.flexGrow = growFactor;
564 if (shrinkFactor) 569 if (shrinkFactor)
565 this.element.style.flexShrink = shrinkFactor; 570 this.element.style.flexShrink = shrinkFactor;
566 if (placeholder) 571 if (placeholder)
567 this.element.setAttribute('placeholder', placeholder); 572 this._input.setAttribute('placeholder', placeholder);
568 this._value = ''; 573
574 if (isSearchField)
575 this._setupSearchControls();
576 }
577
578 _setupSearchControls() {
579 var clearButton = this.element.createChild('div', 'toolbar-input-clear-butto n');
580 clearButton.appendChild(UI.Icon.create('smallicon-clear-input', 'search-canc el-button'));
581 clearButton.addEventListener('click', () => this.setValue('', true));
582 this._input.addEventListener('keydown', event => this._onKeydownCallback(eve nt));
569 } 583 }
570 584
571 /** 585 /**
572 * @param {string} value 586 * @param {string} value
587 * @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.
573 */ 588 */
574 setValue(value) { 589 setValue(value, notify) {
575 this._value = value; 590 this._input.value = value;
576 this.element.value = value; 591 if (notify)
592 this._onChangeCallback();
577 } 593 }
578 594
579 /** 595 /**
580 * @return {string} 596 * @return {string}
581 */ 597 */
582 value() { 598 value() {
583 return this.element.value; 599 return this._input.value;
600 }
601
602 _onKeydownCallback(event) {
dgozman 2017/02/03 20:54:53 JSDoc please.
eostroukhov 2017/02/03 22:59:25 Done.
603 if (event.code === 'ArrowDown')
604 this.dispatchEventToListeners(UI.ToolbarInput.Event.FocusOnResultsRequeste d, 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.
605 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.
606 return;
607
608 this.setValue('', true);
609 event.consume(true);
584 } 610 }
585 611
586 _onChangeCallback() { 612 _onChangeCallback() {
587 this.dispatchEventToListeners(UI.ToolbarInput.Event.TextChanged, this.elemen t.value); 613 this.dispatchEventToListeners(UI.ToolbarInput.Event.TextChanged, this._input .value);
588 } 614 }
589 }; 615 };
590 616
591 UI.ToolbarInput.Event = { 617 UI.ToolbarInput.Event = {
592 TextChanged: Symbol('TextChanged') 618 TextChanged: Symbol('TextChanged'),
619 FocusOnResultsRequested: Symbol('FocusOnResultsRequested')
593 }; 620 };
594 621
595 /** 622 /**
596 * @unrestricted 623 * @unrestricted
597 */ 624 */
598 UI.ToolbarToggle = class extends UI.ToolbarButton { 625 UI.ToolbarToggle = class extends UI.ToolbarButton {
599 /** 626 /**
600 * @param {string} title 627 * @param {string} title
601 * @param {string=} glyph 628 * @param {string=} glyph
602 * @param {string=} toggledGlyph 629 * @param {string=} toggledGlyph
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 1023
997 /** 1024 /**
998 * @override 1025 * @override
999 * @param {boolean} enabled 1026 * @param {boolean} enabled
1000 */ 1027 */
1001 _applyEnabledState(enabled) { 1028 _applyEnabledState(enabled) {
1002 super._applyEnabledState(enabled); 1029 super._applyEnabledState(enabled);
1003 this.inputElement.disabled = !enabled; 1030 this.inputElement.disabled = !enabled;
1004 } 1031 }
1005 }; 1032 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698