Chromium Code Reviews| Index: chrome/browser/resources/media_internals/cache_entry.js |
| diff --git a/chrome/browser/resources/media_internals/cache_entry.js b/chrome/browser/resources/media_internals/cache_entry.js |
| index 60deab4cfe29a91628d454fd9895f01746a647e6..6809d0b7af1c4f944a1e4d49e58ab14b879484f2 100644 |
| --- a/chrome/browser/resources/media_internals/cache_entry.js |
| +++ b/chrome/browser/resources/media_internals/cache_entry.js |
| @@ -3,12 +3,7 @@ |
| // found in the LICENSE file. |
| cr.define('media', function() { |
| - |
| - /** |
| - * The width and height of a CacheEntry canvas in pixels. |
| - */ |
| - var CANVAS_WIDTH = 500; |
| - var CANVAS_HEIGHT = 31; |
| + 'use strict'; |
| /** |
| * This class represents a file cached by net. |
| @@ -31,6 +26,7 @@ cr.define('media', function() { |
| // The <details> summary line. It contains a chart of requested file ranges |
| // and the url if we know it. |
| var summary = document.createElement('summary'); |
| + summary.className = 'ellipsis'; |
|
arv (Not doing code reviews)
2011/09/23 15:59:01
class name should not describe the rendering ut th
scherkus (not reviewing)
2011/09/23 17:43:23
I ditched the entire ellipsis thing instead showin
|
| this.summaryText_ = document.createTextNode(''); |
| summary.appendChild(this.summaryText_); |
| @@ -50,14 +46,14 @@ cr.define('media', function() { |
| clearControl.textContent = '(clear entry)'; |
| controls.appendChild(clearControl); |
| - // The canvas upon which to draw the cached sections of a file. |
| - this.canvas_ = document.createElement('canvas'); |
| - this.canvas_.width = CANVAS_WIDTH; |
| - this.canvas_.height = CANVAS_HEIGHT; |
| - summary.appendChild(this.canvas_); |
| - |
| this.details_.appendChild(summary); |
| + // The canvas upon which to draw the cached sections of a file. |
| + this.canvas = document.createElement('canvas'); |
| + this.canvas.width = media.BAR_WIDTH; |
| + this.canvas.height = 2 * media.BAR_HEIGHT + 1; |
| + this.details_.appendChild(this.canvas); |
| + |
| // A tabular representation of the data in the above canvas. |
| this.detailTable_ = document.createElement('table'); |
| this.detailTable_.className = 'cache-table'; |
| @@ -115,7 +111,7 @@ cr.define('media', function() { |
| }, |
| /** |
| - * Redraw this.canvas_. |
| + * Redraw this.canvas. |
| * It should consist of two horizontal bars with highlighted sections to |
| * represent which parts of a file have been read from (top) and written to |
| * (bottom) the cache. |
| @@ -123,19 +119,21 @@ cr.define('media', function() { |
| * |-----xxxxx-------| |
| */ |
| generateCanvas: function() { |
| - var context = this.canvas_.getContext('2d'); |
| + var width = this.canvas.width; |
| + var height = this.canvas.height; |
| + var context = this.canvas.getContext('2d'); |
| context.textAlign = 'center'; |
| context.textBaseline = 'middle'; |
| context.fillStyle = '#aaa'; |
| - context.fillRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT); |
| + context.fillRect(0, 0, width, height); |
| if (this.size) { |
| var fileSize = this.size; |
| - drawRange = function(start, end, top) { |
| - var left = start / fileSize * CANVAS_WIDTH; |
| - var right = end / fileSize * CANVAS_WIDTH; |
| - context.fillRect(left, top, right - left, top + CANVAS_HEIGHT / 2); |
| + var drawRange = function(start, end, top) { |
| + var left = start / fileSize * width; |
| + var right = end / fileSize * width; |
| + context.fillRect(left, top, right - left, top + height / 2); |
| }; |
| context.fillStyle = '#0a0'; |
| @@ -145,26 +143,22 @@ cr.define('media', function() { |
| context.fillStyle = '#00a'; |
| this.written_.map(function(start, end) { |
| - drawRange(start, end, CANVAS_HEIGHT / 2); |
| + drawRange(start, end, height / 2); |
| }); |
| // Overlay a description of each bar. |
| context.fillStyle = '#fff'; |
| - context.fillText('Read from cache.', CANVAS_WIDTH / 2, |
| - CANVAS_HEIGHT / 4 - 0.5); |
| - context.fillText('Written to cache.', CANVAS_WIDTH / 2, |
| - CANVAS_HEIGHT * 3 / 4 + 0.5); |
| - |
| - // Add a 1px separator line. |
| - context.moveTo(0, CANVAS_HEIGHT / 2); |
| - context.lineTo(CANVAS_WIDTH, CANVAS_HEIGHT / 2); |
| - context.strokeStyle = '#fff'; |
| - context.stroke(); |
| + context.fillText('Read from cache.', width / 2, |
| + height / 4 - 0.5); |
| + context.fillText('Written to cache.', width / 2, |
| + height * 3 / 4 + 0.5); |
| + |
| + media.drawLine(context, height / 2); |
| } else { |
| // We can't draw bars if we don't know how big the file is. |
| context.fillStyle = '#fff'; |
| context.fillText('Unknown file size. See details below.', |
| - CANVAS_WIDTH / 2, CANVAS_HEIGHT / 2); |
| + width / 2, height / 2); |
| } |
| }, |
| @@ -173,12 +167,6 @@ cr.define('media', function() { |
| * this file. |
| */ |
| generateDetails: function() { |
| - function makeElement(type, content) { |
| - var element = document.createElement(type); |
| - element.textContent = content; |
| - return element; |
| - }; |
| - |
| this.details_.id = this.key; |
| this.summaryText_.textContent = this.key || 'Unknown File'; |
| @@ -191,8 +179,8 @@ cr.define('media', function() { |
| this.detailTable_.appendChild(body); |
| var headerRow = document.createElement('tr'); |
| - headerRow.appendChild(makeElement('th', 'Read From Cache')); |
| - headerRow.appendChild(makeElement('th', 'Written To Cache')); |
| + headerRow.appendChild(media.makeElement('th', 'Read From Cache')); |
| + headerRow.appendChild(media.makeElement('th', 'Written To Cache')); |
| header.appendChild(headerRow); |
| var footerRow = document.createElement('tr'); |
| @@ -212,8 +200,8 @@ cr.define('media', function() { |
| var length = Math.max(read.length, written.length); |
| for (var i = 0; i < length; i++) { |
| var row = document.createElement('tr'); |
| - row.appendChild(makeElement('td', read[i] || '')); |
| - row.appendChild(makeElement('td', written[i] || '')); |
| + row.appendChild(media.makeElement('td', read[i] || '')); |
| + row.appendChild(media.makeElement('td', written[i] || '')); |
| body.appendChild(row); |
| } |