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

Side by Side Diff: remoting/tools/javascript_key_tester/chord_tracker.js

Issue 910483002: Remove JS summary. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reviewer feedback. Created 5 years, 10 months 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) 2014 The Chromium Authors. All rights reserved. 1 /* Copyright (c) 2014 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 5
6 /** 6 /**
7 * @constructor 7 * @constructor
8 * @param {HTMLElement} parentDiv 8 * @param {HTMLElement} parentDiv
9 */ 9 */
10 var ChordTracker = function(parentDiv) { 10 var ChordTracker = function(parentDiv) {
11 /** @type {HTMLElement} */ 11 /** @type {HTMLElement} */
12 this.parentDiv_ = parentDiv; 12 this.parentDiv_ = parentDiv;
13 /** @type {HTMLElement} */ 13 /** @type {HTMLElement} */
14 this.currentDiv_ = null; 14 this.currentDiv_ = null;
15 /** @type {Object.<HTMLElement>} */ 15 /** @type {Object.<HTMLElement>} */
16 this.pressedKeys_ = {}; 16 this.pressedKeys_ = {};
17 }; 17 };
18 18
19 /** 19 /**
20 * @param {number|string} keyId Either a Javascript key-code, or a PNaCl "code" 20 * @param {string} code The PNaCl "code" string.
21 * string.
22 * @param {string} title 21 * @param {string} title
23 * @return {void} 22 * @return {void}
24 */ 23 */
25 ChordTracker.prototype.addKeyUpEvent = function(keyId, title) { 24 ChordTracker.prototype.addKeyUpEvent = function(code, title) {
26 var text = this.keyName_(keyId); 25 var span = this.addSpanElement_('key-up', code, title);
27 var span = this.addSpanElement_('key-up', text, title); 26 delete this.pressedKeys_[code];
28 delete this.pressedKeys_[keyId];
29 if (!this.keysPressed_()) { 27 if (!this.keysPressed_()) {
30 this.end_(); 28 this.end_();
31 } 29 }
32 }; 30 };
33 31
34 /** 32 /**
35 * @param {number|string} keyId Either a Javascript key-code, or a PNaCl "code" 33 * @param {string} code The PNaCl "code" string.
36 * string.
37 * @param {string} title 34 * @param {string} title
38 * @return {void} 35 * @return {void}
39 */ 36 */
40 ChordTracker.prototype.addKeyDownEvent = function(keyId, title) { 37 ChordTracker.prototype.addKeyDownEvent = function(code, title) {
41 var text = this.keyName_(keyId); 38 var span = this.addSpanElement_('key-down', code, title);
42 var span = this.addSpanElement_('key-down', text, title); 39 this.pressedKeys_[code] = span;
43 this.pressedKeys_[keyId] = span;
44 }; 40 };
45 41
46 /** 42 /**
47 * @param {string} characterText 43 * @param {string} characterText
48 * @param {string} title 44 * @param {string} title
49 * @return {void} 45 * @return {void}
50 */ 46 */
51 ChordTracker.prototype.addCharEvent = function(characterText, title) { 47 ChordTracker.prototype.addCharEvent = function(characterText, title) {
52 this.addSpanElement_('char-event', characterText, title); 48 this.addSpanElement_('char-event', characterText, title);
53 }; 49 };
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 /** 107 /**
112 * @return {boolean} True if there are any keys pressed down. 108 * @return {boolean} True if there are any keys pressed down.
113 * @private 109 * @private
114 */ 110 */
115 ChordTracker.prototype.keysPressed_ = function() { 111 ChordTracker.prototype.keysPressed_ = function() {
116 for (var property in this.pressedKeys_) { 112 for (var property in this.pressedKeys_) {
117 return true; 113 return true;
118 } 114 }
119 return false; 115 return false;
120 }; 116 };
121
122 /**
123 * @param {number|string} keyId Either a Javascript key-code, or a PNaCl "code"
124 * string.
125 * @return {string} A human-readable representation of the key.
126 * @private
127 */
128 ChordTracker.prototype.keyName_ = function(keyId) {
129 if (typeof keyId == 'string') {
130 return keyId;
131 }
132 var result = keyboardMap[keyId];
133 if (!result) {
134 result = '<' + keyId + '>';
135 }
136 return result;
137 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698