Chromium Code Reviews| Index: chrome/browser/resources/file_manager/audio_player/elements/track_list.js |
| diff --git a/chrome/browser/resources/file_manager/audio_player/elements/track_list.js b/chrome/browser/resources/file_manager/audio_player/elements/track_list.js |
| index 6b373ad6da5d7a6ad960fc101738c22967f0b175..07953d22723e6cb29720fd965ba9aadb29248be6 100644 |
| --- a/chrome/browser/resources/file_manager/audio_player/elements/track_list.js |
| +++ b/chrome/browser/resources/file_manager/audio_player/elements/track_list.js |
| @@ -92,8 +92,9 @@ |
| }, |
| /** |
| - * Invoked when 'tracks' property is clicked. |
| - * @param {Event} event Click event. |
| + * Invoked when 'tracks' property is changed. |
| + * @param {Array.<TrackInfo>} oldValue Old value. |
| + * @param {Array.<TrackInfo>} newValue New value. |
| */ |
| tracksChanged: function(oldValue, newValue) { |
| // Note: Sometimes both oldValue and newValue are null though the actual |
| @@ -101,15 +102,17 @@ |
| // Re-register the observer of 'this.tracks'. |
| this.tracksObserver_.close(); |
| - this.tracksObserver_ = new ArrayObserver( |
| - this.tracks, |
| - this.tracksValueChanged_.bind(this)); |
| + this.tracksObserver_ = new ArrayObserver(this.tracks); |
| + this.tracksObserver_.open(this.tracksValueChanged_.bind(this)); |
| - // Reset play order and current index. |
| - if (this.tracks.length !== 0) |
| - this.generatePlayOrder(false /* no need to keep the current track */); |
| + if (this.tracks.length !== 0) { |
| + // Restore the active track. |
| + if (this.currentTrackIndex !== -1) |
| + this.tracks[this.currentTrackIndex].active = true; |
|
hirono
2014/03/06 08:48:44
How about the case where this.currentTrackIndex >=
yoshiki
2014/03/06 09:24:23
Done.
|
| - if (this.tracks.length === 0) { |
| + // Reset play order and current index. |
| + this.generatePlayOrder(false /* no need to keep the current track */); |
| + } else { |
| this.playOrder = []; |
| this.currentTrackIndex = -1; |
| } |
| @@ -154,10 +157,21 @@ |
| var trackSelector = '.track[index="' + trackIndex + '"]'; |
| var trackElement = this.impl.querySelector(trackSelector); |
| if (trackElement) { |
| - this.scrollTop = Math.max( |
| - 0, |
| - (trackElement.offsetTop + trackElement.offsetHeight - |
| - this.clientHeight)); |
| + var viewTop = this.scrollTop; |
| + var viewHeight = this.clientHeight; |
| + var elementTop = trackElement.offsetTop; |
| + var elementHeight = trackElement.offsetHeight; |
| + |
| + if (elementTop < viewTop) { |
| + // Adjust the tops. |
| + this.scrollTop = elementTop; |
| + } else if (elementTop + elementHeight <= viewTop + viewHeight) { |
| + // The entire element is in the viewport. Do nothing. |
| + } else { |
| + // Adjust the bottoms. |
| + this.scrollTop = Math.max(0, |
| + (elementTop + elementHeight - viewHeight)); |
| + } |
| } |
| }, |