port latest updates to C

This commit is contained in:
Christopher Chedeau
2014-04-22 14:59:59 -07:00
parent fa2f7080e2
commit aad9fab75f
5 changed files with 32931 additions and 26 deletions

View File

@@ -421,9 +421,12 @@ void layoutNode(css_node_t *node) {
leadingCrossDim += remainingCrossDim;
} else if (alignItem == CSS_ALIGN_STRETCH) {
if (!isDimDefined(child, crossAxis)) {
child->layout.dimensions[dim[crossAxis]] = node->layout.dimensions[dim[crossAxis]] -
child->layout.dimensions[dim[crossAxis]] = fmaxf(
node->layout.dimensions[dim[crossAxis]] -
getPaddingAndBorderAxis(node, crossAxis) -
getMarginAxis(child, crossAxis);
getMarginAxis(child, crossAxis),
getPaddingAndBorderAxis(child, crossAxis)
);
}
}
child->layout.position[pos[crossAxis]] += leadingCrossDim;

View File

@@ -63,9 +63,19 @@ typedef struct {
css_flex_t flex;
css_position_type_t position_type;
float margin[4];
float position[4];
/**
* You should skip all the rules that contain negative values for the
* following attributes. For example:
* {padding: 10, paddingLeft: -5}
* should output:
* {left: 10 ...}
* the following two are incorrect:
* {left: -5 ...}
* {left: 0 ...}
*/
float padding[4];
float border[4];
float position[4];
float dimensions[2];
} css_style_t;

File diff suppressed because it is too large Load Diff

View File

@@ -786,7 +786,6 @@ describe('Layout', function() {
for (var i = 0; i < 1000; ++i) {
var node = generateRandomNode();
if (JSON.stringify(computeLayout(node)) !== JSON.stringify(computeDOMLayout(node))) {
node = reduceTest(node);
}

View File

@@ -34,13 +34,18 @@ document.getElementById('layout_code').value = computeLayout.layoutNode.toString
var currentTest = '';
var allTests = [];
var computeDOMLayout = layoutTestUtils.computeDOMLayout;
var computeLayout = layoutTestUtils.computeLayout;
var reduceTest = layoutTestUtils.reduceTest;
var layoutTestUtils = {
testLayout: function(node, expectedLayout) {
allTests.push({name: currentTest, node: node, expectedLayout: expectedLayout});
},
testRandomLayout: function(node, i) {
allTests.push({name: 'Random #' + i, node: node, expectedLayout: computeDOMLayout(node)});
}
},
computeLayout: computeLayout,
computeDOMLayout: computeDOMLayout,
reduceTest: reduceTest
};
function describe(name, cb) { cb(); }
function it(name, cb) { currentTest = name; cb(); }
@@ -70,22 +75,26 @@ function printLayout(test) {
}
}
function addFloat(node, js_key, c_key) {
function addFloat(positive, node, js_key, c_key) {
if (js_key in node.style) {
if (positive === 'positive' && node.style[js_key] < 0) {
// do nothing
} else {
add('node->style' + '.' + c_key + ' = ' + node.style[js_key] + ';');
}
}
}
function addSpacing(node, spacing, suffix) {
addFloat(node, spacing + suffix, spacing + '[CSS_LEFT]');
addFloat(node, spacing + suffix, spacing + '[CSS_TOP]');
addFloat(node, spacing + suffix, spacing + '[CSS_RIGHT]');
addFloat(node, spacing + suffix, spacing + '[CSS_BOTTOM]');
function addSpacing(positive, node, spacing, suffix) {
addFloat(positive, node, spacing + suffix, spacing + '[CSS_LEFT]');
addFloat(positive, node, spacing + suffix, spacing + '[CSS_TOP]');
addFloat(positive, node, spacing + suffix, spacing + '[CSS_RIGHT]');
addFloat(positive, node, spacing + suffix, spacing + '[CSS_BOTTOM]');
addFloat(node, spacing + 'Left' + suffix, spacing + '[CSS_LEFT]');
addFloat(node, spacing + 'Top' + suffix, spacing + '[CSS_TOP]');
addFloat(node, spacing + 'Right' + suffix, spacing + '[CSS_RIGHT]');
addFloat(node, spacing + 'Bottom' + suffix, spacing + '[CSS_BOTTOM]');
addFloat(positive, node, spacing + 'Left' + suffix, spacing + '[CSS_LEFT]');
addFloat(positive, node, spacing + 'Top' + suffix, spacing + '[CSS_TOP]');
addFloat(positive, node, spacing + 'Right' + suffix, spacing + '[CSS_RIGHT]');
addFloat(positive, node, spacing + 'Bottom' + suffix, spacing + '[CSS_BOTTOM]');
}
add('{');
@@ -128,15 +137,15 @@ function printLayout(test) {
'relative': 'CSS_POSITION_RELATIVE',
'absolute': 'CSS_POSITION_ABSOLUTE'
});
addFloat(node, 'width', 'dimensions[CSS_WIDTH]');
addFloat(node, 'height', 'dimensions[CSS_HEIGHT]');
addSpacing(node, 'margin', '');
addSpacing(node, 'padding', '');
addSpacing(node, 'border', 'Width');
addFloat(node, 'left', 'position[CSS_LEFT]');
addFloat(node, 'top', 'position[CSS_TOP]');
addFloat(node, 'right', 'position[CSS_RIGHT]');
addFloat(node, 'bottom', 'position[CSS_BOTTOM]');
addFloat('positive', node, 'width', 'dimensions[CSS_WIDTH]');
addFloat('positive', node, 'height', 'dimensions[CSS_HEIGHT]');
addSpacing('all', node, 'margin', '');
addSpacing('positive', node, 'padding', '');
addSpacing('positive', node, 'border', 'Width');
addFloat('all', node, 'left', 'position[CSS_LEFT]');
addFloat('all', node, 'top', 'position[CSS_TOP]');
addFloat('all', node, 'right', 'position[CSS_RIGHT]');
addFloat('all', node, 'bottom', 'position[CSS_BOTTOM]');
if (node.children) {
add('init_css_node_children(node, ' + node.children.length + ');');