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

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

Issue 604423002: Use an enum for ChromeVox queue mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 2 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 goog.provide('cvox.ChromeVoxHTMLTimeWidget'); 5 goog.provide('cvox.ChromeVoxHTMLTimeWidget');
6 6
7 /** 7 /**
8 * @fileoverview Gives the user spoken feedback as they interact with the time 8 * @fileoverview Gives the user spoken feedback as they interact with the time
9 * widget (input type=time). 9 * widget (input type=time).
10 * 10 *
11 */ 11 */
12 12
13 /** 13 /**
14 * A class containing the information needed to speak 14 * A class containing the information needed to speak
15 * a text change event to the user. 15 * a text change event to the user.
16 * 16 *
17 * @constructor 17 * @constructor
18 * @param {Element} timeElem The time widget element. 18 * @param {Element} timeElem The time widget element.
19 * @param {cvox.TtsInterface} tts The TTS object from ChromeVox. 19 * @param {cvox.TtsInterface} tts The TTS object from ChromeVox.
20 */ 20 */
21 cvox.ChromeVoxHTMLTimeWidget = function(timeElem, tts){ 21 cvox.ChromeVoxHTMLTimeWidget = function(timeElem, tts) {
22 var self = this; 22 var self = this;
23 this.timeElem_ = timeElem; 23 this.timeElem_ = timeElem;
24 this.timeTts_ = tts; 24 this.timeTts_ = tts;
25 this.pHours_ = -1; 25 this.pHours_ = -1;
26 this.pMinutes_ = -1; 26 this.pMinutes_ = -1;
27 this.pSeconds_ = 0; 27 this.pSeconds_ = 0;
28 this.pMilliseconds_ = 0; 28 this.pMilliseconds_ = 0;
29 this.pAmpm_ = ''; 29 this.pAmpm_ = '';
30 this.pos_ = 0; 30 this.pos_ = 0;
31 this.maxPos_ = 2; 31 this.maxPos_ = 2;
32 this.keyListener_ = function(evt) { 32 this.keyListener_ = function(evt) {
33 self.eventHandler_(evt); 33 self.eventHandler_(evt);
34 } 34 };
35 this.blurListener_ = function(evt) { 35 this.blurListener_ = function(evt) {
36 self.shutdown(); 36 self.shutdown();
37 } 37 };
38 if (this.timeElem_.hasAttribute('step')) { 38 if (this.timeElem_.hasAttribute('step')) {
39 var step = this.timeElem_.getAttribute('step'); 39 var step = this.timeElem_.getAttribute('step');
40 if (step > 0) { // 0 or invalid values show hh:mm AM/PM 40 if (step > 0) { // 0 or invalid values show hh:mm AM/PM
41 if (step >= 1) { 41 if (step >= 1) {
42 this.maxPos_ = 3; // Anything larger than 1 shows hh:mm:ss AM/PM 42 this.maxPos_ = 3; // Anything larger than 1 shows hh:mm:ss AM/PM
43 } else { 43 } else {
44 this.maxPos_ = 4; // Anything less than 1 shows hh:mm:ss.ms AM/PM 44 this.maxPos_ = 4; // Anything less than 1 shows hh:mm:ss.ms AM/PM
45 } 45 }
46 } 46 }
47 } 47 }
48 48
49 // Ensure we have a reasonable value to start with. 49 // Ensure we have a reasonable value to start with.
(...skipping 23 matching lines...) Expand all
73 /** 73 /**
74 * Removes the key listeners for the time widget. 74 * Removes the key listeners for the time widget.
75 * 75 *
76 */ 76 */
77 cvox.ChromeVoxHTMLTimeWidget.prototype.shutdown = function() { 77 cvox.ChromeVoxHTMLTimeWidget.prototype.shutdown = function() {
78 this.timeElem_.removeEventListener('blur', this.blurListener_, false); 78 this.timeElem_.removeEventListener('blur', this.blurListener_, false);
79 this.timeElem_.removeEventListener('keydown', this.keyListener_, false); 79 this.timeElem_.removeEventListener('keydown', this.keyListener_, false);
80 this.timeElem_.removeEventListener('keyup', this.keyListener_, false); 80 this.timeElem_.removeEventListener('keyup', this.keyListener_, false);
81 }; 81 };
82 82
83 /**
84 * Initialize to midnight.
85 * @private
86 */
83 cvox.ChromeVoxHTMLTimeWidget.prototype.forceInitTime_ = function() { 87 cvox.ChromeVoxHTMLTimeWidget.prototype.forceInitTime_ = function() {
84 this.timeElem_.setAttribute('value', '12:00'); 88 this.timeElem_.setAttribute('value', '12:00');
85 }; 89 };
86 90
91 /**
92 * Called when the position changes.
93 * @private
94 */
87 cvox.ChromeVoxHTMLTimeWidget.prototype.handlePosChange_ = function() { 95 cvox.ChromeVoxHTMLTimeWidget.prototype.handlePosChange_ = function() {
88 if (this.pos_ < 0){ 96 if (this.pos_ < 0) {
89 this.pos_ = 0; 97 this.pos_ = 0;
90 } 98 }
91 if (this.pos_ > this.maxPos_){ 99 if (this.pos_ > this.maxPos_) {
92 this.pos_ = this.maxPos_; 100 this.pos_ = this.maxPos_;
93 } 101 }
94 // Reset the cached state of the new field so that the field will be spoken 102 // Reset the cached state of the new field so that the field will be spoken
95 // in the update. 103 // in the update.
96 if (this.pos_ == this.maxPos_){ 104 if (this.pos_ == this.maxPos_) {
97 this.pAmpm_ = ''; 105 this.pAmpm_ = '';
98 return; 106 return;
99 } 107 }
100 switch (this.pos_){ 108 switch (this.pos_) {
101 case 0: 109 case 0:
102 this.pHours_ = -1; 110 this.pHours_ = -1;
103 break; 111 break;
104 case 1: 112 case 1:
105 this.pMinutes_ = -1; 113 this.pMinutes_ = -1;
106 break; 114 break;
107 case 2: 115 case 2:
108 this.pSeconds_ = -1; 116 this.pSeconds_ = -1;
109 break; 117 break;
110 case 3: 118 case 3:
111 this.pMilliseconds_ = -1; 119 this.pMilliseconds_ = -1;
112 break; 120 break;
113 } 121 }
114 }; 122 };
115 123
116 124 /**
125 * @param {boolean} shouldSpeakLabel True if the label should be spoken.
126 * @private
127 */
117 cvox.ChromeVoxHTMLTimeWidget.prototype.update_ = function(shouldSpeakLabel) { 128 cvox.ChromeVoxHTMLTimeWidget.prototype.update_ = function(shouldSpeakLabel) {
118 var splitTime = this.timeElem_.value.split(":"); 129 var splitTime = this.timeElem_.value.split(':');
119 if (splitTime.length < 1){ 130 if (splitTime.length < 1) {
120 this.forceInitTime_(); 131 this.forceInitTime_();
121 return; 132 return;
122 } 133 }
123 134
124 var hours = splitTime[0]; 135 var hours = splitTime[0];
125 var minutes = -1; 136 var minutes = -1;
126 var seconds = 0; 137 var seconds = 0;
127 var milliseconds = 0; 138 var milliseconds = 0;
128 var ampm = cvox.ChromeVox.msgs.getMsg('timewidget_am'); 139 var ampm = cvox.ChromeVox.msgs.getMsg('timewidget_am');
129 if (splitTime.length > 1) { 140 if (splitTime.length > 1) {
130 minutes = splitTime[1]; 141 minutes = splitTime[1];
131 } 142 }
132 if (splitTime.length > 2) { 143 if (splitTime.length > 2) {
133 var splitSecondsAndMilliseconds = splitTime[2].split('.'); 144 var splitSecondsAndMilliseconds = splitTime[2].split('.');
134 seconds = splitSecondsAndMilliseconds[0]; 145 seconds = splitSecondsAndMilliseconds[0];
135 if (splitSecondsAndMilliseconds.length > 1){ 146 if (splitSecondsAndMilliseconds.length > 1) {
136 milliseconds = splitSecondsAndMilliseconds[1]; 147 milliseconds = splitSecondsAndMilliseconds[1];
137 } 148 }
138 } 149 }
139 if (hours > 12) { 150 if (hours > 12) {
140 hours = hours - 12; 151 hours = hours - 12;
141 ampm = cvox.ChromeVox.msgs.getMsg('timewidget_pm'); 152 ampm = cvox.ChromeVox.msgs.getMsg('timewidget_pm');
142 } 153 }
143 if (hours == 12) { 154 if (hours == 12) {
144 ampm = cvox.ChromeVox.msgs.getMsg('timewidget_pm'); 155 ampm = cvox.ChromeVox.msgs.getMsg('timewidget_pm');
145 } 156 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 cvox.ChromeVox.msgs.getMsg('timewidget_milliseconds') + '\n'; 188 cvox.ChromeVox.msgs.getMsg('timewidget_milliseconds') + '\n';
178 this.pMilliseconds_ = milliseconds; 189 this.pMilliseconds_ = milliseconds;
179 } 190 }
180 191
181 if (ampm != this.pAmpm_) { 192 if (ampm != this.pAmpm_) {
182 changeMessage = changeMessage + ampm; 193 changeMessage = changeMessage + ampm;
183 this.pAmpm_ = ampm; 194 this.pAmpm_ = ampm;
184 } 195 }
185 196
186 if (changeMessage.length > 0) { 197 if (changeMessage.length > 0) {
187 this.timeTts_.speak(changeMessage, 0, null); 198 this.timeTts_.speak(changeMessage, cvox.QueueMode.FLUSH, null);
188 } 199 }
189 }; 200 };
190 201
202 /**
203 * @param {Object} evt The event to handle.
204 * @private
205 */
191 cvox.ChromeVoxHTMLTimeWidget.prototype.eventHandler_ = function(evt) { 206 cvox.ChromeVoxHTMLTimeWidget.prototype.eventHandler_ = function(evt) {
192 var shouldSpeakLabel = false; 207 var shouldSpeakLabel = false;
193 if (evt.type == 'keydown') { 208 if (evt.type == 'keydown') {
194 if (((evt.keyCode == 9) && !evt.shiftKey) || (evt.keyCode == 39)) { 209 if (((evt.keyCode == 9) && !evt.shiftKey) || (evt.keyCode == 39)) {
195 this.pos_++; 210 this.pos_++;
196 this.handlePosChange_(); 211 this.handlePosChange_();
197 shouldSpeakLabel = true; 212 shouldSpeakLabel = true;
198 } 213 }
199 if (((evt.keyCode == 9) && evt.shiftKey) || (evt.keyCode == 37)) { 214 if (((evt.keyCode == 9) && evt.shiftKey) || (evt.keyCode == 37)) {
200 this.pos_--; 215 this.pos_--;
201 this.handlePosChange_(); 216 this.handlePosChange_();
202 shouldSpeakLabel = true; 217 shouldSpeakLabel = true;
203 } 218 }
204 } 219 }
205 this.update_(shouldSpeakLabel); 220 this.update_(shouldSpeakLabel);
206 }; 221 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698