Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(371)

Side by Side Diff: chrome/browser/resources/file_manager/audio_player/js/audio_player.js

Issue 185653014: [AudioPlayer] Fix a bug on changing 'expanded' status (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * @param {HTMLElement} container Container element. 8 * @param {HTMLElement} container Container element.
9 * @constructor 9 * @constructor
10 */ 10 */
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 */ 96 */
97 AudioPlayer.prototype.load = function(playlist) { 97 AudioPlayer.prototype.load = function(playlist) {
98 this.playlistGeneration_++; 98 this.playlistGeneration_++;
99 this.currentTrackIndex_ = -1; 99 this.currentTrackIndex_ = -1;
100 100
101 // Save the app state, in case of restart. Make a copy of the object, so the 101 // Save the app state, in case of restart. Make a copy of the object, so the
102 // playlist member is not changed after entries are resolved. 102 // playlist member is not changed after entries are resolved.
103 window.appState = JSON.parse(JSON.stringify(playlist)); // cloning 103 window.appState = JSON.parse(JSON.stringify(playlist)); // cloning
104 util.saveAppState(); 104 util.saveAppState();
105 105
106 this.isExpanded_ = this.model_.expanded;
107
106 // Resolving entries has to be done after the volume manager is initialized. 108 // Resolving entries has to be done after the volume manager is initialized.
107 this.volumeManager_.ensureInitialized(function() { 109 this.volumeManager_.ensureInitialized(function() {
108 util.URLsToEntries(playlist.items, function(entries) { 110 util.URLsToEntries(playlist.items, function(entries) {
109 this.entries_ = entries; 111 this.entries_ = entries;
110 112
111 var position = playlist.position || 0; 113 var position = playlist.position || 0;
112 var time = playlist.time || 0; 114 var time = playlist.time || 0;
113 115
114 if (this.entries_.length == 0) 116 if (this.entries_.length == 0)
115 return; 117 return;
116 118
117 this.trackListItems_.splice(0); 119 this.trackListItems_.splice(0);
118 120
121 // Makes it sure that the track list is now empty to the handler, before
122 // adding new tracks.
123 Platform.performMicrotaskCheckpoint();
hirono 2014/03/05 17:24:01 Just curious, what goes wrong without the line? I'
yoshiki 2014/03/05 18:30:41 Yes, that's correct.
hirono 2014/03/06 03:44:47 So how about removing this.trackListItems_ member
yoshiki 2014/03/06 08:25:07 Done
124
119 for (var i = 0; i != this.entries_.length; i++) { 125 for (var i = 0; i != this.entries_.length; i++) {
120 var entry = this.entries_[i]; 126 var entry = this.entries_[i];
121 var onClick = this.select_.bind(this, i, false /* no restore */); 127 var onClick = this.select_.bind(this, i, false /* no restore */);
122 this.trackListItems_.push(new AudioPlayer.TrackInfo(entry, onClick)); 128 this.trackListItems_.push(new AudioPlayer.TrackInfo(entry, onClick));
123 } 129 }
124 130
125 // Makes it sure that the handler of the track list is called, before the 131 // Makes it sure that the handler of the track list is called, before the
126 // handler of the track index. 132 // handler of the track index.
127 Platform.performMicrotaskCheckpoint(); 133 Platform.performMicrotaskCheckpoint();
128 134
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 } 267 }
262 }; 268 };
263 269
264 /* Keep the below constants in sync with the CSS. */ 270 /* Keep the below constants in sync with the CSS. */
265 271
266 /** 272 /**
267 * Window header size in pixels. 273 * Window header size in pixels.
268 * @type {number} 274 * @type {number}
269 * @const 275 * @const
270 */ 276 */
271 AudioPlayer.HEADER_HEIGHT = 28; 277 AudioPlayer.HEADER_HEIGHT = 33; // 32px + border 1px
272 278
273 /** 279 /**
274 * Track height in pixels. 280 * Track height in pixels.
275 * @type {number} 281 * @type {number}
276 * @const 282 * @const
277 */ 283 */
278 AudioPlayer.TRACK_HEIGHT = 44; 284 AudioPlayer.TRACK_HEIGHT = 44;
279 285
280 /** 286 /**
281 * Controls bar height in pixels. 287 * Controls bar height in pixels.
282 * @type {number} 288 * @type {number}
283 * @const 289 * @const
284 */ 290 */
285 AudioPlayer.CONTROLS_HEIGHT = 72; 291 AudioPlayer.CONTROLS_HEIGHT = 73; // 72px + border 1px
286 292
287 /** 293 /**
288 * Default number of items in the expanded mode. 294 * Default number of items in the expanded mode.
289 * @type {number} 295 * @type {number}
290 * @const 296 * @const
291 */ 297 */
292 AudioPlayer.DEFAULT_EXPANDED_ITEMS = 5; 298 AudioPlayer.DEFAULT_EXPANDED_ITEMS = 5;
293 299
294 /** 300 /**
295 * Minimum size of the window in the expanded mode in pixels. 301 * Minimum size of the window in the expanded mode in pixels.
(...skipping 12 matching lines...) Expand all
308 if (this.isExpanded_ !== null && 314 if (this.isExpanded_ !== null &&
309 this.isExpanded_ === newValue) 315 this.isExpanded_ === newValue)
310 return; 316 return;
311 317
312 if (this.isExpanded_ && !newValue) 318 if (this.isExpanded_ && !newValue)
313 this.lastExpandedHeight_ = window.innerHeight; 319 this.lastExpandedHeight_ = window.innerHeight;
314 320
315 if (this.isExpanded_ !== newValue) { 321 if (this.isExpanded_ !== newValue) {
316 this.isExpanded_ = newValue; 322 this.isExpanded_ = newValue;
317 this.syncHeight_(); 323 this.syncHeight_();
324
325 // Saves new state.
326 window.appState.expanded = newValue;
327 util.saveAppState();
318 } 328 }
319 }; 329 };
320 330
321 /** 331 /**
322 * @private 332 * @private
323 */ 333 */
324 AudioPlayer.prototype.syncHeight_ = function() { 334 AudioPlayer.prototype.syncHeight_ = function() {
325 var targetHeight; 335 var targetHeight;
326 336
327 if (this.model_.expanded) { 337 if (this.model_.expanded) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 this.title = (metadata.media && metadata.media.title) || 415 this.title = (metadata.media && metadata.media.title) ||
406 this.getDefaultTitle(); 416 this.getDefaultTitle();
407 this.artist = error || 417 this.artist = error ||
408 (metadata.media && metadata.media.artist) || this.getDefaultArtist(); 418 (metadata.media && metadata.media.artist) || this.getDefaultArtist();
409 }; 419 };
410 420
411 // Starts loading the audio player. 421 // Starts loading the audio player.
412 window.addEventListener('WebComponentsReady', function(e) { 422 window.addEventListener('WebComponentsReady', function(e) {
413 AudioPlayer.load(); 423 AudioPlayer.load();
414 }); 424 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698