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 (function() { | 5 (function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 /** | 8 /** |
9 * Moves |target| element above |anchor| element, in order to match the | 9 * Moves |target| element above |anchor| element, in order to match the |
10 * bottom lines. | 10 * bottom lines. |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 timeSlider.addEventListener('change', function() { | 132 timeSlider.addEventListener('change', function() { |
133 if (this.dragging) | 133 if (this.dragging) |
134 this.dragging = false; | 134 this.dragging = false; |
135 this._setSeekingTime(0); | 135 this._setSeekingTime(0); |
136 }.bind(this)); | 136 }.bind(this)); |
137 timeSlider.addEventListener('immediate-value-change', function() { | 137 timeSlider.addEventListener('immediate-value-change', function() { |
138 this._setSeekingTime(timeSlider.immediateValue); | 138 this._setSeekingTime(timeSlider.immediateValue); |
139 if (!this.dragging) | 139 if (!this.dragging) |
140 this.dragging = true; | 140 this.dragging = true; |
141 }.bind(this)); | 141 }.bind(this)); |
142 timeSlider.addEventListener('keydown', | |
143 this.onProgressKeyDownOrKeyPress_.bind(this)); | |
144 timeSlider.addEventListener('keypress', | |
145 this.onProgressKeyDownOrKeyPress_.bind(this)); | |
146 | 142 |
147 // Update volume on user inputs for volume slider. | 143 // Update volume on user inputs for volume slider. |
148 // During a drag operation, the volume should be updated immediately. | 144 // During a drag operation, the volume should be updated immediately. |
149 var volumeSlider = | 145 var volumeSlider = |
150 /** @type {PaperSliderElement} */ (this.$.volumeSlider); | 146 /** @type {PaperSliderElement} */ (this.$.volumeSlider); |
151 volumeSlider.addEventListener('change', function() { | 147 volumeSlider.addEventListener('change', function() { |
152 this.volume = volumeSlider.value; | 148 this.volume = volumeSlider.value; |
153 }.bind(this)); | 149 }.bind(this)); |
154 volumeSlider.addEventListener('immediate-value-change', function() { | 150 volumeSlider.addEventListener('immediate-value-change', function() { |
155 this.volume = volumeSlider.immediateValue; | 151 this.volume = volumeSlider.immediateValue; |
(...skipping 27 matching lines...) Expand all Loading... |
183 volumeClick: function() { | 179 volumeClick: function() { |
184 if (this.volume !== 0) { | 180 if (this.volume !== 0) { |
185 this.savedVolume_ = this.volume; | 181 this.savedVolume_ = this.volume; |
186 this.volume = 0; | 182 this.volume = 0; |
187 } else { | 183 } else { |
188 this.volume = this.savedVolume_ || 50; | 184 this.volume = this.savedVolume_ || 50; |
189 } | 185 } |
190 }, | 186 }, |
191 | 187 |
192 /** | 188 /** |
| 189 * Skips min(5 seconds, 10% of duration). |
| 190 * @param {boolean} forward Whether to skip forward/backword. |
| 191 */ |
| 192 smallSkip: function(forward) { |
| 193 var millisecondsToSkip = Math.min(5000, this.duration / 10); |
| 194 if (!forward) { |
| 195 millisecondsToSkip *= -1; |
| 196 } |
| 197 this.skip_(millisecondsToSkip); |
| 198 }, |
| 199 |
| 200 /** |
| 201 * Skips min(10 seconds, 20% of duration). |
| 202 * @param {boolean} forward Whether to skip forward/backword. |
| 203 */ |
| 204 bigSkip: function(forward) { |
| 205 var millisecondsToSkip = Math.min(10000, this.duration / 5); |
| 206 if (!forward) { |
| 207 millisecondsToSkip *= -1; |
| 208 } |
| 209 this.skip_(millisecondsToSkip); |
| 210 }, |
| 211 |
| 212 /** |
| 213 * Skips forward/backword. |
| 214 * @param {number} sec Seconds to skip. Set negative value to skip backword. |
| 215 * @private |
| 216 */ |
| 217 skip_: function(millis) { |
| 218 if (this.duration > 0) |
| 219 this.time = Math.max(Math.min(this.time + millis, this.duration), 0); |
| 220 }, |
| 221 |
| 222 /** |
193 * Converts the time into human friendly string. | 223 * Converts the time into human friendly string. |
194 * @param {number} time Time to be converted. | 224 * @param {number} time Time to be converted. |
195 * @return {string} String representation of the given time | 225 * @return {string} String representation of the given time |
196 */ | 226 */ |
197 time2string_: function(time) { | 227 time2string_: function(time) { |
198 return ~~(time / 60000) + ':' + ('0' + ~~(time / 1000 % 60)).slice(-2); | 228 return ~~(time / 60000) + ':' + ('0' + ~~(time / 1000 % 60)).slice(-2); |
199 }, | 229 }, |
200 | 230 |
201 /** | 231 /** |
202 * Converts the time and duration into human friendly string. | 232 * Converts the time and duration into human friendly string. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 this.$.play.setAttribute('aria-label', | 297 this.$.play.setAttribute('aria-label', |
268 this.playing ? ariaLabels.pause : ariaLabels.play); | 298 this.playing ? ariaLabels.pause : ariaLabels.play); |
269 this.$.next.setAttribute('aria-label', ariaLabels.next); | 299 this.$.next.setAttribute('aria-label', ariaLabels.next); |
270 this.$.volumeButton.setAttribute('aria-label', ariaLabels.volume); | 300 this.$.volumeButton.setAttribute('aria-label', ariaLabels.volume); |
271 this.$.playList.setAttribute('aria-label', ariaLabels.playList); | 301 this.$.playList.setAttribute('aria-label', ariaLabels.playList); |
272 this.$.timeSlider.setAttribute('aria-label', ariaLabels.seekSlider); | 302 this.$.timeSlider.setAttribute('aria-label', ariaLabels.seekSlider); |
273 this.$.volumeButton.setAttribute('aria-label', | 303 this.$.volumeButton.setAttribute('aria-label', |
274 this.volume !== 0 ? ariaLabels.mute : ariaLabels.unmute); | 304 this.volume !== 0 ? ariaLabels.mute : ariaLabels.unmute); |
275 this.$.volumeSlider.setAttribute('aria-label', ariaLabels.volumeSlider); | 305 this.$.volumeSlider.setAttribute('aria-label', ariaLabels.volumeSlider); |
276 }, | 306 }, |
277 | |
278 /** | |
279 * Handles arrow keys on time slider to skip forward/backword. | |
280 * @param {!Event} event | |
281 * @private | |
282 */ | |
283 onProgressKeyDownOrKeyPress_: function(event) { | |
284 if (event.code !== 'ArrowRight' && event.code !== 'ArrowLeft' && | |
285 event.code !== 'ArrowUp' && event.code !== 'ArrowDown') { | |
286 return; | |
287 } | |
288 | |
289 event.preventDefault(); | |
290 | |
291 if (this.duration > 0) { | |
292 // Skip 5 seconds or 10% of duration, whichever is smaller. | |
293 var millisecondsToSkip = Math.min(5000, this.duration / 10); | |
294 if (event.code === 'ArrowRight' || event.code === 'ArrowUp') { | |
295 this.time = Math.min(this.time + millisecondsToSkip, this.duration); | |
296 } else { | |
297 this.time = Math.max(this.time - millisecondsToSkip, 0); | |
298 } | |
299 } | |
300 } | |
301 }); | 307 }); |
302 })(); // Anonymous closure | 308 })(); // Anonymous closure |
OLD | NEW |