Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 notify: true | |
| 45 }, | |
| 46 | |
| 47 /** | |
| 48 * Current elapsed time in the current music in millisecond. | |
| 49 */ | |
| 50 time: { | |
| 51 type: Number, | |
| 52 value: 0, | |
| 53 notify: true | |
| 54 }, | |
| 55 | |
| 56 /** | |
| 57 * Total length of the current music in millisecond. | |
| 58 */ | |
| 59 duration: { | |
| 60 type: Number, | |
| 61 value: 0, | |
| 62 notify: true | |
|
yawano
2015/06/10 05:47:48
notify: false? Since this is property is bound as
fukino
2015/06/10 06:24:03
Yes, you are right. Done.
| |
| 63 }, | |
| 64 | |
| 65 /** | |
| 66 * Whether the shuffle button is ON. | |
| 67 */ | |
| 68 shuffle: { | |
| 69 type: Boolean, | |
| 70 notify: true | |
| 71 }, | |
| 72 | |
| 73 /** | |
| 74 * Whether the repeat button is ON. | |
| 75 */ | |
| 76 repeat: { | |
| 77 type: Boolean, | |
| 78 notify: true | |
| 79 }, | |
| 80 | |
| 81 /** | |
| 82 * The audio volume. 0 is silent, and 100 is maximum loud. | |
| 83 */ | |
| 84 volume: { | |
| 85 type: Number, | |
| 86 notify: true | |
| 87 }, | |
| 88 | |
| 89 /** | |
| 90 * Whether the expanded button is ON. | |
| 91 */ | |
| 92 expanded: { | |
| 93 type: Boolean, | |
| 94 notify: true | |
| 95 }, | |
| 96 | |
| 97 /** | |
| 98 * Whether the volume slider is expanded or not. | |
| 99 */ | |
| 100 volumeSliderShown: { | |
| 101 type: Boolean, | |
| 102 value: false, | |
|
yawano
2015/06/10 05:47:48
nit: Why some properties have default value and so
fukino
2015/06/10 06:24:03
Basically, it was based on whether we have default
yawano
2015/06/10 06:46:18
SGTM.
| |
| 103 notify: true | |
| 104 } | |
| 105 }, | |
| 106 | |
| 44 /** | 107 /** |
| 45 * Initializes an element. This method is called automatically when the | 108 * Initializes an element. This method is called automatically when the |
| 46 * element is ready. | 109 * element is ready. |
| 47 */ | 110 */ |
| 48 ready: function() { | 111 ready: function() { |
| 49 var onFocusoutBound = this.onVolumeControllerFocusout_.bind(this); | 112 var onFocusoutBound = this.onVolumeControllerFocusout_.bind(this); |
| 50 | 113 |
| 51 this.volumeSlider = this.$.volumeSlider; | 114 this.volumeSlider = this.$.volumeSlider; |
| 52 this.volumeButton = this.$.volumeButton; | 115 this.volumeButton = this.$.volumeButton; |
| 53 this.volumeContainer = this.$.volumeContainer; | 116 this.volumeContainer = this.$.volumeContainer; |
| 54 | 117 |
| 55 this.volumeSlider.addEventListener('focusout', onFocusoutBound); | 118 this.volumeSlider.addEventListener('focusout', onFocusoutBound); |
| 56 this.volumeButton.addEventListener('focusout', onFocusoutBound); | 119 this.volumeButton.addEventListener('focusout', onFocusoutBound); |
| 57 }, | 120 }, |
| 58 | 121 |
| 59 /** | 122 /** |
| 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. | 123 * Invoked when the next button is clicked. |
| 119 */ | 124 */ |
| 120 nextClick: function() { | 125 nextClick: function() { |
| 121 this.fire('next-clicked'); | 126 this.fire('next-clicked'); |
| 122 }, | 127 }, |
| 123 | 128 |
| 124 /** | 129 /** |
| 125 * Invoked when the play button is clicked. | 130 * Invoked when the play button is clicked. |
| 126 */ | 131 */ |
| 127 playClick: function() { | 132 playClick: function() { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 * @private | 172 * @private |
| 168 */ | 173 */ |
| 169 showVolumeController_: function(show) { | 174 showVolumeController_: function(show) { |
| 170 if (show) { | 175 if (show) { |
| 171 matchBottomLine(this.$.volumeContainer, this.$.volumeButton); | 176 matchBottomLine(this.$.volumeContainer, this.$.volumeButton); |
| 172 this.volumeContainer.style.visibility = 'visible'; | 177 this.volumeContainer.style.visibility = 'visible'; |
| 173 } else { | 178 } else { |
| 174 this.volumeContainer.style.visibility = 'hidden'; | 179 this.volumeContainer.style.visibility = 'hidden'; |
| 175 } | 180 } |
| 176 }, | 181 }, |
| 182 | |
| 183 /** | |
| 184 * Converts the time into human friendly string. | |
| 185 * @param {number} time Time to be converted. | |
| 186 * @return {string} String representation of the given time | |
| 187 */ | |
| 188 time2string_: function(time) { | |
| 189 return ~~(time / 60000) + ':' + ('0' + ~~(time / 1000 % 60)).slice(-2); | |
| 190 }, | |
| 191 | |
| 192 /** | |
| 193 * Computes state for play button based on 'playing' property. | |
| 194 * @return {string} | |
| 195 */ | |
| 196 computePlayState_: function(playing) { | |
| 197 return playing ? "playing" : "ended"; | |
| 198 }, | |
| 199 | |
| 200 /** | |
| 201 * Computes style for '.filled' element of progress bar. | |
| 202 * @return {string} | |
| 203 */ | |
| 204 computeProgressBarStyle_: function(time, duration) { | |
| 205 return 'width: ' + (time / duration * 100) + '%;'; | |
| 206 } | |
| 177 }; | 207 }; |
| 178 | 208 |
| 179 Polymer('control-panel', ControlPanelElement.prototype); | 209 Polymer(ControlPanelElement.prototype); |
| 180 })(); // Anonymous closure | 210 })(); // Anonymous closure |
| OLD | NEW |