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

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

Issue 2346073003: [Polymer] updating (Closed)
Patch Set: Created 4 years, 3 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 * Calculates the normalized key for a KeyboardEvent. 156 * Calculates the normalized key for a KeyboardEvent.
157 * @param {KeyboardEvent} keyEvent 157 * @param {KeyboardEvent} keyEvent
158 * @param {Boolean} [noSpecialChars] Set to true to limit keyEvent.key 158 * @param {Boolean} [noSpecialChars] Set to true to limit keyEvent.key
159 * transformation to alpha-numeric chars. This is useful with key 159 * transformation to alpha-numeric chars. This is useful with key
160 * combinations like shift + 2, which on FF for MacOS produces 160 * combinations like shift + 2, which on FF for MacOS produces
161 * keyEvent.key = @ 161 * keyEvent.key = @
162 * To get 2 returned, set noSpecialChars = true 162 * To get 2 returned, set noSpecialChars = true
163 * To get @ returned, set noSpecialChars = false 163 * To get @ returned, set noSpecialChars = false
164 */ 164 */
165 function normalizedKeyForEvent(keyEvent, noSpecialChars) { 165 function normalizedKeyForEvent(keyEvent, noSpecialChars) {
166 // Fall back from .key, to .keyIdentifier, to .keyCode, and then to 166 // Fall back from .key, to .detail.key for artifical keyboard events,
167 // .detail.key to support artificial keyboard events. 167 // and then to deprecated .keyIdentifier and .keyCode.
168 return transformKey(keyEvent.key, noSpecialChars) || 168 if (keyEvent.key) {
169 transformKeyIdentifier(keyEvent.keyIdentifier) || 169 return transformKey(keyEvent.key, noSpecialChars);
170 transformKeyCode(keyEvent.keyCode) || 170 }
171 transformKey(keyEvent.detail ? keyEvent.detail.key : keyEvent.detail, no SpecialChars) || ''; 171 if (keyEvent.detail && keyEvent.detail.key) {
172 return transformKey(keyEvent.detail.key, noSpecialChars);
173 }
174 return transformKeyIdentifier(keyEvent.keyIdentifier) ||
175 transformKeyCode(keyEvent.keyCode) || '';
172 } 176 }
173 177
174 function keyComboMatchesEvent(keyCombo, event) { 178 function keyComboMatchesEvent(keyCombo, event) {
175 // For combos with modifiers we support only alpha-numeric keys 179 // For combos with modifiers we support only alpha-numeric keys
176 var keyEvent = normalizedKeyForEvent(event, keyCombo.hasModifiers); 180 var keyEvent = normalizedKeyForEvent(event, keyCombo.hasModifiers);
177 return keyEvent === keyCombo.key && 181 return keyEvent === keyCombo.key &&
178 (!keyCombo.hasModifiers || ( 182 (!keyCombo.hasModifiers || (
179 !!event.shiftKey === !!keyCombo.shiftKey && 183 !!event.shiftKey === !!keyCombo.shiftKey &&
180 !!event.ctrlKey === !!keyCombo.ctrlKey && 184 !!event.ctrlKey === !!keyCombo.ctrlKey &&
181 !!event.altKey === !!keyCombo.altKey && 185 !!event.altKey === !!keyCombo.altKey &&
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 detail: detail, 473 detail: detail,
470 cancelable: true 474 cancelable: true
471 }); 475 });
472 this[handlerName].call(this, event); 476 this[handlerName].call(this, event);
473 if (event.defaultPrevented) { 477 if (event.defaultPrevented) {
474 keyboardEvent.preventDefault(); 478 keyboardEvent.preventDefault();
475 } 479 }
476 } 480 }
477 }; 481 };
478 })(); 482 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698