port latest updates to C
This commit is contained in:
@@ -421,9 +421,12 @@ void layoutNode(css_node_t *node) {
|
|||||||
leadingCrossDim += remainingCrossDim;
|
leadingCrossDim += remainingCrossDim;
|
||||||
} else if (alignItem == CSS_ALIGN_STRETCH) {
|
} else if (alignItem == CSS_ALIGN_STRETCH) {
|
||||||
if (!isDimDefined(child, crossAxis)) {
|
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) -
|
getPaddingAndBorderAxis(node, crossAxis) -
|
||||||
getMarginAxis(child, crossAxis);
|
getMarginAxis(child, crossAxis),
|
||||||
|
getPaddingAndBorderAxis(child, crossAxis)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
child->layout.position[pos[crossAxis]] += leadingCrossDim;
|
child->layout.position[pos[crossAxis]] += leadingCrossDim;
|
||||||
|
12
src/Layout.h
12
src/Layout.h
@@ -63,9 +63,19 @@ typedef struct {
|
|||||||
css_flex_t flex;
|
css_flex_t flex;
|
||||||
css_position_type_t position_type;
|
css_position_type_t position_type;
|
||||||
float margin[4];
|
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 padding[4];
|
||||||
float border[4];
|
float border[4];
|
||||||
float position[4];
|
|
||||||
float dimensions[2];
|
float dimensions[2];
|
||||||
} css_style_t;
|
} css_style_t;
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -786,7 +786,6 @@ describe('Layout', function() {
|
|||||||
|
|
||||||
for (var i = 0; i < 1000; ++i) {
|
for (var i = 0; i < 1000; ++i) {
|
||||||
var node = generateRandomNode();
|
var node = generateRandomNode();
|
||||||
|
|
||||||
if (JSON.stringify(computeLayout(node)) !== JSON.stringify(computeDOMLayout(node))) {
|
if (JSON.stringify(computeLayout(node)) !== JSON.stringify(computeDOMLayout(node))) {
|
||||||
node = reduceTest(node);
|
node = reduceTest(node);
|
||||||
}
|
}
|
||||||
|
@@ -34,13 +34,18 @@ document.getElementById('layout_code').value = computeLayout.layoutNode.toString
|
|||||||
var currentTest = '';
|
var currentTest = '';
|
||||||
var allTests = [];
|
var allTests = [];
|
||||||
var computeDOMLayout = layoutTestUtils.computeDOMLayout;
|
var computeDOMLayout = layoutTestUtils.computeDOMLayout;
|
||||||
|
var computeLayout = layoutTestUtils.computeLayout;
|
||||||
|
var reduceTest = layoutTestUtils.reduceTest;
|
||||||
var layoutTestUtils = {
|
var layoutTestUtils = {
|
||||||
testLayout: function(node, expectedLayout) {
|
testLayout: function(node, expectedLayout) {
|
||||||
allTests.push({name: currentTest, node: node, expectedLayout: expectedLayout});
|
allTests.push({name: currentTest, node: node, expectedLayout: expectedLayout});
|
||||||
},
|
},
|
||||||
testRandomLayout: function(node, i) {
|
testRandomLayout: function(node, i) {
|
||||||
allTests.push({name: 'Random #' + i, node: node, expectedLayout: computeDOMLayout(node)});
|
allTests.push({name: 'Random #' + i, node: node, expectedLayout: computeDOMLayout(node)});
|
||||||
}
|
},
|
||||||
|
computeLayout: computeLayout,
|
||||||
|
computeDOMLayout: computeDOMLayout,
|
||||||
|
reduceTest: reduceTest
|
||||||
};
|
};
|
||||||
function describe(name, cb) { cb(); }
|
function describe(name, cb) { cb(); }
|
||||||
function it(name, cb) { currentTest = name; 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 (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] + ';');
|
add('node->style' + '.' + c_key + ' = ' + node.style[js_key] + ';');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function addSpacing(node, spacing, suffix) {
|
function addSpacing(positive, node, spacing, suffix) {
|
||||||
addFloat(node, spacing + suffix, spacing + '[CSS_LEFT]');
|
addFloat(positive, node, spacing + suffix, spacing + '[CSS_LEFT]');
|
||||||
addFloat(node, spacing + suffix, spacing + '[CSS_TOP]');
|
addFloat(positive, node, spacing + suffix, spacing + '[CSS_TOP]');
|
||||||
addFloat(node, spacing + suffix, spacing + '[CSS_RIGHT]');
|
addFloat(positive, node, spacing + suffix, spacing + '[CSS_RIGHT]');
|
||||||
addFloat(node, spacing + suffix, spacing + '[CSS_BOTTOM]');
|
addFloat(positive, node, spacing + suffix, spacing + '[CSS_BOTTOM]');
|
||||||
|
|
||||||
addFloat(node, spacing + 'Left' + suffix, spacing + '[CSS_LEFT]');
|
addFloat(positive, node, spacing + 'Left' + suffix, spacing + '[CSS_LEFT]');
|
||||||
addFloat(node, spacing + 'Top' + suffix, spacing + '[CSS_TOP]');
|
addFloat(positive, node, spacing + 'Top' + suffix, spacing + '[CSS_TOP]');
|
||||||
addFloat(node, spacing + 'Right' + suffix, spacing + '[CSS_RIGHT]');
|
addFloat(positive, node, spacing + 'Right' + suffix, spacing + '[CSS_RIGHT]');
|
||||||
addFloat(node, spacing + 'Bottom' + suffix, spacing + '[CSS_BOTTOM]');
|
addFloat(positive, node, spacing + 'Bottom' + suffix, spacing + '[CSS_BOTTOM]');
|
||||||
}
|
}
|
||||||
|
|
||||||
add('{');
|
add('{');
|
||||||
@@ -128,15 +137,15 @@ function printLayout(test) {
|
|||||||
'relative': 'CSS_POSITION_RELATIVE',
|
'relative': 'CSS_POSITION_RELATIVE',
|
||||||
'absolute': 'CSS_POSITION_ABSOLUTE'
|
'absolute': 'CSS_POSITION_ABSOLUTE'
|
||||||
});
|
});
|
||||||
addFloat(node, 'width', 'dimensions[CSS_WIDTH]');
|
addFloat('positive', node, 'width', 'dimensions[CSS_WIDTH]');
|
||||||
addFloat(node, 'height', 'dimensions[CSS_HEIGHT]');
|
addFloat('positive', node, 'height', 'dimensions[CSS_HEIGHT]');
|
||||||
addSpacing(node, 'margin', '');
|
addSpacing('all', node, 'margin', '');
|
||||||
addSpacing(node, 'padding', '');
|
addSpacing('positive', node, 'padding', '');
|
||||||
addSpacing(node, 'border', 'Width');
|
addSpacing('positive', node, 'border', 'Width');
|
||||||
addFloat(node, 'left', 'position[CSS_LEFT]');
|
addFloat('all', node, 'left', 'position[CSS_LEFT]');
|
||||||
addFloat(node, 'top', 'position[CSS_TOP]');
|
addFloat('all', node, 'top', 'position[CSS_TOP]');
|
||||||
addFloat(node, 'right', 'position[CSS_RIGHT]');
|
addFloat('all', node, 'right', 'position[CSS_RIGHT]');
|
||||||
addFloat(node, 'bottom', 'position[CSS_BOTTOM]');
|
addFloat('all', node, 'bottom', 'position[CSS_BOTTOM]');
|
||||||
|
|
||||||
if (node.children) {
|
if (node.children) {
|
||||||
add('init_css_node_children(node, ' + node.children.length + ');');
|
add('init_css_node_children(node, ' + node.children.length + ');');
|
||||||
|
Reference in New Issue
Block a user