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

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

Issue 1191783002: Support Compat mode inside of the desktop tree. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@commands_alt
Patch Set: Rebase. Created 5 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 Provides a compatibility layer for ChromeVox Classic during the 6 * @fileoverview Provides a compatibility layer for ChromeVox Classic during the
7 * transition to ChromeVox Next. 7 * transition to ChromeVox Next.
8 */ 8 */
9 9
10 goog.provide('ClassicCompatibility'); 10 goog.provide('ClassicCompatibility');
11 11
12 goog.require('cvox.ExtensionBridge');
12 goog.require('cvox.KeyMap'); 13 goog.require('cvox.KeyMap');
13 goog.require('cvox.KeySequence'); 14 goog.require('cvox.KeySequence');
14 goog.require('cvox.KeyUtil'); 15 goog.require('cvox.KeyUtil');
15 goog.require('cvox.SimpleKeyEvent'); 16 goog.require('cvox.SimpleKeyEvent');
16 17
17 /** 18 /**
18 * @param {boolean=} opt_active Whether compatibility is currently active.
19 * @constructor 19 * @constructor
20 */ 20 */
21 var ClassicCompatibility = function(opt_active) { 21 var ClassicCompatibility = function() {
22 /** @type {boolean} */
23 this.active = !!opt_active;
24
25 /** 22 /**
26 * @type {!Array<{description: string, name: string, shortcut: string}>} 23 * @type {!Array<{description: string, name: string, shortcut: string}>}
27 * @private 24 * @private
28 */ 25 */
29 this.commands_ = []; 26 this.commands_ = [];
30 27
31 /** @type {!cvox.KeyMap} */ 28 /** @type {!cvox.KeyMap} */
32 this.keyMap = cvox.KeyMap.fromCurrentKeyMap(); 29 this.keyMap = cvox.KeyMap.fromCurrentKeyMap();
33 30
34 chrome.commands.getAll(function(commands) { 31 chrome.commands.getAll(function(commands) {
35 this.commands_ = commands; 32 this.commands_ = commands;
36 }.bind(this)); 33 }.bind(this));
37 }; 34 };
38 35
39 ClassicCompatibility.prototype = { 36 ClassicCompatibility.prototype = {
40 /** 37 /**
41 * Processes a ChromeVox Next command. 38 * Processes a ChromeVox Next command.
42 * @param {string} command 39 * @param {string} command
43 * @return {boolean} Whether the command was successfully processed. 40 * @return {boolean} Whether the command was successfully processed.
44 */ 41 */
45 onGotCommand: function(command) { 42 onGotCommand: function(command) {
46 if (!this.active) 43 var evt = this.buildKeyEvent_(command);
44 if (!evt)
47 return false; 45 return false;
46 this.simulateKeyDownNext_(evt);
47 return true;
48 },
48 49
50 /**
51 * Processes a ChromeVox Next command while in CLASSIC mode.
52 * @param {string} command
53 * @return {boolean} Whether the command was successfully processed.
54 */
55 onGotClassicCommand: function(command) {
56 var evt = this.buildKeyEvent_(command);
57 if (!evt)
58 return false;
59 this.simulateKeyDownClassic_(evt);
60 return true;
61 },
62
63 /**
64 * @param {string} command
65 * @return {cvox.SimpleKeyEvent?}
66 */
67 buildKeyEvent_: function(command) {
49 var commandInfo = this.commands_.filter(function(c) { 68 var commandInfo = this.commands_.filter(function(c) {
50 return c.name == command; 69 return c.name == command;
51 }.bind(this))[0]; 70 }.bind(this))[0];
52 if (!commandInfo) 71 if (!commandInfo)
53 return false; 72 return null;
54 var shortcut = commandInfo.shortcut; 73 var shortcut = commandInfo.shortcut;
55 var evt = this.convertCommandShortcutToKeyEvent_(shortcut); 74 return this.convertCommandShortcutToKeyEvent_(shortcut);
56 this.simulateKeyDown_(evt);
57 return true;
58 }, 75 },
59 76
60 /** 77 /**
61 * @param {cvox.SimpleKeyEvent} evt 78 * @param {cvox.SimpleKeyEvent} evt
62 * @private 79 * @private
63 */ 80 */
64 simulateKeyDown_: function(evt) { 81 simulateKeyDownNext_: function(evt) {
65 var keySequence = cvox.KeyUtil.keyEventToKeySequence(evt); 82 var keySequence = cvox.KeyUtil.keyEventToKeySequence(evt);
66 var classicCommand = this.keyMap.commandForKey(keySequence); 83 var classicCommand = this.keyMap.commandForKey(keySequence);
67 if (classicCommand) { 84 if (classicCommand) {
68 var nextCommand = this.getNextCommand_(classicCommand); 85 var nextCommand = this.getNextCommand_(classicCommand);
69 if (nextCommand) 86 if (nextCommand)
70 global.backgroundObj.onGotCommand(nextCommand, true); 87 global.backgroundObj.onGotCommand(nextCommand, true);
71 } 88 }
72 }, 89 },
73 90
74 /** 91 /**
92 * @param {cvox.SimpleKeyEvent} evt
93 * @private
94 */
95 simulateKeyDownClassic_: function(evt) {
96 var keySequence = cvox.KeyUtil.keyEventToKeySequence(evt);
97 var classicCommand = this.keyMap.commandForKey(keySequence);
98 if (classicCommand) {
99 cvox.ExtensionBridge.send({
100 'message': 'USER_COMMAND',
101 'command': classicCommand
102 });
103 }
104 },
105
106 /**
75 * @param {string} shortcut 107 * @param {string} shortcut
76 * @return {cvox.SimpleKeyEvent} 108 * @return {cvox.SimpleKeyEvent}
77 * @private 109 * @private
78 */ 110 */
79 convertCommandShortcutToKeyEvent_: function(shortcut) { 111 convertCommandShortcutToKeyEvent_: function(shortcut) {
80 var evt = {}; 112 var evt = {};
81 shortcut.split('+').forEach(function(token) { 113 shortcut.split('+').forEach(function(token) {
82 // Known tokens. 114 // Known tokens.
83 switch (token) { 115 switch (token) {
84 case 'Ctrl': 116 case 'Ctrl':
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 return 'previousLine'; 166 return 'previousLine';
135 case 'forceClickOnCurrentItem': 167 case 'forceClickOnCurrentItem':
136 return 'doDefault'; 168 return 'doDefault';
137 case 'readFromHere': 169 case 'readFromHere':
138 return 'continuousRead'; 170 return 'continuousRead';
139 default: 171 default:
140 return classicCommand; 172 return classicCommand;
141 } 173 }
142 } 174 }
143 }; 175 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698