| 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 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 this.dispatchEventToListeners(UI.ToolbarButton.Events.MouseUp, event); | 540 this.dispatchEventToListeners(UI.ToolbarButton.Events.MouseUp, event); |
| 541 } | 541 } |
| 542 }; | 542 }; |
| 543 | 543 |
| 544 UI.ToolbarButton.Events = { | 544 UI.ToolbarButton.Events = { |
| 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 /** | |
| 551 * @unrestricted | |
| 552 */ | |
| 553 UI.ToolbarInput = class extends UI.ToolbarItem { | 550 UI.ToolbarInput = class extends UI.ToolbarItem { |
| 554 /** | 551 /** |
| 555 * @param {string} placeholder | 552 * @param {string} placeholder |
| 556 * @param {number=} growFactor | 553 * @param {number=} growFactor |
| 557 * @param {number=} shrinkFactor | 554 * @param {number=} shrinkFactor |
| 558 * @param {boolean=} isSearchField | 555 * @param {boolean=} isSearchField |
| 559 */ | 556 */ |
| 560 constructor(placeholder, growFactor, shrinkFactor, isSearchField) { | 557 constructor(placeholder, growFactor, shrinkFactor, isSearchField) { |
| 561 super(createElementWithClass('div', 'toolbar-input')); | 558 super(createElementWithClass('div', 'toolbar-input')); |
| 562 | 559 |
| 563 this.input = this.element.createChild('input'); | 560 this.input = this.element.createChild('input'); |
| 564 this.input.addEventListener('focus', () => this.element.classList.add('focus
ed')); | 561 this.input.addEventListener('focus', () => this.element.classList.add('focus
ed')); |
| 565 this.input.addEventListener('blur', () => this.element.classList.remove('foc
used')); | 562 this.input.addEventListener('blur', () => this.element.classList.remove('foc
used')); |
| 566 this.input.addEventListener('input', () => this._onChangeCallback(), false); | 563 this.input.addEventListener('input', () => this._onChangeCallback(), false); |
| 567 this._isSearchField = !!isSearchField; | 564 this._isSearchField = !!isSearchField; |
| 568 if (growFactor) | 565 if (growFactor) |
| 569 this.element.style.flexGrow = growFactor; | 566 this.element.style.flexGrow = growFactor; |
| 570 if (shrinkFactor) | 567 if (shrinkFactor) |
| 571 this.element.style.flexShrink = shrinkFactor; | 568 this.element.style.flexShrink = shrinkFactor; |
| 572 if (placeholder) | 569 if (placeholder) |
| 573 this.input.setAttribute('placeholder', placeholder); | 570 this.input.setAttribute('placeholder', placeholder); |
| 574 | 571 |
| 575 if (isSearchField) | 572 if (isSearchField) |
| 576 this._setupSearchControls(); | 573 this._setupSearchControls(); |
| 574 |
| 575 this._updateEmptyStyles(); |
| 577 } | 576 } |
| 578 | 577 |
| 579 _setupSearchControls() { | 578 _setupSearchControls() { |
| 580 var clearButton = this.element.createChild('div', 'toolbar-input-clear-butto
n'); | 579 var clearButton = this.element.createChild('div', 'toolbar-input-clear-butto
n'); |
| 581 clearButton.appendChild(UI.Icon.create('smallicon-clear-input', 'search-canc
el-button')); | 580 clearButton.appendChild(UI.Icon.create('smallicon-clear-input', 'search-canc
el-button')); |
| 582 clearButton.addEventListener('click', () => this._internalSetValue('', true)
); | 581 clearButton.addEventListener('click', () => this._internalSetValue('', true)
); |
| 583 this.input.addEventListener('keydown', event => this._onKeydownCallback(even
t)); | 582 this.input.addEventListener('keydown', event => this._onKeydownCallback(even
t)); |
| 584 } | 583 } |
| 585 | 584 |
| 586 /** | 585 /** |
| 587 * @param {string} value | 586 * @param {string} value |
| 588 */ | 587 */ |
| 589 setValue(value) { | 588 setValue(value) { |
| 590 this._internalSetValue(value, false); | 589 this._internalSetValue(value, false); |
| 591 } | 590 } |
| 592 | 591 |
| 593 /** | 592 /** |
| 594 * @param {string} value | 593 * @param {string} value |
| 595 * @param {boolean} notify | 594 * @param {boolean} notify |
| 596 */ | 595 */ |
| 597 _internalSetValue(value, notify) { | 596 _internalSetValue(value, notify) { |
| 598 this.input.value = value; | 597 this.input.value = value; |
| 599 if (notify) | 598 if (notify) |
| 600 this._onChangeCallback(); | 599 this._onChangeCallback(); |
| 600 this._updateEmptyStyles(); |
| 601 } | 601 } |
| 602 | 602 |
| 603 /** | 603 /** |
| 604 * @return {string} | 604 * @return {string} |
| 605 */ | 605 */ |
| 606 value() { | 606 value() { |
| 607 return this.input.value; | 607 return this.input.value; |
| 608 } | 608 } |
| 609 | 609 |
| 610 /** | 610 /** |
| 611 * @param {!Event} event | 611 * @param {!Event} event |
| 612 */ | 612 */ |
| 613 _onKeydownCallback(event) { | 613 _onKeydownCallback(event) { |
| 614 if (this.isSearchField || !isEscKey(event) || !this.input.value) | 614 if (!this._isSearchField || !isEscKey(event) || !this.input.value) |
| 615 return; | 615 return; |
| 616 this._internalSetValue('', true); | 616 this._internalSetValue('', true); |
| 617 event.consume(true); | 617 event.consume(true); |
| 618 } | 618 } |
| 619 | 619 |
| 620 _onChangeCallback() { | 620 _onChangeCallback() { |
| 621 this._updateEmptyStyles(); |
| 621 this.dispatchEventToListeners(UI.ToolbarInput.Event.TextChanged, this.input.
value); | 622 this.dispatchEventToListeners(UI.ToolbarInput.Event.TextChanged, this.input.
value); |
| 622 } | 623 } |
| 624 |
| 625 _updateEmptyStyles() { |
| 626 this.element.classList.toggle('toolbar-input-empty', !this.input.value); |
| 627 } |
| 623 }; | 628 }; |
| 624 | 629 |
| 625 UI.ToolbarInput.Event = { | 630 UI.ToolbarInput.Event = { |
| 626 TextChanged: Symbol('TextChanged') | 631 TextChanged: Symbol('TextChanged') |
| 627 }; | 632 }; |
| 628 | 633 |
| 629 /** | 634 /** |
| 630 * @unrestricted | 635 * @unrestricted |
| 631 */ | 636 */ |
| 632 UI.ToolbarToggle = class extends UI.ToolbarButton { | 637 UI.ToolbarToggle = class extends UI.ToolbarButton { |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1032 | 1037 |
| 1033 /** | 1038 /** |
| 1034 * @override | 1039 * @override |
| 1035 * @param {boolean} enabled | 1040 * @param {boolean} enabled |
| 1036 */ | 1041 */ |
| 1037 _applyEnabledState(enabled) { | 1042 _applyEnabledState(enabled) { |
| 1038 super._applyEnabledState(enabled); | 1043 super._applyEnabledState(enabled); |
| 1039 this.inputElement.disabled = !enabled; | 1044 this.inputElement.disabled = !enabled; |
| 1040 } | 1045 } |
| 1041 }; | 1046 }; |
| OLD | NEW |