Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 /** | 4 /** |
| 5 * @unrestricted | 5 * @unrestricted |
| 6 */ | 6 */ |
| 7 UI.HistoryInput = class extends HTMLInputElement { | 7 UI.HistoryInput = class extends HTMLInputElement { |
| 8 constructor() { | 8 constructor() { |
| 9 super(); | 9 super(); |
| 10 } | 10 } |
| 11 | 11 |
| 12 /** | 12 /** |
| 13 * @return {!UI.HistoryInput} | 13 * @return {!UI.HistoryInput} |
| 14 */ | 14 */ |
| 15 static create() { | 15 static create() { |
| 16 if (!UI.HistoryInput._constructor) | 16 if (!UI.HistoryInput._constructor) |
| 17 UI.HistoryInput._constructor = UI.registerCustomElement('input', 'history- input', UI.HistoryInput.prototype); | 17 UI.HistoryInput._constructor = UI.registerCustomElement('input', 'history- input', UI.HistoryInput.prototype); |
| 18 | 18 |
| 19 return /** @type {!UI.HistoryInput} */ (new UI.HistoryInput._constructor()); | 19 return /** @type {!UI.HistoryInput} */ (new UI.HistoryInput._constructor()); |
| 20 } | 20 } |
| 21 | 21 |
| 22 /** | 22 /** |
| 23 * @override | 23 * @override |
| 24 */ | 24 */ |
| 25 createdCallback() { | 25 createdCallback() { |
| 26 this._history = ['']; | 26 this._history = ['']; |
| 27 this._historyPosition = 0; | 27 this._historyPosition = 0; |
| 28 this.classList.add('default-input'); | |
|
pfeldman
2017/06/01 21:16:57
That way you would not need to do this...
luoe
2017/06/06 00:16:27
Done.
| |
| 28 this.addEventListener('keydown', this._onKeyDown.bind(this), false); | 29 this.addEventListener('keydown', this._onKeyDown.bind(this), false); |
| 29 this.addEventListener('input', this._onInput.bind(this), false); | 30 this.addEventListener('input', this._onInput.bind(this), false); |
| 30 } | 31 } |
| 31 | 32 |
| 32 /** | 33 /** |
| 33 * @param {!Event} event | 34 * @param {!Event} event |
| 34 */ | 35 */ |
| 35 _onInput(event) { | 36 _onInput(event) { |
| 36 if (this._history.length === this._historyPosition + 1) | 37 if (this._history.length === this._historyPosition + 1) |
| 37 this._history[this._history.length - 1] = this.value; | 38 this._history[this._history.length - 1] = this.value; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 57 } | 58 } |
| 58 | 59 |
| 59 _saveToHistory() { | 60 _saveToHistory() { |
| 60 if (this._history.length > 1 && this._history[this._history.length - 2] === this.value) | 61 if (this._history.length > 1 && this._history[this._history.length - 2] === this.value) |
| 61 return; | 62 return; |
| 62 this._history[this._history.length - 1] = this.value; | 63 this._history[this._history.length - 1] = this.value; |
| 63 this._historyPosition = this._history.length - 1; | 64 this._historyPosition = this._history.length - 1; |
| 64 this._history.push(''); | 65 this._history.push(''); |
| 65 } | 66 } |
| 66 }; | 67 }; |
| OLD | NEW |