support <Text>

This commit is contained in:
Christopher Chedeau
2014-04-26 19:02:16 -07:00
parent 61919a1b2f
commit a0ffafe37d
3 changed files with 40 additions and 7 deletions

View File

@@ -28,6 +28,9 @@ var layoutTestUtils = (function() {
})();
var body = iframe.contentDocument.body;
var iframeText = document.createElement('iframe');
document.body.appendChild(iframeText);
var realComputeLayout = computeLayout;
function computeCSSLayout(rootNode) {
@@ -222,16 +225,27 @@ var layoutTestUtils = (function() {
computeDOMLayout: computeDOMLayout,
reduceTest: reduceTest,
text: function(text) {
var body = iframeText.contentDocument.body;
var fn = function(width) {
var div = document.createElement('div');
var span = document.createElement('span');
span.style.position = 'absolute';
if (width !== undefined) {
span.style.display = 'flex';
body.style.display = 'block';
if (width === 'grow') {
span.style.position = 'absolute';
} else if (width === 'shrink') {
div.style.display = 'flex';
div.style.position = 'relative';
body.style.display = 'flex';
span.style.position = 'absolute';
} else {
span.style.width = width + 'px';
}
span.innerText = text;
body.appendChild(span);
div.appendChild(span);
body.appendChild(div);
var rect = span.getBoundingClientRect();
body.removeChild(span);
body.removeChild(div);
return {
width: rect.width,
height: rect.height