Merge pull request #154 from majak/width

This commit is contained in:
Lucas Rocha
2015-12-14 16:28:52 +00:00
29 changed files with 1139 additions and 294 deletions

56
dist/css-layout.h vendored
View File

@@ -95,6 +95,7 @@ typedef struct {
bool should_update;
float last_requested_dimensions[2];
float last_parent_max_width;
float last_parent_max_height;
float last_dimensions[2];
float last_position[2];
css_direction_t last_direction;
@@ -143,7 +144,7 @@ struct css_node {
css_node_t* next_absolute_child;
css_node_t* next_flex_child;
css_dim_t (*measure)(void *context, float width);
css_dim_t (*measure)(void *context, float width, float height);
void (*print)(void *context);
struct css_node* (*get_child)(void *context, int i);
bool (*is_dirty)(void *context);
@@ -165,7 +166,7 @@ typedef enum {
void print_css_node(css_node_t *node, css_print_options_t options);
// Function that computes the layout!
void layoutNode(css_node_t *node, float maxWidth, css_direction_t parentDirection);
void layoutNode(css_node_t *node, float maxWidth, float maxHeight, css_direction_t parentDirection);
bool isUndefined(float value);
#endif
@@ -249,6 +250,7 @@ void init_css_node(css_node_t *node) {
node->layout.last_requested_dimensions[CSS_WIDTH] = -1;
node->layout.last_requested_dimensions[CSS_HEIGHT] = -1;
node->layout.last_parent_max_width = -1;
node->layout.last_parent_max_height = -1;
node->layout.last_direction = (css_direction_t)-1;
node->layout.should_update = true;
}
@@ -689,7 +691,7 @@ static float getRelativePosition(css_node_t *node, css_flex_direction_t axis) {
return -getPosition(node, trailing[axis]);
}
static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction_t parentDirection) {
static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, float parentMaxHeight, css_direction_t parentDirection) {
/** START_GENERATED **/
css_direction_t direction = resolveDirection(node, parentDirection);
css_flex_direction_t mainAxis = resolveAxis(getFlexDirection(node), direction);
@@ -718,6 +720,7 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
// invocations during the layout calculation.
int childCount = node->children_count;
float paddingAndBorderAxisResolvedRow = getPaddingAndBorderAxis(node, resolvedRowAxis);
float paddingAndBorderAxisColumn = getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN);
if (isMeasureDefined(node)) {
bool isResolvedRowDimDefined = !isUndefined(node->layout.dimensions[dim[resolvedRowAxis]]);
@@ -733,6 +736,17 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
}
width -= paddingAndBorderAxisResolvedRow;
float height = CSS_UNDEFINED;
if (isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN)) {
height = node->style.dimensions[CSS_HEIGHT];
} else if (!isUndefined(node->layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]])) {
height = node->layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]];
} else {
height = parentMaxHeight -
getMarginAxis(node, resolvedRowAxis);
}
height -= getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN);
// 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.
@@ -745,7 +759,8 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
css_dim_t measureDim = node->measure(
node->context,
width
width,
height
);
if (isRowUndefined) {
node->layout.dimensions[CSS_WIDTH] = measureDim.dimensions[CSS_WIDTH] +
@@ -753,7 +768,7 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
}
if (isColumnUndefined) {
node->layout.dimensions[CSS_HEIGHT] = measureDim.dimensions[CSS_HEIGHT] +
getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN);
paddingAndBorderAxisColumn;
}
}
if (childCount == 0) {
@@ -834,6 +849,7 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
float crossDim = 0;
float maxWidth;
float maxHeight;
for (i = startLine; i < childCount; ++i) {
child = node->get_child(node->context, i);
child->line_index = linesCount;
@@ -914,6 +930,8 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
} else {
maxWidth = CSS_UNDEFINED;
maxHeight = CSS_UNDEFINED;
if (!isMainRowDirection) {
if (isDimDefined(node, resolvedRowAxis)) {
maxWidth = node->layout.dimensions[dim[resolvedRowAxis]] -
@@ -923,11 +941,20 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
getMarginAxis(node, resolvedRowAxis) -
paddingAndBorderAxisResolvedRow;
}
} else {
if (isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN)) {
maxHeight = node->layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] -
paddingAndBorderAxisColumn;
} else {
maxHeight = parentMaxHeight -
getMarginAxis(node, CSS_FLEX_DIRECTION_COLUMN) -
paddingAndBorderAxisColumn;
}
}
// This is the main recursive call. We layout non flexible children.
if (alreadyComputedNextLayout == 0) {
layoutNode(child, maxWidth, direction);
layoutNode(child, maxWidth, maxHeight, direction);
}
// Absolute positioned elements do not take part of the layout, so we
@@ -1057,9 +1084,18 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
getMarginAxis(node, resolvedRowAxis) -
paddingAndBorderAxisResolvedRow;
}
maxHeight = CSS_UNDEFINED;
if (isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN)) {
maxHeight = node->layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] -
paddingAndBorderAxisColumn;
} else if (isMainRowDirection) {
maxHeight = parentMaxHeight -
getMarginAxis(node, CSS_FLEX_DIRECTION_COLUMN) -
paddingAndBorderAxisColumn;
}
// And we recursively call the layout algorithm for this child
layoutNode(currentFlexChild, maxWidth, direction);
layoutNode(currentFlexChild, maxWidth, maxHeight, direction);
child = currentFlexChild;
currentFlexChild = currentFlexChild->next_flex_child;
@@ -1378,7 +1414,7 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
/** END_GENERATED **/
}
void layoutNode(css_node_t *node, float parentMaxWidth, css_direction_t parentDirection) {
void layoutNode(css_node_t *node, float parentMaxWidth, float parentMaxHeight, css_direction_t parentDirection) {
css_layout_t *layout = &node->layout;
css_direction_t direction = node->style.direction;
layout->should_update = true;
@@ -1388,6 +1424,7 @@ void layoutNode(css_node_t *node, float parentMaxWidth, css_direction_t parentDi
eq(layout->last_requested_dimensions[CSS_WIDTH], layout->dimensions[CSS_WIDTH]) &&
eq(layout->last_requested_dimensions[CSS_HEIGHT], layout->dimensions[CSS_HEIGHT]) &&
eq(layout->last_parent_max_width, parentMaxWidth);
eq(layout->last_parent_max_height, parentMaxHeight);
eq(layout->last_direction, direction);
if (skipLayout) {
@@ -1399,9 +1436,10 @@ void layoutNode(css_node_t *node, float parentMaxWidth, css_direction_t parentDi
layout->last_requested_dimensions[CSS_WIDTH] = layout->dimensions[CSS_WIDTH];
layout->last_requested_dimensions[CSS_HEIGHT] = layout->dimensions[CSS_HEIGHT];
layout->last_parent_max_width = parentMaxWidth;
layout->last_parent_max_height = parentMaxHeight;
layout->last_direction = direction;
layoutNodeImpl(node, parentMaxWidth, parentDirection);
layoutNodeImpl(node, parentMaxWidth, parentMaxHeight, parentDirection);
layout->last_dimensions[CSS_WIDTH] = layout->dimensions[CSS_WIDTH];
layout->last_dimensions[CSS_HEIGHT] = layout->dimensions[CSS_HEIGHT];

BIN
dist/css-layout.jar vendored

Binary file not shown.

55
dist/css-layout.js vendored
View File

@@ -100,6 +100,11 @@ var computeLayout = (function() {
if (!node.children) {
node.children = [];
}
if (node.style.measure && node.children && node.children.length) {
throw new Error('Using custom measure function is supported only for leaf nodes.');
}
node.children.forEach(fillNodes);
return node;
}
@@ -458,7 +463,7 @@ var computeLayout = (function() {
return -getPosition(node, trailing[axis]);
}
function layoutNodeImpl(node, parentMaxWidth, /*css_direction_t*/parentDirection) {
function layoutNodeImpl(node, parentMaxWidth, parentMaxHeight, /*css_direction_t*/parentDirection) {
var/*css_direction_t*/ direction = resolveDirection(node, parentDirection);
var/*(c)!css_flex_direction_t*//*(java)!int*/ mainAxis = resolveAxis(getFlexDirection(node), direction);
var/*(c)!css_flex_direction_t*//*(java)!int*/ crossAxis = getCrossFlexDirection(mainAxis, direction);
@@ -486,6 +491,7 @@ var computeLayout = (function() {
// invocations during the layout calculation.
var/*int*/ childCount = node.children.length;
var/*float*/ paddingAndBorderAxisResolvedRow = getPaddingAndBorderAxis(node, resolvedRowAxis);
var/*float*/ paddingAndBorderAxisColumn = getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN);
if (isMeasureDefined(node)) {
var/*bool*/ isResolvedRowDimDefined = !isUndefined(node.layout[dim[resolvedRowAxis]]);
@@ -501,6 +507,17 @@ var computeLayout = (function() {
}
width -= paddingAndBorderAxisResolvedRow;
var/*float*/ height = CSS_UNDEFINED;
if (isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN)) {
height = node.style.height;
} else if (!isUndefined(node.layout[dim[CSS_FLEX_DIRECTION_COLUMN]])) {
height = node.layout[dim[CSS_FLEX_DIRECTION_COLUMN]];
} else {
height = parentMaxHeight -
getMarginAxis(node, resolvedRowAxis);
}
height -= getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN);
// 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.
@@ -513,7 +530,8 @@ var computeLayout = (function() {
var/*css_dim_t*/ measureDim = node.style.measure(
/*(c)!node->context,*/
/*(java)!layoutContext.measureOutput,*/
width
width,
height
);
if (isRowUndefined) {
node.layout.width = measureDim.width +
@@ -521,7 +539,7 @@ var computeLayout = (function() {
}
if (isColumnUndefined) {
node.layout.height = measureDim.height +
getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN);
paddingAndBorderAxisColumn;
}
}
if (childCount === 0) {
@@ -602,6 +620,7 @@ var computeLayout = (function() {
var/*float*/ crossDim = 0;
var/*float*/ maxWidth;
var/*float*/ maxHeight;
for (i = startLine; i < childCount; ++i) {
child = node.children[i];
child.lineIndex = linesCount;
@@ -682,6 +701,8 @@ var computeLayout = (function() {
} else {
maxWidth = CSS_UNDEFINED;
maxHeight = CSS_UNDEFINED;
if (!isMainRowDirection) {
if (isDimDefined(node, resolvedRowAxis)) {
maxWidth = node.layout[dim[resolvedRowAxis]] -
@@ -691,11 +712,20 @@ var computeLayout = (function() {
getMarginAxis(node, resolvedRowAxis) -
paddingAndBorderAxisResolvedRow;
}
} else {
if (isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN)) {
maxHeight = node.layout[dim[CSS_FLEX_DIRECTION_COLUMN]] -
paddingAndBorderAxisColumn;
} else {
maxHeight = parentMaxHeight -
getMarginAxis(node, CSS_FLEX_DIRECTION_COLUMN) -
paddingAndBorderAxisColumn;
}
}
// This is the main recursive call. We layout non flexible children.
if (alreadyComputedNextLayout === 0) {
layoutNode(/*(java)!layoutContext, */child, maxWidth, direction);
layoutNode(/*(java)!layoutContext, */child, maxWidth, maxHeight, direction);
}
// Absolute positioned elements do not take part of the layout, so we
@@ -825,9 +855,18 @@ var computeLayout = (function() {
getMarginAxis(node, resolvedRowAxis) -
paddingAndBorderAxisResolvedRow;
}
maxHeight = CSS_UNDEFINED;
if (isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN)) {
maxHeight = node.layout[dim[CSS_FLEX_DIRECTION_COLUMN]] -
paddingAndBorderAxisColumn;
} else if (isMainRowDirection) {
maxHeight = parentMaxHeight -
getMarginAxis(node, CSS_FLEX_DIRECTION_COLUMN) -
paddingAndBorderAxisColumn;
}
// And we recursively call the layout algorithm for this child
layoutNode(/*(java)!layoutContext, */currentFlexChild, maxWidth, direction);
layoutNode(/*(java)!layoutContext, */currentFlexChild, maxWidth, maxHeight, direction);
child = currentFlexChild;
currentFlexChild = currentFlexChild.nextFlexChild;
@@ -1145,7 +1184,7 @@ var computeLayout = (function() {
}
}
function layoutNode(node, parentMaxWidth, parentDirection) {
function layoutNode(node, parentMaxWidth, parentMaxHeight, parentDirection) {
node.shouldUpdate = true;
var direction = node.style.direction || CSS_DIRECTION_LTR;
@@ -1155,6 +1194,7 @@ var computeLayout = (function() {
node.lastLayout.requestedHeight === node.layout.height &&
node.lastLayout.requestedWidth === node.layout.width &&
node.lastLayout.parentMaxWidth === parentMaxWidth &&
node.lastLayout.parentMaxHeight === parentMaxHeight &&
node.lastLayout.direction === direction;
if (skipLayout) {
@@ -1170,6 +1210,7 @@ var computeLayout = (function() {
node.lastLayout.requestedWidth = node.layout.width;
node.lastLayout.requestedHeight = node.layout.height;
node.lastLayout.parentMaxWidth = parentMaxWidth;
node.lastLayout.parentMaxHeight = parentMaxHeight;
node.lastLayout.direction = direction;
// Reset child layouts
@@ -1180,7 +1221,7 @@ var computeLayout = (function() {
child.layout.left = 0;
});
layoutNodeImpl(node, parentMaxWidth, parentDirection);
layoutNodeImpl(node, parentMaxWidth, parentMaxHeight, parentDirection);
node.lastLayout.width = node.layout.width;
node.lastLayout.height = node.layout.height;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -108,7 +108,7 @@ function __transpileSingleTestToCSharp(code) {
function(str, match1, match2, match3) {
return 'style.' + match1 + match2.toUpperCase() + match3;
})
.replace(/(\w+)\.measure\s+=\s+.+/, '$1.setMeasureFunction(sTestMeasureFunction);')
.replace(/(\w+)\.measure\s+=\s+.+/g, '$1.setMeasureFunction(sTestMeasureFunction);')
// additional case conversions

View File

@@ -101,7 +101,7 @@ function __transpileSingleTestToJava(code) {
function(str, match1, match2, match3) {
return 'style.' + match1 + match2.toUpperCase() + match3;
})
.replace(/(\w+)\.measure\s+=\s+.+/, '$1.setMeasureFunction(sTestMeasureFunction);');
.replace(/(\w+)\.measure\s+=\s+.+/g, '$1.setMeasureFunction(sTestMeasureFunction);');
}
function indent(code) {

View File

@@ -33,6 +33,7 @@ __forceinline const float fminf(const float a, const float b) {
#define BIG_MIN_WIDTH 100
#define SMALL_TEXT "small"
#define LONG_TEXT "loooooooooong with space"
#define MEASURE_WITH_RATIO_2 "measureWithRatio2"
/** END_GENERATED **/
typedef struct failed_test_t {
@@ -80,23 +81,40 @@ static bool are_layout_equal(css_node_t *a, css_node_t *b) {
return true;
}
css_dim_t measure(void *context, float width) {
css_dim_t measure(void *context, float width, float height) {
const char *text = (const char *)context;
css_dim_t dim;
if (strcmp(text, SMALL_TEXT) == 0) {
if (width != width) {
width = 1000000;
}
if (strcmp(text, SMALL_TEXT) == 0) {
dim.dimensions[CSS_WIDTH] = fminf(SMALL_WIDTH, width);
dim.dimensions[CSS_HEIGHT] = SMALL_HEIGHT;
return dim;
}
if (strcmp(text, LONG_TEXT) == 0) {
if (width != width) {
width = 1000000;
}
dim.dimensions[CSS_WIDTH] = width >= BIG_WIDTH ? BIG_WIDTH : fmaxf(BIG_MIN_WIDTH, width);
dim.dimensions[CSS_HEIGHT] = width >= BIG_WIDTH ? SMALL_HEIGHT : BIG_HEIGHT;
return dim;
}
if (strcmp(text, MEASURE_WITH_RATIO_2) == 0) {
if (width > 0) {
dim.dimensions[CSS_WIDTH] = width;
dim.dimensions[CSS_HEIGHT] = width * 2;
} else if (height > 0) {
dim.dimensions[CSS_WIDTH] = height * 2;
dim.dimensions[CSS_HEIGHT] = height;
} else {
dim.dimensions[CSS_WIDTH] = 99999;
dim.dimensions[CSS_HEIGHT] = 99999;
}
return dim;
}
// Should not go here
dim.dimensions[CSS_WIDTH] = CSS_UNDEFINED;
dim.dimensions[CSS_HEIGHT] = CSS_UNDEFINED;
@@ -106,7 +124,7 @@ css_dim_t measure(void *context, float width) {
static int test_ran_count = 0;
void test(const char *name, css_node_t *style, css_node_t *expected_layout) {
++test_ran_count;
layoutNode(style, CSS_UNDEFINED, (css_direction_t)-1);
layoutNode(style, CSS_UNDEFINED, CSS_UNDEFINED, (css_direction_t)-1);
if (!are_layout_equal(style, expected_layout)) {
printf("%sF%s", "\x1B[31m", "\x1B[0m");

View File

@@ -13,6 +13,6 @@
void test(const char *name, css_node_t *style, css_node_t *expected_layout);
int tests_finished(void);
css_dim_t measure(void *context, float width);
css_dim_t measure(void *context, float width, float height);
void init_css_node_children(css_node_t *node, int children_count);
css_node_t *new_test_css_node(void);

View File

@@ -471,6 +471,12 @@ var layoutTestUtils = (function() {
inplaceRoundNumbersInObject(domLayout);
testNamedLayout('layout-dom', layout, domLayout);
},
testLayoutAgainstExpectedOnly: function(node, expectedLayout) {
var layout = computeCSSLayout(node);
inplaceRoundNumbersInObject(layout);
inplaceRoundNumbersInObject(expectedLayout);
testNamedLayout('expected-dom', expectedLayout, layout);
},
testFillNodes: testFillNodes,
testExtractNodes: testExtractNodes,
testRandomLayout: function(node) {
@@ -488,7 +494,7 @@ var layoutTestUtils = (function() {
computeDOMLayout: computeDOMLayout,
reduceTest: reduceTest,
text: function(text) {
var fn = function(width) {
var fn = function(width, height) {
if (width === undefined || isNaN(width)) {
width = Infinity;
}
@@ -510,8 +516,28 @@ var layoutTestUtils = (function() {
return res;
}
};
// Name of the function is used in DOM tests as a text in the measured node
// and as a way to tell different measure functions apart in transpiled tests
fn.toString = function() { return text; };
return fn;
},
measureWithRatio2: function() {
var fn = function(width, height) {
if (width > 0) {
height = width * 2;
} else if (height > 0) {
width = height * 2;
} else {
// This should be Infinity, but it would be pain to transpile,
// so let's just go with big numbers.
height = 99999;
width = 99999;
}
return {width: width, height: height};
};
// This is necessary for transpiled tests, see previous comment
fn.toString = function() { return 'measureWithRatio2'; };
return fn;
}
};
})();

View File

@@ -76,6 +76,7 @@ void init_css_node(css_node_t *node) {
node->layout.last_requested_dimensions[CSS_WIDTH] = -1;
node->layout.last_requested_dimensions[CSS_HEIGHT] = -1;
node->layout.last_parent_max_width = -1;
node->layout.last_parent_max_height = -1;
node->layout.last_direction = (css_direction_t)-1;
node->layout.should_update = true;
}
@@ -516,7 +517,7 @@ static float getRelativePosition(css_node_t *node, css_flex_direction_t axis) {
return -getPosition(node, trailing[axis]);
}
static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction_t parentDirection) {
static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, float parentMaxHeight, css_direction_t parentDirection) {
/** START_GENERATED **/
css_direction_t direction = resolveDirection(node, parentDirection);
css_flex_direction_t mainAxis = resolveAxis(getFlexDirection(node), direction);
@@ -545,6 +546,7 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
// invocations during the layout calculation.
int childCount = node->children_count;
float paddingAndBorderAxisResolvedRow = getPaddingAndBorderAxis(node, resolvedRowAxis);
float paddingAndBorderAxisColumn = getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN);
if (isMeasureDefined(node)) {
bool isResolvedRowDimDefined = !isUndefined(node->layout.dimensions[dim[resolvedRowAxis]]);
@@ -560,6 +562,17 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
}
width -= paddingAndBorderAxisResolvedRow;
float height = CSS_UNDEFINED;
if (isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN)) {
height = node->style.dimensions[CSS_HEIGHT];
} else if (!isUndefined(node->layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]])) {
height = node->layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]];
} else {
height = parentMaxHeight -
getMarginAxis(node, resolvedRowAxis);
}
height -= getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN);
// 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.
@@ -572,7 +585,8 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
css_dim_t measureDim = node->measure(
node->context,
width
width,
height
);
if (isRowUndefined) {
node->layout.dimensions[CSS_WIDTH] = measureDim.dimensions[CSS_WIDTH] +
@@ -580,7 +594,7 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
}
if (isColumnUndefined) {
node->layout.dimensions[CSS_HEIGHT] = measureDim.dimensions[CSS_HEIGHT] +
getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN);
paddingAndBorderAxisColumn;
}
}
if (childCount == 0) {
@@ -661,6 +675,7 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
float crossDim = 0;
float maxWidth;
float maxHeight;
for (i = startLine; i < childCount; ++i) {
child = node->get_child(node->context, i);
child->line_index = linesCount;
@@ -741,6 +756,8 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
} else {
maxWidth = CSS_UNDEFINED;
maxHeight = CSS_UNDEFINED;
if (!isMainRowDirection) {
if (isDimDefined(node, resolvedRowAxis)) {
maxWidth = node->layout.dimensions[dim[resolvedRowAxis]] -
@@ -750,11 +767,20 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
getMarginAxis(node, resolvedRowAxis) -
paddingAndBorderAxisResolvedRow;
}
} else {
if (isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN)) {
maxHeight = node->layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] -
paddingAndBorderAxisColumn;
} else {
maxHeight = parentMaxHeight -
getMarginAxis(node, CSS_FLEX_DIRECTION_COLUMN) -
paddingAndBorderAxisColumn;
}
}
// This is the main recursive call. We layout non flexible children.
if (alreadyComputedNextLayout == 0) {
layoutNode(child, maxWidth, direction);
layoutNode(child, maxWidth, maxHeight, direction);
}
// Absolute positioned elements do not take part of the layout, so we
@@ -884,9 +910,18 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
getMarginAxis(node, resolvedRowAxis) -
paddingAndBorderAxisResolvedRow;
}
maxHeight = CSS_UNDEFINED;
if (isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN)) {
maxHeight = node->layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] -
paddingAndBorderAxisColumn;
} else if (isMainRowDirection) {
maxHeight = parentMaxHeight -
getMarginAxis(node, CSS_FLEX_DIRECTION_COLUMN) -
paddingAndBorderAxisColumn;
}
// And we recursively call the layout algorithm for this child
layoutNode(currentFlexChild, maxWidth, direction);
layoutNode(currentFlexChild, maxWidth, maxHeight, direction);
child = currentFlexChild;
currentFlexChild = currentFlexChild->next_flex_child;
@@ -1205,7 +1240,7 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
/** END_GENERATED **/
}
void layoutNode(css_node_t *node, float parentMaxWidth, css_direction_t parentDirection) {
void layoutNode(css_node_t *node, float parentMaxWidth, float parentMaxHeight, css_direction_t parentDirection) {
css_layout_t *layout = &node->layout;
css_direction_t direction = node->style.direction;
layout->should_update = true;
@@ -1215,6 +1250,7 @@ void layoutNode(css_node_t *node, float parentMaxWidth, css_direction_t parentDi
eq(layout->last_requested_dimensions[CSS_WIDTH], layout->dimensions[CSS_WIDTH]) &&
eq(layout->last_requested_dimensions[CSS_HEIGHT], layout->dimensions[CSS_HEIGHT]) &&
eq(layout->last_parent_max_width, parentMaxWidth);
eq(layout->last_parent_max_height, parentMaxHeight);
eq(layout->last_direction, direction);
if (skipLayout) {
@@ -1226,9 +1262,10 @@ void layoutNode(css_node_t *node, float parentMaxWidth, css_direction_t parentDi
layout->last_requested_dimensions[CSS_WIDTH] = layout->dimensions[CSS_WIDTH];
layout->last_requested_dimensions[CSS_HEIGHT] = layout->dimensions[CSS_HEIGHT];
layout->last_parent_max_width = parentMaxWidth;
layout->last_parent_max_height = parentMaxHeight;
layout->last_direction = direction;
layoutNodeImpl(node, parentMaxWidth, parentDirection);
layoutNodeImpl(node, parentMaxWidth, parentMaxHeight, parentDirection);
layout->last_dimensions[CSS_WIDTH] = layout->dimensions[CSS_WIDTH];
layout->last_dimensions[CSS_HEIGHT] = layout->dimensions[CSS_HEIGHT];

View File

@@ -91,6 +91,7 @@ typedef struct {
bool should_update;
float last_requested_dimensions[2];
float last_parent_max_width;
float last_parent_max_height;
float last_dimensions[2];
float last_position[2];
css_direction_t last_direction;
@@ -139,7 +140,7 @@ struct css_node {
css_node_t* next_absolute_child;
css_node_t* next_flex_child;
css_dim_t (*measure)(void *context, float width);
css_dim_t (*measure)(void *context, float width, float height);
void (*print)(void *context);
struct css_node* (*get_child)(void *context, int i);
bool (*is_dirty)(void *context);
@@ -161,7 +162,7 @@ typedef enum {
void print_css_node(css_node_t *node, css_print_options_t options);
// Function that computes the layout!
void layoutNode(css_node_t *node, float maxWidth, css_direction_t parentDirection);
void layoutNode(css_node_t *node, float maxWidth, float maxHeight, css_direction_t parentDirection);
bool isUndefined(float value);
#endif

View File

@@ -81,6 +81,11 @@ var computeLayout = (function() {
if (!node.children) {
node.children = [];
}
if (node.style.measure && node.children && node.children.length) {
throw new Error('Using custom measure function is supported only for leaf nodes.');
}
node.children.forEach(fillNodes);
return node;
}
@@ -439,7 +444,7 @@ var computeLayout = (function() {
return -getPosition(node, trailing[axis]);
}
function layoutNodeImpl(node, parentMaxWidth, /*css_direction_t*/parentDirection) {
function layoutNodeImpl(node, parentMaxWidth, parentMaxHeight, /*css_direction_t*/parentDirection) {
var/*css_direction_t*/ direction = resolveDirection(node, parentDirection);
var/*(c)!css_flex_direction_t*//*(java)!int*/ mainAxis = resolveAxis(getFlexDirection(node), direction);
var/*(c)!css_flex_direction_t*//*(java)!int*/ crossAxis = getCrossFlexDirection(mainAxis, direction);
@@ -467,6 +472,7 @@ var computeLayout = (function() {
// invocations during the layout calculation.
var/*int*/ childCount = node.children.length;
var/*float*/ paddingAndBorderAxisResolvedRow = getPaddingAndBorderAxis(node, resolvedRowAxis);
var/*float*/ paddingAndBorderAxisColumn = getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN);
if (isMeasureDefined(node)) {
var/*bool*/ isResolvedRowDimDefined = !isUndefined(node.layout[dim[resolvedRowAxis]]);
@@ -482,6 +488,17 @@ var computeLayout = (function() {
}
width -= paddingAndBorderAxisResolvedRow;
var/*float*/ height = CSS_UNDEFINED;
if (isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN)) {
height = node.style.height;
} else if (!isUndefined(node.layout[dim[CSS_FLEX_DIRECTION_COLUMN]])) {
height = node.layout[dim[CSS_FLEX_DIRECTION_COLUMN]];
} else {
height = parentMaxHeight -
getMarginAxis(node, resolvedRowAxis);
}
height -= getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN);
// 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.
@@ -494,7 +511,8 @@ var computeLayout = (function() {
var/*css_dim_t*/ measureDim = node.style.measure(
/*(c)!node->context,*/
/*(java)!layoutContext.measureOutput,*/
width
width,
height
);
if (isRowUndefined) {
node.layout.width = measureDim.width +
@@ -502,7 +520,7 @@ var computeLayout = (function() {
}
if (isColumnUndefined) {
node.layout.height = measureDim.height +
getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN);
paddingAndBorderAxisColumn;
}
}
if (childCount === 0) {
@@ -583,6 +601,7 @@ var computeLayout = (function() {
var/*float*/ crossDim = 0;
var/*float*/ maxWidth;
var/*float*/ maxHeight;
for (i = startLine; i < childCount; ++i) {
child = node.children[i];
child.lineIndex = linesCount;
@@ -663,6 +682,8 @@ var computeLayout = (function() {
} else {
maxWidth = CSS_UNDEFINED;
maxHeight = CSS_UNDEFINED;
if (!isMainRowDirection) {
if (isDimDefined(node, resolvedRowAxis)) {
maxWidth = node.layout[dim[resolvedRowAxis]] -
@@ -672,11 +693,20 @@ var computeLayout = (function() {
getMarginAxis(node, resolvedRowAxis) -
paddingAndBorderAxisResolvedRow;
}
} else {
if (isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN)) {
maxHeight = node.layout[dim[CSS_FLEX_DIRECTION_COLUMN]] -
paddingAndBorderAxisColumn;
} else {
maxHeight = parentMaxHeight -
getMarginAxis(node, CSS_FLEX_DIRECTION_COLUMN) -
paddingAndBorderAxisColumn;
}
}
// This is the main recursive call. We layout non flexible children.
if (alreadyComputedNextLayout === 0) {
layoutNode(/*(java)!layoutContext, */child, maxWidth, direction);
layoutNode(/*(java)!layoutContext, */child, maxWidth, maxHeight, direction);
}
// Absolute positioned elements do not take part of the layout, so we
@@ -806,9 +836,18 @@ var computeLayout = (function() {
getMarginAxis(node, resolvedRowAxis) -
paddingAndBorderAxisResolvedRow;
}
maxHeight = CSS_UNDEFINED;
if (isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN)) {
maxHeight = node.layout[dim[CSS_FLEX_DIRECTION_COLUMN]] -
paddingAndBorderAxisColumn;
} else if (isMainRowDirection) {
maxHeight = parentMaxHeight -
getMarginAxis(node, CSS_FLEX_DIRECTION_COLUMN) -
paddingAndBorderAxisColumn;
}
// And we recursively call the layout algorithm for this child
layoutNode(/*(java)!layoutContext, */currentFlexChild, maxWidth, direction);
layoutNode(/*(java)!layoutContext, */currentFlexChild, maxWidth, maxHeight, direction);
child = currentFlexChild;
currentFlexChild = currentFlexChild.nextFlexChild;
@@ -1126,7 +1165,7 @@ var computeLayout = (function() {
}
}
function layoutNode(node, parentMaxWidth, parentDirection) {
function layoutNode(node, parentMaxWidth, parentMaxHeight, parentDirection) {
node.shouldUpdate = true;
var direction = node.style.direction || CSS_DIRECTION_LTR;
@@ -1136,6 +1175,7 @@ var computeLayout = (function() {
node.lastLayout.requestedHeight === node.layout.height &&
node.lastLayout.requestedWidth === node.layout.width &&
node.lastLayout.parentMaxWidth === parentMaxWidth &&
node.lastLayout.parentMaxHeight === parentMaxHeight &&
node.lastLayout.direction === direction;
if (skipLayout) {
@@ -1151,6 +1191,7 @@ var computeLayout = (function() {
node.lastLayout.requestedWidth = node.layout.width;
node.lastLayout.requestedHeight = node.layout.height;
node.lastLayout.parentMaxWidth = parentMaxWidth;
node.lastLayout.parentMaxHeight = parentMaxHeight;
node.lastLayout.direction = direction;
// Reset child layouts
@@ -1161,7 +1202,7 @@ var computeLayout = (function() {
child.layout.left = 0;
});
layoutNodeImpl(node, parentMaxWidth, parentDirection);
layoutNodeImpl(node, parentMaxWidth, parentMaxHeight, parentDirection);
node.lastLayout.width = node.layout.width;
node.lastLayout.height = node.layout.height;

View File

@@ -3972,6 +3972,158 @@ int main()
test("should layout node with just text", 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] = 100;
node_0->measure = measure;
node_0->context = "measureWithRatio2";
}
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] = 100;
node_0->layout.dimensions[CSS_HEIGHT] = 200;
}
test("should layout node with fixed width and custom measure function", 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_HEIGHT] = 100;
node_0->measure = measure;
node_0->context = "measureWithRatio2";
}
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] = 100;
}
test("should layout node with fixed height and custom measure function", 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] = 100;
node_0->style.dimensions[CSS_HEIGHT] = 100;
node_0->measure = measure;
node_0->context = "measureWithRatio2";
}
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] = 100;
node_0->layout.dimensions[CSS_HEIGHT] = 100;
}
test("should layout node with fixed height and fixed width, ignoring custom measure function", root_node, root_layout);
}
{
css_node_t *root_node = new_test_css_node();
{
css_node_t *node_0 = root_node;
node_0->measure = measure;
node_0->context = "measureWithRatio2";
}
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] = 99999;
node_0->layout.dimensions[CSS_HEIGHT] = 99999;
}
test("should layout node with no fixed dimension and custom measure function", root_node, root_layout);
}
{
css_node_t *root_node = new_test_css_node();
{
css_node_t *node_0 = root_node;
node_0->style.flex_direction = CSS_FLEX_DIRECTION_COLUMN;
node_0->style.dimensions[CSS_WIDTH] = 320;
init_css_node_children(node_0, 2);
{
css_node_t *node_1;
node_1 = node_0->get_child(node_0->context, 0);
node_1->measure = measure;
node_1->context = "measureWithRatio2";
node_1 = node_0->get_child(node_0->context, 1);
node_1->style.flex_direction = CSS_FLEX_DIRECTION_ROW;
node_1->style.dimensions[CSS_HEIGHT] = 100;
init_css_node_children(node_1, 2);
{
css_node_t *node_2;
node_2 = node_1->get_child(node_1->context, 0);
node_2->measure = measure;
node_2->context = "measureWithRatio2";
node_2 = node_1->get_child(node_1->context, 1);
node_2->measure = measure;
node_2->context = "measureWithRatio2";
}
}
}
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] = 320;
node_0->layout.dimensions[CSS_HEIGHT] = 740;
init_css_node_children(node_0, 2);
{
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] = 320;
node_1->layout.dimensions[CSS_HEIGHT] = 640;
node_1 = node_0->get_child(node_0->context, 1);
node_1->layout.position[CSS_TOP] = 640;
node_1->layout.position[CSS_LEFT] = 0;
node_1->layout.dimensions[CSS_WIDTH] = 320;
node_1->layout.dimensions[CSS_HEIGHT] = 100;
init_css_node_children(node_1, 2);
{
css_node_t *node_2;
node_2 = node_1->get_child(node_1->context, 0);
node_2->layout.position[CSS_TOP] = 0;
node_2->layout.position[CSS_LEFT] = 0;
node_2->layout.dimensions[CSS_WIDTH] = 200;
node_2->layout.dimensions[CSS_HEIGHT] = 100;
node_2 = node_1->get_child(node_1->context, 1);
node_2->layout.position[CSS_TOP] = 0;
node_2->layout.position[CSS_LEFT] = 200;
node_2->layout.dimensions[CSS_WIDTH] = 200;
node_2->layout.dimensions[CSS_HEIGHT] = 100;
}
}
}
test("should layout node with nested stacks and custom measure function", root_node, root_layout);
}
{
css_node_t *root_node = new_test_css_node();
{

View File

@@ -10,10 +10,12 @@
var testLayout = layoutTestUtils.testLayout;
var testLayoutAgainstDomOnly = layoutTestUtils.testLayoutAgainstDomOnly;
var testLayoutAgainstExpectedOnly = layoutTestUtils.testLayoutAgainstExpectedOnly;
var testFillNodes = layoutTestUtils.testFillNodes;
var text = layoutTestUtils.text;
var texts = layoutTestUtils.texts;
var textSizes = layoutTestUtils.textSizes;
var measureWithRatio2 = layoutTestUtils.measureWithRatio2();
describe('Javascript Only', function() {
it('should fill root node with layout, style, and children', function() {
@@ -1192,6 +1194,65 @@ describe('Layout', function() {
);
});
it('should layout node with fixed width and custom measure function', function() {
testLayoutAgainstExpectedOnly(
{style: {
measure: measureWithRatio2,
width: 100
}},
{width: 100, height: 200, top: 0, left: 0}
);
});
it('should layout node with fixed height and custom measure function', function() {
testLayoutAgainstExpectedOnly(
{style: {
measure: measureWithRatio2,
height: 100
}},
{width: 200, height: 100, top: 0, left: 0}
);
});
it('should layout node with fixed height and fixed width, ignoring custom measure function', function() {
testLayoutAgainstExpectedOnly(
{style: {
measure: measureWithRatio2,
width: 100,
height: 100
}},
{width: 100, height: 100, top: 0, left: 0}
);
});
it('should layout node with no fixed dimension and custom measure function', function() {
testLayoutAgainstExpectedOnly(
{style: {
measure: measureWithRatio2,
}},
{width: 99999, height: 99999, top: 0, left: 0}
);
});
it('should layout node with nested stacks and custom measure function', function() {
testLayoutAgainstExpectedOnly(
{style: {width: 320, flexDirection: 'column'}, children: [
{style: {measure: measureWithRatio2}},
{style: {height: 100, flexDirection: 'row'}, children: [
{style: {measure: measureWithRatio2}},
{style: {measure: measureWithRatio2}}
]},
]},
{width: 320, height: 740, top: 0, left: 0, children: [
{width: 320, height: 640, top: 0, left: 0},
{width: 320, height: 100, top: 640, left: 0, children: [
{width: 200, height: 100, top: 0, left: 0},
{width: 200, height: 100, top: 0, left: 200}
]},
]}
);
});
it('should layout node with text and width', function() {
testLayout(
{style: {measure: text(texts.small), width: 10}},

View File

@@ -24,7 +24,7 @@ namespace Facebook.CSSLayout.Tests
CSSNode parent = new CSSNode();
CSSNode child = new CSSNode();
Assert.Null(child.getParent());
Assert.IsNull(child.getParent());
Assert.AreEqual(0, parent.getChildCount());
parent.addChildAt(child, 0);
@@ -35,7 +35,7 @@ namespace Facebook.CSSLayout.Tests
parent.removeChildAt(0);
Assert.Null(child.getParent());
Assert.IsNull(child.getParent());
Assert.AreEqual(0, parent.getChildCount());
}

View File

@@ -54,7 +54,7 @@ namespace Facebook.CSSLayout.Tests
markLayoutAppliedForTree(root);
root.calculateLayout();
Assert.True(root.HasNewLayout);
Assert.IsTrue(root.HasNewLayout);
assertTreeHasNewLayout(false, c0);
assertTreeHasNewLayout(false, c1);
}
@@ -81,14 +81,14 @@ namespace Facebook.CSSLayout.Tests
c0.addChildAt(c0c1, 1);
root.calculateLayout();
Assert.True(root.HasNewLayout);
Assert.True(c0.HasNewLayout);
Assert.True(c0c1.HasNewLayout);
Assert.IsTrue(root.HasNewLayout);
Assert.IsTrue(c0.HasNewLayout);
Assert.IsTrue(c0c1.HasNewLayout);
Assert.True(c0c0.HasNewLayout);
Assert.True(c1.HasNewLayout);
Assert.IsTrue(c0c0.HasNewLayout);
Assert.IsTrue(c1.HasNewLayout);
Assert.False(c1c0.HasNewLayout);
Assert.IsFalse(c1c0.HasNewLayout);
}
[Test]
@@ -108,11 +108,11 @@ namespace Facebook.CSSLayout.Tests
c1.AlignSelf = CSSAlign.Center;
root.calculateLayout();
Assert.True(root.HasNewLayout);
Assert.True(c1.HasNewLayout);
Assert.IsTrue(root.HasNewLayout);
Assert.IsTrue(c1.HasNewLayout);
Assert.True(c0.HasNewLayout);
Assert.False(c0c0.HasNewLayout);
Assert.IsTrue(c0.HasNewLayout);
Assert.IsFalse(c0c0.HasNewLayout);
}
[Test]
@@ -132,11 +132,11 @@ namespace Facebook.CSSLayout.Tests
c1.SetMargin(CSSSpacingType.Left, 10);
root.calculateLayout();
Assert.True(root.HasNewLayout);
Assert.True(c1.HasNewLayout);
Assert.IsTrue(root.HasNewLayout);
Assert.IsTrue(c1.HasNewLayout);
Assert.True(c0.HasNewLayout);
Assert.False(c0c0.HasNewLayout);
Assert.IsTrue(c0.HasNewLayout);
Assert.IsFalse(c0c0.HasNewLayout);
}
[Test]
@@ -158,12 +158,12 @@ namespace Facebook.CSSLayout.Tests
c0.Height = 200;
root.calculateLayout();
Assert.True(root.HasNewLayout);
Assert.True(c0.HasNewLayout);
Assert.True(c0c0.HasNewLayout);
Assert.IsTrue(root.HasNewLayout);
Assert.IsTrue(c0.HasNewLayout);
Assert.IsTrue(c0c0.HasNewLayout);
Assert.True(c1.HasNewLayout);
Assert.False(c1c0.HasNewLayout);
Assert.IsTrue(c1.HasNewLayout);
Assert.IsFalse(c1c0.HasNewLayout);
}
[Test]
@@ -184,7 +184,7 @@ namespace Facebook.CSSLayout.Tests
root.Width = 200;
root.calculateLayout();
Assert.True(root.HasNewLayout);
Assert.IsTrue(root.HasNewLayout);
assertTreeHasNewLayout(false, c0);
assertTreeHasNewLayout(false, c1);
}
@@ -206,10 +206,10 @@ namespace Facebook.CSSLayout.Tests
c0.Height = 100;
root.calculateLayout();
Assert.True(root.HasNewLayout);
Assert.True(c0.HasNewLayout);
Assert.True(c1.HasNewLayout);
Assert.False(c1c0.HasNewLayout);
Assert.IsTrue(root.HasNewLayout);
Assert.IsTrue(c0.HasNewLayout);
Assert.IsTrue(c1.HasNewLayout);
Assert.IsFalse(c1c0.HasNewLayout);
}
[Test]
@@ -226,15 +226,15 @@ namespace Facebook.CSSLayout.Tests
root.calculateLayout();
markLayoutAppliedForTree(root);
c1.setMeasureFunction((node, width) => new MeasureOutput(100, 20));
c1.setMeasureFunction((node, width, height) => new MeasureOutput(100, 20));
root.calculateLayout();
Assert.True(root.HasNewLayout);
Assert.True(c1.HasNewLayout);
Assert.IsTrue(root.HasNewLayout);
Assert.IsTrue(c1.HasNewLayout);
Assert.True(c0.HasNewLayout);
Assert.False(c0c0.HasNewLayout);
Assert.IsTrue(c0.HasNewLayout);
Assert.IsFalse(c0c0.HasNewLayout);
}
}
}

View File

@@ -25,26 +25,34 @@ public class LayoutEngineTest
const int DIMENSION_HEIGHT = CSSLayout.DIMENSION_HEIGHT;
const int DIMENSION_WIDTH = CSSLayout.DIMENSION_WIDTH;
static readonly MeasureFunction sTestMeasureFunction = (node, width) =>
static readonly MeasureFunction sTestMeasureFunction = (node, width, height) =>
{
TestCSSNode testNode = (TestCSSNode) node;
if (testNode.context.Equals(TestConstants.SMALL_TEXT)) {
if (CSSConstants.IsUndefined(width)) {
width = 10000000;
}
TestCSSNode testNode = (TestCSSNode) node;
if (testNode.context.Equals(TestConstants.SMALL_TEXT))
{
return new MeasureOutput(
Math.Min(width, TestConstants.SMALL_WIDTH),
TestConstants.SMALL_HEIGHT);
} else if (testNode.context.Equals(TestConstants.LONG_TEXT))
{
} else if (testNode.context.Equals(TestConstants.LONG_TEXT)) {
if (CSSConstants.IsUndefined(width)) {
width = 10000000;
}
return new MeasureOutput(width >= TestConstants.BIG_WIDTH
? TestConstants.BIG_WIDTH
: Math.Max(TestConstants.BIG_MIN_WIDTH, width),
width >= TestConstants.BIG_WIDTH
? TestConstants.SMALL_HEIGHT
: TestConstants.BIG_HEIGHT);
} else if (testNode.context.Equals(TestConstants.MEASURE_WITH_RATIO_2)) {
if (width > 0) {
return new MeasureOutput(width, width * 2);
} else if (height > 0) {
return new MeasureOutput(height * 2, height);
} else {
return new MeasureOutput(99999, 99999);
}
} else {
throw new Exception("Got unknown test: " + testNode.context);
}
@@ -71,7 +79,7 @@ public class LayoutEngineTest
}
private static void assertLayoutsEqual(String message, CSSNode actual, CSSNode expected) {
Assert.True(
Assert.IsTrue(
areLayoutsEqual(actual, expected),
message + "\nActual:\n" + actual.ToString() + "\nExpected:\n" + expected.ToString()
);
@@ -4249,6 +4257,168 @@ public class LayoutEngineTest
[Test]
public void TestCase95()
{
TestCSSNode root_node = new TestCSSNode();
{
TestCSSNode node_0 = root_node;
node_0.style.dimensions[DIMENSION_WIDTH] = 100;
node_0.setMeasureFunction(sTestMeasureFunction);
node_0.context = "measureWithRatio2";
}
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] = 100;
node_0.layout.dimensions[DIMENSION_HEIGHT] = 200;
}
test("should layout node with fixed width and custom measure function", root_node, root_layout);
}
[Test]
public void TestCase96()
{
TestCSSNode root_node = new TestCSSNode();
{
TestCSSNode node_0 = root_node;
node_0.style.dimensions[DIMENSION_HEIGHT] = 100;
node_0.setMeasureFunction(sTestMeasureFunction);
node_0.context = "measureWithRatio2";
}
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] = 100;
}
test("should layout node with fixed height and custom measure function", root_node, root_layout);
}
[Test]
public void TestCase97()
{
TestCSSNode root_node = new TestCSSNode();
{
TestCSSNode node_0 = root_node;
node_0.style.dimensions[DIMENSION_WIDTH] = 100;
node_0.style.dimensions[DIMENSION_HEIGHT] = 100;
node_0.setMeasureFunction(sTestMeasureFunction);
node_0.context = "measureWithRatio2";
}
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] = 100;
node_0.layout.dimensions[DIMENSION_HEIGHT] = 100;
}
test("should layout node with fixed height and fixed width, ignoring custom measure function", root_node, root_layout);
}
[Test]
public void TestCase98()
{
TestCSSNode root_node = new TestCSSNode();
{
TestCSSNode node_0 = root_node;
node_0.setMeasureFunction(sTestMeasureFunction);
node_0.context = "measureWithRatio2";
}
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] = 99999;
node_0.layout.dimensions[DIMENSION_HEIGHT] = 99999;
}
test("should layout node with no fixed dimension and custom measure function", root_node, root_layout);
}
[Test]
public void TestCase99()
{
TestCSSNode root_node = new TestCSSNode();
{
TestCSSNode node_0 = root_node;
node_0.style.flexDirection = CSSFlexDirection.Column;
node_0.style.dimensions[DIMENSION_WIDTH] = 320;
addChildren(node_0, 2);
{
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.setMeasureFunction(sTestMeasureFunction);
node_1.context = "measureWithRatio2";
node_1 = node_0.getChildAt(1);
node_1.style.flexDirection = CSSFlexDirection.Row;
node_1.style.dimensions[DIMENSION_HEIGHT] = 100;
addChildren(node_1, 2);
{
TestCSSNode node_2;
node_2 = node_1.getChildAt(0);
node_2.setMeasureFunction(sTestMeasureFunction);
node_2.context = "measureWithRatio2";
node_2 = node_1.getChildAt(1);
node_2.setMeasureFunction(sTestMeasureFunction);
node_2.context = "measureWithRatio2";
}
}
}
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] = 320;
node_0.layout.dimensions[DIMENSION_HEIGHT] = 740;
addChildren(node_0, 2);
{
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] = 320;
node_1.layout.dimensions[DIMENSION_HEIGHT] = 640;
node_1 = node_0.getChildAt(1);
node_1.layout.position[POSITION_TOP] = 640;
node_1.layout.position[POSITION_LEFT] = 0;
node_1.layout.dimensions[DIMENSION_WIDTH] = 320;
node_1.layout.dimensions[DIMENSION_HEIGHT] = 100;
addChildren(node_1, 2);
{
TestCSSNode node_2;
node_2 = node_1.getChildAt(0);
node_2.layout.position[POSITION_TOP] = 0;
node_2.layout.position[POSITION_LEFT] = 0;
node_2.layout.dimensions[DIMENSION_WIDTH] = 200;
node_2.layout.dimensions[DIMENSION_HEIGHT] = 100;
node_2 = node_1.getChildAt(1);
node_2.layout.position[POSITION_TOP] = 0;
node_2.layout.position[POSITION_LEFT] = 200;
node_2.layout.dimensions[DIMENSION_WIDTH] = 200;
node_2.layout.dimensions[DIMENSION_HEIGHT] = 100;
}
}
}
test("should layout node with nested stacks and custom measure function", root_node, root_layout);
}
[Test]
public void TestCase100()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4271,7 +4441,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase96()
public void TestCase101()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4293,7 +4463,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase97()
public void TestCase102()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4344,7 +4514,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase98()
public void TestCase103()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4397,7 +4567,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase99()
public void TestCase104()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4451,7 +4621,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase100()
public void TestCase105()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4504,7 +4674,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase101()
public void TestCase106()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4558,7 +4728,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase102()
public void TestCase107()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4597,7 +4767,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase103()
public void TestCase108()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4662,7 +4832,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase104()
public void TestCase109()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4705,7 +4875,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase105()
public void TestCase110()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4749,7 +4919,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase106()
public void TestCase111()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4787,7 +4957,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase107()
public void TestCase112()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4826,7 +4996,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase108()
public void TestCase113()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4884,7 +5054,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase109()
public void TestCase114()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4943,7 +5113,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase110()
public void TestCase115()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5000,7 +5170,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase111()
public void TestCase116()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5041,7 +5211,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase112()
public void TestCase117()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5088,7 +5258,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase113()
public void TestCase118()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5136,7 +5306,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase114()
public void TestCase119()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5184,7 +5354,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase115()
public void TestCase120()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5229,7 +5399,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase116()
public void TestCase121()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5267,7 +5437,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase117()
public void TestCase122()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5325,7 +5495,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase118()
public void TestCase123()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5362,7 +5532,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase119()
public void TestCase124()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5399,7 +5569,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase120()
public void TestCase125()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5437,7 +5607,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase121()
public void TestCase126()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5475,7 +5645,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase122()
public void TestCase127()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5512,7 +5682,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase123()
public void TestCase128()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5549,7 +5719,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase124()
public void TestCase129()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5585,7 +5755,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase125()
public void TestCase130()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5621,7 +5791,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase126()
public void TestCase131()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5657,7 +5827,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase127()
public void TestCase132()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5693,7 +5863,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase128()
public void TestCase133()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5743,7 +5913,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase129()
public void TestCase134()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5798,7 +5968,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase130()
public void TestCase135()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5854,7 +6024,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase131()
public void TestCase136()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5898,7 +6068,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase132()
public void TestCase137()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5922,7 +6092,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase133()
public void TestCase138()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5946,7 +6116,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase134()
public void TestCase139()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5972,7 +6142,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase135()
public void TestCase140()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5998,7 +6168,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase136()
public void TestCase141()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6022,7 +6192,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase137()
public void TestCase142()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6046,7 +6216,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase138()
public void TestCase143()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6072,7 +6242,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase139()
public void TestCase144()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6098,7 +6268,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase140()
public void TestCase145()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6151,7 +6321,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase141()
public void TestCase146()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6205,7 +6375,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase142()
public void TestCase147()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6259,7 +6429,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase143()
public void TestCase148()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6314,7 +6484,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase144()
public void TestCase149()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6367,7 +6537,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase145()
public void TestCase150()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6421,7 +6591,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase146()
public void TestCase151()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6476,7 +6646,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase147()
public void TestCase152()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6532,7 +6702,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase148()
public void TestCase153()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6587,7 +6757,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase149()
public void TestCase154()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6643,7 +6813,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase150()
public void TestCase155()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6682,7 +6852,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase151()
public void TestCase156()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6720,7 +6890,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase152()
public void TestCase157()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6758,7 +6928,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase153()
public void TestCase158()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6806,7 +6976,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase154()
public void TestCase159()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6852,7 +7022,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase155()
public void TestCase160()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6898,7 +7068,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase156()
public void TestCase161()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6939,7 +7109,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase157()
public void TestCase162()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6978,7 +7148,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase158()
public void TestCase163()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7017,7 +7187,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase159()
public void TestCase164()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7056,7 +7226,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase160()
public void TestCase165()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7096,7 +7266,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase161()
public void TestCase166()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7139,7 +7309,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase162()
public void TestCase167()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7182,7 +7352,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase163()
public void TestCase168()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7248,7 +7418,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase164()
public void TestCase169()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7320,7 +7490,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase165()
public void TestCase170()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7382,7 +7552,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase166()
public void TestCase171()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7476,7 +7646,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase167()
public void TestCase172()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7557,7 +7727,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase168()
public void TestCase173()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7597,7 +7767,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase169()
public void TestCase174()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7637,7 +7807,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase170()
public void TestCase175()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7677,7 +7847,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase171()
public void TestCase176()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7715,7 +7885,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase172()
public void TestCase177()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7754,7 +7924,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase173()
public void TestCase178()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7792,7 +7962,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase174()
public void TestCase179()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7831,7 +8001,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase175()
public void TestCase180()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7869,7 +8039,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase176()
public void TestCase181()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7908,7 +8078,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase177()
public void TestCase182()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7944,7 +8114,7 @@ public class LayoutEngineTest
}
[Test]
public void TestCase178()
public void TestCase183()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -8193,4 +8363,3 @@ public class LayoutEngineTest
}
}

View File

@@ -23,6 +23,7 @@ namespace Facebook.CSSLayout.Tests
public static readonly float BIG_MIN_WIDTH = 100f;
public static readonly string SMALL_TEXT = "small";
public static readonly string LONG_TEXT = "loooooooooong with space";
public static readonly string MEASURE_WITH_RATIO_2 = "measureWithRatio2";
/** END_GENERATED **/
}
}

View File

@@ -17,7 +17,7 @@ namespace Facebook.CSSLayout
* Should measure the given node and put the result in the given MeasureOutput.
*/
public delegate MeasureOutput MeasureFunction(CSSNode node, float width);
public delegate MeasureOutput MeasureFunction(CSSNode node, float width, float height);
/**
* A CSS Node. It has a style object you can manipulate at {@link #style}. After calling
@@ -140,13 +140,13 @@ namespace Facebook.CSSLayout
get { return mMeasureFunction != null; }
}
internal MeasureOutput measure(MeasureOutput measureOutput, float width)
internal MeasureOutput measure(MeasureOutput measureOutput, float width, float height)
{
if (!IsMeasureDefined)
{
throw new Exception("Measure function isn't defined!");
}
return Assertions.assertNotNull(mMeasureFunction)(this, width);
return Assertions.assertNotNull(mMeasureFunction)(this, width, height);
}
/**
@@ -156,7 +156,7 @@ namespace Facebook.CSSLayout
public void CalculateLayout()
{
layout.resetResult();
LayoutEngine.layoutNode(DummyLayoutContext, this, CSSConstants.Undefined, null);
LayoutEngine.layoutNode(DummyLayoutContext, this, CSSConstants.Undefined, CSSConstants.Undefined, null);
}
static readonly CSSLayoutContext DummyLayoutContext = new CSSLayoutContext();

View File

@@ -20,5 +20,6 @@ namespace Facebook.CSSLayout
public float requestedWidth = CSSConstants.Undefined;
public float requestedHeight = CSSConstants.Undefined;
public float parentMaxWidth = CSSConstants.Undefined;
public float parentMaxHeight = CSSConstants.Undefined;
}
}

View File

@@ -14,7 +14,7 @@ namespace Facebook.CSSLayout
{
/**
* Calculates layouts based on CSS style. See {@link #layoutNode(CSSNode, float)}.
* Calculates layouts based on CSS style. See {@link #layoutNode(CSSNode, float, float)}.
*/
static class LayoutEngine
@@ -205,7 +205,7 @@ namespace Facebook.CSSLayout
return node.IsMeasureDefined;
}
static boolean needsRelayout(CSSNode node, float parentMaxWidth)
static boolean needsRelayout(CSSNode node, float parentMaxWidth, float parentMaxHeight)
{
return node.isDirty() ||
!FloatUtil.floatsEqual(
@@ -214,18 +214,20 @@ namespace Facebook.CSSLayout
!FloatUtil.floatsEqual(
node.lastLayout.requestedWidth,
node.layout.dimensions[DIMENSION_WIDTH]) ||
!FloatUtil.floatsEqual(node.lastLayout.parentMaxWidth, parentMaxWidth);
!FloatUtil.floatsEqual(node.lastLayout.parentMaxWidth, parentMaxWidth) ||
!FloatUtil.floatsEqual(node.lastLayout.parentMaxHeight, parentMaxHeight);
}
internal static void layoutNode(CSSLayoutContext layoutContext, CSSNode node, float parentMaxWidth, CSSDirection? parentDirection)
internal static void layoutNode(CSSLayoutContext layoutContext, CSSNode node, float parentMaxWidth, float parentMaxHeight, CSSDirection? parentDirection)
{
if (needsRelayout(node, parentMaxWidth))
if (needsRelayout(node, parentMaxWidth, parentMaxHeight))
{
node.lastLayout.requestedWidth = node.layout.dimensions[DIMENSION_WIDTH];
node.lastLayout.requestedHeight = node.layout.dimensions[DIMENSION_HEIGHT];
node.lastLayout.parentMaxWidth = parentMaxWidth;
node.lastLayout.parentMaxHeight = parentMaxHeight;
layoutNodeImpl(layoutContext, node, parentMaxWidth, parentDirection);
layoutNodeImpl(layoutContext, node, parentMaxWidth, parentMaxHeight, parentDirection);
node.lastLayout.copy(node.layout);
}
else
@@ -236,7 +238,7 @@ namespace Facebook.CSSLayout
node.markHasNewLayout();
}
static void layoutNodeImpl(CSSLayoutContext layoutContext, CSSNode node, float parentMaxWidth, CSSDirection? parentDirection)
static void layoutNodeImpl(CSSLayoutContext layoutContext, CSSNode node, float parentMaxWidth, float parentMaxHeight, CSSDirection? parentDirection)
{
var childCount_ = node.getChildCount();
for (int i_ = 0; i_ < childCount_; i_++)
@@ -274,6 +276,7 @@ namespace Facebook.CSSLayout
// invocations during the layout calculation.
int childCount = node.getChildCount();
float paddingAndBorderAxisResolvedRow = ((node.style.padding.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis]) + node.style.border.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis])) + (node.style.padding.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis]) + node.style.border.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis])));
float paddingAndBorderAxisColumn = ((node.style.padding.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN])) + (node.style.padding.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])));
if (isMeasureDefined(node)) {
boolean isResolvedRowDimDefined = !float.IsNaN(node.layout.dimensions[dim[resolvedRowAxis]]);
@@ -289,6 +292,17 @@ namespace Facebook.CSSLayout
}
width -= paddingAndBorderAxisResolvedRow;
float height = CSSConstants.Undefined;
if ((!float.IsNaN(node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]) && node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] >= 0.0)) {
height = node.style.dimensions[DIMENSION_HEIGHT];
} else if (!float.IsNaN(node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]])) {
height = node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]];
} else {
height = parentMaxHeight -
(node.style.margin.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis]) + node.style.margin.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis]));
}
height -= ((node.style.padding.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN])) + (node.style.padding.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])));
// 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.
@@ -301,7 +315,8 @@ namespace Facebook.CSSLayout
MeasureOutput measureDim = node.measure(
layoutContext.measureOutput,
width
width,
height
);
if (isRowUndefined) {
node.layout.dimensions[DIMENSION_WIDTH] = measureDim.width +
@@ -309,7 +324,7 @@ namespace Facebook.CSSLayout
}
if (isColumnUndefined) {
node.layout.dimensions[DIMENSION_HEIGHT] = measureDim.height +
((node.style.padding.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN])) + (node.style.padding.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])));
paddingAndBorderAxisColumn;
}
}
if (childCount == 0) {
@@ -390,6 +405,7 @@ namespace Facebook.CSSLayout
float crossDim = 0;
float maxWidth;
float maxHeight;
for (i = startLine; i < childCount; ++i) {
child = node.getChildAt(i);
child.lineIndex = linesCount;
@@ -470,6 +486,8 @@ namespace Facebook.CSSLayout
} else {
maxWidth = CSSConstants.Undefined;
maxHeight = CSSConstants.Undefined;
if (!isMainRowDirection) {
if ((!float.IsNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] >= 0.0)) {
maxWidth = node.layout.dimensions[dim[resolvedRowAxis]] -
@@ -479,11 +497,20 @@ namespace Facebook.CSSLayout
(node.style.margin.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis]) + node.style.margin.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis])) -
paddingAndBorderAxisResolvedRow;
}
} else {
if ((!float.IsNaN(node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]) && node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] >= 0.0)) {
maxHeight = node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] -
paddingAndBorderAxisColumn;
} else {
maxHeight = parentMaxHeight -
(node.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + node.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])) -
paddingAndBorderAxisColumn;
}
}
// This is the main recursive call. We layout non flexible children.
if (alreadyComputedNextLayout == 0) {
layoutNode(layoutContext, child, maxWidth, direction);
layoutNode(layoutContext, child, maxWidth, maxHeight, direction);
}
// Absolute positioned elements do not take part of the layout, so we
@@ -613,9 +640,18 @@ namespace Facebook.CSSLayout
(node.style.margin.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis]) + node.style.margin.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis])) -
paddingAndBorderAxisResolvedRow;
}
maxHeight = CSSConstants.Undefined;
if ((!float.IsNaN(node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]) && node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] >= 0.0)) {
maxHeight = node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] -
paddingAndBorderAxisColumn;
} else if (isMainRowDirection) {
maxHeight = parentMaxHeight -
(node.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + node.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])) -
paddingAndBorderAxisColumn;
}
// And we recursively call the layout algorithm for this child
layoutNode(layoutContext, currentFlexChild, maxWidth, direction);
layoutNode(layoutContext, currentFlexChild, maxWidth, maxHeight, direction);
child = currentFlexChild;
currentFlexChild = currentFlexChild.nextFlexChild;

