2016-08-11 11:45:45 -07:00
|
|
|
/**
|
2018-09-11 15:27:47 -07:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2016-08-11 11:45:45 -07:00
|
|
|
*
|
2018-02-16 18:24:55 -08:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-08-11 11:45:45 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
window.onload = function() {
|
2016-10-23 10:27:30 -07:00
|
|
|
checkDefaultValues();
|
|
|
|
|
|
|
|
printTest(
|
|
|
|
new CPPEmitter(),
|
|
|
|
document.body.children[0],
|
|
|
|
document.body.children[1],
|
|
|
|
document.body.children[2]);
|
|
|
|
|
|
|
|
printTest(
|
|
|
|
new JavaEmitter(),
|
|
|
|
document.body.children[0],
|
|
|
|
document.body.children[1],
|
|
|
|
document.body.children[2]);
|
|
|
|
|
|
|
|
printTest(
|
|
|
|
new CSEmitter(),
|
|
|
|
document.body.children[0],
|
2017-01-02 02:22:45 -08:00
|
|
|
document.body.children[1],
|
|
|
|
document.body.children[2]);
|
|
|
|
|
|
|
|
printTest(
|
|
|
|
new JavascriptEmitter(),
|
|
|
|
document.body.children[0],
|
2016-10-23 10:27:30 -07:00
|
|
|
document.body.children[1],
|
|
|
|
document.body.children[2]);
|
2016-08-11 11:45:45 -07:00
|
|
|
}
|
|
|
|
|
2016-10-23 10:27:30 -07:00
|
|
|
function assert(condition, message) {
|
|
|
|
if (!condition) {
|
|
|
|
throw new Error(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function printTest(e, LTRContainer, RTLContainer, genericContainer) {
|
|
|
|
e.push([
|
2016-08-11 11:45:45 -07:00
|
|
|
'/**',
|
|
|
|
' * Copyright (c) 2014-present, Facebook, Inc.',
|
|
|
|
' *',
|
2018-02-16 18:25:02 -08:00
|
|
|
' * This source code is licensed under the MIT license found in the',
|
|
|
|
' * LICENSE file in the root directory of this source tree.',
|
2016-08-11 11:45:45 -07:00
|
|
|
' */',
|
|
|
|
'',
|
2017-01-31 09:28:07 -08:00
|
|
|
'// @Generated by gentest/gentest.rb from gentest/fixtures/' + document.title + '.html',
|
2016-08-11 11:45:45 -07:00
|
|
|
'',
|
2016-10-23 10:27:30 -07:00
|
|
|
]);
|
|
|
|
e.emitPrologue();
|
2016-08-11 11:45:45 -07:00
|
|
|
|
2016-09-14 08:51:07 -07:00
|
|
|
var LTRLayoutTree = calculateTree(LTRContainer);
|
|
|
|
var RTLLayoutTree = calculateTree(RTLContainer);
|
|
|
|
var genericLayoutTree = calculateTree(genericContainer);
|
2016-08-11 11:45:45 -07:00
|
|
|
|
2016-10-23 10:27:30 -07:00
|
|
|
|
2016-09-14 08:51:07 -07:00
|
|
|
for (var i = 0; i < genericLayoutTree.length; i++) {
|
2016-11-23 11:12:51 -08:00
|
|
|
e.emitTestPrologue(genericLayoutTree[i].name, genericLayoutTree[i].experiments);
|
2016-10-23 10:27:30 -07:00
|
|
|
|
|
|
|
if (genericLayoutTree[i].name == 'wrap_column') {
|
|
|
|
// Modify width and left values due to both safari and chrome not abiding by the
|
|
|
|
// specification. The undefined dimension of a parent should be defined by the total size
|
|
|
|
// of their children in that dimension.
|
|
|
|
// See diagram under flex-wrap header https://www.w3.org/TR/css-flexbox-1/
|
|
|
|
assert(LTRLayoutTree[0].width == 30, 'wrap_column LTR root.width should be 30');
|
|
|
|
LTRLayoutTree[0].width = 60;
|
|
|
|
assert(RTLLayoutTree[0].width == 30, 'wrap_column RTL root.width should be 30');
|
|
|
|
RTLLayoutTree[0].width = 60;
|
|
|
|
var children = RTLLayoutTree[0].children;
|
|
|
|
assert(children[0].left == 0, 'wrap_column RTL root_child0.left should be 0');
|
|
|
|
children[0].left = 30;
|
|
|
|
assert(children[1].left == 0, 'wrap_column RTL root_child0.left should be 0');
|
|
|
|
children[1].left = 30;
|
|
|
|
assert(children[2].left == 0, 'wrap_column RTL root_child2.left should be 0');
|
|
|
|
children[2].left = 30;
|
|
|
|
assert(children[3].left == -30, 'wrap_column RTL root_child3.left should be -30');
|
|
|
|
children[3].left = 0;
|
|
|
|
}
|
2016-09-14 08:51:07 -07:00
|
|
|
|
2016-10-23 10:27:30 -07:00
|
|
|
setupTestTree(
|
|
|
|
e,
|
2016-09-27 08:46:07 -07:00
|
|
|
undefined,
|
|
|
|
LTRLayoutTree[i],
|
|
|
|
genericLayoutTree[i],
|
|
|
|
'root',
|
2016-10-23 10:27:30 -07:00
|
|
|
null);
|
2016-08-11 11:45:45 -07:00
|
|
|
|
2017-03-01 09:19:55 -08:00
|
|
|
e.YGNodeCalculateLayout('root', e.YGDirectionLTR, genericLayoutTree[i].experiments);
|
2016-10-23 10:27:30 -07:00
|
|
|
e.push('');
|
2016-08-15 09:15:07 -07:00
|
|
|
|
2016-10-23 10:27:30 -07:00
|
|
|
assertTestTree(e, LTRLayoutTree[i], 'root', null);
|
|
|
|
e.push('');
|
2016-09-14 08:51:07 -07:00
|
|
|
|
2017-03-01 09:19:55 -08:00
|
|
|
e.YGNodeCalculateLayout('root', e.YGDirectionRTL, genericLayoutTree[i].experiments);
|
2016-10-23 10:27:30 -07:00
|
|
|
e.push('');
|
2016-09-14 08:51:07 -07:00
|
|
|
|
2016-10-23 10:27:30 -07:00
|
|
|
assertTestTree(e, RTLLayoutTree[i], 'root', null);
|
2016-08-11 11:45:45 -07:00
|
|
|
|
2016-11-23 11:12:51 -08:00
|
|
|
e.emitTestEpilogue(genericLayoutTree[i].experiments);
|
2016-08-15 09:15:07 -07:00
|
|
|
}
|
2016-10-23 10:27:30 -07:00
|
|
|
e.emitEpilogue();
|
2016-08-11 11:45:45 -07:00
|
|
|
|
2016-10-23 10:27:30 -07:00
|
|
|
e.print();
|
2016-08-11 11:45:45 -07:00
|
|
|
}
|
|
|
|
|
2016-10-23 10:27:30 -07:00
|
|
|
function assertTestTree(e, node, nodeName, parentName) {
|
2016-12-03 04:40:21 -08:00
|
|
|
e.AssertEQ(node.left, e.YGNodeLayoutGetLeft(nodeName));
|
|
|
|
e.AssertEQ(node.top, e.YGNodeLayoutGetTop(nodeName));
|
|
|
|
e.AssertEQ(node.width, e.YGNodeLayoutGetWidth(nodeName));
|
|
|
|
e.AssertEQ(node.height, e.YGNodeLayoutGetHeight(nodeName));
|
2016-08-11 11:45:45 -07:00
|
|
|
|
|
|
|
for (var i = 0; i < node.children.length; i++) {
|
2016-10-23 10:27:30 -07:00
|
|
|
e.push('');
|
2016-08-11 11:45:45 -07:00
|
|
|
var childName = nodeName + '_child' + i;
|
2016-10-23 10:27:30 -07:00
|
|
|
assertTestTree(e, node.children[i], childName, nodeName);
|
2016-08-11 11:45:45 -07:00
|
|
|
}
|
2016-10-23 10:27:30 -07:00
|
|
|
}
|
2016-08-11 11:45:45 -07:00
|
|
|
|
2016-10-23 10:27:30 -07:00
|
|
|
function checkDefaultValues() {
|
2016-12-02 05:47:43 -08:00
|
|
|
// Sanity check of the Yoga default values by test-template.html
|
2016-10-23 10:27:30 -07:00
|
|
|
[
|
|
|
|
{style:'flex-direction', value:'column'},
|
|
|
|
{style:'justify-content', value:'flex-start'},
|
|
|
|
{style:'align-content', value:'flex-start'},
|
|
|
|
{style:'align-items', value:'stretch'},
|
|
|
|
{style:'position', value:'relative'},
|
|
|
|
{style:'flex-wrap', value:'nowrap'},
|
|
|
|
{style:'overflow', value:'visible'},
|
|
|
|
{style:'flex-grow', value:'0'},
|
|
|
|
{style:'flex-shrink', value:'0'},
|
2016-11-09 09:10:54 -08:00
|
|
|
{style:'left', value:'undefined'},
|
|
|
|
{style:'top', value:'undefined'},
|
|
|
|
{style:'right', value:'undefined'},
|
|
|
|
{style:'bottom', value:'undefined'},
|
2017-02-06 09:31:22 -08:00
|
|
|
{style:'display', value:'flex'},
|
2016-10-23 10:27:30 -07:00
|
|
|
].forEach(function(item) {
|
|
|
|
assert(item.value === getDefaultStyleValue(item.style),
|
|
|
|
item.style + ' should be ' + item.value);
|
|
|
|
});
|
2016-08-11 11:45:45 -07:00
|
|
|
}
|
|
|
|
|
2016-10-23 10:27:30 -07:00
|
|
|
function setupTestTree(e, parent, node, genericNode, nodeName, parentName, index) {
|
|
|
|
e.emitTestTreePrologue(nodeName);
|
2016-08-11 11:45:45 -07:00
|
|
|
|
|
|
|
for (var style in node.style) {
|
2016-08-25 15:28:35 -07:00
|
|
|
// Skip position info for root as it messes up tests
|
|
|
|
if (node.declaredStyle[style] === "" &&
|
|
|
|
(style == 'position' ||
|
|
|
|
style == 'left' ||
|
|
|
|
style == 'top' ||
|
|
|
|
style == 'right' ||
|
|
|
|
style == 'bottom' ||
|
|
|
|
style == 'width' ||
|
|
|
|
style == 'height')) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-08-11 11:45:45 -07:00
|
|
|
if (node.style[style] !== getDefaultStyleValue(style)) {
|
|
|
|
switch (style) {
|
|
|
|
case 'direction':
|
2016-12-03 04:40:21 -08:00
|
|
|
e.YGNodeStyleSetDirection(nodeName, directionValue(e, node.style[style]));
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'flex-direction':
|
2016-12-03 04:40:21 -08:00
|
|
|
e.YGNodeStyleSetFlexDirection(nodeName, flexDirectionValue(e, node.style[style]));
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'justify-content':
|
2016-12-03 04:40:21 -08:00
|
|
|
e.YGNodeStyleSetJustifyContent(nodeName, justifyValue(e, node.style[style]));
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'align-content':
|
2016-12-03 04:40:21 -08:00
|
|
|
e.YGNodeStyleSetAlignContent(nodeName, alignValue(e, node.style[style]));
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'align-items':
|
2016-12-03 04:40:21 -08:00
|
|
|
e.YGNodeStyleSetAlignItems(nodeName, alignValue(e, node.style[style]));
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'align-self':
|
2016-09-27 08:46:07 -07:00
|
|
|
if (!parent || node.style[style] !== parent.style['align-items']) {
|
2016-12-03 04:40:21 -08:00
|
|
|
e.YGNodeStyleSetAlignSelf(nodeName, alignValue(e, node.style[style]));
|
2016-09-27 08:46:07 -07:00
|
|
|
}
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'position':
|
2016-12-03 04:40:21 -08:00
|
|
|
e.YGNodeStyleSetPositionType(nodeName, positionValue(e, node.style[style]));
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'flex-wrap':
|
2016-12-03 04:40:21 -08:00
|
|
|
e.YGNodeStyleSetFlexWrap(nodeName, wrapValue(e, node.style[style]));
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'overflow':
|
2016-12-03 04:40:21 -08:00
|
|
|
e.YGNodeStyleSetOverflow(nodeName, overflowValue(e, node.style[style]));
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'flex-grow':
|
2016-12-03 04:40:21 -08:00
|
|
|
e.YGNodeStyleSetFlexGrow(nodeName, node.style[style]);
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'flex-shrink':
|
2016-12-03 04:40:21 -08:00
|
|
|
e.YGNodeStyleSetFlexShrink(nodeName, node.style[style]);
|
2016-08-15 09:15:05 -07:00
|
|
|
break;
|
|
|
|
case 'flex-basis':
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetFlexBasis(nodeName, pointValue(e, node.style[style]));
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'left':
|
2016-09-14 08:51:07 -07:00
|
|
|
if (genericNode.rawStyle.indexOf('start:') >= 0) {
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetPosition(nodeName, e.YGEdgeStart, pointValue(e, node.style[style]));
|
2016-09-14 08:51:07 -07:00
|
|
|
} else {
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetPosition(nodeName, e.YGEdgeLeft, pointValue(e, node.style[style]));
|
2016-09-14 08:51:07 -07:00
|
|
|
}
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'top':
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetPosition(nodeName, e.YGEdgeTop, pointValue(e, node.style[style]));
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'right':
|
2016-09-14 08:51:07 -07:00
|
|
|
if (genericNode.rawStyle.indexOf('end:') >= 0) {
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetPosition(nodeName, e.YGEdgeEnd, pointValue(e, node.style[style]));
|
2016-09-14 08:51:07 -07:00
|
|
|
} else {
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetPosition(nodeName, e.YGEdgeRight, pointValue(e, node.style[style]));
|
2016-09-14 08:51:07 -07:00
|
|
|
}
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'bottom':
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetPosition(nodeName, e.YGEdgeBottom, pointValue(e, node.style[style]));
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'margin-left':
|
2016-09-14 08:51:07 -07:00
|
|
|
if (genericNode.rawStyle.indexOf('margin-start:') >= 0) {
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetMargin(nodeName, e.YGEdgeStart, pointValue(e, node.style[style]));
|
2016-09-14 08:51:07 -07:00
|
|
|
} else {
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetMargin(nodeName, e.YGEdgeLeft, pointValue(e, node.style[style]));
|
2016-09-14 08:51:07 -07:00
|
|
|
}
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'margin-top':
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetMargin(nodeName, e.YGEdgeTop, pointValue(e, node.style[style]));
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'margin-right':
|
2016-09-14 08:51:07 -07:00
|
|
|
if (genericNode.rawStyle.indexOf('margin-end:') >= 0) {
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetMargin(nodeName, e.YGEdgeEnd, pointValue(e, node.style[style]));
|
2016-09-14 08:51:07 -07:00
|
|
|
} else {
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetMargin(nodeName, e.YGEdgeRight, pointValue(e, node.style[style]));
|
2016-09-14 08:51:07 -07:00
|
|
|
}
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'margin-bottom':
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetMargin(nodeName, e.YGEdgeBottom, pointValue(e, node.style[style]));
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'padding-left':
|
2016-09-14 08:51:07 -07:00
|
|
|
if (genericNode.rawStyle.indexOf('padding-start:') >= 0) {
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetPadding(nodeName, e.YGEdgeStart, pointValue(e, node.style[style]));
|
2016-09-14 08:51:07 -07:00
|
|
|
} else {
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetPadding(nodeName, e.YGEdgeLeft, pointValue(e, node.style[style]));
|
2016-09-14 08:51:07 -07:00
|
|
|
}
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'padding-top':
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetPadding(nodeName, e.YGEdgeTop, pointValue(e, node.style[style]));
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'padding-right':
|
2016-09-14 08:51:07 -07:00
|
|
|
if (genericNode.rawStyle.indexOf('padding-end:') >= 0) {
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetPadding(nodeName, e.YGEdgeEnd, pointValue(e, node.style[style]));
|
2016-09-14 08:51:07 -07:00
|
|
|
} else {
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetPadding(nodeName, e.YGEdgeRight, pointValue(e, node.style[style]));
|
2016-09-14 08:51:07 -07:00
|
|
|
}
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'padding-bottom':
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetPadding(nodeName, e.YGEdgeBottom, pointValue(e, node.style[style]));
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'border-left-width':
|
2016-09-14 08:51:07 -07:00
|
|
|
if (genericNode.rawStyle.indexOf('border-start-width:') >= 0) {
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetBorder(nodeName, e.YGEdgeStart, pointValue(e, node.style[style]));
|
2016-09-14 08:51:07 -07:00
|
|
|
} else {
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetBorder(nodeName, e.YGEdgeLeft, pointValue(e, node.style[style]));
|
2016-09-14 08:51:07 -07:00
|
|
|
}
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'border-top-width':
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetBorder(nodeName, e.YGEdgeTop, pointValue(e, node.style[style]));
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'border-right-width':
|
2016-09-14 08:51:07 -07:00
|
|
|
if (genericNode.rawStyle.indexOf('border-end-width:') >= 0) {
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetBorder(nodeName, e.YGEdgeEnd, pointValue(e, node.style[style]));
|
2016-09-14 08:51:07 -07:00
|
|
|
} else {
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetBorder(nodeName, e.YGEdgeRight, pointValue(e, node.style[style]));
|
2016-09-14 08:51:07 -07:00
|
|
|
}
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'border-bottom-width':
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetBorder(nodeName, e.YGEdgeBottom, pointValue(e, node.style[style]));
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'width':
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetWidth(nodeName, pointValue(e, node.style[style]));
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'min-width':
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetMinWidth(nodeName, pointValue(e, node.style[style]));
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'max-width':
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetMaxWidth(nodeName, pointValue(e, node.style[style]));
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'height':
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetHeight(nodeName, pointValue(e, node.style[style]));
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'min-height':
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetMinHeight(nodeName, pointValue(e, node.style[style]));
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
|
|
|
case 'max-height':
|
2017-02-14 14:26:13 -08:00
|
|
|
e.YGNodeStyleSetMaxHeight(nodeName, pointValue(e, node.style[style]));
|
2016-08-11 11:45:45 -07:00
|
|
|
break;
|
2017-02-06 09:31:22 -08:00
|
|
|
case 'display':
|
|
|
|
e.YGNodeStyleSetDisplay(nodeName, displayValue(e, node.style[style]))
|
|
|
|
break;
|
2016-08-11 11:45:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parentName) {
|
2016-12-03 04:40:21 -08:00
|
|
|
e.YGNodeInsertChild(parentName, nodeName, index);
|
2016-08-11 11:45:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < node.children.length; i++) {
|
2016-10-23 10:27:30 -07:00
|
|
|
e.push('');
|
2016-08-11 11:45:45 -07:00
|
|
|
var childName = nodeName + '_child' + i;
|
2016-10-23 10:27:30 -07:00
|
|
|
setupTestTree(
|
|
|
|
e,
|
|
|
|
node,
|
|
|
|
node.children[i],
|
|
|
|
genericNode.children[i],
|
|
|
|
childName,
|
|
|
|
nodeName,
|
|
|
|
i);
|
2016-08-11 11:45:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-23 10:27:30 -07:00
|
|
|
function overflowValue(e, value) {
|
2016-08-11 11:45:45 -07:00
|
|
|
switch (value) {
|
2016-12-02 05:47:43 -08:00
|
|
|
case 'visible': return e.YGOverflowVisible;
|
|
|
|
case 'hidden': return e.YGOverflowHidden;
|
2016-08-11 11:45:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-23 10:27:30 -07:00
|
|
|
function wrapValue(e, value) {
|
2016-08-11 11:45:45 -07:00
|
|
|
switch (value) {
|
2016-12-02 05:47:43 -08:00
|
|
|
case 'wrap': return e.YGWrapWrap;
|
2017-02-15 13:35:24 -08:00
|
|
|
case 'wrap-reverse': return e.YGWrapWrapReverse;
|
2016-12-02 05:47:43 -08:00
|
|
|
case 'nowrap': return e.YGWrapNoWrap;
|
2016-08-11 11:45:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-23 10:27:30 -07:00
|
|
|
function flexDirectionValue(e, value) {
|
2016-08-11 11:45:45 -07:00
|
|
|
switch (value) {
|
2016-12-02 05:47:43 -08:00
|
|
|
case 'row': return e.YGFlexDirectionRow;
|
|
|
|
case 'row-reverse': return e.YGFlexDirectionRowReverse;
|
|
|
|
case 'column': return e.YGFlexDirectionColumn;
|
|
|
|
case 'column-reverse': return e.YGFlexDirectionColumnReverse;
|
2016-08-11 11:45:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-23 10:27:30 -07:00
|
|
|
function justifyValue(e, value) {
|
2016-08-11 11:45:45 -07:00
|
|
|
switch (value) {
|
2016-12-02 05:47:43 -08:00
|
|
|
case 'center': return e.YGJustifyCenter;
|
|
|
|
case 'space-around': return e.YGJustifySpaceAround;
|
|
|
|
case 'space-between': return e.YGJustifySpaceBetween;
|
2017-11-27 03:40:01 -08:00
|
|
|
case 'space-evenly': return e.YGJustifySpaceEvenly;
|
2016-12-02 05:47:43 -08:00
|
|
|
case 'flex-start': return e.YGJustifyFlexStart;
|
|
|
|
case 'flex-end': return e.YGJustifyFlexEnd;
|
2016-08-11 11:45:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-23 10:27:30 -07:00
|
|
|
function positionValue(e, value) {
|
2016-08-11 11:45:45 -07:00
|
|
|
switch (value) {
|
2016-12-02 05:47:43 -08:00
|
|
|
case 'absolute': return e.YGPositionTypeAbsolute;
|
|
|
|
default: return e.YGPositionTypeRelative
|
2016-08-11 11:45:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-23 10:27:30 -07:00
|
|
|
function directionValue(e, value) {
|
2016-08-11 11:45:45 -07:00
|
|
|
switch (value) {
|
2016-12-02 05:47:43 -08:00
|
|
|
case 'ltr': return e.YGDirectionLTR;
|
|
|
|
case 'rtl': return e.YGDirectionRTL;
|
|
|
|
case 'inherit': return e.YGDirectionInherit;
|
2016-08-11 11:45:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-23 10:27:30 -07:00
|
|
|
function alignValue(e, value) {
|
2016-08-11 11:45:45 -07:00
|
|
|
switch (value) {
|
2016-12-02 05:47:43 -08:00
|
|
|
case 'auto': return e.YGAlignAuto;
|
|
|
|
case 'center': return e.YGAlignCenter;
|
|
|
|
case 'stretch': return e.YGAlignStretch;
|
|
|
|
case 'flex-start': return e.YGAlignFlexStart;
|
|
|
|
case 'flex-end': return e.YGAlignFlexEnd;
|
2017-02-11 08:32:48 -08:00
|
|
|
case 'space-between': return e.YGAlignSpaceBetween;
|
|
|
|
case 'space-around': return e.YGAlignSpaceAround;
|
2017-01-06 06:51:56 -08:00
|
|
|
case 'baseline': return e.YGAlignBaseline;
|
2016-08-11 11:45:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-14 14:26:13 -08:00
|
|
|
function pointValue(e, value) {
|
2016-08-11 11:45:45 -07:00
|
|
|
switch (value) {
|
2017-02-14 14:26:09 -08:00
|
|
|
case 'auto': return e.YGAuto;
|
2016-12-02 05:47:43 -08:00
|
|
|
case 'undefined': return e.YGUndefined;
|
Add feature to use percentage as value unit
Summary:
Adds the feature to use percentage as a value unit.
You can use the function ```YGPx(float)``` and ```YGPercent(float)``` for convenience.
I did some benchmarks:
```
Without Percentage Feature - Release x86:
Stack with flex: median: 0.000000 ms, stddev: 0.146683 ms
Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.136525 ms
Nested flex: median: 0.000000 ms, stddev: 0.490101 ms
Huge nested layout: median: 23.000000 ms, stddev: 0.928291 ms
Stack with flex: median: 0.000000 ms, stddev: 0.170587 ms
Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.143384 ms
Nested flex: median: 0.000000 ms, stddev: 0.477791 ms
Huge nested layout: median: 22.000000 ms, stddev: 2.129779 ms
With Percentage Feature - Release x86:
Stack with flex: median: 0.000000 ms, stddev: 0.132951 ms
Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.136525 ms
Nested flex: median: 0.000000 ms, stddev: 0.489570 ms
Huge nested layout: median: 21.000000 ms, stddev: 1.390476 ms
Closes https://github.com/facebook/yoga/pull/258
Reviewed By: dshahidehpour
Differential Revision: D4361945
Pulled By: emilsjolander
fbshipit-source-id: a8f5bc63ad352eb9410d792729e56664468cd76a
2017-01-02 05:20:37 -08:00
|
|
|
default: return value;
|
2016-08-11 11:45:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-06 09:31:22 -08:00
|
|
|
function displayValue(e, value){
|
|
|
|
switch(value){
|
|
|
|
case 'flex': return e.YGDisplayFlex;
|
|
|
|
case 'none': return e.YGDisplayNone;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-11 11:45:45 -07:00
|
|
|
function getDefaultStyleValue(style) {
|
2016-08-25 15:28:38 -07:00
|
|
|
if (style == 'position') {
|
|
|
|
return 'relative';
|
|
|
|
}
|
2016-11-09 09:10:54 -08:00
|
|
|
switch (style) {
|
|
|
|
case 'left':
|
|
|
|
case 'top':
|
|
|
|
case 'right':
|
|
|
|
case 'bottom':
|
|
|
|
case 'start':
|
|
|
|
case 'end':
|
|
|
|
return 'undefined';
|
|
|
|
}
|
2016-08-11 11:45:45 -07:00
|
|
|
var node = document.getElementById('default');
|
|
|
|
return getComputedStyle(node, null).getPropertyValue(style);
|
|
|
|
}
|
|
|
|
|
New round-to-pixel-grid algorithm that fixes possible subpixel gaps between sibling nodes
Summary:
This diff introduces new, little bit sophisticated round-to-pixel-grid algorithm.
**Motivation:**
Previous simple and straightforward solution works in most cases but sometimes produce the not-so-great result. A while ago Nick Lockwood described this problem and proposed the solution in RN's RCTShadowView class:
For example, say you have the following structure:
// +--------+---------+--------+
// | |+-------+| |
// | || || |
// | |+-------+| |
// +--------+---------+--------+
Say the screen width is 320 pts so the three big views will get the following x bounds from our layout system:
{0, 106.667}, {106.667, 213.333}, {213.333, 320}
Assuming screen scale is 2, these numbers must be rounded to the nearest 0.5 to fit the pixel grid:
{0, 106.5}, {106.5, 213.5}, {213.5, 320}
You'll notice that the three widths are 106.5, 107, 106.5.
This is great for the parent views but it gets trickier when we consider rounding for the subview. When we go to round the bounds for the subview in the middle, it's relative bounds are {0, 106.667} which gets rounded to {0, 106.5}. This will cause the subview to be one pixel smaller than it should be. This is why we need to pass in the absolute position in order to do the rounding relative to the screen's grid rather than the view's grid. After passing in the absolutePosition of {106.667, y}, we do the following calculations:
absoluteLeft = round(absolutePosition.x + viewPosition.left) = round(106.667 + 0) = 106.5
absoluteRight = round(absolutePosition.x + viewPosition.left + viewSize.width) + round(106.667 + 0 + 106.667) = 213.5
width = 213.5 - 106.5 = 107
You'll notice that this is the same width we calculated for the parent view because we've taken its position into account.
I believe this is awesome. I also believe that we have to decouple this logic from RN and put it into awesome Yoga. So I did it in this diff.
**Fun fact:**
The original implementation of this algorithm in RN had (and still have) a bug, which was found by Dustin dshahidehpour and fixed in D4133643. Therefore that diff was unlanded because it broke something unrelated inside RN text engine. I will fix that problem in RN later.
**Why do we need to change test methodology?**
Because the way we receive layout metrics from Chrome browser actually directly related to rounding problem. Previously we used `offsetHeight` and `offsetWidth` properties of the DOM node, which contain naively rounded values from `computedStyle` or `getBoundingClientRect`. (Which is we are trying to fix!) So, I added the new function that computes node size using two-step-rounding approach, conceptually similar to one that implemented in Yoga. Note: Chrome browser performs rounding layout as part of rendering process and actual values that can ve computed by counting actual pixel are different from these natively rounded ones.
**Why do some tests now have different desired values?**
These changes actually prove that my approach is correct and more useful for actual view rendering goals. So, let's take a look at test with changed values `rounding_fractial_input_3`:
Previously: 64+25+24=114 (Incorrect!)
Now: 65+24+25=114 (Correct!)
Previously: 64+25+24=114 (Incorrect!)
Now: 65+24+25=114 (Correct!)
Reviewed By: emilsjolander
Differential Revision: D4941266
fbshipit-source-id: 07500f5cc93c628219500e9e07291438e9d5d36c
2017-04-25 17:29:27 -07:00
|
|
|
function getRoundedSize(node) {
|
|
|
|
var boundingRect = node.getBoundingClientRect();
|
|
|
|
return {
|
|
|
|
width: Math.round(boundingRect.right) - Math.round(boundingRect.left),
|
|
|
|
height: Math.round(boundingRect.bottom) - Math.round(boundingRect.top)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function calculateTree(root, roundToPixelGrid) {
|
2016-08-11 11:45:45 -07:00
|
|
|
var rootLayout = [];
|
|
|
|
|
|
|
|
for (var i = 0; i < root.children.length; i++) {
|
|
|
|
var child = root.children[i];
|
New round-to-pixel-grid algorithm that fixes possible subpixel gaps between sibling nodes
Summary:
This diff introduces new, little bit sophisticated round-to-pixel-grid algorithm.
**Motivation:**
Previous simple and straightforward solution works in most cases but sometimes produce the not-so-great result. A while ago Nick Lockwood described this problem and proposed the solution in RN's RCTShadowView class:
For example, say you have the following structure:
// +--------+---------+--------+
// | |+-------+| |
// | || || |
// | |+-------+| |
// +--------+---------+--------+
Say the screen width is 320 pts so the three big views will get the following x bounds from our layout system:
{0, 106.667}, {106.667, 213.333}, {213.333, 320}
Assuming screen scale is 2, these numbers must be rounded to the nearest 0.5 to fit the pixel grid:
{0, 106.5}, {106.5, 213.5}, {213.5, 320}
You'll notice that the three widths are 106.5, 107, 106.5.
This is great for the parent views but it gets trickier when we consider rounding for the subview. When we go to round the bounds for the subview in the middle, it's relative bounds are {0, 106.667} which gets rounded to {0, 106.5}. This will cause the subview to be one pixel smaller than it should be. This is why we need to pass in the absolute position in order to do the rounding relative to the screen's grid rather than the view's grid. After passing in the absolutePosition of {106.667, y}, we do the following calculations:
absoluteLeft = round(absolutePosition.x + viewPosition.left) = round(106.667 + 0) = 106.5
absoluteRight = round(absolutePosition.x + viewPosition.left + viewSize.width) + round(106.667 + 0 + 106.667) = 213.5
width = 213.5 - 106.5 = 107
You'll notice that this is the same width we calculated for the parent view because we've taken its position into account.
I believe this is awesome. I also believe that we have to decouple this logic from RN and put it into awesome Yoga. So I did it in this diff.
**Fun fact:**
The original implementation of this algorithm in RN had (and still have) a bug, which was found by Dustin dshahidehpour and fixed in D4133643. Therefore that diff was unlanded because it broke something unrelated inside RN text engine. I will fix that problem in RN later.
**Why do we need to change test methodology?**
Because the way we receive layout metrics from Chrome browser actually directly related to rounding problem. Previously we used `offsetHeight` and `offsetWidth` properties of the DOM node, which contain naively rounded values from `computedStyle` or `getBoundingClientRect`. (Which is we are trying to fix!) So, I added the new function that computes node size using two-step-rounding approach, conceptually similar to one that implemented in Yoga. Note: Chrome browser performs rounding layout as part of rendering process and actual values that can ve computed by counting actual pixel are different from these natively rounded ones.
**Why do some tests now have different desired values?**
These changes actually prove that my approach is correct and more useful for actual view rendering goals. So, let's take a look at test with changed values `rounding_fractial_input_3`:
Previously: 64+25+24=114 (Incorrect!)
Now: 65+24+25=114 (Correct!)
Previously: 64+25+24=114 (Incorrect!)
Now: 65+24+25=114 (Correct!)
Reviewed By: emilsjolander
Differential Revision: D4941266
fbshipit-source-id: 07500f5cc93c628219500e9e07291438e9d5d36c
2017-04-25 17:29:27 -07:00
|
|
|
var layout = {
|
2016-08-26 10:22:58 -07:00
|
|
|
name: child.id !== '' ? child.id : 'INSERT_NAME_HERE',
|
2016-08-31 08:02:43 -07:00
|
|
|
left: child.offsetLeft + child.parentNode.clientLeft,
|
|
|
|
top: child.offsetTop + child.parentNode.clientTop,
|
2016-08-11 11:45:45 -07:00
|
|
|
width: child.offsetWidth,
|
|
|
|
height: child.offsetHeight,
|
New round-to-pixel-grid algorithm that fixes possible subpixel gaps between sibling nodes
Summary:
This diff introduces new, little bit sophisticated round-to-pixel-grid algorithm.
**Motivation:**
Previous simple and straightforward solution works in most cases but sometimes produce the not-so-great result. A while ago Nick Lockwood described this problem and proposed the solution in RN's RCTShadowView class:
For example, say you have the following structure:
// +--------+---------+--------+
// | |+-------+| |
// | || || |
// | |+-------+| |
// +--------+---------+--------+
Say the screen width is 320 pts so the three big views will get the following x bounds from our layout system:
{0, 106.667}, {106.667, 213.333}, {213.333, 320}
Assuming screen scale is 2, these numbers must be rounded to the nearest 0.5 to fit the pixel grid:
{0, 106.5}, {106.5, 213.5}, {213.5, 320}
You'll notice that the three widths are 106.5, 107, 106.5.
This is great for the parent views but it gets trickier when we consider rounding for the subview. When we go to round the bounds for the subview in the middle, it's relative bounds are {0, 106.667} which gets rounded to {0, 106.5}. This will cause the subview to be one pixel smaller than it should be. This is why we need to pass in the absolute position in order to do the rounding relative to the screen's grid rather than the view's grid. After passing in the absolutePosition of {106.667, y}, we do the following calculations:
absoluteLeft = round(absolutePosition.x + viewPosition.left) = round(106.667 + 0) = 106.5
absoluteRight = round(absolutePosition.x + viewPosition.left + viewSize.width) + round(106.667 + 0 + 106.667) = 213.5
width = 213.5 - 106.5 = 107
You'll notice that this is the same width we calculated for the parent view because we've taken its position into account.
I believe this is awesome. I also believe that we have to decouple this logic from RN and put it into awesome Yoga. So I did it in this diff.
**Fun fact:**
The original implementation of this algorithm in RN had (and still have) a bug, which was found by Dustin dshahidehpour and fixed in D4133643. Therefore that diff was unlanded because it broke something unrelated inside RN text engine. I will fix that problem in RN later.
**Why do we need to change test methodology?**
Because the way we receive layout metrics from Chrome browser actually directly related to rounding problem. Previously we used `offsetHeight` and `offsetWidth` properties of the DOM node, which contain naively rounded values from `computedStyle` or `getBoundingClientRect`. (Which is we are trying to fix!) So, I added the new function that computes node size using two-step-rounding approach, conceptually similar to one that implemented in Yoga. Note: Chrome browser performs rounding layout as part of rendering process and actual values that can ve computed by counting actual pixel are different from these natively rounded ones.
**Why do some tests now have different desired values?**
These changes actually prove that my approach is correct and more useful for actual view rendering goals. So, let's take a look at test with changed values `rounding_fractial_input_3`:
Previously: 64+25+24=114 (Incorrect!)
Now: 65+24+25=114 (Correct!)
Previously: 64+25+24=114 (Incorrect!)
Now: 65+24+25=114 (Correct!)
Reviewed By: emilsjolander
Differential Revision: D4941266
fbshipit-source-id: 07500f5cc93c628219500e9e07291438e9d5d36c
2017-04-25 17:29:27 -07:00
|
|
|
children: calculateTree(child, roundToPixelGrid),
|
2016-12-03 04:40:21 -08:00
|
|
|
style: getYogaStyle(child),
|
2016-08-25 15:28:35 -07:00
|
|
|
declaredStyle: child.style,
|
2016-09-14 08:51:07 -07:00
|
|
|
rawStyle: child.getAttribute('style'),
|
2016-11-23 11:12:51 -08:00
|
|
|
experiments: child.getAttribute('experiments')
|
|
|
|
? child.getAttribute('experiments').split(' ')
|
|
|
|
: [],
|
New round-to-pixel-grid algorithm that fixes possible subpixel gaps between sibling nodes
Summary:
This diff introduces new, little bit sophisticated round-to-pixel-grid algorithm.
**Motivation:**
Previous simple and straightforward solution works in most cases but sometimes produce the not-so-great result. A while ago Nick Lockwood described this problem and proposed the solution in RN's RCTShadowView class:
For example, say you have the following structure:
// +--------+---------+--------+
// | |+-------+| |
// | || || |
// | |+-------+| |
// +--------+---------+--------+
Say the screen width is 320 pts so the three big views will get the following x bounds from our layout system:
{0, 106.667}, {106.667, 213.333}, {213.333, 320}
Assuming screen scale is 2, these numbers must be rounded to the nearest 0.5 to fit the pixel grid:
{0, 106.5}, {106.5, 213.5}, {213.5, 320}
You'll notice that the three widths are 106.5, 107, 106.5.
This is great for the parent views but it gets trickier when we consider rounding for the subview. When we go to round the bounds for the subview in the middle, it's relative bounds are {0, 106.667} which gets rounded to {0, 106.5}. This will cause the subview to be one pixel smaller than it should be. This is why we need to pass in the absolute position in order to do the rounding relative to the screen's grid rather than the view's grid. After passing in the absolutePosition of {106.667, y}, we do the following calculations:
absoluteLeft = round(absolutePosition.x + viewPosition.left) = round(106.667 + 0) = 106.5
absoluteRight = round(absolutePosition.x + viewPosition.left + viewSize.width) + round(106.667 + 0 + 106.667) = 213.5
width = 213.5 - 106.5 = 107
You'll notice that this is the same width we calculated for the parent view because we've taken its position into account.
I believe this is awesome. I also believe that we have to decouple this logic from RN and put it into awesome Yoga. So I did it in this diff.
**Fun fact:**
The original implementation of this algorithm in RN had (and still have) a bug, which was found by Dustin dshahidehpour and fixed in D4133643. Therefore that diff was unlanded because it broke something unrelated inside RN text engine. I will fix that problem in RN later.
**Why do we need to change test methodology?**
Because the way we receive layout metrics from Chrome browser actually directly related to rounding problem. Previously we used `offsetHeight` and `offsetWidth` properties of the DOM node, which contain naively rounded values from `computedStyle` or `getBoundingClientRect`. (Which is we are trying to fix!) So, I added the new function that computes node size using two-step-rounding approach, conceptually similar to one that implemented in Yoga. Note: Chrome browser performs rounding layout as part of rendering process and actual values that can ve computed by counting actual pixel are different from these natively rounded ones.
**Why do some tests now have different desired values?**
These changes actually prove that my approach is correct and more useful for actual view rendering goals. So, let's take a look at test with changed values `rounding_fractial_input_3`:
Previously: 64+25+24=114 (Incorrect!)
Now: 65+24+25=114 (Correct!)
Previously: 64+25+24=114 (Incorrect!)
Now: 65+24+25=114 (Correct!)
Reviewed By: emilsjolander
Differential Revision: D4941266
fbshipit-source-id: 07500f5cc93c628219500e9e07291438e9d5d36c
2017-04-25 17:29:27 -07:00
|
|
|
};
|
|
|
|
|
2017-04-27 07:09:24 -07:00
|
|
|
var size = getRoundedSize(child);
|
|
|
|
layout.width = size.width;
|
|
|
|
layout.height = size.height;
|
New round-to-pixel-grid algorithm that fixes possible subpixel gaps between sibling nodes
Summary:
This diff introduces new, little bit sophisticated round-to-pixel-grid algorithm.
**Motivation:**
Previous simple and straightforward solution works in most cases but sometimes produce the not-so-great result. A while ago Nick Lockwood described this problem and proposed the solution in RN's RCTShadowView class:
For example, say you have the following structure:
// +--------+---------+--------+
// | |+-------+| |
// | || || |
// | |+-------+| |
// +--------+---------+--------+
Say the screen width is 320 pts so the three big views will get the following x bounds from our layout system:
{0, 106.667}, {106.667, 213.333}, {213.333, 320}
Assuming screen scale is 2, these numbers must be rounded to the nearest 0.5 to fit the pixel grid:
{0, 106.5}, {106.5, 213.5}, {213.5, 320}
You'll notice that the three widths are 106.5, 107, 106.5.
This is great for the parent views but it gets trickier when we consider rounding for the subview. When we go to round the bounds for the subview in the middle, it's relative bounds are {0, 106.667} which gets rounded to {0, 106.5}. This will cause the subview to be one pixel smaller than it should be. This is why we need to pass in the absolute position in order to do the rounding relative to the screen's grid rather than the view's grid. After passing in the absolutePosition of {106.667, y}, we do the following calculations:
absoluteLeft = round(absolutePosition.x + viewPosition.left) = round(106.667 + 0) = 106.5
absoluteRight = round(absolutePosition.x + viewPosition.left + viewSize.width) + round(106.667 + 0 + 106.667) = 213.5
width = 213.5 - 106.5 = 107
You'll notice that this is the same width we calculated for the parent view because we've taken its position into account.
I believe this is awesome. I also believe that we have to decouple this logic from RN and put it into awesome Yoga. So I did it in this diff.
**Fun fact:**
The original implementation of this algorithm in RN had (and still have) a bug, which was found by Dustin dshahidehpour and fixed in D4133643. Therefore that diff was unlanded because it broke something unrelated inside RN text engine. I will fix that problem in RN later.
**Why do we need to change test methodology?**
Because the way we receive layout metrics from Chrome browser actually directly related to rounding problem. Previously we used `offsetHeight` and `offsetWidth` properties of the DOM node, which contain naively rounded values from `computedStyle` or `getBoundingClientRect`. (Which is we are trying to fix!) So, I added the new function that computes node size using two-step-rounding approach, conceptually similar to one that implemented in Yoga. Note: Chrome browser performs rounding layout as part of rendering process and actual values that can ve computed by counting actual pixel are different from these natively rounded ones.
**Why do some tests now have different desired values?**
These changes actually prove that my approach is correct and more useful for actual view rendering goals. So, let's take a look at test with changed values `rounding_fractial_input_3`:
Previously: 64+25+24=114 (Incorrect!)
Now: 65+24+25=114 (Correct!)
Previously: 64+25+24=114 (Incorrect!)
Now: 65+24+25=114 (Correct!)
Reviewed By: emilsjolander
Differential Revision: D4941266
fbshipit-source-id: 07500f5cc93c628219500e9e07291438e9d5d36c
2017-04-25 17:29:27 -07:00
|
|
|
|
|
|
|
rootLayout.push(layout);
|
2016-08-11 11:45:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return rootLayout;
|
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:21 -08:00
|
|
|
function getYogaStyle(node) {
|
2016-08-11 11:45:45 -07:00
|
|
|
return [
|
|
|
|
'direction',
|
|
|
|
'flex-direction',
|
|
|
|
'justify-content',
|
|
|
|
'align-content',
|
|
|
|
'align-items',
|
|
|
|
'align-self',
|
|
|
|
'position',
|
|
|
|
'flex-wrap',
|
|
|
|
'overflow',
|
|
|
|
'flex-grow',
|
|
|
|
'flex-shrink',
|
2016-08-15 09:15:05 -07:00
|
|
|
'flex-basis',
|
2016-08-11 11:45:45 -07:00
|
|
|
'left',
|
|
|
|
'top',
|
|
|
|
'right',
|
|
|
|
'bottom',
|
|
|
|
'margin-left',
|
|
|
|
'margin-top',
|
|
|
|
'margin-right',
|
|
|
|
'margin-bottom',
|
|
|
|
'padding-left',
|
|
|
|
'padding-top',
|
|
|
|
'padding-right',
|
|
|
|
'padding-bottom',
|
|
|
|
'border-left-width',
|
|
|
|
'border-top-width',
|
|
|
|
'border-right-width',
|
|
|
|
'border-bottom-width',
|
|
|
|
'width',
|
|
|
|
'min-width',
|
|
|
|
'max-width',
|
|
|
|
'height',
|
|
|
|
'min-height',
|
|
|
|
'max-height',
|
2017-02-06 09:31:22 -08:00
|
|
|
'display',
|
2016-09-14 08:51:07 -07:00
|
|
|
].reduce(function(map, key) {
|
2016-10-17 06:27:59 -07:00
|
|
|
map[key] = node.style[key] || getComputedStyle(node, null).getPropertyValue(key);
|
2016-09-14 08:51:07 -07:00
|
|
|
return map;
|
2016-08-11 11:45:45 -07:00
|
|
|
}, {});
|
|
|
|
}
|
2016-10-23 10:27:30 -07:00
|
|
|
|
|
|
|
var Emitter = function(lang, indent) {
|
|
|
|
this.lang = lang;
|
|
|
|
this.indent = indent;
|
|
|
|
this.indents = [];
|
|
|
|
this.lines = [];
|
|
|
|
};
|
|
|
|
|
|
|
|
Emitter.prototype = Object.create(Object.prototype, {
|
|
|
|
constructor:{value:Emitter},
|
|
|
|
|
|
|
|
pushIndent:{value:function() {
|
|
|
|
this.indents.push(this.indent);
|
|
|
|
}},
|
|
|
|
|
|
|
|
popIndent:{value:function() {
|
|
|
|
this.indents.pop();
|
|
|
|
}},
|
|
|
|
|
|
|
|
push:{value:function(line) {
|
|
|
|
if (line instanceof Array) {
|
|
|
|
line.forEach(function(element) {
|
|
|
|
this.push(element);
|
|
|
|
}, this);
|
|
|
|
return;
|
|
|
|
} else if (line.length > 0) {
|
|
|
|
line = this.indents.join('') + line;
|
|
|
|
}
|
|
|
|
this.lines.push(line);
|
|
|
|
}},
|
|
|
|
|
|
|
|
print:{value:function() {
|
|
|
|
console.log(this.lines.join('\n'));
|
|
|
|
}},
|
|
|
|
});
|