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

Side by Side Diff: content/browser/resources/media/client_renderer.js

Issue 68173025: Introduce new interface for MediaInternals updates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add JavaScript. Created 7 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 var ClientRenderer = (function() { 5 var ClientRenderer = (function() {
6 var ClientRenderer = function() { 6 var ClientRenderer = function() {
7 this.playerListElement = document.getElementById('player-list'); 7 this.playerListElement = document.getElementById('player-list');
8 this.audioStreamListElement = document.getElementById('audio-stream-list'); 8 this.propertiesTable =
9 this.propertiesTable = document.getElementById('property-table'); 9 document.getElementById('property-table').querySelector('tbody');
10 this.logTable = document.getElementById('log'); 10 this.logTable = document.getElementById('log').querySelector('tbody');
11 this.graphElement = document.getElementById('graphs'); 11 this.graphElement = document.getElementById('graphs');
12 12
13 this.selectedPlayer = null; 13 this.selectedPlayer = null;
14 this.selectedStream = null; 14 this.selectedAudioComponentType = null;
15 this.selectedAudioComponentId = null;
16 this.selectedAudioCompontentData = null;
15 17
16 this.selectedPlayerLogIndex = 0; 18 this.selectedPlayerLogIndex = 0;
17 19
18 this.filterFunction = function() { return true; }; 20 this.filterFunction = function() { return true; };
19 this.filterText = document.getElementById('filter-text'); 21 this.filterText = document.getElementById('filter-text');
20 this.filterText.onkeyup = this.onTextChange_.bind(this); 22 this.filterText.onkeyup = this.onTextChange_.bind(this);
21 23
22 this.bufferCanvas = document.createElement('canvas'); 24 this.bufferCanvas = document.createElement('canvas');
23 this.bufferCanvas.width = media.BAR_WIDTH; 25 this.bufferCanvas.width = media.BAR_WIDTH;
24 this.bufferCanvas.height = media.BAR_HEIGHT; 26 this.bufferCanvas.height = media.BAR_HEIGHT;
25 27
26 this.clipboardTextarea = document.getElementById('clipboard-textarea'); 28 this.clipboardTextarea = document.getElementById('clipboard-textarea');
27 this.clipboardButton = document.getElementById('copy-button'); 29 this.clipboardButton = document.getElementById('copy-button');
28 this.clipboardButton.onclick = this.copyToClipboard_.bind(this); 30 this.clipboardButton.onclick = this.copyToClipboard_.bind(this);
31
32 this.hiddenKeys = ['component_id', 'component_type', 'owner_id'];
29 }; 33 };
30 34
31 function removeChildren(element) { 35 function removeChildren(element) {
32 while (element.hasChildNodes()) { 36 while (element.hasChildNodes()) {
33 element.removeChild(element.lastChild); 37 element.removeChild(element.lastChild);
34 } 38 }
35 }; 39 };
36 40
37 function createButton(text, select_cb) { 41 function createButton(text, select_cb) {
38 var button = document.createElement('button'); 42 var button = document.createElement('button');
39 43
40 button.appendChild(document.createTextNode(text)); 44 button.appendChild(document.createTextNode(text));
41 button.onclick = function() { 45 button.onclick = function() {
42 select_cb(); 46 select_cb();
43 }; 47 };
44 48
45 return button; 49 return button;
46 }; 50 };
47 51
48 ClientRenderer.prototype = { 52 ClientRenderer.prototype = {
49 audioStreamAdded: function(audioStreams, audioStreamAdded) { 53 /**
50 this.redrawAudioStreamList_(audioStreams); 54 * Called when an audio component is added to the collection.
51 }, 55 * @param componentType Integer AudioComponent enum value; must match values
56 * from the AudioLogFactory::AudioComponent enum.
57 * @param components The entire map of components (name -> dict).
58 */
59 audioComponentAdded: function(componentType, components) {
60 this.redrawAudioComponentList_(componentType, components);
52 61
53 audioStreamUpdated: function(audioStreams, stream, key, value) { 62 // Redraw the component if it's currently selected.
54 if (stream === this.selectedStream) { 63 if (this.selectedAudioComponentType == componentType &&
55 this.drawProperties_(stream); 64 this.selectedAudioComponentId &&
65 this.selectedAudioComponentId in components) {
66 this.selectAudioComponent_(
67 componentType, this.selectedAudioComponentId,
68 components[this.selectedAudioComponentId]);
56 } 69 }
57 }, 70 },
58 71
59 audioStreamRemoved: function(audioStreams, audioStreamRemoved) { 72 /**
60 this.redrawAudioStreamList_(audioStreams); 73 * Called when an audio component is removed from the collection.
74 * @param componentType Integer AudioComponent enum value; must match values
75 * from the AudioLogFactory::AudioComponent enum.
76 * @param components The entire map of components (name -> dict).
77 */
78 audioComponentRemoved: function(componentType, components) {
79 this.redrawAudioComponentList_(componentType, components);
80
81 // Clear the component if it was previously currently selected.
82 if (this.selectedAudioComponentType == componentType &&
83 !(this.selectedAudioComponentId in components)) {
84 this.selectAudioComponent_(null, null, {});
85 }
61 }, 86 },
62 87
63 /** 88 /**
64 * Called when a player is added to the collection. 89 * Called when a player is added to the collection.
65 * @param players The entire map of id -> player. 90 * @param players The entire map of id -> player.
66 * @param player_added The player that is added. 91 * @param player_added The player that is added.
67 */ 92 */
68 playerAdded: function(players, playerAdded) { 93 playerAdded: function(players, playerAdded) {
69 this.redrawPlayerList_(players); 94 this.redrawPlayerList_(players);
70 }, 95 },
(...skipping 18 matching lines...) Expand all
89 if (player === this.selectedPlayer) { 114 if (player === this.selectedPlayer) {
90 this.drawProperties_(player.properties); 115 this.drawProperties_(player.properties);
91 this.drawLog_(); 116 this.drawLog_();
92 this.drawGraphs_(); 117 this.drawGraphs_();
93 } 118 }
94 if (key === 'name' || key === 'url') { 119 if (key === 'name' || key === 'url') {
95 this.redrawPlayerList_(players); 120 this.redrawPlayerList_(players);
96 } 121 }
97 }, 122 },
98 123
99 redrawAudioStreamList_: function(streams) { 124 redrawAudioComponentList_: function(componentType, components) {
100 removeChildren(this.audioStreamListElement); 125 function redrawList(renderer, baseName, element) {
126 removeChildren(element);
127 for (id in components) {
acolwell GONE FROM CHROMIUM 2013/11/26 01:33:17 If this can get large, you might consider using a
DaleCurtis 2013/11/26 03:02:21 Done.
128 var li = document.createElement('li');
129 li.appendChild(createButton(
130 baseName + ' ' + id, renderer.selectAudioComponent_.bind(
131 renderer, componentType, id, components[id])));
132 element.appendChild(li);
133 }
134 }
101 135
102 for (id in streams) { 136 switch (componentType) {
103 var li = document.createElement('li'); 137 case 0:
104 li.appendChild(createButton( 138 redrawList(this, 'Controller', document.getElementById(
105 id, this.selectAudioStream_.bind(this, streams[id]))); 139 'audio-input-controller-list'));
106 this.audioStreamListElement.appendChild(li); 140 break;
141 case 1:
142 redrawList(this, 'Controller', document.getElementById(
143 'audio-output-controller-list'));
144 break;
145 case 2:
146 redrawList(this, 'Stream', document.getElementById(
147 'audio-output-stream-list'));
148 break;
149 default:
150 break;
107 } 151 }
108 }, 152 },
109 153
110 selectAudioStream_: function(audioStream) { 154 selectAudioComponent_: function(componentType, componentId, componentData) {
111 this.selectedStream = audioStream;
112 this.selectedPlayer = null; 155 this.selectedPlayer = null;
113 this.drawProperties_(audioStream); 156 this.selectedAudioComponentType = componentType;
114 removeChildren(this.logTable.querySelector('tbody')); 157 this.selectedAudioComponentId = componentId;
158 this.selectedAudioCompontentData = componentData;
159 this.drawProperties_(componentData);
160 removeChildren(this.logTable);
115 removeChildren(this.graphElement); 161 removeChildren(this.graphElement);
116 }, 162 },
117 163
118 redrawPlayerList_: function(players) { 164 redrawPlayerList_: function(players) {
119 removeChildren(this.playerListElement); 165 removeChildren(this.playerListElement);
120 166
121 for (id in players) { 167 for (id in players) {
122 var li = document.createElement('li'); 168 var li = document.createElement('li');
123 var player = players[id]; 169 var player = players[id];
124 var usableName = player.properties.name || 170 var usableName = player.properties.name ||
125 player.properties.url || 171 player.properties.url ||
126 'player ' + player.id; 172 'Player ' + player.id;
127 173
128 li.appendChild(createButton( 174 li.appendChild(createButton(
129 usableName, this.selectPlayer_.bind(this, player))); 175 usableName, this.selectPlayer_.bind(this, player)));
130 this.playerListElement.appendChild(li); 176 this.playerListElement.appendChild(li);
131 } 177 }
132 }, 178 },
133 179
134 selectPlayer_: function(player) { 180 selectPlayer_: function(player) {
135 this.selectedPlayer = player; 181 this.selectedPlayer = player;
136 this.selectedPlayerLogIndex = 0; 182 this.selectedPlayerLogIndex = 0;
137 this.selectedStream = null; 183 this.selectedAudioComponentType = null;
184 this.selectedAudioComponentId = null;
185 this.selectedAudioCompontentData = null;
138 this.drawProperties_(player.properties); 186 this.drawProperties_(player.properties);
139 187
140 removeChildren(this.logTable.querySelector('tbody')); 188 removeChildren(this.logTable);
141 removeChildren(this.graphElement); 189 removeChildren(this.graphElement);
142 this.drawLog_(); 190 this.drawLog_();
143 this.drawGraphs_(); 191 this.drawGraphs_();
144 }, 192 },
145 193
146 drawProperties_: function(propertyMap) { 194 drawProperties_: function(propertyMap) {
147 removeChildren(this.propertiesTable); 195 removeChildren(this.propertiesTable);
148
149 var sortedKeys = Object.keys(propertyMap).sort(); 196 var sortedKeys = Object.keys(propertyMap).sort();
150 for (var i = 0; i < sortedKeys.length; ++i) { 197 for (var i = 0; i < sortedKeys.length; ++i) {
151 var key = sortedKeys[i]; 198 var key = sortedKeys[i];
199 if (this.hiddenKeys.indexOf(key) >= 0)
200 continue;
201
152 var value = propertyMap[key]; 202 var value = propertyMap[key];
153
154 var row = this.propertiesTable.insertRow(-1); 203 var row = this.propertiesTable.insertRow(-1);
155 var keyCell = row.insertCell(-1); 204 var keyCell = row.insertCell(-1);
156 var valueCell = row.insertCell(-1); 205 var valueCell = row.insertCell(-1);
157 206
158 keyCell.appendChild(document.createTextNode(key)); 207 keyCell.appendChild(document.createTextNode(key));
159 valueCell.appendChild(document.createTextNode(value)); 208 valueCell.appendChild(document.createTextNode(value));
160 } 209 }
161 }, 210 },
162 211
163 appendEventToLog_: function(event) { 212 appendEventToLog_: function(event) {
164 if (this.filterFunction(event.key)) { 213 if (this.filterFunction(event.key)) {
165 var row = this.logTable.querySelector('tbody').insertRow(-1); 214 var row = this.logTable.insertRow(-1);
166 215
167 row.insertCell(-1).appendChild(document.createTextNode( 216 row.insertCell(-1).appendChild(document.createTextNode(
168 util.millisecondsToString(event.time))); 217 util.millisecondsToString(event.time)));
169 row.insertCell(-1).appendChild(document.createTextNode(event.key)); 218 row.insertCell(-1).appendChild(document.createTextNode(event.key));
170 row.insertCell(-1).appendChild(document.createTextNode(event.value)); 219 row.insertCell(-1).appendChild(document.createTextNode(event.value));
171 } 220 }
172 }, 221 },
173 222
174 drawLog_: function() { 223 drawLog_: function() {
175 var toDraw = this.selectedPlayer.allEvents.slice( 224 var toDraw = this.selectedPlayer.allEvents.slice(
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 var middle = current * scale_factor; 291 var middle = current * scale_factor;
243 var right = end * scale_factor; 292 var right = end * scale_factor;
244 293
245 ctx.fillStyle = '#a0a'; 294 ctx.fillStyle = '#a0a';
246 ctx.fillRect(left, 0, middle - left, height); 295 ctx.fillRect(left, 0, middle - left, height);
247 ctx.fillStyle = '#aa0'; 296 ctx.fillStyle = '#aa0';
248 ctx.fillRect(middle, 0, right - middle, height); 297 ctx.fillRect(middle, 0, right - middle, height);
249 }, 298 },
250 299
251 copyToClipboard_: function() { 300 copyToClipboard_: function() {
252 var properties = this.selectedStream || 301 var properties = this.selectedAudioCompontentData ||
253 this.selectedPlayer.properties || false; 302 this.selectedPlayer.properties || false;
254 if (!properties) { 303 if (!properties) {
255 return; 304 return;
256 } 305 }
257 var stringBuffer = []; 306 var stringBuffer = [];
258 307
259 for (var key in properties) { 308 for (var key in properties) {
260 var value = properties[key]; 309 var value = properties[key];
261 stringBuffer.push(key.toString()); 310 stringBuffer.push(key.toString());
262 stringBuffer.push(': '); 311 stringBuffer.push(': ');
263 stringBuffer.push(value.toString()); 312 stringBuffer.push(value.toString());
264 stringBuffer.push('\n'); 313 stringBuffer.push('\n');
265 } 314 }
266 315
267 this.clipboardTextarea.value = stringBuffer.join(''); 316 this.clipboardTextarea.value = stringBuffer.join('');
268 this.clipboardTextarea.classList.remove('hidden'); 317 this.clipboardTextarea.classList.remove('hiddenClipboard');
269 this.clipboardTextarea.focus(); 318 this.clipboardTextarea.focus();
270 this.clipboardTextarea.select(); 319 this.clipboardTextarea.select();
271 320
272 // The act of copying anything from the textarea gets canceled 321 // Hide the clipboard element when it loses focus.
273 // if the element in question gets the class 'hidden' (which contains the 322 this.clipboardTextarea.onblur = function(event) {
274 // css property display:none) before the event is finished. For this, it
275 // is necessary put the property setting on the event loop to be executed
276 // after the copy has taken place.
277 this.clipboardTextarea.oncopy = function(event) {
278 setTimeout(function(element) { 323 setTimeout(function(element) {
279 event.target.classList.add('hidden'); 324 event.target.classList.add('hiddenClipboard');
280 }, 0); 325 }, 0);
281 }; 326 };
282 }, 327 },
283 328
284 onTextChange_: function(event) { 329 onTextChange_: function(event) {
285 var text = this.filterText.value.toLowerCase(); 330 var text = this.filterText.value.toLowerCase();
286 var parts = text.split(',').map(function(part) { 331 var parts = text.split(',').map(function(part) {
287 return part.trim(); 332 return part.trim();
288 }).filter(function(part) { 333 }).filter(function(part) {
289 return part.trim().length > 0; 334 return part.trim().length > 0;
290 }); 335 });
291 336
292 this.filterFunction = function(text) { 337 this.filterFunction = function(text) {
293 text = text.toLowerCase(); 338 text = text.toLowerCase();
294 return parts.length === 0 || parts.some(function(part) { 339 return parts.length === 0 || parts.some(function(part) {
295 return text.indexOf(part) != -1; 340 return text.indexOf(part) != -1;
296 }); 341 });
297 }; 342 };
298 343
299 if (this.selectedPlayer) { 344 if (this.selectedPlayer) {
300 removeChildren(this.logTable.querySelector('tbody')); 345 removeChildren(this.logTable);
301 this.selectedPlayerLogIndex = 0; 346 this.selectedPlayerLogIndex = 0;
302 this.drawLog_(); 347 this.drawLog_();
303 } 348 }
304 }, 349 },
305 }; 350 };
306 351
307 return ClientRenderer; 352 return ClientRenderer;
308 })(); 353 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698