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

Side by Side Diff: third_party/polymer/v1_0/components-chromium/iron-a11y-keys-behavior/iron-a11y-keys-behavior-extracted.js

Issue 1849403002: Update PolymerElements/iron-a11y-keys-behavior for ESC key fix (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 (function() { 1 (function() {
2 'use strict'; 2 'use strict';
3 3
4 /** 4 /**
5 * Chrome uses an older version of DOM Level 3 Keyboard Events 5 * Chrome uses an older version of DOM Level 3 Keyboard Events
6 * 6 *
7 * Most keys are labeled as text, but some are Unicode codepoints. 7 * Most keys are labeled as text, but some are Unicode codepoints.
8 * Values taken from: http://www.w3.org/TR/2007/WD-DOM-Level-3-Events-200712 21/keyset.html#KeySet-Set 8 * Values taken from: http://www.w3.org/TR/2007/WD-DOM-Level-3-Events-200712 21/keyset.html#KeySet-Set
9 */ 9 */
10 var KEY_IDENTIFIER = { 10 var KEY_IDENTIFIER = {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 */ 71 */
72 var ARROW_KEY = /^arrow/; 72 var ARROW_KEY = /^arrow/;
73 73
74 /** 74 /**
75 * Matches space keys everywhere (notably including IE10's exceptional name 75 * Matches space keys everywhere (notably including IE10's exceptional name
76 * `spacebar`). 76 * `spacebar`).
77 */ 77 */
78 var SPACE_KEY = /^space(bar)?/; 78 var SPACE_KEY = /^space(bar)?/;
79 79
80 /** 80 /**
81 * Matches ESC key.
82 *
83 * Value from: http://w3c.github.io/uievents-key/#key-Escape
84 */
85 var ESC_KEY = /^escape$/;
86
87 /**
81 * Transforms the key. 88 * Transforms the key.
82 * @param {string} key The KeyBoardEvent.key 89 * @param {string} key The KeyBoardEvent.key
83 * @param {Boolean} [noSpecialChars] Limits the transformation to 90 * @param {Boolean} [noSpecialChars] Limits the transformation to
84 * alpha-numeric characters. 91 * alpha-numeric characters.
85 */ 92 */
86 function transformKey(key, noSpecialChars) { 93 function transformKey(key, noSpecialChars) {
87 var validKey = ''; 94 var validKey = '';
88 if (key) { 95 if (key) {
89 var lKey = key.toLowerCase(); 96 var lKey = key.toLowerCase();
90 if (lKey === ' ' || SPACE_KEY.test(lKey)) { 97 if (lKey === ' ' || SPACE_KEY.test(lKey)) {
91 validKey = 'space'; 98 validKey = 'space';
99 } else if (ESC_KEY.test(lKey)) {
100 validKey = 'esc';
92 } else if (lKey.length == 1) { 101 } else if (lKey.length == 1) {
93 if (!noSpecialChars || KEY_CHAR.test(lKey)) { 102 if (!noSpecialChars || KEY_CHAR.test(lKey)) {
94 validKey = lKey; 103 validKey = lKey;
95 } 104 }
96 } else if (ARROW_KEY.test(lKey)) { 105 } else if (ARROW_KEY.test(lKey)) {
97 validKey = lKey.replace('arrow', ''); 106 validKey = lKey.replace('arrow', '');
98 } else if (lKey == 'multiply') { 107 } else if (lKey == 'multiply') {
99 // numpad '*' can map to Multiply on IE/Windows 108 // numpad '*' can map to Multiply on IE/Windows
100 validKey = '*'; 109 validKey = '*';
101 } else { 110 } else {
(...skipping 23 matching lines...) Expand all
125 if (Number(keyCode)) { 134 if (Number(keyCode)) {
126 if (keyCode >= 65 && keyCode <= 90) { 135 if (keyCode >= 65 && keyCode <= 90) {
127 // ascii a-z 136 // ascii a-z
128 // lowercase is 32 offset from uppercase 137 // lowercase is 32 offset from uppercase
129 validKey = String.fromCharCode(32 + keyCode); 138 validKey = String.fromCharCode(32 + keyCode);
130 } else if (keyCode >= 112 && keyCode <= 123) { 139 } else if (keyCode >= 112 && keyCode <= 123) {
131 // function keys f1-f12 140 // function keys f1-f12
132 validKey = 'f' + (keyCode - 112); 141 validKey = 'f' + (keyCode - 112);
133 } else if (keyCode >= 48 && keyCode <= 57) { 142 } else if (keyCode >= 48 && keyCode <= 57) {
134 // top 0-9 keys 143 // top 0-9 keys
135 validKey = String(48 - keyCode); 144 validKey = String(keyCode - 48);
136 } else if (keyCode >= 96 && keyCode <= 105) { 145 } else if (keyCode >= 96 && keyCode <= 105) {
137 // num pad 0-9 146 // num pad 0-9
138 validKey = String(96 - keyCode); 147 validKey = String(keyCode - 96);
139 } else { 148 } else {
140 validKey = KEY_CODE[keyCode]; 149 validKey = KEY_CODE[keyCode];
141 } 150 }
142 } 151 }
143 return validKey; 152 return validKey;
144 } 153 }
145 154
146 /** 155 /**
147 * Calculates the normalized key for a KeyboardEvent. 156 * Calculates the normalized key for a KeyboardEvent.
148 * @param {KeyboardEvent} keyEvent 157 * @param {KeyboardEvent} keyEvent
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 302
294 /** 303 /**
295 * When called, will remove all imperatively-added key bindings. 304 * When called, will remove all imperatively-added key bindings.
296 */ 305 */
297 removeOwnKeyBindings: function() { 306 removeOwnKeyBindings: function() {
298 this._imperativeKeyBindings = {}; 307 this._imperativeKeyBindings = {};
299 this._prepKeyBindings(); 308 this._prepKeyBindings();
300 this._resetKeyEventListeners(); 309 this._resetKeyEventListeners();
301 }, 310 },
302 311
312 /**
313 * Returns true if a keyboard event matches `eventString`.
314 *
315 * @param {KeyboardEvent} event
316 * @param {string} eventString
317 * @return {boolean}
318 */
303 keyboardEventMatchesKeys: function(event, eventString) { 319 keyboardEventMatchesKeys: function(event, eventString) {
304 var keyCombos = parseEventString(eventString); 320 var keyCombos = parseEventString(eventString);
305 for (var i = 0; i < keyCombos.length; ++i) { 321 for (var i = 0; i < keyCombos.length; ++i) {
306 if (keyComboMatchesEvent(keyCombos[i], event)) { 322 if (keyComboMatchesEvent(keyCombos[i], event)) {
307 return true; 323 return true;
308 } 324 }
309 } 325 }
310 return false; 326 return false;
311 }, 327 },
312 328
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 detail: detail, 439 detail: detail,
424 cancelable: true 440 cancelable: true
425 }); 441 });
426 this[handlerName].call(this, event); 442 this[handlerName].call(this, event);
427 if (event.defaultPrevented) { 443 if (event.defaultPrevented) {
428 keyboardEvent.preventDefault(); 444 keyboardEvent.preventDefault();
429 } 445 }
430 } 446 }
431 }; 447 };
432 })(); 448 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698