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 = 16; |
| 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 * Appends each key-value pair in a dictionary to a row in a table. |
| 52 * @param {Object} dict The dictionary to append. |
| 53 * @param {HTMLElement} table The <table> element to append to. |
| 54 */ |
| 55 function appendDictionaryToTable(dict, table) { |
| 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 return { |
| 67 BAR_WIDTH: BAR_WIDTH, |
| 68 BAR_HEIGHT: BAR_HEIGHT, |
| 69 drawLine: drawLine, |
| 70 makeElement: makeElement, |
| 71 createDetailsLi: createDetailsLi, |
| 72 appendDictionaryToTable: appendDictionaryToTable |
| 73 }; |
| 74 }); |
OLD | NEW |