| OLD | NEW |
| 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 * |
| (...skipping 19 matching lines...) Expand all Loading... |
| 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. |
| 50 if (this.timeElem_.value.length == 0) { | 50 if (this.timeElem_.value.length == 0) { |
| 51 this.forceInitTime_(); | 51 this.forceInitTime_(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 // Move the cursor to the first position so that we are guaranteed to start | 54 // Move the cursor to the first position so that we are guaranteed to start |
| 55 // off at the hours position. | 55 // off at the hours position. |
| 56 for (var i = 0; i < this.maxPos_; i++) { | 56 for (var i = 0; i < this.maxPos_; i++) { |
| 57 var evt = document.createEvent('KeyboardEvent'); | 57 var evt = document.createEvent('KeyboardEvent'); |
| 58 evt.initKeyboardEvent( | 58 evt.initKeyboardEvent( |
| 59 'keydown', true, true, window, 'Left', 0, false, false, false, false); | 59 'keydown', true, true, window, 'Left', 0, false, false, false, false); |
| 60 this.timeElem_.dispatchEvent(evt); | 60 this.timeElem_.dispatchEvent(evt); |
| 61 evt = document.createEvent('KeyboardEvent'); | 61 evt = document.createEvent('KeyboardEvent'); |
| 62 evt.initKeyboardEvent( | 62 evt.initKeyboardEvent( |
| 63 'keyup', true, true, window, 'Left', 0, false, false, false, false); | 63 'keyup', true, true, window, 'Left', 0, false, false, false, false); |
| 64 this.timeElem_.dispatchEvent(evt); | 64 this.timeElem_.dispatchEvent(evt); |
| 65 } | 65 } |
| 66 | 66 |
| 67 this.timeElem_.addEventListener('keydown', this.keyListener_, false); | 67 this.timeElem_.addEventListener('keydown', this.keyListener_, false); |
| 68 this.timeElem_.addEventListener('keyup', this.keyListener_, false); | 68 this.timeElem_.addEventListener('keyup', this.keyListener_, false); |
| 69 this.timeElem_.addEventListener('blur', this.blurListener_, false); | 69 this.timeElem_.addEventListener('blur', this.blurListener_, false); |
| 70 this.update_(true); | 70 this.update_(true); |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 /** | 73 /** |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 ampm = Msgs.getMsg('timewidget_am'); | 159 ampm = Msgs.getMsg('timewidget_am'); |
| 160 } | 160 } |
| 161 | 161 |
| 162 var changeMessage = ''; | 162 var changeMessage = ''; |
| 163 | 163 |
| 164 if (shouldSpeakLabel) { | 164 if (shouldSpeakLabel) { |
| 165 changeMessage = cvox.DomUtil.getName(this.timeElem_, true, true) + '\n'; | 165 changeMessage = cvox.DomUtil.getName(this.timeElem_, true, true) + '\n'; |
| 166 } | 166 } |
| 167 | 167 |
| 168 if (hours != this.pHours_) { | 168 if (hours != this.pHours_) { |
| 169 changeMessage = changeMessage + hours + ' ' + | 169 changeMessage = |
| 170 Msgs.getMsg('timewidget_hours') + '\n'; | 170 changeMessage + hours + ' ' + Msgs.getMsg('timewidget_hours') + '\n'; |
| 171 this.pHours_ = hours; | 171 this.pHours_ = hours; |
| 172 } | 172 } |
| 173 | 173 |
| 174 if (minutes != this.pMinutes_) { | 174 if (minutes != this.pMinutes_) { |
| 175 changeMessage = changeMessage + minutes + ' ' + | 175 changeMessage = changeMessage + minutes + ' ' + |
| 176 Msgs.getMsg('timewidget_minutes') + '\n'; | 176 Msgs.getMsg('timewidget_minutes') + '\n'; |
| 177 this.pMinutes_ = minutes; | 177 this.pMinutes_ = minutes; |
| 178 } | 178 } |
| 179 | 179 |
| 180 if (seconds != this.pSeconds_) { | 180 if (seconds != this.pSeconds_) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 shouldSpeakLabel = true; | 212 shouldSpeakLabel = true; |
| 213 } | 213 } |
| 214 if (((evt.keyCode == 9) && evt.shiftKey) || (evt.keyCode == 37)) { | 214 if (((evt.keyCode == 9) && evt.shiftKey) || (evt.keyCode == 37)) { |
| 215 this.pos_--; | 215 this.pos_--; |
| 216 this.handlePosChange_(); | 216 this.handlePosChange_(); |
| 217 shouldSpeakLabel = true; | 217 shouldSpeakLabel = true; |
| 218 } | 218 } |
| 219 } | 219 } |
| 220 this.update_(shouldSpeakLabel); | 220 this.update_(shouldSpeakLabel); |
| 221 }; | 221 }; |
| OLD | NEW |