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

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/host/chrome/braille.js

Issue 1302763002: Add tests for braille commands. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@js2gtesterr
Patch Set: Rebase Created 5 years, 4 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 Bridge that sends Braille messages from content scripts or 6 * @fileoverview Bridge that sends Braille messages from content scripts or
7 * other pages to the main background page. 7 * other pages to the main background page.
8 * 8 *
9 */ 9 */
10 10
11 goog.provide('cvox.ChromeBraille'); 11 goog.provide('cvox.ChromeBraille');
12 12
13 goog.require('cvox.AbstractBraille'); 13 goog.require('cvox.BrailleInterface');
14 goog.require('cvox.BrailleKeyEvent'); 14 goog.require('cvox.BrailleKeyEvent');
15 goog.require('cvox.ChromeVoxUserCommands'); 15 goog.require('cvox.ChromeVoxUserCommands');
16 goog.require('cvox.HostFactory'); 16 goog.require('cvox.HostFactory');
17 17
18 18
19 /** 19 /**
20 * @constructor 20 * @constructor
21 * @extends {cvox.AbstractBraille} 21 * @implements {cvox.BrailleInterface}
22 */ 22 */
23 cvox.ChromeBraille = function() { 23 cvox.ChromeBraille = function() {
24 goog.base(this);
25 /**
26 * @type {function(!cvox.BrailleKeyEvent, cvox.NavBraille)}
27 * @private
28 */
29 this.commandListener_ = this.defaultCommandListener_;
30 /** 24 /**
31 * @type {cvox.NavBraille} 25 * @type {cvox.NavBraille}
32 * @private 26 * @private
33 */ 27 */
34 this.lastContent_ = null; 28 this.lastContent_ = null;
35 /** 29 /**
36 * @type {string} 30 * @type {string}
37 * @private 31 * @private
38 */ 32 */
39 this.lastContentId_ = ''; 33 this.lastContentId_ = '';
(...skipping 10 matching lines...) Expand all
50 // Don't process the event if this document isn't focused or focus lies in 44 // Don't process the event if this document isn't focused or focus lies in
51 // a descendant. 45 // a descendant.
52 if (!cvox.ChromeVox.documentHasFocus()) { 46 if (!cvox.ChromeVox.documentHasFocus()) {
53 return; 47 return;
54 } 48 }
55 if (msg['message'] == 'BRAILLE' && msg['args']) { 49 if (msg['message'] == 'BRAILLE' && msg['args']) {
56 var content = null; 50 var content = null;
57 if (msg['contentId'] == this.lastContentId_) { 51 if (msg['contentId'] == this.lastContentId_) {
58 content = this.lastContent_; 52 content = this.lastContent_;
59 } 53 }
60 this.commandListener_(msg['args'], content); 54 this.onKeyEvent_(msg['args'], content);
61 } 55 }
62 }, this)); 56 }, this));
63 }; 57 };
64 goog.inherits(cvox.ChromeBraille, cvox.AbstractBraille);
65 58
66 59
67 /** @override */ 60 /** @override */
68 cvox.ChromeBraille.prototype.write = function(params) { 61 cvox.ChromeBraille.prototype.write = function(params) {
69 this.lastContent_ = params; 62 this.lastContent_ = params;
70 this.updateLastContentId_(); 63 this.updateLastContentId_();
71 var outParams = params.toJson(); 64 var outParams = params.toJson();
72 65
73 var message = {'target': 'BRAILLE', 66 var message = {'target': 'BRAILLE',
74 'action': 'write', 67 'action': 'write',
75 'params': outParams, 68 'params': outParams,
76 'contentId' : this.lastContentId_}; 69 'contentId' : this.lastContentId_};
77 70
78 cvox.ExtensionBridge.send(message); 71 cvox.ExtensionBridge.send(message);
79 }; 72 };
80 73
81 74
82 /** @private */ 75 /** @private */
83 cvox.ChromeBraille.prototype.updateLastContentId_ = function() { 76 cvox.ChromeBraille.prototype.updateLastContentId_ = function() {
84 this.lastContentId_ = cvox.ExtensionBridge.uniqueId() + '.' + 77 this.lastContentId_ = cvox.ExtensionBridge.uniqueId() + '.' +
85 this.nextLocalId_++; 78 this.nextLocalId_++;
86 }; 79 };
87 80
88 81
89 /** @override */
90 cvox.ChromeBraille.prototype.setCommandListener = function(func) {
91 this.commandListener_ = func;
92 };
93
94
95 /** 82 /**
96 * Dispatches braille input commands. 83 * Dispatches braille input commands.
97 * @param {!cvox.BrailleKeyEvent} brailleEvt The braille key event. 84 * @param {!cvox.BrailleKeyEvent} brailleEvt The braille key event.
98 * @param {cvox.NavBraille} content display content when command was issued, 85 * @param {cvox.NavBraille} content display content when command was issued,
99 * if available. 86 * if available.
100 * @private 87 * @private
101 */ 88 */
102 cvox.ChromeBraille.prototype.defaultCommandListener_ = function(brailleEvt, 89 cvox.ChromeBraille.prototype.onKeyEvent_ = function(brailleEvt,
103 content) { 90 content) {
104 var command = cvox.ChromeVoxUserCommands.commands[brailleEvt.command]; 91 var command = cvox.ChromeVoxUserCommands.commands[brailleEvt.command];
105 if (command) { 92 if (command) {
106 command({event: brailleEvt, content: content}); 93 command({event: brailleEvt, content: content});
107 } else { 94 } else {
108 console.error('Unknown braille command: ' + JSON.stringify(brailleEvt)); 95 console.error('Unknown braille command: ' + JSON.stringify(brailleEvt));
109 } 96 }
110 }; 97 };
111 98
112 99
100 /**
101 * Overrides the key event handler
102 * @param {function(!cvox.BrailleKeyEvent, cvox.NavBraille):void} listener
103 */
104 cvox.ChromeBraille.prototype.setKeyEventHandlerForTest = function(listener) {
105 this.onKeyEvent_ = listener;
106 };
107
108
113 /** Export platform constructor. */ 109 /** Export platform constructor. */
114 cvox.HostFactory.brailleConstructor = cvox.ChromeBraille; 110 cvox.HostFactory.brailleConstructor = cvox.ChromeBraille;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698