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

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

Issue 7653001: Display active media players on chrome://media-internals. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 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
7 /**
8 * The width and height of a bar drawn on a file canvas in pixels.
9 */
10 BAR_WIDTH = 500;
11 BAR_HEIGHT = 15;
12
13 // Maximum display length of a url in characters. Lengthy urls will be clipped
14 // and postfixed with an ellipsis.
15 MAX_URL_LENGTH = 50;
16
17 /**
18 * Draws a 1px white horizontal line across |context|.
19 */
20 drawLine = function(context, top) {
21 context.moveTo(0, top);
22 context.lineTo(BAR_WIDTH, top);
23 context.strokeStyle = '#fff';
24 context.stroke();
25 };
26
27 /**
28 * Creates an HTMLElement of type |type| with textContent |content|.
29 * @param {string} type The type of element to create.
30 * @param {string} content The content to place in the element.
31 * @return {HTMLElement} A newly initialized element.
32 */
33 makeElement = function(type, content) {
34 var element = document.createElement(type);
35 element.textContent = content;
36 return element;
37 };
38
39 /**
40 * Truncates a URL to MAX_URL_LENGTH. If the URL was too long, the last
41 * three characters of the returned string will be '...', and its length will
42 * be MAX_URL_LENGTH.
43 * @param {string} url The url to truncate.
44 * @return {string} A truncated url.
45 */
46 clipURL = function(url) {
47 if (url && url.length > MAX_URL_LENGTH)
48 return url.slice(0, MAX_URL_LENGTH - 3) + '...';
49 return url;
50 };
51
52 /**
53 * Creates a new <li> containing a <details> with a <summary> and sets
54 * properties to reference them.
55 * @return {Object} The new <li>.
56 */
57 createDetailsLi = function() {
58 li = document.createElement('li');
59 li.details = document.createElement('details');
60 li.summary = document.createElement('summary');
61 li.appendChild(li.details);
62 li.details.appendChild(li.summary);
63 return li
64 };
65
66 /**
67 * Prints each key-value pair in a dictionary to a row in a table.
68 * @param {Object} dict The dictionary to print.
69 * @param {HTMLElement} table The <table> element to print to.
70 */
71 printDictionaryToTable = function(dict, table) {
72 table.textContent = '';
73 for (var key in dict) {
74 var tr = document.createElement('tr');
75 tr.appendChild(makeElement('td', key + ':'));
76 tr.appendChild(makeElement('td', dict[key]));
77 table.appendChild(tr);
78 }
79 return table;
80 };
81
82 /**
83 * Rounds a number, leaving the specified number of digits after the decimal;
84 * defaults to 1.
85 * @param {number} n The number to be rounded.
86 * @param {int} digits The number of digits to leave after the decimal.
87 * @return {number} |n| rounded to |digits| decimal places.
88 */
89 round = function(n, digits) {
90 digits = digits || 1;
91 factor = Math.pow(10, digits);
92 return Math.round(n * factor) / factor;
93 };
94
95 return {
96 BAR_WIDTH: BAR_WIDTH,
97 BAR_HEIGHT: BAR_HEIGHT,
98 drawLine: drawLine,
99 makeElement: makeElement,
100 clipURL: clipURL,
101 createDetailsLi: createDetailsLi,
102 printDictionaryToTable: printDictionaryToTable,
103 round: round,
104 };
105 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698