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.
10 * @extends {PolymerElement}
12 var VolumeControllerElement = function() {};
14 VolumeControllerElement.prototype = {
16 * Initializes an element. This method is called automatically when the
20 this.style.width = this.width + 'px';
21 this.style.height = this.height + 'px';
23 this.rawValueInput = this.$.rawValueInput;
24 this.bar = this.$.bar;
26 this.rawValueInput.style.width = this.height + 'px';
27 this.rawValueInput.style.height = this.width + 'px';
28 this.rawValueInput.style.webkitTransformOrigin =
29 (this.width / 2) + 'px ' +
30 (this.width / 2 - 2) + 'px';
32 var barLeft = (this.width / 2 - 1);
33 this.bar.style.left = barLeft + 'px';
34 this.bar.style.right = barLeft + 'px';
36 this.addEventListener('keydown', this.onKeyDown_.bind(this));
40 * Registers handlers for changing of external variables
43 'model.volume': 'onVolumeChanged',
47 * Model object of the Audio Player.
48 * @type {AudioPlayerModel}
53 * Invoked when the model changed.
54 * @param {AudioPlayerModel} oldValue Old Value.
55 * @param {AudioPlayerModel} newValue New Value.
57 modelChanged: function(oldValue, newValue) {
58 this.onVolumeChanged((oldValue || {}).volume, (newValue || {}).volume);
62 * Volume. 0 is silent, and 100 is maximum.
68 * Volume. 1000 is silent, and 0 is maximum.
74 * Height of the element in pixels. Must be specified before ready() is
75 * called. Dynamic change is not supported.
81 * Width of the element in pixels. Must be specified before ready() is
82 * called. Dynamic change is not supported.
88 * Invoked when the 'volume' value in the model is changed.
89 * @param {number} oldValue Old value.
90 * @param {number} newValue New value.
92 onVolumeChanged: function(oldValue, newValue) {
93 if (oldValue != newValue)
94 this.rawValue = 100 - newValue;
98 * Invoked when the 'rawValue' property is changed.
99 * @param {number} oldValue Old value.
100 * @param {number} newValue New value.
102 rawValueChanged: function(oldValue, newValue) {
103 if (oldValue != newValue)
104 this.model.volume = 100 - newValue;
108 * Invoked when the 'keydown' event is fired.
109 * @param {Event} event The event object.
111 onKeyDown_: function(event) {
112 switch (event.keyIdentifier) {
113 // Prevents the default behavior. These key should be handled in
114 // <audio-player> element.
119 event.preventDefault();
125 Polymer('volume-controller', VolumeControllerElement.prototype);
126 })(); // Anonymous closure