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 body = iframe.contentDocument.body;
var iframeText = document.createElement('iframe');
document.body.appendChild(iframeText);
var realComputeLayout = computeLayout; var realComputeLayout = computeLayout;
function computeCSSLayout(rootNode) { function computeCSSLayout(rootNode) {
@@ -222,16 +225,27 @@ var layoutTestUtils = (function() {
computeDOMLayout: computeDOMLayout, computeDOMLayout: computeDOMLayout,
reduceTest: reduceTest, reduceTest: reduceTest,
text: function(text) { text: function(text) {
var body = iframeText.contentDocument.body;
var fn = function(width) { var fn = function(width) {
var div = document.createElement('div');
var span = document.createElement('span'); var span = document.createElement('span');
span.style.position = 'absolute'; span.style.display = 'flex';
if (width !== undefined) { 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.style.width = width + 'px';
} }
span.innerText = text; span.innerText = text;
body.appendChild(span); div.appendChild(span);
body.appendChild(div);
var rect = span.getBoundingClientRect(); var rect = span.getBoundingClientRect();
body.removeChild(span); body.removeChild(div);
return { return {
width: rect.width, width: rect.width,
height: rect.height height: rect.height

View File

@@ -216,7 +216,15 @@ var computeLayout = (function() {
getRelativePosition(node, crossAxis); getRelativePosition(node, crossAxis);
if ('measure' in node.style) { if ('measure' in node.style) {
var dimensions = node.style.measure(node.style.width); var width;
if (isDimDefined(node, 'row')) {
width = node.style.width;
} else if (node.style.position === 'absolute') {
width = 'shrink';
} else {
width = 'grow';
}
var dimensions = node.style.measure(width);
if (!isDimDefined(node, 'row')) { if (!isDimDefined(node, 'row')) {
node.layout.width = dimensions.width + getPaddingAndBorderAxis(node, 'row'); node.layout.width = dimensions.width + getPaddingAndBorderAxis(node, 'row');
} }

View File

@@ -745,7 +745,7 @@ describe('Layout', function() {
) )
}); });
it('should layout node with text', function() { it('should layout node with just text', function() {
testLayout( testLayout(
{style: {measure: text('kikoo')}}, {style: {measure: text('kikoo')}},
{width: 36, height: 18, top: 0, left: 0} {width: 36, height: 18, top: 0, left: 0}
@@ -759,13 +759,24 @@ describe('Layout', function() {
) )
}); });
it('should layout node with padding and margin', function() { it('should layout node with text, padding and margin', function() {
testLayout( testLayout(
{style: {measure: text('kikoo loool'), padding: 5, margin: 5}}, {style: {measure: text('kikoo loool'), padding: 5, margin: 5}},
{width: 82, height: 28, top: 5, left: 5} {width: 82, height: 28, top: 5, left: 5}
) )
}); });
it('should layout node with text and position absolute', function() {
testLayout(
{style: {}, children: [
{style: {measure: text('kikoo loool'), position: 'absolute'}}
]},
{width: 0, height: 0, top: 0, left: 0, children: [
{width: 36, height: 36, top: 0, left: 0}
]}
)
});
it('should layout randomly', function() { it('should layout randomly', function() {