Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / file_manager / audio_player / elements / volume_controller.js
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.
4
5 (function() {
6   'use strict';
7
8   Polymer('volume-controller', {
9     /**
10      * Initializes an element. This method is called automatically when the
11      * element is ready.
12      */
13     ready: function() {
14       this.style.width = this.width + 'px';
15       this.style.height = this.height + 'px';
16
17       this.$.rawValueInput.style.width = this.height + 'px';
18       this.$.rawValueInput.style.height = this.width + 'px';
19       this.$.rawValueInput.style.webkitTransformOrigin =
20           (this.width / 2) + 'px ' +
21           (this.width / 2 - 2) + 'px';
22
23       var barLeft = (this.width / 2 - 1);
24       this.$.bar.style.left = barLeft + 'px';
25       this.$.bar.style.right = barLeft + 'px';
26     },
27
28     /**
29      * Registers handlers for changing of external variables
30      */
31     observe: {
32       'model.volume': 'onVolumeChanged',
33     },
34
35     /**
36      * Model object of the Audio Player.
37      * @type {AudioPlayerModel}
38      */
39     model: null,
40
41     /**
42      * Invoked when the model changed.
43      * @param {AudioPlayerModel} oldValue Old Value.
44      * @param {AudioPlayerModel} newValue Nld Value.
45      */
46     modelChanged: function(oldValue, newValue) {
47       this.onVolumeChanged((oldValue || {}).volume, (newValue || {}).volume);
48     },
49
50     /**
51      * Volume. 0 is silent, and 100 is maximum.
52      * @type {number}
53      */
54     value: 50,
55
56     /**
57      * Volume. 1000 is silent, and 0 is maximum.
58      * @type {number}
59      */
60     rawValue: 0,
61
62     /**
63      * Height of the element in pixels. Must be specified before ready() is
64      * called. Dynamic change is not supprted.
65      * @type {number}
66      */
67     height: 100,
68
69     /**
70      * Width of the element in pixels. Must be specified before ready() is
71      * called. Dynamic change is not supported.
72      * @type {number}
73      */
74     width: 32,
75
76     /**
77      * Invoked the 'volume' value in the model is changed.
78      * @param {number} oldValue Old value.
79      * @param {number} newValue New value.
80      */
81     onVolumeChanged: function(oldValue, newValue) {
82       if (oldValue != newValue)
83         this.rawValue = 100 - newValue;
84     },
85
86     /**
87      * Invoked the 'rawValue' property is changed.
88      * @param {number} oldValue Old value.
89      * @param {number} newValue New value.
90      */
91     rawValueChanged: function(oldValue, newValue) {
92       if (oldValue != newValue)
93         this.model.volume = 100 - newValue;
94     },
95   });
96 })();  // Anonymous closure