OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 holds a list of MediaLogEvents. | |
10 * It inherits from <li> and contains a tabular list of said events, | |
11 * the time at which they occurred, and their parameters. | |
12 */ | |
13 var EventList = cr.ui.define('li'); | |
14 | |
15 EventList.prototype = { | |
16 __proto__: HTMLLIElement.prototype, | |
17 startTime_: null, | |
18 | |
19 /** | |
20 * Decorate this list item as an EventList. | |
21 */ | |
22 decorate: function() { | |
23 this.table_ = document.createElement('table'); | |
24 var details = document.createElement('details'); | |
25 var summary = media.makeElement('summary', 'Log:'); | |
26 details.appendChild(summary); | |
27 details.appendChild(this.table_); | |
28 this.appendChild(details); | |
29 | |
30 var hRow = document.createElement('tr'); | |
31 hRow.appendChild(media.makeElement('th', 'Time:')); | |
32 hRow.appendChild(media.makeElement('th', 'Event:')); | |
33 hRow.appendChild(media.makeElement('th', 'Parameters:')); | |
34 var header = document.createElement('thead'); | |
35 header.appendChild(hRow); | |
36 this.table_.appendChild(header); | |
37 }, | |
38 | |
39 /** | |
40 * Add an event to the list. It is stored as a new row in this.table_. | |
41 * @param {Object} event The MediaLogEvent that has occurred. | |
42 */ | |
43 addEvent: function(event) { | |
44 this.startTime_ = this.startTime_ || event.ticksMillis; | |
45 var normalizedTicksMillis = event.ticksMillis - this.startTime_; | |
46 | |
47 var row = document.createElement('tr'); | |
48 row.appendChild(media.makeElement( | |
49 'td', normalizedTicksMillis.toFixed(1))); | |
50 row.appendChild(media.makeElement('td', event.type)); | |
51 var params = []; | |
52 for (var key in event.params) { | |
53 params.push(key + ': ' + event.params[key]); | |
54 } | |
55 | |
56 row.appendChild(media.makeElement('td', params.join(', '))); | |
57 this.table_.appendChild(row); | |
58 } | |
59 }; | |
60 | |
61 return { | |
62 EventList: EventList | |
63 }; | |
64 }); | |
OLD | NEW |