View File

@@ -53,7 +53,7 @@ public class CSSNode {
*
* NB: measure is NOT guaranteed to be threadsafe/re-entrant safe!
*/
public void measure(CSSNode node, float width, MeasureOutput measureOutput);
public void measure(CSSNode node, float width, float height, MeasureOutput measureOutput);
}
// VisibleForTesting
@@ -125,13 +125,13 @@ public class CSSNode {
return mMeasureFunction != null;
}
/*package*/ MeasureOutput measure(MeasureOutput measureOutput, float width) {
/*package*/ MeasureOutput measure(MeasureOutput measureOutput, float width, float height) {
if (!isMeasureDefined()) {
throw new RuntimeException("Measure function isn't defined!");
}
measureOutput.height = CSSConstants.UNDEFINED;
measureOutput.width = CSSConstants.UNDEFINED;
Assertions.assertNotNull(mMeasureFunction).measure(this, width, measureOutput);
Assertions.assertNotNull(mMeasureFunction).measure(this, width, height, measureOutput);
return measureOutput;
}
@@ -140,7 +140,7 @@ public class CSSNode {
*/
public void calculateLayout(CSSLayoutContext layoutContext) {
layout.resetResult();
LayoutEngine.layoutNode(layoutContext, this, CSSConstants.UNDEFINED, null);
LayoutEngine.layoutNode(layoutContext, this, CSSConstants.UNDEFINED, CSSConstants.UNDEFINED, null);
}
/**

View File

@@ -18,4 +18,5 @@ public class CachedCSSLayout extends CSSLayout {
public float requestedWidth = CSSConstants.UNDEFINED;
public float requestedHeight = CSSConstants.UNDEFINED;
public float parentMaxWidth = CSSConstants.UNDEFINED;
public float parentMaxHeight = CSSConstants.UNDEFINED;
}

View File

@@ -16,7 +16,7 @@ import static com.facebook.csslayout.CSSLayout.POSITION_RIGHT;
import static com.facebook.csslayout.CSSLayout.POSITION_TOP;
/**
* Calculates layouts based on CSS style. See {@link #layoutNode(CSSNode, float)}.
* Calculates layouts based on CSS style. See {@link #layoutNode(CSSNode, float, float)}.
*/
public class LayoutEngine {
@@ -180,7 +180,7 @@ public class LayoutEngine {
return node.isMeasureDefined();
}
static boolean needsRelayout(CSSNode node, float parentMaxWidth) {
static boolean needsRelayout(CSSNode node, float parentMaxWidth, float parentMaxHeight) {
return node.isDirty() ||
!FloatUtil.floatsEqual(
node.lastLayout.requestedHeight,
@@ -188,20 +188,23 @@ public class LayoutEngine {
!FloatUtil.floatsEqual(
node.lastLayout.requestedWidth,
node.layout.dimensions[DIMENSION_WIDTH]) ||
!FloatUtil.floatsEqual(node.lastLayout.parentMaxWidth, parentMaxWidth);
!FloatUtil.floatsEqual(node.lastLayout.parentMaxWidth, parentMaxWidth) ||
!FloatUtil.floatsEqual(node.lastLayout.parentMaxHeight, parentMaxHeight);
}
/*package*/ static void layoutNode(
CSSLayoutContext layoutContext,
CSSNode node,
float parentMaxWidth,
float parentMaxHeight,
CSSDirection parentDirection) {
if (needsRelayout(node, parentMaxWidth)) {
if (needsRelayout(node, parentMaxWidth, parentMaxHeight)) {
node.lastLayout.requestedWidth = node.layout.dimensions[DIMENSION_WIDTH];
node.lastLayout.requestedHeight = node.layout.dimensions[DIMENSION_HEIGHT];
node.lastLayout.parentMaxWidth = parentMaxWidth;
node.lastLayout.parentMaxHeight = parentMaxHeight;
layoutNodeImpl(layoutContext, node, parentMaxWidth, parentDirection);
layoutNodeImpl(layoutContext, node, parentMaxWidth, parentMaxHeight, parentDirection);
node.lastLayout.copy(node.layout);
} else {
node.layout.copy(node.lastLayout);
@@ -214,6 +217,7 @@ public class LayoutEngine {
CSSLayoutContext layoutContext,
CSSNode node,
float parentMaxWidth,
float parentMaxHeight,
CSSDirection parentDirection) {
for (int i = 0, childCount = node.getChildCount(); i < childCount; i++) {
node.getChildAt(i).layout.resetResult();
@@ -248,6 +252,7 @@ public class LayoutEngine {
// invocations during the layout calculation.
int childCount = node.getChildCount();
float paddingAndBorderAxisResolvedRow = ((node.style.padding.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis]) + node.style.border.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis])) + (node.style.padding.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis]) + node.style.border.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis])));
float paddingAndBorderAxisColumn = ((node.style.padding.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN])) + (node.style.padding.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])));
if (isMeasureDefined(node)) {
boolean isResolvedRowDimDefined = !Float.isNaN(node.layout.dimensions[dim[resolvedRowAxis]]);
@@ -263,6 +268,17 @@ public class LayoutEngine {
}
width -= paddingAndBorderAxisResolvedRow;
float height = CSSConstants.UNDEFINED;
if ((!Float.isNaN(node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]) && node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] >= 0.0)) {
height = node.style.dimensions[DIMENSION_HEIGHT];
} else if (!Float.isNaN(node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]])) {
height = node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]];
} else {
height = parentMaxHeight -
(node.style.margin.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis]) + node.style.margin.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis]));
}
height -= ((node.style.padding.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN])) + (node.style.padding.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])));
// 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.
@@ -275,7 +291,8 @@ public class LayoutEngine {
MeasureOutput measureDim = node.measure(
layoutContext.measureOutput,
width
width,
height
);
if (isRowUndefined) {
node.layout.dimensions[DIMENSION_WIDTH] = measureDim.width +
@@ -283,7 +300,7 @@ public class LayoutEngine {
}
if (isColumnUndefined) {
node.layout.dimensions[DIMENSION_HEIGHT] = measureDim.height +
((node.style.padding.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN])) + (node.style.padding.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])));
paddingAndBorderAxisColumn;
}
}
if (childCount == 0) {
@@ -364,6 +381,7 @@ public class LayoutEngine {
float crossDim = 0;
float maxWidth;
float maxHeight;
for (i = startLine; i < childCount; ++i) {
child = node.getChildAt(i);
child.lineIndex = linesCount;
@@ -444,6 +462,8 @@ public class LayoutEngine {
} else {
maxWidth = CSSConstants.UNDEFINED;
maxHeight = CSSConstants.UNDEFINED;
if (!isMainRowDirection) {
if ((!Float.isNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] >= 0.0)) {
maxWidth = node.layout.dimensions[dim[resolvedRowAxis]] -
@@ -453,11 +473,20 @@ public class LayoutEngine {
(node.style.margin.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis]) + node.style.margin.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis])) -
paddingAndBorderAxisResolvedRow;
}
} else {
if ((!Float.isNaN(node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]) && node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] >= 0.0)) {
maxHeight = node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] -
paddingAndBorderAxisColumn;
} else {
maxHeight = parentMaxHeight -
(node.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + node.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])) -
paddingAndBorderAxisColumn;
}
}
// This is the main recursive call. We layout non flexible children.
if (alreadyComputedNextLayout == 0) {
layoutNode(layoutContext, child, maxWidth, direction);
layoutNode(layoutContext, child, maxWidth, maxHeight, direction);
}
// Absolute positioned elements do not take part of the layout, so we
@@ -587,9 +616,18 @@ public class LayoutEngine {
(node.style.margin.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis]) + node.style.margin.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis])) -
paddingAndBorderAxisResolvedRow;
}
maxHeight = CSSConstants.UNDEFINED;
if ((!Float.isNaN(node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]) && node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] >= 0.0)) {
maxHeight = node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] -
paddingAndBorderAxisColumn;
} else if (isMainRowDirection) {
maxHeight = parentMaxHeight -
(node.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + node.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])) -
paddingAndBorderAxisColumn;
}
// And we recursively call the layout algorithm for this child
layoutNode(layoutContext, currentFlexChild, maxWidth, direction);
layoutNode(layoutContext, currentFlexChild, maxWidth, maxHeight, direction);
child = currentFlexChild;
currentFlexChild = currentFlexChild.nextFlexChild;

