Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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) ; | |
| 567 this._isSearchField = !!isSearchField; | |
| 562 if (growFactor) | 568 if (growFactor) |
| 563 this.element.style.flexGrow = growFactor; | 569 this.element.style.flexGrow = growFactor; |
| 564 if (shrinkFactor) | 570 if (shrinkFactor) |
| 565 this.element.style.flexShrink = shrinkFactor; | 571 this.element.style.flexShrink = shrinkFactor; |
| 566 if (placeholder) | 572 if (placeholder) |
| 567 this.element.setAttribute('placeholder', placeholder); | 573 this._input.setAttribute('placeholder', placeholder); |
| 568 this._value = ''; | 574 |
| 575 if (isSearchField) | |
| 576 this._setupSearchControls(); | |
| 577 } | |
| 578 | |
| 579 _setupSearchControls() { | |
| 580 var clearButton = this.element.createChild('div', 'toolbar-input-clear-butto n'); | |
| 581 clearButton.appendChild(UI.Icon.create('smallicon-clear-input', 'search-canc el-button')); | |
| 582 clearButton.addEventListener('click', () => this._internalSetValue('', true) ); | |
| 583 this._input.addEventListener('keydown', event => this._onKeydownCallback(eve nt)); | |
| 569 } | 584 } |
| 570 | 585 |
| 571 /** | 586 /** |
| 572 * @param {string} value | 587 * @param {string} value |
| 573 */ | 588 */ |
| 574 setValue(value) { | 589 setValue(value) { |
| 575 this._value = value; | 590 this._internalSetValue(value, false); |
| 576 this.element.value = value; | 591 } |
| 592 | |
| 593 /** | |
| 594 * @param {string} value | |
| 595 * @param {boolean} notify | |
| 596 */ | |
| 597 _internalSetValue(value, notify) { | |
| 598 this._input.value = value; | |
| 599 if (notify) | |
| 600 this._onChangeCallback(); | |
| 577 } | 601 } |
| 578 | 602 |
| 579 /** | 603 /** |
| 580 * @return {string} | 604 * @return {string} |
| 581 */ | 605 */ |
| 582 value() { | 606 value() { |
| 583 return this.element.value; | 607 return this._input.value; |
| 608 } | |
| 609 | |
| 610 /** | |
| 611 * @param {!Event} event | |
| 612 */ | |
| 613 _onKeydownCallback(event) { | |
| 614 this.dispatchEventToListeners(UI.ToolbarInput.Event.KeyDown, event); | |
| 615 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.
| |
| 616 return; | |
| 617 this._internalSetValue('', true); | |
| 618 event.consume(true); | |
| 584 } | 619 } |
| 585 | 620 |
| 586 _onChangeCallback() { | 621 _onChangeCallback() { |
| 587 this.dispatchEventToListeners(UI.ToolbarInput.Event.TextChanged, this.elemen t.value); | 622 this.dispatchEventToListeners(UI.ToolbarInput.Event.TextChanged, this._input .value); |
| 588 } | 623 } |
| 589 }; | 624 }; |
| 590 | 625 |
| 591 UI.ToolbarInput.Event = { | 626 UI.ToolbarInput.Event = { |
| 592 TextChanged: Symbol('TextChanged') | 627 TextChanged: Symbol('TextChanged'), |
| 628 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
| |
| 593 }; | 629 }; |
| 594 | 630 |
| 595 /** | 631 /** |
| 596 * @unrestricted | 632 * @unrestricted |
| 597 */ | 633 */ |
| 598 UI.ToolbarToggle = class extends UI.ToolbarButton { | 634 UI.ToolbarToggle = class extends UI.ToolbarButton { |
| 599 /** | 635 /** |
| 600 * @param {string} title | 636 * @param {string} title |
| 601 * @param {string=} glyph | 637 * @param {string=} glyph |
| 602 * @param {string=} toggledGlyph | 638 * @param {string=} toggledGlyph |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 998 | 1034 |
| 999 /** | 1035 /** |
| 1000 * @override | 1036 * @override |
| 1001 * @param {boolean} enabled | 1037 * @param {boolean} enabled |
| 1002 */ | 1038 */ |
| 1003 _applyEnabledState(enabled) { | 1039 _applyEnabledState(enabled) { |
| 1004 super._applyEnabledState(enabled); | 1040 super._applyEnabledState(enabled); |
| 1005 this.inputElement.disabled = !enabled; | 1041 this.inputElement.disabled = !enabled; |
| 1006 } | 1042 } |
| 1007 }; | 1043 }; |
| OLD | NEW |