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

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/cvox2/background/keyboard_handler.js

Issue 2150623002: Refactor: Extract a KeyboardHandler and CommandHandler from Background (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test. Created 4 years, 5 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * @fileoverview ChromeVox keyboard handler.
7 */
8
9 goog.provide('BackgroundKeyboardHandler');
10
11 goog.require('cvox.ChromeVoxKbHandler');
12
13 /** @constructor */
14 BackgroundKeyboardHandler = function() {
15 // Classic keymap.
16 cvox.ChromeVoxKbHandler.handlerKeyMap = cvox.KeyMap.fromDefaults();
17
18 /** @type {number} @private */
19 this.passThroughKeyUpCount_ = 0;
20
21 document.addEventListener('keydown', this.onKeyDown.bind(this), false);
22 document.addEventListener('keyup', this.onKeyUp.bind(this), false);
23 };
24
25 BackgroundKeyboardHandler.prototype = {
26 /**
27 * Handles key down events.
28 * @param {Event} evt The key down event to process.
29 * @return {boolean} True if the default action should be performed.
30 */
31 onKeyDown: function(evt) {
32 evt.stickyMode = cvox.ChromeVox.isStickyModeOn() && cvox.ChromeVox.isActive;
33 if (cvox.ChromeVox.passThroughMode)
34 return false;
35
36 if (ChromeVoxState.instance.mode != ChromeVoxMode.CLASSIC &&
37 !cvox.ChromeVoxKbHandler.basicKeyDownActionsListener(evt)) {
38 evt.preventDefault();
39 evt.stopPropagation();
40 }
41 Output.flushNextSpeechUtterance();
42 return false;
43 },
44
45 /**
46 * Handles key up events.
47 * @param {Event} evt The key down event to process.
48 * @return {boolean} True if the default action should be performed.
49 */
50 onKeyUp: function(evt) {
51 // Reset pass through mode once a keyup (not involving the pass through key)
52 // is seen. The pass through command involves three keys.
53 if (cvox.ChromeVox.passThroughMode) {
54 if (this.passThroughKeyUpCount_ >= 3) {
55 cvox.ChromeVox.passThroughMode = false;
56 this.passThroughKeyUpCount_ = 0;
57 } else {
58 this.passThroughKeyUpCount_++;
59 }
60 }
61 return false;
62 },
63
64 /**
65 * React to mode changes.
66 * @param {ChromeVoxMode} newMode
67 * @param {ChromeVoxMode?} oldMode
68 */
69 onModeChanged: function(newMode, oldMode) {
70 if (newMode == ChromeVoxMode.CLASSIC) {
71 chrome.accessibilityPrivate.setKeyboardListener(false, false);
72 } else {
73 chrome.accessibilityPrivate.setKeyboardListener(
74 true, cvox.ChromeVox.isStickyPrefOn);
75 }
76
77 // Switching out of next, force next, or uninitialized (on startup).
78 if (newMode === ChromeVoxMode.NEXT ||
79 newMode === ChromeVoxMode.FORCE_NEXT) {
80 window['prefs'].switchToKeyMap('keymap_next');
81 } else {
82 // Moving from next to classic/compat should be the only case where
83 // keymaps get reset. Note the classic <-> compat switches should preserve
84 // keymaps especially if a user selected a different one.
85 if (oldMode &&
86 oldMode != ChromeVoxMode.CLASSIC &&
87 oldMode != ChromeVoxMode.COMPAT) {
88 // The user's configured key map gets wiped here; this is consistent
89 // with previous behavior when switching keymaps.
90 window['prefs'].switchToKeyMap('keymap_next');
91 }
92 }
93 }
94 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698