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

Side by Side Diff: content/browser/resources/media/util/tablegen.js

Issue 18889006: Removed old media-internals page and rewrote it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 5 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
(Empty)
1 /**
2 * @fileoverview Helper functions for generating tables
3 */
4
5 /**
6 * Given an array of strings (or anything that will be cast to a string)
7 * generate an HTML <tr> element that contains <td>s that contain an element
8 * in the array.
9 *
10 * Meant to be used with appendRow()
11 */
12 function genRow(arr) {
13 "use strict";
14
15 var tr = document.createElement('tr');
16
17 goog.array.forEach(arr, function (text) {
18 var td = document.createElement('td');
19 var textNode = document.createTextNode(text);
20 td.appendChild(textNode);
21 tr.appendChild(td);
22 });
23 return tr;
24 }
25
26 function genLogRow(logObj) {
27 "use strict";
28 var tr = document.createElement("tr");
29
30 // Unrolled for performance.
31 // This function gets called potentially thousands of times per second
32 var td1 = document.createElement('td');
33 var td2 = document.createElement('td');
34 var td3 = document.createElement('td');
35
36 var text1 = document.createTextNode(goog.time.millisToString(logObj.time));
37 var text2 = document.createTextNode(logObj.key);
38 var text3 = document.createTextNode(logObj.value);
39
40 td1.appendChild(text1);
41 td2.appendChild(text2);
42 td3.appendChild(text3);
43
44 tr.appendChild(td1);
45 tr.appendChild(td2);
46 tr.appendChild(td3);
47
48 return tr;
49 }
50
51 /**
52 * Creates an HTML <table> element that contains <thead>
53 * and <tbody> elements. If arguments are applied to this function,
54 * those arguments are inserted into the <thead> section.
55 */
56 function makeTable(headers) {
57 "use strict";
58
59 var table = document.createElement('table');
60
61 if (arguments.length > 0) {
62 var thead = document.createElement('thead');
63 var tr = document.createElement('tr');
64 thead.appendChild(tr);
65 table.appendChild(thead);
66
67 goog.array.forEach(arguments, function (arg) {
68 var td = document.createElement('td');
69 var text = document.createTextNode(arg);
70 td.appendChild(text);
71 tr.appendChild(td);
72 });
73 }
74
75 var tbody = document.createElement('tbody');
76 table.appendChild(tbody);
77 return table;
78 }
79
80 /**
81 * Adds a row to a table
82 */
83 function appendRow(table, row) {
84 "use strict";
85
86 // console.trace();
87 // throw "error";
88
89 // last child should be the <tbody>
90 table.lastChild.appendChild(row);
91 }
92
93 function removeChildren(element) {
94 "use strict";
95
96 // console.trace();
97 // throw "error";
98
99 while (element.hasChildNodes()) {
100 element.removeChild(element.lastChild);
101 }
102 }
103
104
105 /* If you are treating a table like it is a map where the first <td>
106 * is the name, and the remaining <td>s are properties of that object, then
107 * it might be useful to update that table.
108 */
109 function modRow(table, key, valueMult) {
110 "use strict";
111
112 // Since we can get multiple values as arguments, make a list of them.
113 // leaving off the first two args.
114 // Then reverse beause we pop them off in the opposite order.
115 var values = goog.array.toArray(arguments).splice(2).reverse();
116
117 var tbody = table.querySelector("tbody");
118 var rows = tbody.querySelectorAll("tr");
119
120 goog.array.forEach(rows, function (row) {
121 // We need to copy them because we are going to pop them out to
122 // populate the columns
123 var modValues = goog.array.toArray(values);
124 var firstColumn = row.querySelector("td");
125 if (firstColumn.textContent.trim() === key) {
126 var remainingColumns = goog.array.toArray(
127 row.querySelectorAll("td")).slice(1);
128 goog.array.forEach(remainingColumns, function (column) {
129 var replacement = modValues.pop();
130 // If the value is either null or undefined,
131 // don't update the text.
132 if (replacement) {
133 column.textContent = replacement;
134 }
135 });
136 }
137 });
138 }
OLDNEW
« content/browser/resources/media/util/goog.js ('K') | « content/browser/resources/media/util/goog.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698