Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(902)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/ui/HistoryInput.js

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 WebInspector.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 {!WebInspector.HistoryInput} 13 * @return {!UI.HistoryInput}
14 */ 14 */
15 static create() { 15 static create() {
16 if (!WebInspector.HistoryInput._constructor) 16 if (!UI.HistoryInput._constructor)
17 WebInspector.HistoryInput._constructor = 17 UI.HistoryInput._constructor =
18 registerCustomElement('input', 'history-input', WebInspector.HistoryIn put.prototype); 18 registerCustomElement('input', 'history-input', UI.HistoryInput.protot ype);
19 19
20 return /** @type {!WebInspector.HistoryInput} */ (new WebInspector.HistoryIn put._constructor()); 20 return /** @type {!UI.HistoryInput} */ (new UI.HistoryInput._constructor());
21 } 21 }
22 22
23 /** 23 /**
24 * @override 24 * @override
25 */ 25 */
26 createdCallback() { 26 createdCallback() {
27 this._history = ['']; 27 this._history = [''];
28 this._historyPosition = 0; 28 this._historyPosition = 0;
29 this.addEventListener('keydown', this._onKeyDown.bind(this), false); 29 this.addEventListener('keydown', this._onKeyDown.bind(this), false);
30 this.addEventListener('input', this._onInput.bind(this), false); 30 this.addEventListener('input', this._onInput.bind(this), false);
31 } 31 }
32 32
33 /** 33 /**
34 * @param {!Event} event 34 * @param {!Event} event
35 */ 35 */
36 _onInput(event) { 36 _onInput(event) {
37 if (this._history.length === this._historyPosition + 1) 37 if (this._history.length === this._historyPosition + 1)
38 this._history[this._history.length - 1] = this.value; 38 this._history[this._history.length - 1] = this.value;
39 } 39 }
40 40
41 /** 41 /**
42 * @param {!Event} event 42 * @param {!Event} event
43 */ 43 */
44 _onKeyDown(event) { 44 _onKeyDown(event) {
45 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Up.code) { 45 if (event.keyCode === UI.KeyboardShortcut.Keys.Up.code) {
46 this._historyPosition = Math.max(this._historyPosition - 1, 0); 46 this._historyPosition = Math.max(this._historyPosition - 1, 0);
47 this.value = this._history[this._historyPosition]; 47 this.value = this._history[this._historyPosition];
48 this.dispatchEvent(new Event('input', {'bubbles': true, 'cancelable': true })); 48 this.dispatchEvent(new Event('input', {'bubbles': true, 'cancelable': true }));
49 event.consume(true); 49 event.consume(true);
50 } else if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Down.code) { 50 } else if (event.keyCode === UI.KeyboardShortcut.Keys.Down.code) {
51 this._historyPosition = Math.min(this._historyPosition + 1, this._history. length - 1); 51 this._historyPosition = Math.min(this._historyPosition + 1, this._history. length - 1);
52 this.value = this._history[this._historyPosition]; 52 this.value = this._history[this._historyPosition];
53 this.dispatchEvent(new Event('input', {'bubbles': true, 'cancelable': true })); 53 this.dispatchEvent(new Event('input', {'bubbles': true, 'cancelable': true }));
54 event.consume(true); 54 event.consume(true);
55 } else if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Enter.code) { 55 } else if (event.keyCode === UI.KeyboardShortcut.Keys.Enter.code) {
56 this._saveToHistory(); 56 this._saveToHistory();
57 } 57 }
58 } 58 }
59 59
60 _saveToHistory() { 60 _saveToHistory() {
61 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)
62 return; 62 return;
63 this._history[this._history.length - 1] = this.value; 63 this._history[this._history.length - 1] = this.value;
64 this._historyPosition = this._history.length - 1; 64 this._historyPosition = this._history.length - 1;
65 this._history.push(''); 65 this._history.push('');
66 } 66 }
67 }; 67 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698