Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: ui/file_manager/audio_player/elements/volume_controller.js

Issue 1176483002: AudioPlayer.app: Migrate to Polymer 1.0. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 * @constructor 9 * @constructor
10 * @extends {PolymerElement} 10 * @extends {PolymerElement}
11 */ 11 */
12 var VolumeControllerElement = function() {}; 12 var VolumeControllerElement = function() {};
13 13
14 VolumeControllerElement.prototype = { 14 VolumeControllerElement.prototype = {
15 is: 'volume-controller',
16
17 properties: {
18 /**
19 * Width of the element in pixels. Must be specified before ready() is
20 * called. Dynamic change is not supported.
21 * @type {number}
22 */
23 width: {
24 type: Number,
25 value: 32
26 },
27
28 /**
29 * Height of the element in pixels. Must be specified before ready() is
30 * called. Dynamic change is not supported.
31 * @type {number}
32 */
33 height: {
34 type: Number,
35 },
36
37 /**
38 * Volume. 0 is silent, and 100 is maximum.
39 * @type {number}
40 */
41 value: {
42 type: Number,
43 value: 50,
44 observer: 'valueChanged',
45 notify: true
46 },
47
48 /**
49 * Volume. 100 is silent, and 0 is maximum.
50 * @type {number}
51 */
52 rawValue: {
53 type: Number,
54 observer: 'rawValueChanged',
55 notify: true
56 }
57 },
58
15 /** 59 /**
16 * Initializes an element. This method is called automatically when the 60 * Initializes an element. This method is called automatically when the
17 * element is ready. 61 * element is ready.
18 */ 62 */
19 ready: function() { 63 ready: function() {
20 this.style.width = this.width + 'px'; 64 this.style.width = this.width + 'px';
21 this.style.height = this.height + 'px'; 65 this.style.height = this.height + 'px';
22 66
23 this.rawValueInput = this.$.rawValueInput; 67 this.rawValueInput = this.$.rawValueInput;
24 this.bar = this.$.bar; 68 this.bar = this.$.bar;
25 69
26 this.rawValueInput.style.width = this.height + 'px'; 70 this.rawValueInput.style.width = this.height + 'px';
27 this.rawValueInput.style.height = this.width + 'px'; 71 this.rawValueInput.style.height = this.width + 'px';
28 this.rawValueInput.style.webkitTransformOrigin = 72 this.rawValueInput.style.webkitTransformOrigin =
29 (this.width / 2) + 'px ' + 73 (this.width / 2) + 'px ' +
30 (this.width / 2 - 2) + 'px'; 74 (this.width / 2 - 2) + 'px';
31 75
32 var barLeft = (this.width / 2 - 1); 76 var barLeft = (this.width / 2 - 1);
33 this.bar.style.left = barLeft + 'px'; 77 this.bar.style.left = barLeft + 'px';
34 this.bar.style.right = barLeft + 'px'; 78 this.bar.style.right = barLeft + 'px';
35 79
36 this.addEventListener('keydown', this.onKeyDown_.bind(this)); 80 this.addEventListener('keydown', this.onKeyDown_.bind(this));
37 }, 81 },
38 82
39 /** 83 /**
40 * Registers handlers for changing of external variables 84 * Invoked when the 'volume' value is changed.
85 * @param {number} newValue New value.
86 * @param {number} oldValue Old value.
41 */ 87 */
42 observe: { 88 valueChanged: function(newValue, oldValue) {
43 'model.volume': 'onVolumeChanged',
44 },
45
46 /**
47 * Model object of the Audio Player.
48 * @type {AudioPlayerModel}
49 */
50 model: null,
51
52 /**
53 * Invoked when the model changed.
54 * @param {AudioPlayerModel} oldValue Old Value.
55 * @param {AudioPlayerModel} newValue New Value.
56 */
57 modelChanged: function(oldValue, newValue) {
58 this.onVolumeChanged((oldValue || {}).volume, (newValue || {}).volume);
59 },
60
61 /**
62 * Volume. 0 is silent, and 100 is maximum.
63 * @type {number}
64 */
65 value: 50,
66
67 /**
68 * Volume. 1000 is silent, and 0 is maximum.
69 * @type {number}
70 */
71 rawValue: 0,
72
73 /**
74 * Height of the element in pixels. Must be specified before ready() is
75 * called. Dynamic change is not supported.
76 * @type {number}
77 */
78 height: 100,
79
80 /**
81 * Width of the element in pixels. Must be specified before ready() is
82 * called. Dynamic change is not supported.
83 * @type {number}
84 */
85 width: 32,
86
87 /**
88 * Invoked when the 'volume' value in the model is changed.
89 * @param {number} oldValue Old value.
90 * @param {number} newValue New value.
91 */
92 onVolumeChanged: function(oldValue, newValue) {
93 if (oldValue != newValue) 89 if (oldValue != newValue)
94 this.rawValue = 100 - newValue; 90 this.rawValue = 100 - newValue;
95 }, 91 },
96 92
97 /** 93 /**
98 * Invoked when the 'rawValue' property is changed. 94 * Invoked when the 'rawValue' property is changed.
95 * @param {number} newValue New value.
99 * @param {number} oldValue Old value. 96 * @param {number} oldValue Old value.
100 * @param {number} newValue New value.
101 */ 97 */
102 rawValueChanged: function(oldValue, newValue) { 98 rawValueChanged: function(newValue, oldValue) {
103 if (oldValue != newValue) 99 if (oldValue != newValue)
yawano 2015/06/10 05:47:48 very small nit: !==
fukino 2015/06/10 06:24:03 Done.
104 this.model.volume = 100 - newValue; 100 this.value = 100 - newValue;
105 }, 101 },
106 102
107 /** 103 /**
108 * Invoked when the 'keydown' event is fired. 104 * Invoked when the 'keydown' event is fired.
109 * @param {Event} event The event object. 105 * @param {Event} event The event object.
110 */ 106 */
111 onKeyDown_: function(event) { 107 onKeyDown_: function(event) {
112 switch (event.keyIdentifier) { 108 switch (event.keyIdentifier) {
113 // Prevents the default behavior. These key should be handled in 109 // Prevents the default behavior. These key should be handled in
114 // <audio-player> element. 110 // <audio-player> element.
115 case 'Up': 111 case 'Up':
116 case 'Down': 112 case 'Down':
117 case 'PageUp': 113 case 'PageUp':
118 case 'PageDown': 114 case 'PageDown':
119 event.preventDefault(); 115 event.preventDefault();
120 break; 116 break;
121 } 117 }
122 }, 118 },
119
120 /**
121 * Computes style for '.filled' element based on raw value.
122 * @return {string}
123 */
124 computeFilledStyle_: function(rawValue) {
125 return 'height: ' + rawValue + '%;';
126 }
123 }; 127 };
124 128
125 Polymer('volume-controller', VolumeControllerElement.prototype); 129 Polymer(VolumeControllerElement.prototype);
126 })(); // Anonymous closure 130 })(); // Anonymous closure
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698