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

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/common/key_sequence.js

Issue 2768703002: Wire up an api to darken screen for accessibility (Closed)
Patch Set: Rebase. Created 3 years, 9 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 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 * @fileoverview A JavaScript class that represents a sequence of keys entered 6 * @fileoverview A JavaScript class that represents a sequence of keys entered
7 * by the user. 7 * by the user.
8 */ 8 */
9 9
10 10
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } else { 62 } else {
63 this.cvoxModifier = opt_cvoxModifier; 63 this.cvoxModifier = opt_cvoxModifier;
64 } 64 }
65 this.stickyMode = !!originalEvent['stickyMode']; 65 this.stickyMode = !!originalEvent['stickyMode'];
66 this.prefixKey = !!originalEvent['keyPrefix']; 66 this.prefixKey = !!originalEvent['keyPrefix'];
67 67
68 if (this.stickyMode && this.prefixKey) { 68 if (this.stickyMode && this.prefixKey) {
69 throw 'Prefix key and sticky mode cannot both be enabled: ' + originalEvent; 69 throw 'Prefix key and sticky mode cannot both be enabled: ' + originalEvent;
70 } 70 }
71 71
72 var event = this.resolveChromeOSSpecialKeys_(originalEvent);
73
74 // TODO (rshearer): We should take the user out of sticky mode if they 72 // TODO (rshearer): We should take the user out of sticky mode if they
75 // try to use the CVox modifier or prefix key. 73 // try to use the CVox modifier or prefix key.
76 74
77 /** 75 /**
78 * Stores the key codes and modifiers for the keys in the key sequence. 76 * Stores the key codes and modifiers for the keys in the key sequence.
79 * TODO(rshearer): Consider making this structure an array of minimal 77 * TODO(rshearer): Consider making this structure an array of minimal
80 * keyEvent-like objects instead so we don't have to worry about what happens 78 * keyEvent-like objects instead so we don't have to worry about what happens
81 * when ctrlKey.length is different from altKey.length. 79 * when ctrlKey.length is different from altKey.length.
82 * 80 *
83 * NOTE: If a modifier key is pressed by itself, we will store the keyCode 81 * NOTE: If a modifier key is pressed by itself, we will store the keyCode
84 * *and* set the appropriate modKey to be true. This mirrors the way key 82 * *and* set the appropriate modKey to be true. This mirrors the way key
85 * events are created on Mac and Windows. For example, if the Meta key was 83 * events are created on Mac and Windows. For example, if the Meta key was
86 * pressed by itself, the keys object will have: 84 * pressed by itself, the keys object will have:
87 * {metaKey: [true], keyCode:[91]} 85 * {metaKey: [true], keyCode:[91]}
88 * 86 *
89 * @type {Object} 87 * @type {Object}
90 */ 88 */
91 this.keys = { 89 this.keys = {
92 ctrlKey: [], 90 ctrlKey: [],
93 searchKeyHeld: [], 91 searchKeyHeld: [],
94 altKey: [], 92 altKey: [],
95 altGraphKey: [], 93 altGraphKey: [],
96 shiftKey: [], 94 shiftKey: [],
97 metaKey: [], 95 metaKey: [],
98 keyCode: [] 96 keyCode: []
99 }; 97 };
100 98
101 this.extractKey_(event); 99 this.extractKey_(originalEvent);
102 }; 100 };
103 101
104 102
105 // TODO(dtseng): This is incomplete; pull once we have appropriate libs. 103 // TODO(dtseng): This is incomplete; pull once we have appropriate libs.
106 /** 104 /**
107 * Maps a keypress keycode to a keydown or keyup keycode. 105 * Maps a keypress keycode to a keydown or keyup keycode.
108 * @type {Object<number, number>} 106 * @type {Object<number, number>}
109 */ 107 */
110 cvox.KeySequence.KEY_PRESS_CODE = { 108 cvox.KeySequence.KEY_PRESS_CODE = {
111 39: 222, 109 39: 222,
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 } else if (keyName == 'Cmd') { 561 } else if (keyName == 'Cmd') {
564 seqEvent['metaKey'] = true; 562 seqEvent['metaKey'] = true;
565 seqEvent['keyCode'] = 91; 563 seqEvent['keyCode'] = 91;
566 } else if (keyName == 'Win') { 564 } else if (keyName == 'Win') {
567 seqEvent['metaKey'] = true; 565 seqEvent['metaKey'] = true;
568 seqEvent['keyCode'] = 91; 566 seqEvent['keyCode'] = 91;
569 } else if (keyName == 'Insert') { 567 } else if (keyName == 'Insert') {
570 seqEvent['keyCode'] = 45; 568 seqEvent['keyCode'] = 45;
571 } 569 }
572 }; 570 };
573
574
575 /**
576 * Used to resolve special ChromeOS keys (see link for more detail).
577 * http://crbug.com/162268
578 * @param {Object} originalEvent The event.
579 * @return {Object} The resolved event.
580 * @private
581 */
582 cvox.KeySequence.prototype.resolveChromeOSSpecialKeys_ =
583 function(originalEvent) {
584 if (!this.cvoxModifier || this.stickyMode || this.prefixKey ||
585 !cvox.ChromeVox.isChromeOS) {
586 return originalEvent;
587 }
588 var evt = {};
589 for (var key in originalEvent) {
590 evt[key] = originalEvent[key];
591 }
592 switch (evt['keyCode']) {
593 case 33: // Page up.
594 evt['keyCode'] = 38; // Up arrow.
595 break;
596 case 34: // Page down.
597 evt['keyCode'] = 40; // Down arrow.
598 break;
599 case 35: // End.
600 evt['keyCode'] = 39; // Right arrow.
601 break;
602 case 36: // Home.
603 evt['keyCode'] = 37; // Left arrow.
604 break;
605 case 45: // Insert.
606 evt['keyCode'] = 190; // Period.
607 break;
608 case 46: // Delete.
609 evt['keyCode'] = 8; // Backspace.
610 break;
611 case 112: // F1.
612 evt['keyCode'] = 49; // 1.
613 break;
614 case 113: // F2.
615 evt['keyCode'] = 50; // 2.
616 break;
617 case 114: // F3.
618 evt['keyCode'] = 51; // 3.
619 break;
620 case 115: // F4.
621 evt['keyCode'] = 52; // 4.
622 break;
623 case 116: // F5.
624 evt['keyCode'] = 53; // 5.
625 break;
626 case 117: // F6.
627 evt['keyCode'] = 54; // 6.
628 break;
629 case 118: // F7.
630 evt['keyCode'] = 55; // 7.
631 break;
632 case 119: // F8.
633 evt['keyCode'] = 56; // 8.
634 break;
635 case 120: // F9.
636 evt['keyCode'] = 57; // 9.
637 break;
638 case 121: // F10.
639 evt['keyCode'] = 48; // 0.
640 break;
641 case 122: // F11
642 evt['keyCode'] = 189; // Hyphen.
643 break;
644 case 123: // F12
645 evt['keyCode'] = 187; // Equals.
646 break;
647 }
648 return evt;
649 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698