Fix width being ignored when has a value of 0

8f6a96adbc added a test in isDimDefined that checks if `value > 0.0`, but unfortunately, it did not faithfully port the JavaScript version which is `value >= 0.0`. Sadly, no test covered this so it went unnoticed.
This commit is contained in:
Christopher Chedeau
2015-09-25 13:09:58 -07:00
parent 246005cc84
commit e280a577ae
14 changed files with 140 additions and 23 deletions

2
dist/css-layout.h vendored
View File

@@ -613,7 +613,7 @@ static float getDimWithMargin(css_node_t *node, css_flex_direction_t axis) {
static bool isDimDefined(css_node_t *node, css_flex_direction_t axis) {
float value = node->style.dimensions[dim[axis]];
return !isUndefined(value) && value > 0.0;
return !isUndefined(value) && value >= 0.0;
}
static bool isPosDefined(css_node_t *node, css_position_t position) {

BIN
dist/css-layout.jar vendored

Binary file not shown.

2
dist/css-layout.js vendored
View File

@@ -1095,7 +1095,7 @@ var computeLayout = (function() {
})();
// This module export is only used for the purposes of unit testing this file. When
// the library is packaged this file is included within css-layout.js which forms
// the library is packaged this file is included within css-layout.js which forms
// the public API.
if (typeof exports === 'object') {
module.exports = computeLayout;

File diff suppressed because one or more lines are too long

View File

@@ -30,7 +30,7 @@ function __transpileToCSharpCommon(code) {
.replace(/getJustifyContent\((.+?)\)/g, '$1.style.justifyContent')
.replace(/getAlignContent\((.+?)\)/g, '$1.style.alignContent')
.replace(/isPosDefined\((.+?),\s*(.+?)\)/g, '!isUndefined\($1.style.position[$2]\)')
.replace(/isDimDefined\((.+?),\s*(.+?)\)/g, '\(!isUndefined\($1.style.dimensions[dim[$2]]\) && $1.style.dimensions[dim[$2]] > 0.0\)')
.replace(/isDimDefined\((.+?),\s*(.+?)\)/g, '\(!isUndefined\($1.style.dimensions[dim[$2]]\) && $1.style.dimensions[dim[$2]] >= 0.0\)')
.replace(/getPosition\((.+?),\s*(.+?)\)/g, '\(isUndefined\($1.style.position[$2]\) ? 0 : $1.style.position[$2]\)')
.replace(/setTrailingPosition\((.+?),\s*(.+?),\s*(.+?)\)/g, '$2.layout.position[trailing[$3]] = $1.layout.dimensions[dim[$3]] - $2.layout.dimensions[dim[$3]] - $2.layout.position[pos[$3]]')
.replace(/isFlex\((.+?)\)/g, '\($1.style.positionType == CSSPositionType.RELATIVE && $1.style.flex > 0\)')

View File

@@ -30,7 +30,7 @@ function __transpileToJavaCommon(code) {
.replace(/getJustifyContent\((.+?)\)/g, '$1.style.justifyContent')
.replace(/getAlignContent\((.+?)\)/g, '$1.style.alignContent')
.replace(/isPosDefined\((.+?),\s*(.+?)\)/g, '!isUndefined\($1.style.position[$2]\)')
.replace(/isDimDefined\((.+?),\s*(.+?)\)/g, '\(!isUndefined\($1.style.dimensions[dim[$2]]\) && $1.style.dimensions[dim[$2]] > 0.0\)')
.replace(/isDimDefined\((.+?),\s*(.+?)\)/g, '\(!isUndefined\($1.style.dimensions[dim[$2]]\) && $1.style.dimensions[dim[$2]] >= 0.0\)')
.replace(/getPosition\((.+?),\s*(.+?)\)/g, '\(isUndefined\($1.style.position[$2]\) ? 0 : $1.style.position[$2]\)')
.replace(/setTrailingPosition\((.+?),\s*(.+?),\s*(.+?)\)/g, '$2.layout.position[trailing[$3]] = $1.layout.dimensions[dim[$3]] - $2.layout.dimensions[dim[$3]] - $2.layout.position[pos[$3]]')
.replace(/isFlex\((.+?)\)/g, '\($1.style.positionType == CSSPositionType.RELATIVE && $1.style.flex > 0\)')

View File

@@ -440,7 +440,7 @@ static float getDimWithMargin(css_node_t *node, css_flex_direction_t axis) {
static bool isDimDefined(css_node_t *node, css_flex_direction_t axis) {
float value = node->style.dimensions[dim[axis]];
return !isUndefined(value) && value > 0.0;
return !isUndefined(value) && value >= 0.0;
}
static bool isPosDefined(css_node_t *node, css_position_t position) {

View File

@@ -1076,7 +1076,7 @@ var computeLayout = (function() {
})();
// This module export is only used for the purposes of unit testing this file. When
// the library is packaged this file is included within css-layout.js which forms
// the library is packaged this file is included within css-layout.js which forms
// the public API.
if (typeof exports === 'object') {
module.exports = computeLayout;

View File

@@ -7468,6 +7468,40 @@ int main()
test("should layout node with correct start/end border in rtl", root_node, root_layout);
}
{
css_node_t *root_node = new_test_css_node();
{
css_node_t *node_0 = root_node;
node_0->style.dimensions[CSS_WIDTH] = 200;
init_css_node_children(node_0, 1);
{
css_node_t *node_1;
node_1 = node_0->get_child(node_0->context, 0);
node_1->style.dimensions[CSS_WIDTH] = 0;
}
}
css_node_t *root_layout = new_test_css_node();
{
css_node_t *node_0 = root_layout;
node_0->layout.position[CSS_TOP] = 0;
node_0->layout.position[CSS_LEFT] = 0;
node_0->layout.dimensions[CSS_WIDTH] = 200;
node_0->layout.dimensions[CSS_HEIGHT] = 0;
init_css_node_children(node_0, 1);
{
css_node_t *node_1;
node_1 = node_0->get_child(node_0->context, 0);
node_1->layout.position[CSS_TOP] = 0;
node_1->layout.position[CSS_LEFT] = 0;
node_1->layout.dimensions[CSS_WIDTH] = 0;
node_1->layout.dimensions[CSS_HEIGHT] = 0;
}
}
test("should layout node with a 0 width", root_node, root_layout);
}
{
css_node_t *root_node = new_test_css_node();
{

View File

@@ -2298,6 +2298,17 @@ describe('Layout', function() {
);
});
it('should layout node with a 0 width', function() {
testLayout(
{style: {width: 200}, children: [
{style: {width: 0}}
]},
{width: 200, height: 0, top: 0, left: 0, children: [
{width: 0, height: 0, top: 0, left: 0}
]}
);
});
xit('should stretch a nested child', function() {
testLayout(
{children: [

View File

@@ -7903,6 +7903,42 @@ public class LayoutEngineTest
[Test]
public void TestCase177()
{
TestCSSNode root_node = new TestCSSNode();
{
TestCSSNode node_0 = root_node;
node_0.style.dimensions[DIMENSION_WIDTH] = 200;
addChildren(node_0, 1);
{
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.style.dimensions[DIMENSION_WIDTH] = 0;
}
}
TestCSSNode root_layout = new TestCSSNode();
{
TestCSSNode node_0 = root_layout;
node_0.layout.position[POSITION_TOP] = 0;
node_0.layout.position[POSITION_LEFT] = 0;
node_0.layout.dimensions[DIMENSION_WIDTH] = 200;
node_0.layout.dimensions[DIMENSION_HEIGHT] = 0;
addChildren(node_0, 1);
{
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.layout.position[POSITION_TOP] = 0;
node_1.layout.position[POSITION_LEFT] = 0;
node_1.layout.dimensions[DIMENSION_WIDTH] = 0;
node_1.layout.dimensions[DIMENSION_HEIGHT] = 0;
}
}
test("should layout node with a 0 width", root_node, root_layout);
}
[Test]
public void TestCase178()
{
TestCSSNode root_node = new TestCSSNode();
{

View File

@@ -273,7 +273,7 @@ namespace Facebook.CSSLayout
boolean isResolvedRowDimDefined = !float.IsNaN(node.layout.dimensions[dim[resolvedRowAxis]]);
float width = CSSConstants.Undefined;
if ((!float.IsNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] > 0.0)) {
if ((!float.IsNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] >= 0.0)) {
width = node.style.dimensions[DIMENSION_WIDTH];
} else if (isResolvedRowDimDefined) {
width = node.layout.dimensions[dim[resolvedRowAxis]];
@@ -286,8 +286,8 @@ namespace Facebook.CSSLayout
// We only need to give a dimension for the text if we haven't got any
// for it computed yet. It can either be from the style attribute or because
// the element is flexible.
boolean isRowUndefined = !(!float.IsNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] > 0.0) && !isResolvedRowDimDefined;
boolean isColumnUndefined = !(!float.IsNaN(node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]) && node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] > 0.0) &&
boolean isRowUndefined = !(!float.IsNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] >= 0.0) && !isResolvedRowDimDefined;
boolean isColumnUndefined = !(!float.IsNaN(node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]) && node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] >= 0.0) &&
float.IsNaN(node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]);
// Let's not measure the text if we already know both dimensions
@@ -398,7 +398,7 @@ namespace Facebook.CSSLayout
if (alignItem == CSSAlign.Stretch &&
child.style.positionType == CSSPositionType.Relative &&
isCrossDimDefined &&
!(!float.IsNaN(child.style.dimensions[dim[crossAxis]]) && child.style.dimensions[dim[crossAxis]] > 0.0)) {
!(!float.IsNaN(child.style.dimensions[dim[crossAxis]]) && child.style.dimensions[dim[crossAxis]] >= 0.0)) {
child.layout.dimensions[dim[crossAxis]] = Math.Max(
boundAxis(child, crossAxis, node.layout.dimensions[dim[crossAxis]] -
paddingAndBorderAxisCross - (child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + child.style.margin.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]))),
@@ -421,7 +421,7 @@ namespace Facebook.CSSLayout
for (ii = 0; ii < 2; ii++) {
axis = (ii != 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN;
if (!float.IsNaN(node.layout.dimensions[dim[axis]]) &&
!(!float.IsNaN(child.style.dimensions[dim[axis]]) && child.style.dimensions[dim[axis]] > 0.0) &&
!(!float.IsNaN(child.style.dimensions[dim[axis]]) && child.style.dimensions[dim[axis]] >= 0.0) &&
!float.IsNaN(child.style.position[leading[axis]]) &&
!float.IsNaN(child.style.position[trailing[axis]])) {
child.layout.dimensions[dim[axis]] = Math.Max(
@@ -465,7 +465,7 @@ namespace Facebook.CSSLayout
} else {
maxWidth = CSSConstants.Undefined;
if (!isMainRowDirection) {
if ((!float.IsNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] > 0.0)) {
if ((!float.IsNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] >= 0.0)) {
maxWidth = node.layout.dimensions[dim[resolvedRowAxis]] -
paddingAndBorderAxisResolvedRow;
} else {
@@ -599,7 +599,7 @@ namespace Facebook.CSSLayout
);
maxWidth = CSSConstants.Undefined;
if ((!float.IsNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] > 0.0)) {
if ((!float.IsNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] >= 0.0)) {
maxWidth = node.layout.dimensions[dim[resolvedRowAxis]] -
paddingAndBorderAxisResolvedRow;
} else if (!isMainRowDirection) {
@@ -894,7 +894,7 @@ namespace Facebook.CSSLayout
axis = (ii != 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN;
if (!float.IsNaN(node.layout.dimensions[dim[axis]]) &&
!(!float.IsNaN(currentAbsoluteChild.style.dimensions[dim[axis]]) && currentAbsoluteChild.style.dimensions[dim[axis]] > 0.0) &&
!(!float.IsNaN(currentAbsoluteChild.style.dimensions[dim[axis]]) && currentAbsoluteChild.style.dimensions[dim[axis]] >= 0.0) &&
!float.IsNaN(currentAbsoluteChild.style.position[leading[axis]]) &&
!float.IsNaN(currentAbsoluteChild.style.position[trailing[axis]])) {
currentAbsoluteChild.layout.dimensions[dim[axis]] = Math.Max(

View File

@@ -253,7 +253,7 @@ public class LayoutEngine {
boolean isResolvedRowDimDefined = !Float.isNaN(node.layout.dimensions[dim[resolvedRowAxis]]);
float width = CSSConstants.UNDEFINED;
if ((!Float.isNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] > 0.0)) {
if ((!Float.isNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] >= 0.0)) {
width = node.style.dimensions[DIMENSION_WIDTH];
} else if (isResolvedRowDimDefined) {
width = node.layout.dimensions[dim[resolvedRowAxis]];
@@ -266,8 +266,8 @@ public class LayoutEngine {
// We only need to give a dimension for the text if we haven't got any
// for it computed yet. It can either be from the style attribute or because
// the element is flexible.
boolean isRowUndefined = !(!Float.isNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] > 0.0) && !isResolvedRowDimDefined;
boolean isColumnUndefined = !(!Float.isNaN(node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]) && node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] > 0.0) &&
boolean isRowUndefined = !(!Float.isNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] >= 0.0) && !isResolvedRowDimDefined;
boolean isColumnUndefined = !(!Float.isNaN(node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]) && node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] >= 0.0) &&
Float.isNaN(node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]);
// Let's not measure the text if we already know both dimensions
@@ -378,7 +378,7 @@ public class LayoutEngine {
if (alignItem == CSSAlign.STRETCH &&
child.style.positionType == CSSPositionType.RELATIVE &&
isCrossDimDefined &&
!(!Float.isNaN(child.style.dimensions[dim[crossAxis]]) && child.style.dimensions[dim[crossAxis]] > 0.0)) {
!(!Float.isNaN(child.style.dimensions[dim[crossAxis]]) && child.style.dimensions[dim[crossAxis]] >= 0.0)) {
child.layout.dimensions[dim[crossAxis]] = Math.max(
boundAxis(child, crossAxis, node.layout.dimensions[dim[crossAxis]] -
paddingAndBorderAxisCross - (child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + child.style.margin.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]))),
@@ -401,7 +401,7 @@ public class LayoutEngine {
for (ii = 0; ii < 2; ii++) {
axis = (ii != 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN;
if (!Float.isNaN(node.layout.dimensions[dim[axis]]) &&
!(!Float.isNaN(child.style.dimensions[dim[axis]]) && child.style.dimensions[dim[axis]] > 0.0) &&
!(!Float.isNaN(child.style.dimensions[dim[axis]]) && child.style.dimensions[dim[axis]] >= 0.0) &&
!Float.isNaN(child.style.position[leading[axis]]) &&
!Float.isNaN(child.style.position[trailing[axis]])) {
child.layout.dimensions[dim[axis]] = Math.max(
@@ -445,7 +445,7 @@ public class LayoutEngine {
} else {
maxWidth = CSSConstants.UNDEFINED;
if (!isMainRowDirection) {
if ((!Float.isNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] > 0.0)) {
if ((!Float.isNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] >= 0.0)) {
maxWidth = node.layout.dimensions[dim[resolvedRowAxis]] -
paddingAndBorderAxisResolvedRow;
} else {
@@ -579,7 +579,7 @@ public class LayoutEngine {
);
maxWidth = CSSConstants.UNDEFINED;
if ((!Float.isNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] > 0.0)) {
if ((!Float.isNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] >= 0.0)) {
maxWidth = node.layout.dimensions[dim[resolvedRowAxis]] -
paddingAndBorderAxisResolvedRow;
} else if (!isMainRowDirection) {
@@ -874,7 +874,7 @@ public class LayoutEngine {
axis = (ii != 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN;
if (!Float.isNaN(node.layout.dimensions[dim[axis]]) &&
!(!Float.isNaN(currentAbsoluteChild.style.dimensions[dim[axis]]) && currentAbsoluteChild.style.dimensions[dim[axis]] > 0.0) &&
!(!Float.isNaN(currentAbsoluteChild.style.dimensions[dim[axis]]) && currentAbsoluteChild.style.dimensions[dim[axis]] >= 0.0) &&
!Float.isNaN(currentAbsoluteChild.style.position[leading[axis]]) &&
!Float.isNaN(currentAbsoluteChild.style.position[trailing[axis]])) {
currentAbsoluteChild.layout.dimensions[dim[axis]] = Math.max(

View File

@@ -7906,6 +7906,42 @@ public class LayoutEngineTest {
@Test
public void testCase177()
{
TestCSSNode root_node = new TestCSSNode();
{
TestCSSNode node_0 = root_node;
node_0.style.dimensions[DIMENSION_WIDTH] = 200;
addChildren(node_0, 1);
{
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.style.dimensions[DIMENSION_WIDTH] = 0;
}
}
TestCSSNode root_layout = new TestCSSNode();
{
TestCSSNode node_0 = root_layout;
node_0.layout.position[POSITION_TOP] = 0;
node_0.layout.position[POSITION_LEFT] = 0;
node_0.layout.dimensions[DIMENSION_WIDTH] = 200;
node_0.layout.dimensions[DIMENSION_HEIGHT] = 0;
addChildren(node_0, 1);
{
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.layout.position[POSITION_TOP] = 0;
node_1.layout.position[POSITION_LEFT] = 0;
node_1.layout.dimensions[DIMENSION_WIDTH] = 0;
node_1.layout.dimensions[DIMENSION_HEIGHT] = 0;
}
}
test("should layout node with a 0 width", root_node, root_layout);
}
@Test
public void testCase178()
{
TestCSSNode root_node = new TestCSSNode();
{