View File

@@ -223,7 +223,7 @@ public class LayoutCachingTest {
c1.setMeasureFunction(new CSSNode.MeasureFunction() {
@Override
public void measure(CSSNode node, float width, MeasureOutput measureOutput) {
public void measure(CSSNode node, float width, float height, MeasureOutput measureOutput) {
measureOutput.width = 100;
measureOutput.height = 20;
}

View File

@@ -27,20 +27,33 @@ public class LayoutEngineTest {
new CSSNode.MeasureFunction() {
@Override
public void measure(CSSNode node, float width, MeasureOutput measureOutput) {
public void measure(CSSNode node, float width, float height, MeasureOutput measureOutput) {
TestCSSNode testNode = (TestCSSNode) node;
if (testNode.context.equals(TestConstants.SMALL_TEXT)) {
if (CSSConstants.isUndefined(width)) {
width = 10000000;
}
TestCSSNode testNode = (TestCSSNode) node;
if (testNode.context.equals(TestConstants.SMALL_TEXT)) {
measureOutput.width = Math.min(width, TestConstants.SMALL_WIDTH);
measureOutput.height = TestConstants.SMALL_HEIGHT;
} else if (testNode.context.equals(TestConstants.LONG_TEXT)) {
if (CSSConstants.isUndefined(width)) {
width = 10000000;
}
measureOutput.width = width >= TestConstants.BIG_WIDTH ?
TestConstants.BIG_WIDTH : Math.max(TestConstants.BIG_MIN_WIDTH, width);
measureOutput.height = width >= TestConstants.BIG_WIDTH ?
TestConstants.SMALL_HEIGHT : TestConstants.BIG_HEIGHT;
} else if (testNode.context.equals(TestConstants.MEASURE_WITH_RATIO_2)) {
if (width > 0) {
measureOutput.width = width;
measureOutput.height = width * 2;
} else if (height > 0) {
measureOutput.width = height * 2;
measureOutput.height = height;
} else {
measureOutput.width = 99999;
measureOutput.height = 99999;
}
} else {
throw new RuntimeException("Got unknown test: " + testNode.context);
}
@@ -4246,6 +4259,168 @@ public class LayoutEngineTest {
@Test
public void testCase95()
{
TestCSSNode root_node = new TestCSSNode();
{
TestCSSNode node_0 = root_node;
node_0.style.dimensions[DIMENSION_WIDTH] = 100;
node_0.setMeasureFunction(sTestMeasureFunction);
node_0.context = "measureWithRatio2";
}
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] = 100;
node_0.layout.dimensions[DIMENSION_HEIGHT] = 200;
}
test("should layout node with fixed width and custom measure function", root_node, root_layout);
}
@Test
public void testCase96()
{
TestCSSNode root_node = new TestCSSNode();
{
TestCSSNode node_0 = root_node;
node_0.style.dimensions[DIMENSION_HEIGHT] = 100;
node_0.setMeasureFunction(sTestMeasureFunction);
node_0.context = "measureWithRatio2";
}
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] = 100;
}
test("should layout node with fixed height and custom measure function", root_node, root_layout);
}
@Test
public void testCase97()
{
TestCSSNode root_node = new TestCSSNode();
{
TestCSSNode node_0 = root_node;
node_0.style.dimensions[DIMENSION_WIDTH] = 100;
node_0.style.dimensions[DIMENSION_HEIGHT] = 100;
node_0.setMeasureFunction(sTestMeasureFunction);
node_0.context = "measureWithRatio2";
}
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] = 100;
node_0.layout.dimensions[DIMENSION_HEIGHT] = 100;
}
test("should layout node with fixed height and fixed width, ignoring custom measure function", root_node, root_layout);
}
@Test
public void testCase98()
{
TestCSSNode root_node = new TestCSSNode();
{
TestCSSNode node_0 = root_node;
node_0.setMeasureFunction(sTestMeasureFunction);
node_0.context = "measureWithRatio2";
}
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] = 99999;
node_0.layout.dimensions[DIMENSION_HEIGHT] = 99999;
}
test("should layout node with no fixed dimension and custom measure function", root_node, root_layout);
}
@Test
public void testCase99()
{
TestCSSNode root_node = new TestCSSNode();
{
TestCSSNode node_0 = root_node;
node_0.style.flexDirection = CSSFlexDirection.COLUMN;
node_0.style.dimensions[DIMENSION_WIDTH] = 320;
addChildren(node_0, 2);
{
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.setMeasureFunction(sTestMeasureFunction);
node_1.context = "measureWithRatio2";
node_1 = node_0.getChildAt(1);
node_1.style.flexDirection = CSSFlexDirection.ROW;
node_1.style.dimensions[DIMENSION_HEIGHT] = 100;
addChildren(node_1, 2);
{
TestCSSNode node_2;
node_2 = node_1.getChildAt(0);
node_2.setMeasureFunction(sTestMeasureFunction);
node_2.context = "measureWithRatio2";
node_2 = node_1.getChildAt(1);
node_2.setMeasureFunction(sTestMeasureFunction);
node_2.context = "measureWithRatio2";
}
}
}
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] = 320;
node_0.layout.dimensions[DIMENSION_HEIGHT] = 740;
addChildren(node_0, 2);
{
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] = 320;
node_1.layout.dimensions[DIMENSION_HEIGHT] = 640;
node_1 = node_0.getChildAt(1);
node_1.layout.position[POSITION_TOP] = 640;
node_1.layout.position[POSITION_LEFT] = 0;
node_1.layout.dimensions[DIMENSION_WIDTH] = 320;
node_1.layout.dimensions[DIMENSION_HEIGHT] = 100;
addChildren(node_1, 2);
{
TestCSSNode node_2;
node_2 = node_1.getChildAt(0);
node_2.layout.position[POSITION_TOP] = 0;
node_2.layout.position[POSITION_LEFT] = 0;
node_2.layout.dimensions[DIMENSION_WIDTH] = 200;
node_2.layout.dimensions[DIMENSION_HEIGHT] = 100;
node_2 = node_1.getChildAt(1);
node_2.layout.position[POSITION_TOP] = 0;
node_2.layout.position[POSITION_LEFT] = 200;
node_2.layout.dimensions[DIMENSION_WIDTH] = 200;
node_2.layout.dimensions[DIMENSION_HEIGHT] = 100;
}
}
}
test("should layout node with nested stacks and custom measure function", root_node, root_layout);
}
@Test
public void testCase100()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4268,7 +4443,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase96()
public void testCase101()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4290,7 +4465,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase97()
public void testCase102()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4341,7 +4516,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase98()
public void testCase103()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4394,7 +4569,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase99()
public void testCase104()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4448,7 +4623,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase100()
public void testCase105()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4501,7 +4676,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase101()
public void testCase106()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4555,7 +4730,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase102()
public void testCase107()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4594,7 +4769,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase103()
public void testCase108()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4659,7 +4834,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase104()
public void testCase109()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4702,7 +4877,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase105()
public void testCase110()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4746,7 +4921,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase106()
public void testCase111()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4784,7 +4959,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase107()
public void testCase112()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4823,7 +4998,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase108()
public void testCase113()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4881,7 +5056,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase109()
public void testCase114()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4940,7 +5115,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase110()
public void testCase115()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -4997,7 +5172,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase111()
public void testCase116()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5038,7 +5213,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase112()
public void testCase117()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5085,7 +5260,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase113()
public void testCase118()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5133,7 +5308,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase114()
public void testCase119()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5181,7 +5356,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase115()
public void testCase120()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5226,7 +5401,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase116()
public void testCase121()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5264,7 +5439,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase117()
public void testCase122()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5322,7 +5497,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase118()
public void testCase123()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5359,7 +5534,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase119()
public void testCase124()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5396,7 +5571,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase120()
public void testCase125()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5434,7 +5609,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase121()
public void testCase126()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5472,7 +5647,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase122()
public void testCase127()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5509,7 +5684,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase123()
public void testCase128()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5546,7 +5721,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase124()
public void testCase129()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5582,7 +5757,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase125()
public void testCase130()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5618,7 +5793,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase126()
public void testCase131()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5654,7 +5829,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase127()
public void testCase132()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5690,7 +5865,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase128()
public void testCase133()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5740,7 +5915,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase129()
public void testCase134()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5795,7 +5970,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase130()
public void testCase135()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5851,7 +6026,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase131()
public void testCase136()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5895,7 +6070,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase132()
public void testCase137()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5919,7 +6094,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase133()
public void testCase138()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5943,7 +6118,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase134()
public void testCase139()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5969,7 +6144,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase135()
public void testCase140()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -5995,7 +6170,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase136()
public void testCase141()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6019,7 +6194,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase137()
public void testCase142()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6043,7 +6218,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase138()
public void testCase143()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6069,7 +6244,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase139()
public void testCase144()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6095,7 +6270,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase140()
public void testCase145()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6148,7 +6323,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase141()
public void testCase146()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6202,7 +6377,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase142()
public void testCase147()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6256,7 +6431,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase143()
public void testCase148()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6311,7 +6486,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase144()
public void testCase149()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6364,7 +6539,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase145()
public void testCase150()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6418,7 +6593,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase146()
public void testCase151()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6473,7 +6648,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase147()
public void testCase152()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6529,7 +6704,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase148()
public void testCase153()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6584,7 +6759,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase149()
public void testCase154()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6640,7 +6815,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase150()
public void testCase155()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6679,7 +6854,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase151()
public void testCase156()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6717,7 +6892,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase152()
public void testCase157()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6755,7 +6930,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase153()
public void testCase158()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6803,7 +6978,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase154()
public void testCase159()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6849,7 +7024,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase155()
public void testCase160()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6895,7 +7070,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase156()
public void testCase161()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6936,7 +7111,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase157()
public void testCase162()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -6975,7 +7150,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase158()
public void testCase163()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7014,7 +7189,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase159()
public void testCase164()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7053,7 +7228,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase160()
public void testCase165()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7093,7 +7268,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase161()
public void testCase166()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7136,7 +7311,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase162()
public void testCase167()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7179,7 +7354,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase163()
public void testCase168()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7245,7 +7420,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase164()
public void testCase169()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7317,7 +7492,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase165()
public void testCase170()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7379,7 +7554,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase166()
public void testCase171()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7473,7 +7648,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase167()
public void testCase172()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7554,7 +7729,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase168()
public void testCase173()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7594,7 +7769,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase169()
public void testCase174()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7634,7 +7809,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase170()
public void testCase175()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7674,7 +7849,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase171()
public void testCase176()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7712,7 +7887,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase172()
public void testCase177()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7751,7 +7926,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase173()
public void testCase178()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7789,7 +7964,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase174()
public void testCase179()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7828,7 +8003,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase175()
public void testCase180()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7866,7 +8041,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase176()
public void testCase181()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7905,7 +8080,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase177()
public void testCase182()
{
TestCSSNode root_node = new TestCSSNode();
{
@@ -7941,7 +8116,7 @@ public class LayoutEngineTest {
}
@Test
public void testCase178()
public void testCase183()
{
TestCSSNode root_node = new TestCSSNode();
{

View File

@@ -21,5 +21,6 @@ public class TestConstants {
public static final float BIG_MIN_WIDTH = 100f;
public static final String SMALL_TEXT = "small";
public static final String LONG_TEXT = "loooooooooong with space";
public static final String MEASURE_WITH_RATIO_2 = "measureWithRatio2";
/** END_GENERATED **/
}

View File

@@ -26,11 +26,15 @@ global.layoutTestUtils = {
testRandomLayout: function(node, i) {
allTests.push({name: 'Random #' + i, node: node, expectedLayout: computeDOMLayout(node)});
},
testLayoutAgainstExpectedOnly: function(node, expectedLayout) {
allTests.push({name: currentTest, node: node, expectedLayout: expectedLayout});
},
computeLayout: layoutTestUtils.computeLayout,
reduceTest: reduceTest,
text: layoutTestUtils.text,
texts: layoutTestUtils.texts,
textSizes: layoutTestUtils.textSizes
textSizes: layoutTestUtils.textSizes,
measureWithRatio2: layoutTestUtils.measureWithRatio2
};
global.describe = function(name, cb) {
@@ -114,6 +118,9 @@ function printLayout(test) {
function addMeasure(node) {
if ('measure' in node.style) {
if (node.children && node.children.length) {
throw new Error('Using custom measure function is supported only for leaf nodes.');
}
add('node_' + (level - 3) + '->measure = measure;');
add('node_' + (level - 3) + '->context = "' + node.style.measure.toString() + '";');
}
@@ -289,7 +296,8 @@ function makeConstDefs() {
'#define BIG_HEIGHT ' + layoutTestUtils.textSizes.bigHeight,
'#define BIG_MIN_WIDTH ' + layoutTestUtils.textSizes.bigMinWidth,
'#define SMALL_TEXT "' + layoutTestUtils.texts.small + '"',
'#define LONG_TEXT "' + layoutTestUtils.texts.big + '"'
'#define LONG_TEXT "' + layoutTestUtils.texts.big + '"',
'#define MEASURE_WITH_RATIO_2 "' + layoutTestUtils.measureWithRatio2() + '"'
];
return lines.join('\n');
}