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

Side by Side Diff: ui/file_manager/audio_player/elements/control_panel.js

Issue 1176483002: AudioPlayer.app: Migrate to Polymer 1.0. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments. Created 5 years, 6 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
OLDNEW
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.
11 * @param {HTMLElement} target Target element. 11 * @param {HTMLElement} target Target element.
12 * @param {HTMLElement} anchor Anchor element. 12 * @param {HTMLElement} anchor Anchor element.
13 */ 13 */
14 function matchBottomLine(target, anchor) { 14 function matchBottomLine(target, anchor) {
15 var targetRect = target.getBoundingClientRect(); 15 var targetRect = target.getBoundingClientRect();
16 var anchorRect = anchor.getBoundingClientRect(); 16 var anchorRect = anchor.getBoundingClientRect();
17 17
18 var pos = { 18 var pos = {
19 left: anchorRect.left + anchorRect.width / 2 - targetRect.width / 2, 19 left: anchorRect.left + anchorRect.width / 2 - targetRect.width / 2,
20 bottom: window.innerHeight - anchorRect.bottom, 20 bottom: window.innerHeight - anchorRect.bottom,
21 }; 21 };
22 22
23 target.style.position = 'fixed'; 23 target.style.position = 'fixed';
24 target.style.left = pos.left + 'px'; 24 target.style.left = pos.left + 'px';
25 target.style.bottom = pos.bottom + 'px'; 25 target.style.bottom = pos.bottom + 'px';
26 } 26 }
27 27
28 /** 28 /**
29 * Converts the time into human friendly string.
30 * @param {number} time Time to be converted.
31 * @return {string} String representation of the given time
32 */
33 function time2string(time) {
34 return ~~(time / 60000) + ':' + ('0' + ~~(time / 1000 % 60)).slice(-2);
35 }
36
37 /**
38 * @constructor 29 * @constructor
39 * @extends {PolymerElement} 30 * @extends {PolymerElement}
40 */ 31 */
41 var ControlPanelElement = function() {}; 32 var ControlPanelElement = function() {};
42 33
43 ControlPanelElement.prototype = { 34 ControlPanelElement.prototype = {
35 is: 'control-panel',
36
37 properties: {
38 /**
39 * Flag whether the audio is playing or paused. True if playing, or false
40 * paused.
41 */
42 playing: {
43 type: Boolean,
44 value: false,
45 notify: true
46 },
47
48 /**
49 * Current elapsed time in the current music in millisecond.
50 */
51 time: {
52 type: Number,
53 value: 0,
54 notify: true
55 },
56
57 /**
58 * Total length of the current music in millisecond.
59 */
60 duration: {
61 type: Number,
62 value: 0
63 },
64
65 /**
66 * Whether the shuffle button is ON.
67 */
68 shuffle: {
69 type: Boolean,
70 value: false,
71 notify: true
72 },
73
74 /**
75 * Whether the repeat button is ON.
76 */
77 repeat: {
78 type: Boolean,
79 value: false,
80 notify: true
81 },
82
83 /**
84 * The audio volume. 0 is silent, and 100 is maximum loud.
85 */
86 volume: {
87 type: Number,
88 notify: true
89 },
90
91 /**
92 * Whether the expanded button is ON.
93 */
94 expanded: {
95 type: Boolean,
96 value: false,
97 notify: true
98 },
99
100 /**
101 * Whether the volume slider is expanded or not.
102 */
103 volumeSliderShown: {
104 type: Boolean,
105 value: false,
106 notify: true
107 }
108 },
109
44 /** 110 /**
45 * Initializes an element. This method is called automatically when the 111 * Initializes an element. This method is called automatically when the
46 * element is ready. 112 * element is ready.
47 */ 113 */
48 ready: function() { 114 ready: function() {
49 var onFocusoutBound = this.onVolumeControllerFocusout_.bind(this); 115 var onFocusoutBound = this.onVolumeControllerFocusout_.bind(this);
50 116
51 this.volumeSlider = this.$.volumeSlider; 117 this.volumeSlider = this.$.volumeSlider;
52 this.volumeButton = this.$.volumeButton; 118 this.volumeButton = this.$.volumeButton;
53 this.volumeContainer = this.$.volumeContainer; 119 this.volumeContainer = this.$.volumeContainer;
54 120
55 this.volumeSlider.addEventListener('focusout', onFocusoutBound); 121 this.volumeSlider.addEventListener('focusout', onFocusoutBound);
56 this.volumeButton.addEventListener('focusout', onFocusoutBound); 122 this.volumeButton.addEventListener('focusout', onFocusoutBound);
57 }, 123 },
58 124
59 /** 125 /**
60 * Model object of the Audio Player.
61 * @type {AudioPlayerModel}
62 */
63 model: null,
64
65 /**
66 * Invoked when the model changed.
67 * @param {AudioPlayerModel} oldValue Old Value.
68 * @param {AudioPlayerModel} newValue New Value.
69 */
70 modelChanged: function(oldValue, newValue) {
71 this.volumeSlider.model = newValue;
72 },
73
74 /**
75 * Current elapsed time in the current music in millisecond.
76 * @type {number}
77 */
78 time: 0,
79
80 /**
81 * String representation of 'time'.
82 * @type {number}
83 * @private
84 */
85 get timeString_() {
86 return time2string(this.time);
87 },
88
89 /**
90 * Total length of the current music in millisecond.
91 * @type {number}
92 */
93 duration: 0,
94
95 /**
96 * String representation of 'duration'.
97 * @type {string}
98 * @private
99 */
100 get durationString_() {
101 return time2string(this.duration);
102 },
103
104 /**
105 * Flag whether the volume slider is expanded or not.
106 * @type {boolean}
107 */
108 volumeSliderShown: false,
109
110 /**
111 * Flag whether the audio is playing or paused. True if playing, or false
112 * paused.
113 * @type {boolean}
114 */
115 playing: false,
116
117 /**
118 * Invoked when the next button is clicked. 126 * Invoked when the next button is clicked.
119 */ 127 */
120 nextClick: function() { 128 nextClick: function() {
121 this.fire('next-clicked'); 129 this.fire('next-clicked');
122 }, 130 },
123 131
124 /** 132 /**
125 * Invoked when the play button is clicked. 133 * Invoked when the play button is clicked.
126 */ 134 */
127 playClick: function() { 135 playClick: function() {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 * @private 175 * @private
168 */ 176 */
169 showVolumeController_: function(show) { 177 showVolumeController_: function(show) {
170 if (show) { 178 if (show) {
171 matchBottomLine(this.$.volumeContainer, this.$.volumeButton); 179 matchBottomLine(this.$.volumeContainer, this.$.volumeButton);
172 this.volumeContainer.style.visibility = 'visible'; 180 this.volumeContainer.style.visibility = 'visible';
173 } else { 181 } else {
174 this.volumeContainer.style.visibility = 'hidden'; 182 this.volumeContainer.style.visibility = 'hidden';
175 } 183 }
176 }, 184 },
185
186 /**
187 * Converts the time into human friendly string.
188 * @param {number} time Time to be converted.
189 * @return {string} String representation of the given time
190 */
191 time2string_: function(time) {
192 return ~~(time / 60000) + ':' + ('0' + ~~(time / 1000 % 60)).slice(-2);
193 },
194
195 /**
196 * Computes state for play button based on 'playing' property.
197 * @return {string}
198 */
199 computePlayState_: function(playing) {
200 return playing ? "playing" : "ended";
201 },
202
203 /**
204 * Computes style for '.filled' element of progress bar.
205 * @return {string}
206 */
207 computeProgressBarStyle_: function(time, duration) {
208 return 'width: ' + (time / duration * 100) + '%;';
209 }
177 }; 210 };
178 211
179 Polymer('control-panel', ControlPanelElement.prototype); 212 Polymer(ControlPanelElement.prototype);
180 })(); // Anonymous closure 213 })(); // Anonymous closure
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698