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 * The width and height of a bar drawn on a file canvas in pixels. | |
10 */ | |
11 var BAR_WIDTH = 500; | |
12 var BAR_HEIGHT = 15; | |
13 | |
14 /** | |
15 * Draws a 1px white horizontal line across |context|. | |
16 */ | |
17 function drawLine(context, top) { | |
18 context.moveTo(0, top); | |
19 context.lineTo(BAR_WIDTH, top); | |
20 context.strokeStyle = '#fff'; | |
21 context.stroke(); | |
22 } | |
23 | |
24 /** | |
25 * Creates an HTMLElement of type |type| with textContent |content|. | |
26 * @param {string} type The type of element to create. | |
27 * @param {string} content The content to place in the element. | |
28 * @return {HTMLElement} A newly initialized element. | |
29 */ | |
30 function makeElement(type, content) { | |
31 var element = document.createElement(type); | |
32 element.textContent = content; | |
33 return element; | |
34 } | |
35 | |
36 /** | |
37 * Creates a new <li> containing a <details> with a <summary> and sets | |
38 * properties to reference them. | |
39 * @return {Object} The new <li>. | |
40 */ | |
41 function createDetailsLi() { | |
42 var li = document.createElement('li'); | |
43 li.details = document.createElement('details'); | |
44 li.summary = document.createElement('summary'); | |
45 li.appendChild(li.details); | |
46 li.details.appendChild(li.summary); | |
47 return li | |
48 } | |
49 | |
50 /** | |
51 * Prints each key-value pair in a dictionary to a row in a table. | |
52 * @param {Object} dict The dictionary to print. | |
53 * @param {HTMLElement} table The <table> element to print to. | |
54 */ | |
55 function printDictionaryToTable(dict, table) { | |
arv (Not doing code reviews)
2011/10/18 20:50:07
Please rename. print is not the right word here
scherkus (not reviewing)
2011/10/19 00:19:43
s/print/append
| |
56 table.textContent = ''; | |
57 for (var key in dict) { | |
58 var tr = document.createElement('tr'); | |
59 tr.appendChild(makeElement('td', key + ':')); | |
60 tr.appendChild(makeElement('td', dict[key])); | |
61 table.appendChild(tr); | |
62 } | |
63 return table; | |
64 } | |
65 | |
66 /** | |
67 * Rounds a number, leaving the specified number of digits after the decimal, | |
68 * defaulting to 1. | |
69 * @param {number} n The number to be rounded. | |
70 * @param {number} digits The number of digits to leave after the decimal. | |
71 * @return {number} |n| rounded to |digits| decimal places. | |
72 */ | |
73 function round(n, digits) { | |
arv (Not doing code reviews)
2011/10/18 20:50:07
Can you use toFixed instead?
scherkus (not reviewing)
2011/10/19 00:19:43
Done.
| |
74 digits = digits || 1; | |
75 var factor = Math.pow(10, digits); | |
76 return Math.round(n * factor) / factor; | |
77 } | |
78 | |
79 return { | |
80 BAR_WIDTH: BAR_WIDTH, | |
81 BAR_HEIGHT: BAR_HEIGHT, | |
82 drawLine: drawLine, | |
83 makeElement: makeElement, | |
84 createDetailsLi: createDetailsLi, | |
85 printDictionaryToTable: printDictionaryToTable, | |
86 round: round, | |
87 }; | |
88 }); | |
OLD | NEW |