OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 MediaControls class implements media playback controls | 6 * @fileoverview MediaControls class implements media playback controls |
7 * that exist outside of the audio/video HTML element. | 7 * that exist outside of the audio/video HTML element. |
8 */ | 8 */ |
9 | 9 |
10 /** | 10 /** |
11 * @param {HTMLMediaElement} mediaElement The media element to control. | 11 * @param {HTMLMediaElement} mediaElement The media element to control. |
12 * @param {HTMLElement} containerElement The container for the controls. | 12 * @param {HTMLElement} containerElement The container for the controls. |
13 * @constructor | 13 * @constructor |
14 */ | 14 */ |
15 function MediaControls(mediaElement, containerElement) { | 15 function MediaControls(mediaElement, containerElement) { |
16 this.media_ = mediaElement; | 16 this.media_ = mediaElement; |
17 this.container_ = containerElement; | 17 this.container_ = containerElement; |
18 this.document_ = this.container_.ownerDocument; | 18 this.document_ = this.container_.ownerDocument; |
19 | 19 |
20 this.setupPlaybackControls_(); | 20 this.setupPlaybackControls_(); |
21 | 21 |
22 this.setupMediaEvents_(); | 22 this.setupMediaEvents_(); |
| 23 |
| 24 this.document_.defaultView.addEventListener( |
| 25 'resize', this.onWindowResize.bind(this)); |
23 } | 26 } |
24 | 27 |
25 /** | 28 /** |
26 * Load the given url into the media element. | 29 * Load the given url into the media element. |
27 * | 30 * |
28 * @param {string} url | 31 * @param {string} url |
29 */ | 32 */ |
30 MediaControls.prototype.load = function(url) { | 33 MediaControls.prototype.load = function(url) { |
31 this.media_.src = url; | 34 this.media_.src = url; |
32 this.media_.load(); | 35 this.media_.load(); |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 } | 275 } |
273 }; | 276 }; |
274 | 277 |
275 MediaControls.prototype.onVolumeMouseDown_ = function () { | 278 MediaControls.prototype.onVolumeMouseDown_ = function () { |
276 if (this.media_.volume != 0) { | 279 if (this.media_.volume != 0) { |
277 this.savedVolume_ = this.media_.volume; | 280 this.savedVolume_ = this.media_.volume; |
278 } | 281 } |
279 }; | 282 }; |
280 | 283 |
281 MediaControls.prototype.onFullscreenButtonClick_ = function() { | 284 MediaControls.prototype.onFullscreenButtonClick_ = function() { |
282 this.fullscreenButton_.classList.toggle('on'); | 285 if (chrome.fileBrowserPrivate) { |
283 // TODO: invoke the actual full screen mode | 286 chrome.fileBrowserPrivate.toggleFullscreen(); |
| 287 } |
| 288 }; |
| 289 |
| 290 MediaControls.prototype.onWindowResize = function() { |
| 291 // There is no notification to tell us when the user enters/leaves the |
| 292 // fullscreen mode using the built-in Chrome controls. All we can do is |
| 293 // query the current fullscreen state. |
| 294 // The best place to do it is a window resize handler. |
| 295 if (chrome.fileBrowserPrivate) { |
| 296 chrome.fileBrowserPrivate.isFullscreen( |
| 297 this.updateFullscreenStatus_.bind(this)); |
| 298 } |
| 299 }; |
| 300 |
| 301 MediaControls.prototype.updateFullscreenStatus_ = function(on) { |
| 302 if (on) { |
| 303 this.fullscreenButton_.classList.add('on'); |
| 304 } else { |
| 305 this.fullscreenButton_.classList.remove('on'); |
| 306 } |
284 }; | 307 }; |
285 | 308 |
286 /** | 309 /** |
287 * Attach media event handlers. | 310 * Attach media event handlers. |
288 */ | 311 */ |
289 MediaControls.prototype.setupMediaEvents_ = function() { | 312 MediaControls.prototype.setupMediaEvents_ = function() { |
290 this.media_.addEventListener( | 313 this.media_.addEventListener( |
291 'play', this.onMediaPlay_.bind(this, true)); | 314 'play', this.onMediaPlay_.bind(this, true)); |
292 this.media_.addEventListener( | 315 this.media_.addEventListener( |
293 'pause', this.onMediaPlay_.bind(this, false)); | 316 'pause', this.onMediaPlay_.bind(this, false)); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 /** | 455 /** |
433 * Compute the proportion in which the given position divides the slider bar. | 456 * Compute the proportion in which the given position divides the slider bar. |
434 * | 457 * |
435 * @param {number} position in pixels. | 458 * @param {number} position in pixels. |
436 * @return {number} [0..1] proportion. | 459 * @return {number} [0..1] proportion. |
437 */ | 460 */ |
438 MediaControls.Slider.prototype.getProportion = function (position) { | 461 MediaControls.Slider.prototype.getProportion = function (position) { |
439 var rect = this.bar_.getBoundingClientRect(); | 462 var rect = this.bar_.getBoundingClientRect(); |
440 return Math.max(0, Math.min(1, (position - rect.left) / rect.width)); | 463 return Math.max(0, Math.min(1, (position - rect.left) / rect.width)); |
441 }; | 464 }; |
OLD | NEW |