| 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 /** | |
| 9 * Moves |target| element above |anchor| element, in order to match the | |
| 10 * bottom lines. | |
| 11 * @param {HTMLElement} target Target element. | |
| 12 * @param {HTMLElement} anchor Anchor element. | |
| 13 */ | |
| 14 function matchBottomLine(target, anchor) { | |
| 15 var targetRect = target.getBoundingClientRect(); | |
| 16 var anchorRect = anchor.getBoundingClientRect(); | |
| 17 | |
| 18 var pos = { | |
| 19 left: anchorRect.left + anchorRect.width / 2 - targetRect.width / 2, | |
| 20 bottom: window.innerHeight - anchorRect.bottom, | |
| 21 }; | |
| 22 | |
| 23 target.style.position = 'fixed'; | |
| 24 target.style.left = pos.left + 'px'; | |
| 25 target.style.bottom = pos.bottom + 'px'; | |
| 26 } | |
| 27 | |
| 28 Polymer({ | 8 Polymer({ |
| 29 is: 'control-panel', | 9 is: 'control-panel', |
| 30 | 10 |
| 31 properties: { | 11 properties: { |
| 32 /** | 12 /** |
| 33 * Flag whether the audio is playing or paused. True if playing, or false | 13 * Flag whether the audio is playing or paused. True if playing, or false |
| 34 * paused. | 14 * paused. |
| 35 */ | 15 */ |
| 36 playing: { | 16 playing: { |
| 37 type: Boolean, | 17 type: Boolean, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 value: false, | 70 value: false, |
| 91 notify: true | 71 notify: true |
| 92 }, | 72 }, |
| 93 | 73 |
| 94 /** | 74 /** |
| 95 * Whether the volume slider is expanded or not. | 75 * Whether the volume slider is expanded or not. |
| 96 */ | 76 */ |
| 97 volumeSliderShown: { | 77 volumeSliderShown: { |
| 98 type: Boolean, | 78 type: Boolean, |
| 99 value: false, | 79 value: false, |
| 100 observer: 'volumeSliderShownChanged', | 80 notify: true, |
| 101 notify: true | 81 reflectToAttribute: true |
| 102 }, | 82 }, |
| 103 | 83 |
| 104 /** | 84 /** |
| 105 * Whether the knob of time slider is being dragged. | 85 * Whether the knob of time slider is being dragged. |
| 106 */ | 86 */ |
| 107 dragging: { | 87 dragging: { |
| 108 type: Boolean, | 88 type: Boolean, |
| 109 value: false, | 89 value: false, |
| 110 notify: true | 90 notify: true |
| 111 } | 91 } |
| 112 }, | 92 }, |
| 113 | 93 |
| 114 /** | 94 /** |
| 115 * Initializes an element. This method is called automatically when the | 95 * Initializes an element. This method is called automatically when the |
| 116 * element is ready. | 96 * element is ready. |
| 117 */ | 97 */ |
| 118 ready: function() { | 98 ready: function() { |
| 119 var onFocusoutBound = this.onVolumeControllerFocusout_.bind(this); | |
| 120 | |
| 121 this.$.volumeSlider.addEventListener('focusout', onFocusoutBound); | |
| 122 this.$.volumeButton.addEventListener('focusout', onFocusoutBound); | |
| 123 | |
| 124 this.$.timeSlider.addEventListener('value-change', function() { | 99 this.$.timeSlider.addEventListener('value-change', function() { |
| 125 if (this.dragging) | 100 if (this.dragging) |
| 126 this.dragging = false; | 101 this.dragging = false; |
| 127 }.bind(this)); | 102 }.bind(this)); |
| 128 this.$.timeSlider.addEventListener('immediate-value-change', function() { | 103 this.$.timeSlider.addEventListener('immediate-value-change', function() { |
| 129 if (!this.dragging) | 104 if (!this.dragging) |
| 130 this.dragging = true; | 105 this.dragging = true; |
| 131 }.bind(this)); | 106 }.bind(this)); |
| 132 }, | 107 }, |
| 133 | 108 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 146 }, | 121 }, |
| 147 | 122 |
| 148 /** | 123 /** |
| 149 * Invoked when the previous button is clicked. | 124 * Invoked when the previous button is clicked. |
| 150 */ | 125 */ |
| 151 previousClick: function() { | 126 previousClick: function() { |
| 152 this.fire('previous-clicked'); | 127 this.fire('previous-clicked'); |
| 153 }, | 128 }, |
| 154 | 129 |
| 155 /** | 130 /** |
| 156 * Invoked when the property 'volumeSliderShown' changes. | |
| 157 * @param {boolean} shown | |
| 158 */ | |
| 159 volumeSliderShownChanged: function(shown) { | |
| 160 this.showVolumeController_(shown); | |
| 161 }, | |
| 162 | |
| 163 /** | |
| 164 * Invoked when the focus goes out of the volume elements. | |
| 165 * @param {!UIEvent} event The focusout event. | |
| 166 * @private | |
| 167 */ | |
| 168 onVolumeControllerFocusout_: function(event) { | |
| 169 if (this.volumeSliderShown) { | |
| 170 // If the focus goes out of the volume, hide the volume control. | |
| 171 if (!event.relatedTarget || | |
| 172 (!this.$.volumeButton.contains(event.relatedTarget) && | |
| 173 !this.$.volumeSlider.contains(event.relatedTarget))) { | |
| 174 this.volumeSliderShown = false; | |
| 175 } | |
| 176 } | |
| 177 }, | |
| 178 | |
| 179 /** | |
| 180 * Shows/hides the volume controller. | |
| 181 * @param {boolean} show True to show the controller, false to hide. | |
| 182 * @private | |
| 183 */ | |
| 184 showVolumeController_: function(show) { | |
| 185 if (show) { | |
| 186 matchBottomLine(this.$.volumeContainer, this.$.volumeButton); | |
| 187 this.$.volumeContainer.style.visibility = 'visible'; | |
| 188 } else { | |
| 189 this.$.volumeContainer.style.visibility = 'hidden'; | |
| 190 } | |
| 191 }, | |
| 192 | |
| 193 /** | |
| 194 * Converts the time into human friendly string. | 131 * Converts the time into human friendly string. |
| 195 * @param {number} time Time to be converted. | 132 * @param {number} time Time to be converted. |
| 196 * @return {string} String representation of the given time | 133 * @return {string} String representation of the given time |
| 197 */ | 134 */ |
| 198 time2string_: function(time) { | 135 time2string_: function(time) { |
| 199 return ~~(time / 60000) + ':' + ('0' + ~~(time / 1000 % 60)).slice(-2); | 136 return ~~(time / 60000) + ':' + ('0' + ~~(time / 1000 % 60)).slice(-2); |
| 200 }, | 137 }, |
| 201 | 138 |
| 202 /** | 139 /** |
| 203 * Converts the time and duration into human friendly string. | 140 * Converts the time and duration into human friendly string. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 219 | 156 |
| 220 /** | 157 /** |
| 221 * Computes style for '.filled' element of progress bar. | 158 * Computes style for '.filled' element of progress bar. |
| 222 * @return {string} | 159 * @return {string} |
| 223 */ | 160 */ |
| 224 computeProgressBarStyle_: function(time, duration) { | 161 computeProgressBarStyle_: function(time, duration) { |
| 225 return 'width: ' + (time / duration * 100) + '%;'; | 162 return 'width: ' + (time / duration * 100) + '%;'; |
| 226 } | 163 } |
| 227 }); | 164 }); |
| 228 })(); // Anonymous closure | 165 })(); // Anonymous closure |
| OLD | NEW |