Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / ui / file_manager / audio_player / elements / control_panel.js
blob94c6db1d615cf9605dec15bc243e4da7669c4084
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
3 // found in the LICENSE file.
5 (function() {
6 'use strict';
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.
14 function matchBottomLine(target, anchor) {
15 var targetRect = target.getBoundingClientRect();
16 var anchorRect = anchor.getBoundingClientRect();
18 var pos = {
19 left: anchorRect.left + anchorRect.width / 2 - targetRect.width / 2,
20 bottom: window.innerHeight - anchorRect.bottom,
23 target.style.position = 'fixed';
24 target.style.left = pos.left + 'px';
25 target.style.bottom = pos.bottom + 'px';
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
33 function time2string(time) {
34 return ~~(time / 60000) + ':' + ('0' + ~~(time / 1000 % 60)).slice(-2);
37 Polymer('control-panel', {
38 /**
39 * Initializes an element. This method is called automatically when the
40 * element is ready.
42 ready: function() {
43 var onFocusoutBound = this.onVolumeControllerFocusout_.bind(this);
44 this.$.volumeSlider.addEventListener('focusout', onFocusoutBound);
45 this.$.volumeButton.addEventListener('focusout', onFocusoutBound);
48 /**
49 * Model object of the Audio Player.
50 * @type {AudioPlayerModel}
52 model: null,
54 /**
55 * Invoked when the model changed.
56 * @param {AudioPlayerModel} oldValue Old Value.
57 * @param {AudioPlayerModel} newValue New Value.
59 modelChanged: function(oldValue, newValue) {
60 this.$.volumeSlider.model = newValue;
63 /**
64 * Current elapsed time in the current music in millisecond.
65 * @type {number}
67 time: 0,
69 /**
70 * String representation of 'time'.
71 * @type {number}
72 * @private
74 get timeString_() {
75 return time2string(this.time);
78 /**
79 * Total length of the current music in millisecond.
80 * @type {number}
82 duration: 0,
84 /**
85 * String representation of 'duration'.
86 * @type {string}
87 * @private
89 get durationString_() {
90 return time2string(this.duration);
93 /**
94 * Flag whether the volume slider is expanded or not.
95 * @type {boolean}
97 volumeSliderShown: false,
99 /**
100 * Flag whether the audio is playing or paused. True if playing, or false
101 * paused.
102 * @type {boolean}
104 playing: false,
107 * Invoked when the 'duration' property is changed.
108 * @param {number} oldValue old value.
109 * @param {number} newValue new value.
111 durationChanged: function(oldValue, newValue) {
112 // Reset the current playback position.
113 this.time = 0;
117 * Invoked when the next button is clicked.
119 nextClick: function() {
120 this.fire('next-clicked');
124 * Invoked when the play button is clicked.
126 playClick: function() {
127 this.playing = !this.playing;
131 * Invoked when the previous button is clicked.
133 previousClick: function() {
134 this.fire('previous-clicked');
138 * Invoked the volume button is clicked.
139 * @type {Event} event The event.
141 volumeButtonClick: function(event) {
142 this.showVolumeController_(this.volumeSliderShown);
143 event.stopPropagation();
147 * Invoked when the focus goes out of the volume elements.
148 * @param {FocusEvent} event The focusout event.
149 * @private
151 onVolumeControllerFocusout_: function(event) {
152 if (this.volumeSliderShown) {
153 // If the focus goes out of the volume, hide the volume control.
154 if (!event.relatedTarget ||
155 (event.relatedTarget !== this.$.volumeButton &&
156 event.relatedTarget !== this.$.volumeSlider)) {
157 this.showVolumeController_(false);
158 this.volumeSliderShown = false;
164 * Shows/hides the volume controller.
165 * @param {boolean} show True to show the controller, false to hide.
166 * @private
168 showVolumeController_: function(show) {
169 if (show) {
170 matchBottomLine(this.$.volumeContainer, this.$.volumeButton);
171 this.$.volumeContainer.style.visibility = 'visible';
172 } else {
173 this.$.volumeContainer.style.visibility = 'hidden';
177 })(); // Anonymous closure