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

Side by Side Diff: chrome/browser/resources/media_internals/util.js

Issue 7972028: Display active media players on chrome://media-internals. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: fixes Created 9 years, 3 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 | Annotate | Revision Log
OLDNEW
(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 // Maximum display length of a url in characters. Lengthy urls will be clipped
15 // and postfixed with an ellipsis.
16 var MAX_URL_LENGTH = 50;
17
18 /**
19 * Draws a 1px white horizontal line across |context|.
20 */
21 function drawLine(context, top) {
22 context.moveTo(0, top);
23 context.lineTo(BAR_WIDTH, top);
24 context.strokeStyle = '#fff';
25 context.stroke();
26 };
27
28 /**
29 * Creates an HTMLElement of type |type| with textContent |content|.
30 * @param {string} type The type of element to create.
31 * @param {string} content The content to place in the element.
32 * @return {HTMLElement} A newly initialized element.
33 */
34 function makeElement(type, content) {
35 var element = document.createElement(type);
36 element.textContent = content;
37 return element;
38 };
39
40 /**
41 * Creates a new <li> containing a <details> with a <summary> and sets
42 * properties to reference them.
43 * @return {Object} The new <li>.
44 */
45 function createDetailsLi() {
46 var li = document.createElement('li');
47 li.details = document.createElement('details');
48 li.summary = document.createElement('summary');
49 li.appendChild(li.details);
50 li.details.appendChild(li.summary);
51 return li
52 };
53
54 /**
55 * Prints each key-value pair in a dictionary to a row in a table.
56 * @param {Object} dict The dictionary to print.
57 * @param {HTMLElement} table The <table> element to print to.
58 */
59 function printDictionaryToTable(dict, table) {
60 table.textContent = '';
61 for (var key in dict) {
62 var tr = document.createElement('tr');
63 tr.appendChild(makeElement('td', key + ':'));
64 tr.appendChild(makeElement('td', dict[key]));
65 table.appendChild(tr);
66 }
67 return table;
68 };
69
70 /**
71 * Rounds a number, leaving the specified number of digits after the decimal,
72 * defaulting to 1.
73 * @param {number} n The number to be rounded.
74 * @param {int} digits The number of digits to leave after the decimal.
arv (Not doing code reviews) 2011/09/23 15:59:01 {number}
scherkus (not reviewing) 2011/09/23 17:43:23 Done.
75 * @return {number} |n| rounded to |digits| decimal places.
76 */
77 function round(n, digits) {
78 digits = digits || 1;
79 var factor = Math.pow(10, digits);
80 return Math.round(n * factor) / factor;
81 };
82
83 return {
84 BAR_WIDTH: BAR_WIDTH,
85 BAR_HEIGHT: BAR_HEIGHT,
86 drawLine: drawLine,
87 makeElement: makeElement,
88 createDetailsLi: createDetailsLi,
89 printDictionaryToTable: printDictionaryToTable,
90 round: round,
91 };
92 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698