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
3 // found in the LICENSE file.
7 * @extends {HTMLInputElement}
9 WebInspector
.HistoryInput = function()
14 * @return {!WebInspector.HistoryInput}
16 WebInspector
.HistoryInput
.create = function()
18 if (!WebInspector
.HistoryInput
._constructor
)
19 WebInspector
.HistoryInput
._constructor
= registerCustomElement("input", "history-input", WebInspector
.HistoryInput
.prototype);
21 return /** @type {!WebInspector.HistoryInput} */(new WebInspector
.HistoryInput
._constructor());
24 WebInspector
.HistoryInput
.prototype = {
25 createdCallback: function()
28 this._historyPosition
= 0;
29 this.addEventListener("keydown", this._onKeyDown
.bind(this), false);
30 this.addEventListener("input", this._onInput
.bind(this), false);
34 * @param {!Event} event
36 _onInput: function(event
)
38 if (this._history
.length
=== this._historyPosition
+ 1)
39 this._history
[this._history
.length
- 1] = this.value
;
43 * @param {!Event} event
45 _onKeyDown: function(event
)
47 if (event
.keyCode
=== WebInspector
.KeyboardShortcut
.Keys
.Up
.code
) {
48 this._historyPosition
= Math
.max(this._historyPosition
- 1, 0);
49 this.value
= this._history
[this._historyPosition
];
50 this.dispatchEvent(createEvent("input", true, true));
52 } else if (event
.keyCode
=== WebInspector
.KeyboardShortcut
.Keys
.Down
.code
) {
53 this._historyPosition
= Math
.min(this._historyPosition
+ 1, this._history
.length
- 1);
54 this.value
= this._history
[this._historyPosition
];
55 this.dispatchEvent(createEvent("input", true, true));
57 } else if (event
.keyCode
=== WebInspector
.KeyboardShortcut
.Keys
.Enter
.code
) {
58 this._saveToHistory();
62 _saveToHistory: function()
64 if (this._history
.length
> 1 && this._history
[this._history
.length
- 2] === this.value
)
66 this._history
[this._history
.length
- 1] = this.value
;
67 this._historyPosition
= this._history
.length
- 1;
68 this._history
.push("");
71 __proto__
: HTMLInputElement
.prototype