blob: 022b43f1379035857d7e5f53677f5248d41a82ad (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
cr.define('tracing', function() {
/**
* Uses an embedded iframe to measure provided elements without forcing layout
* on the main document.
* @constructor
* @extends {Object}
*/
function MeasuringStick() {
var iframe = document.createElement('iframe');
iframe.style.cssText = 'width:100%;height:0;border:0;visibility:hidden';
document.body.appendChild(iframe);
this._doc = iframe.contentDocument;
this._window = iframe.contentWindow;
this._doc.body.style.cssText = 'padding:0;margin:0;overflow:hidden';
var stylesheets = document.querySelectorAll('link[rel=stylesheet]');
for (var i = 0; i < stylesheets.length; i++) {
var stylesheet = stylesheets[i];
var link = this._doc.createElement('link');
link.rel = 'stylesheet';
link.href = stylesheet.href;
this._doc.head.appendChild(link);
}
}
MeasuringStick.prototype = {
__proto__: Object.prototype,
/**
* Measures the provided element without forcing layout on the main
* document.
*/
measure: function(element) {
this._doc.body.appendChild(element);
var style = this._window.getComputedStyle(element);
var width = parseInt(style.width, 10);
var height = parseInt(style.height, 10);
this._doc.body.removeChild(element);
return { width: width, height: height };
}
};
return {
MeasuringStick: MeasuringStick
};
});
|