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 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 567 this._isSearchField = !!isSearchField; | 567 this._isSearchField = !!isSearchField; |
| 568 if (growFactor) | 568 if (growFactor) |
| 569 this.element.style.flexGrow = growFactor; | 569 this.element.style.flexGrow = growFactor; |
| 570 if (shrinkFactor) | 570 if (shrinkFactor) |
| 571 this.element.style.flexShrink = shrinkFactor; | 571 this.element.style.flexShrink = shrinkFactor; |
| 572 if (placeholder) | 572 if (placeholder) |
| 573 this.input.setAttribute('placeholder', placeholder); | 573 this.input.setAttribute('placeholder', placeholder); |
| 574 | 574 |
| 575 if (isSearchField) | 575 if (isSearchField) |
| 576 this._setupSearchControls(); | 576 this._setupSearchControls(); |
| 577 | |
| 578 this._updateIfEmpty(); | |
| 577 } | 579 } |
| 578 | 580 |
| 579 _setupSearchControls() { | 581 _setupSearchControls() { |
| 580 var clearButton = this.element.createChild('div', 'toolbar-input-clear-butto n'); | 582 var clearButton = this.element.createChild('div', 'toolbar-input-clear-butto n'); |
| 581 clearButton.appendChild(UI.Icon.create('smallicon-clear-input', 'search-canc el-button')); | 583 clearButton.appendChild(UI.Icon.create('smallicon-clear-input', 'search-canc el-button')); |
| 582 clearButton.addEventListener('click', () => this._internalSetValue('', true) ); | 584 clearButton.addEventListener('click', () => this._internalSetValue('', true) ); |
| 583 this.input.addEventListener('keydown', event => this._onKeydownCallback(even t)); | 585 this.input.addEventListener('keydown', event => this._onKeydownCallback(even t)); |
| 584 } | 586 } |
| 585 | 587 |
| 586 /** | 588 /** |
| 587 * @param {string} value | 589 * @param {string} value |
| 588 */ | 590 */ |
| 589 setValue(value) { | 591 setValue(value) { |
| 590 this._internalSetValue(value, false); | 592 this._internalSetValue(value, false); |
| 591 } | 593 } |
| 592 | 594 |
| 593 /** | 595 /** |
| 594 * @param {string} value | 596 * @param {string} value |
| 595 * @param {boolean} notify | 597 * @param {boolean} notify |
| 596 */ | 598 */ |
| 597 _internalSetValue(value, notify) { | 599 _internalSetValue(value, notify) { |
| 598 this.input.value = value; | 600 this.input.value = value; |
| 599 if (notify) | 601 if (notify) |
| 600 this._onChangeCallback(); | 602 this._onChangeCallback(); |
| 603 this._updateIfEmpty(); | |
| 601 } | 604 } |
| 602 | 605 |
| 603 /** | 606 /** |
| 604 * @return {string} | 607 * @return {string} |
| 605 */ | 608 */ |
| 606 value() { | 609 value() { |
| 607 return this.input.value; | 610 return this.input.value; |
| 608 } | 611 } |
| 609 | 612 |
| 610 /** | 613 /** |
| 611 * @param {!Event} event | 614 * @param {!Event} event |
| 612 */ | 615 */ |
| 613 _onKeydownCallback(event) { | 616 _onKeydownCallback(event) { |
| 614 if (this.isSearchField || !isEscKey(event) || !this.input.value) | 617 if (this.isSearchField || !isEscKey(event) || !this.input.value) |
| 615 return; | 618 return; |
| 616 this._internalSetValue('', true); | 619 this._internalSetValue('', true); |
| 617 event.consume(true); | 620 event.consume(true); |
| 618 } | 621 } |
| 619 | 622 |
| 620 _onChangeCallback() { | 623 _onChangeCallback() { |
| 624 this._updateIfEmpty(); | |
| 621 this.dispatchEventToListeners(UI.ToolbarInput.Event.TextChanged, this.input. value); | 625 this.dispatchEventToListeners(UI.ToolbarInput.Event.TextChanged, this.input. value); |
| 622 } | 626 } |
| 627 | |
| 628 _updateIfEmpty() { | |
|
phulce
2017/02/09 18:43:10
not a huge fan of the name, can we specify what we
pfeldman
2017/02/09 18:45:15
+1 _updateEmptyStyles
| |
| 629 this.element.classList.toggle('toolbar-input-empty', !this.input.value); | |
| 630 } | |
| 623 }; | 631 }; |
| 624 | 632 |
| 625 UI.ToolbarInput.Event = { | 633 UI.ToolbarInput.Event = { |
| 626 TextChanged: Symbol('TextChanged') | 634 TextChanged: Symbol('TextChanged') |
| 627 }; | 635 }; |
| 628 | 636 |
| 629 /** | 637 /** |
| 630 * @unrestricted | 638 * @unrestricted |
| 631 */ | 639 */ |
| 632 UI.ToolbarToggle = class extends UI.ToolbarButton { | 640 UI.ToolbarToggle = class extends UI.ToolbarButton { |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1032 | 1040 |
| 1033 /** | 1041 /** |
| 1034 * @override | 1042 * @override |
| 1035 * @param {boolean} enabled | 1043 * @param {boolean} enabled |
| 1036 */ | 1044 */ |
| 1037 _applyEnabledState(enabled) { | 1045 _applyEnabledState(enabled) { |
| 1038 super._applyEnabledState(enabled); | 1046 super._applyEnabledState(enabled); |
| 1039 this.inputElement.disabled = !enabled; | 1047 this.inputElement.disabled = !enabled; |
| 1040 } | 1048 } |
| 1041 }; | 1049 }; |
| OLD | NEW |