Chromium Code Reviews| Index: chrome/browser/resources/file_manager/js/media/media_controls.js |
| diff --git a/chrome/browser/resources/file_manager/js/media/media_controls.js b/chrome/browser/resources/file_manager/js/media/media_controls.js |
| index 623e3eb246edaa4320aebe2d1d33bab673f4eab4..25ec5c077e6e78d88d112780c38fd54b6ffd6a95 100644 |
| --- a/chrome/browser/resources/file_manager/js/media/media_controls.js |
| +++ b/chrome/browser/resources/file_manager/js/media/media_controls.js |
| @@ -70,17 +70,18 @@ MediaControls.prototype.createControl = function(className, opt_parent) { |
| * @param {string} className Class name. |
| * @param {function(Event)} handler Click handler. |
| * @param {HTMLElement=} opt_parent Parent element or container if undefined. |
| - * @param {boolean=} opt_toggle True if the button has toggle state. |
| + * @param {number=} opt_numStates Number of states, default: 1. |
|
yoshiki
2013/03/08 08:20:07
Expressing the status as a raw number is difficult
mtomasz
2013/03/11 03:47:16
Done.
|
| * @return {HTMLElement} The new button element. |
| */ |
| MediaControls.prototype.createButton = function( |
| - className, handler, opt_parent, opt_toggle) { |
| + className, handler, opt_parent, opt_numStates) { |
| + opt_numStates = opt_numStates || 1; |
|
yoshiki
2013/03/08 08:20:07
nit: |opt_numStates| is no longer optional. Please
mtomasz
2013/03/08 09:10:00
We use this pattern very often. opt_sth = opt_sth
yoshiki
2013/03/11 01:45:32
I prefer adding additional value, but it's not str
mtomasz
2013/03/11 03:47:16
The reason I'd prefer this is that I don't think t
yoshiki
2013/03/11 04:42:45
Ok, let's leave it as it is.
But the code may be
|
| + |
| var button = this.createControl(className, opt_parent); |
| button.classList.add('media-button'); |
| button.addEventListener('click', handler); |
| - var numStates = opt_toggle ? 2 : 1; |
| - for (var state = 0; state != numStates; state++) { |
| + for (var state = 0; state != opt_numStates; state++) { |
| var stateClass = 'state' + state; |
| this.createControl('normal ' + stateClass, button); |
| this.createControl('hover ' + stateClass, button); |
| @@ -151,7 +152,7 @@ MediaControls.prototype.togglePlayState = function() { |
| */ |
| MediaControls.prototype.initPlayButton = function(opt_parent) { |
| this.playButton_ = this.createButton('play media-control', |
| - this.togglePlayState.bind(this), opt_parent, true /* toggle */); |
| + this.togglePlayState.bind(this), opt_parent, 3 /* States. */); |
| }; |
| /* |
| @@ -231,6 +232,7 @@ MediaControls.prototype.onProgressDrag_ = function(on) { |
| else |
| this.media_.play(); |
| } |
| + this.updatePlayButtonState_(this.isPlaying()); |
| } |
| }; |
| @@ -365,7 +367,7 @@ MediaControls.prototype.onMediaPlay_ = function(playing) { |
| if (this.progressSlider_.isDragging()) |
| return; |
| - this.playButton_.setAttribute('state', playing ? '1' : '0'); |
| + this.updatePlayButtonState_(playing); |
| this.onPlayStateChanged(); |
| }; |
| @@ -436,6 +438,21 @@ MediaControls.prototype.onMediaComplete = function() {}; |
| MediaControls.prototype.onPlayStateChanged = function() {}; |
| /** |
| + * Updates the play button state. |
| + * @param {boolean} playing If the video is playing. |
| + * @private |
| + */ |
| +MediaControls.prototype.updatePlayButtonState_ = function(playing) { |
| + if (playing) { |
| + this.playButton_.setAttribute('state', '1'); // Pause icon. |
| + } else if (!this.media_.ended) { |
| + this.playButton_.setAttribute('state', '0'); // Play icon. |
| + } else { |
| + this.playButton_.setAttribute('state', '2'); // Replay icon. |
| + } |
| +}; |
| + |
| +/** |
| * Restore play state. Base implementation is empty. |
| */ |
| MediaControls.prototype.restorePlayState = function() {}; |