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('tracing', function() { | |
6 | |
James Hawkins
2011/11/10 01:06:13
nit: Remove blank line.
nduca
2011/11/10 02:24:35
Done.
| |
7 /** | |
8 * Uses an embedded iframe to measure provided elements without forcing layout | |
9 * on the main document. | |
10 * @constructor | |
11 * @extends {Object} | |
12 */ | |
13 function MeasuringStick() { | |
14 var iframe = document.createElement('iframe'); | |
15 iframe.style.cssText = 'width:100%;height:0;border:0;visibility:hidden'; | |
16 document.body.appendChild(iframe); | |
17 this._doc = iframe.contentDocument; | |
18 this._window = iframe.contentWindow; | |
19 this._doc.body.style.cssText = 'padding:0;margin:0;overflow:hidden'; | |
20 | |
21 var stylesheets = document.querySelectorAll('link[rel=stylesheet]'); | |
22 for (var i = 0; i < stylesheets.length; ++i) { | |
James Hawkins
2011/11/10 01:06:13
nit: JS style is to use i++.
nduca
2011/11/10 02:24:35
Done.
| |
23 var stylesheet = stylesheets[i]; | |
24 var link = this._doc.createElement('link'); | |
25 link.rel = 'stylesheet'; | |
26 link.href = stylesheet.href; | |
27 this._doc.head.appendChild(link); | |
28 } | |
29 } | |
30 | |
31 MeasuringStick.prototype = { | |
32 __proto__: Object.prototype, | |
33 | |
34 /** | |
35 * Measures the provided element without forcing layout on the main | |
36 * document. | |
37 */ | |
38 measure: function(element) | |
James Hawkins
2011/11/10 01:06:13
nit: Opening brace goes on this line.
nduca
2011/11/10 02:24:35
Done.
| |
39 { | |
40 this._doc.body.appendChild(element); | |
41 var style = this._window.getComputedStyle(element); | |
42 var width = parseInt(style.width, 10); | |
43 var height = parseInt(style.height, 10); | |
44 this._doc.body.removeChild(element); | |
45 return { width: width, height: height }; | |
46 } | |
47 }; | |
48 | |
49 return { | |
50 MeasuringStick: MeasuringStick | |
51 }; | |
52 }); | |
OLD | NEW |