OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 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 cr.define('media', function() { | |
6 'use strict'; | |
7 | |
8 /** | |
9 * This class inherits from <li> and is designed to store and display | |
10 * information about an open media player. | |
11 */ | |
12 var MediaPlayer = cr.ui.define('li'); | |
13 | |
14 MediaPlayer.prototype = { | |
15 __proto__: HTMLLIElement.prototype, | |
16 renderer: null, | |
17 id: null, | |
18 | |
19 /** | |
20 * Decorate this <li> as a MediaPlayer. | |
21 */ | |
22 decorate: function() { | |
23 this.properties = {}; | |
24 | |
25 this.details_ = document.createElement('details'); | |
26 this.summary_ = document.createElement('summary'); | |
27 this.details_.open = true; | |
28 this.details_.appendChild(this.summary_); | |
29 | |
30 this.propertyTable_ = document.createElement('table'); | |
31 this.events_ = new media.EventList; | |
32 this.metrics_ = new media.Metrics; | |
33 | |
34 var properties = media.createDetailsLi(); | |
35 properties.summary.textContent = 'Properties:'; | |
36 properties.details.appendChild(this.propertyTable_); | |
37 | |
38 var ul = document.createElement('ul'); | |
39 ul.appendChild(properties); | |
40 ul.appendChild(this.metrics_); | |
41 ul.appendChild(this.events_); | |
42 this.details_.appendChild(ul); | |
43 | |
44 this.appendChild(this.details_); | |
45 document.getElementById('media-players').appendChild(this); | |
46 }, | |
47 | |
48 /** | |
49 * Record an event and update statistics etc. | |
50 * @param {Object} event The event that occurred. | |
51 */ | |
52 addEvent: function(event) { | |
53 for (var key in event.params) { | |
54 this.properties[key] = event.params[key]; | |
55 } | |
56 | |
57 if (event.type == 'BUFFERED_EXTENTS_CHANGED') | |
58 return; | |
59 this.events_.addEvent(event); | |
60 this.metrics_.addEvent(event); | |
61 }, | |
62 | |
63 /** | |
64 * Update the summary line and properties table and redraw the canvas. | |
65 * @return {HTMLElement} A <li> representing this MediaPlayer. | |
66 */ | |
67 redraw: function() { | |
68 media.printDictionaryToTable(this.properties, this.propertyTable_); | |
69 | |
70 this.setAttribute('status', this.properties.state); | |
71 this.summary_.textContent = ''; | |
72 this.summary_.appendChild(document.createTextNode( | |
73 this.id + ' (' + this.properties.url + '):')); | |
74 this.summary_.appendChild(document.createElement('br')); | |
75 | |
76 // Draw the state of BufferedResourceLoader. | |
77 var canvas = document.createElement('canvas'); | |
78 canvas.width = media.BAR_WIDTH; | |
79 canvas.height = 3 * media.BAR_HEIGHT + 2; | |
80 canvas.className = 'buffer-canvas'; | |
81 this.summary_.appendChild(canvas); | |
82 | |
83 var context = canvas.getContext('2d'); | |
84 context.textAlign = 'center'; | |
85 context.textBaseline = 'middle'; | |
86 context.fillStyle = '#aaa'; | |
87 context.fillRect(0, 0, canvas.width, canvas.height); | |
88 | |
89 var size = this.properties.total_bytes; | |
90 if (!size) { | |
91 context.fillStyle = '#fff'; | |
92 context.fillText('Unknown file size.', canvas.width / 2, | |
arv (Not doing code reviews)
2011/10/18 20:50:07
To me it always suspicious when fillText is used.
scherkus (not reviewing)
2011/10/19 00:19:43
such as a <div> of text w/ z-index:1 over top of t
arv (Not doing code reviews)
2011/10/19 20:30:21
Yeah, a <p> or something like that would make more
| |
93 canvas.height / 2); | |
94 return; | |
95 } | |
96 | |
97 var left = this.properties.buffer_start / size * canvas.width; | |
98 var middle = this.properties.buffer_current / size * canvas.width; | |
99 var right = this.properties.buffer_end / size * canvas.width; | |
100 context.fillStyle = '#a0a'; | |
101 context.fillRect(left, 0, middle - left, media.BAR_HEIGHT); | |
102 context.fillStyle = '#aa0'; | |
103 context.fillRect(middle, 0, right - middle, media.BAR_HEIGHT); | |
104 | |
105 media.drawLine(context, media.BAR_HEIGHT + 0.5); | |
106 | |
107 context.fillStyle = '#fff'; | |
108 context.fillText('Buffered by player.', canvas.width / 2, | |
109 media.BAR_HEIGHT / 2); | |
110 | |
111 if (!media.cacheEntriesByKey[this.properties.url]) { | |
112 context.fillText('No cache entry for this file.', canvas.width / 2, | |
113 2 * canvas.height / 3); | |
114 } else { | |
115 var cached = media.cacheEntriesByKey[this.properties.url].canvas; | |
116 var data = cached.getContext('2d').getImageData(0, 0, cached.width, | |
117 cached.height); | |
118 context.putImageData(data, 0, media.BAR_HEIGHT + 1); | |
119 } | |
120 }, | |
121 }; | |
122 | |
123 return { | |
124 MediaPlayer: MediaPlayer | |
125 }; | |
126 }); | |
OLD | NEW |