mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-29 12:45:37 +08:00
Fix row height
Reviewed By: @frantic Differential Revision: D2480265
This commit is contained in:
committed by
facebook-github-bot-7
parent
1487ebfe01
commit
ec8b5425e5
@@ -582,7 +582,7 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
|
|||||||
if (isRowUndefined || isColumnUndefined) {
|
if (isRowUndefined || isColumnUndefined) {
|
||||||
css_dim_t measureDim = node->measure(
|
css_dim_t measureDim = node->measure(
|
||||||
node->context,
|
node->context,
|
||||||
|
|
||||||
width
|
width
|
||||||
);
|
);
|
||||||
if (isRowUndefined) {
|
if (isRowUndefined) {
|
||||||
@@ -1004,7 +1004,7 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
|
|||||||
if (alignItem == CSS_ALIGN_STRETCH) {
|
if (alignItem == CSS_ALIGN_STRETCH) {
|
||||||
// You can only stretch if the dimension has not already been set
|
// You can only stretch if the dimension has not already been set
|
||||||
// previously.
|
// previously.
|
||||||
if (isUndefined(child->layout.dimensions[dim[crossAxis]])) {
|
if (!isDimDefined(child, crossAxis)) {
|
||||||
child->layout.dimensions[dim[crossAxis]] = fmaxf(
|
child->layout.dimensions[dim[crossAxis]] = fmaxf(
|
||||||
boundAxis(child, crossAxis, containerCrossAxis -
|
boundAxis(child, crossAxis, containerCrossAxis -
|
||||||
paddingAndBorderAxisCross - getMarginAxis(child, crossAxis)),
|
paddingAndBorderAxisCross - getMarginAxis(child, crossAxis)),
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// NOTE: this file is auto-copied from https://github.com/facebook/css-layout
|
// NOTE: this file is auto-copied from https://github.com/facebook/css-layout
|
||||||
// @generated SignedSource<<e7c34406ea5072e4584a2b054ab56d9f>>
|
// @generated SignedSource<<4cabe0d63a4ed878edf6b5be8762746a>>
|
||||||
|
|
||||||
package com.facebook.csslayout;
|
package com.facebook.csslayout;
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ public class LayoutEngine {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// We only run if there's a width or height defined
|
// We only run if there's a width or height defined
|
||||||
if (Float.isNaN(node.style.dimensions[dim[axis]]) ||
|
if (Float.isNaN(node.style.dimensions[dim[axis]]) ||
|
||||||
node.style.dimensions[dim[axis]] <= 0.0) {
|
node.style.dimensions[dim[axis]] <= 0.0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -223,19 +223,19 @@ public class LayoutEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** START_GENERATED **/
|
/** START_GENERATED **/
|
||||||
|
|
||||||
CSSDirection direction = resolveDirection(node, parentDirection);
|
CSSDirection direction = resolveDirection(node, parentDirection);
|
||||||
int mainAxis = resolveAxis(getFlexDirection(node), direction);
|
int mainAxis = resolveAxis(getFlexDirection(node), direction);
|
||||||
int crossAxis = getCrossFlexDirection(mainAxis, direction);
|
int crossAxis = getCrossFlexDirection(mainAxis, direction);
|
||||||
int resolvedRowAxis = resolveAxis(CSS_FLEX_DIRECTION_ROW, direction);
|
int resolvedRowAxis = resolveAxis(CSS_FLEX_DIRECTION_ROW, direction);
|
||||||
|
|
||||||
// Handle width and height style attributes
|
// Handle width and height style attributes
|
||||||
setDimensionFromStyle(node, mainAxis);
|
setDimensionFromStyle(node, mainAxis);
|
||||||
setDimensionFromStyle(node, crossAxis);
|
setDimensionFromStyle(node, crossAxis);
|
||||||
|
|
||||||
// Set the resolved resolution in the node's layout
|
// Set the resolved resolution in the node's layout
|
||||||
node.layout.direction = direction;
|
node.layout.direction = direction;
|
||||||
|
|
||||||
// The position is set by the parent, but we need to complete it with a
|
// The position is set by the parent, but we need to complete it with a
|
||||||
// delta composed of the margin and left/top/right/bottom
|
// delta composed of the margin and left/top/right/bottom
|
||||||
node.layout.position[leading[mainAxis]] += node.style.margin.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) +
|
node.layout.position[leading[mainAxis]] += node.style.margin.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) +
|
||||||
@@ -246,15 +246,15 @@ public class LayoutEngine {
|
|||||||
getRelativePosition(node, crossAxis);
|
getRelativePosition(node, crossAxis);
|
||||||
node.layout.position[trailing[crossAxis]] += node.style.margin.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]) +
|
node.layout.position[trailing[crossAxis]] += node.style.margin.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]) +
|
||||||
getRelativePosition(node, crossAxis);
|
getRelativePosition(node, crossAxis);
|
||||||
|
|
||||||
// Inline immutable values from the target node to avoid excessive method
|
// Inline immutable values from the target node to avoid excessive method
|
||||||
// invocations during the layout calculation.
|
// invocations during the layout calculation.
|
||||||
int childCount = node.getChildCount();
|
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 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])));
|
||||||
|
|
||||||
if (isMeasureDefined(node)) {
|
if (isMeasureDefined(node)) {
|
||||||
boolean isResolvedRowDimDefined = !Float.isNaN(node.layout.dimensions[dim[resolvedRowAxis]]);
|
boolean isResolvedRowDimDefined = !Float.isNaN(node.layout.dimensions[dim[resolvedRowAxis]]);
|
||||||
|
|
||||||
float width = CSSConstants.UNDEFINED;
|
float width = CSSConstants.UNDEFINED;
|
||||||
if ((!Float.isNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] > 0.0)) {
|
if ((!Float.isNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] > 0.0)) {
|
||||||
width = node.style.dimensions[DIMENSION_WIDTH];
|
width = node.style.dimensions[DIMENSION_WIDTH];
|
||||||
@@ -265,18 +265,18 @@ public class LayoutEngine {
|
|||||||
(node.style.margin.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis]) + node.style.margin.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis]));
|
(node.style.margin.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis]) + node.style.margin.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis]));
|
||||||
}
|
}
|
||||||
width -= paddingAndBorderAxisResolvedRow;
|
width -= paddingAndBorderAxisResolvedRow;
|
||||||
|
|
||||||
// We only need to give a dimension for the text if we haven't got any
|
// 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
|
// for it computed yet. It can either be from the style attribute or because
|
||||||
// the element is flexible.
|
// the element is flexible.
|
||||||
boolean isRowUndefined = !(!Float.isNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] > 0.0) && !isResolvedRowDimDefined;
|
boolean isRowUndefined = !(!Float.isNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] > 0.0) && !isResolvedRowDimDefined;
|
||||||
boolean isColumnUndefined = !(!Float.isNaN(node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]) && node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] > 0.0) &&
|
boolean isColumnUndefined = !(!Float.isNaN(node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]) && node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] > 0.0) &&
|
||||||
Float.isNaN(node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]);
|
Float.isNaN(node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]);
|
||||||
|
|
||||||
// Let's not measure the text if we already know both dimensions
|
// Let's not measure the text if we already know both dimensions
|
||||||
if (isRowUndefined || isColumnUndefined) {
|
if (isRowUndefined || isColumnUndefined) {
|
||||||
MeasureOutput measureDim = node.measure(
|
MeasureOutput measureDim = node.measure(
|
||||||
|
|
||||||
layoutContext.measureOutput,
|
layoutContext.measureOutput,
|
||||||
width
|
width
|
||||||
);
|
);
|
||||||
@@ -293,33 +293,33 @@ public class LayoutEngine {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isNodeFlexWrap = (node.style.flexWrap == CSSWrap.WRAP);
|
boolean isNodeFlexWrap = (node.style.flexWrap == CSSWrap.WRAP);
|
||||||
|
|
||||||
CSSJustify justifyContent = node.style.justifyContent;
|
CSSJustify justifyContent = node.style.justifyContent;
|
||||||
|
|
||||||
float leadingPaddingAndBorderMain = (node.style.padding.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + node.style.border.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]));
|
float leadingPaddingAndBorderMain = (node.style.padding.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + node.style.border.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]));
|
||||||
float leadingPaddingAndBorderCross = (node.style.padding.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + node.style.border.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]));
|
float leadingPaddingAndBorderCross = (node.style.padding.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + node.style.border.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]));
|
||||||
float paddingAndBorderAxisMain = ((node.style.padding.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + node.style.border.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis])) + (node.style.padding.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]) + node.style.border.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis])));
|
float paddingAndBorderAxisMain = ((node.style.padding.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + node.style.border.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis])) + (node.style.padding.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]) + node.style.border.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis])));
|
||||||
float paddingAndBorderAxisCross = ((node.style.padding.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + node.style.border.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis])) + (node.style.padding.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]) + node.style.border.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis])));
|
float paddingAndBorderAxisCross = ((node.style.padding.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + node.style.border.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis])) + (node.style.padding.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]) + node.style.border.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis])));
|
||||||
|
|
||||||
boolean isMainDimDefined = !Float.isNaN(node.layout.dimensions[dim[mainAxis]]);
|
boolean isMainDimDefined = !Float.isNaN(node.layout.dimensions[dim[mainAxis]]);
|
||||||
boolean isCrossDimDefined = !Float.isNaN(node.layout.dimensions[dim[crossAxis]]);
|
boolean isCrossDimDefined = !Float.isNaN(node.layout.dimensions[dim[crossAxis]]);
|
||||||
boolean isMainRowDirection = (mainAxis == CSS_FLEX_DIRECTION_ROW || mainAxis == CSS_FLEX_DIRECTION_ROW_REVERSE);
|
boolean isMainRowDirection = (mainAxis == CSS_FLEX_DIRECTION_ROW || mainAxis == CSS_FLEX_DIRECTION_ROW_REVERSE);
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
int ii;
|
int ii;
|
||||||
CSSNode child;
|
CSSNode child;
|
||||||
int axis;
|
int axis;
|
||||||
|
|
||||||
CSSNode firstAbsoluteChild = null;
|
CSSNode firstAbsoluteChild = null;
|
||||||
CSSNode currentAbsoluteChild = null;
|
CSSNode currentAbsoluteChild = null;
|
||||||
|
|
||||||
float definedMainDim = CSSConstants.UNDEFINED;
|
float definedMainDim = CSSConstants.UNDEFINED;
|
||||||
if (isMainDimDefined) {
|
if (isMainDimDefined) {
|
||||||
definedMainDim = node.layout.dimensions[dim[mainAxis]] - paddingAndBorderAxisMain;
|
definedMainDim = node.layout.dimensions[dim[mainAxis]] - paddingAndBorderAxisMain;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We want to execute the next two loops one per line with flex-wrap
|
// We want to execute the next two loops one per line with flex-wrap
|
||||||
int startLine = 0;
|
int startLine = 0;
|
||||||
int endLine = 0;
|
int endLine = 0;
|
||||||
@@ -331,19 +331,19 @@ public class LayoutEngine {
|
|||||||
int linesCount = 0;
|
int linesCount = 0;
|
||||||
while (endLine < childCount) {
|
while (endLine < childCount) {
|
||||||
// <Loop A> Layout non flexible children and count children by type
|
// <Loop A> Layout non flexible children and count children by type
|
||||||
|
|
||||||
// mainContentDim is accumulation of the dimensions and margin of all the
|
// mainContentDim is accumulation of the dimensions and margin of all the
|
||||||
// non flexible children. This will be used in order to either set the
|
// non flexible children. This will be used in order to either set the
|
||||||
// dimensions of the node if none already exist, or to compute the
|
// dimensions of the node if none already exist, or to compute the
|
||||||
// remaining space left for the flexible children.
|
// remaining space left for the flexible children.
|
||||||
float mainContentDim = 0;
|
float mainContentDim = 0;
|
||||||
|
|
||||||
// There are three kind of children, non flexible, flexible and absolute.
|
// There are three kind of children, non flexible, flexible and absolute.
|
||||||
// We need to know how many there are in order to distribute the space.
|
// We need to know how many there are in order to distribute the space.
|
||||||
int flexibleChildrenCount = 0;
|
int flexibleChildrenCount = 0;
|
||||||
float totalFlexible = 0;
|
float totalFlexible = 0;
|
||||||
int nonFlexibleChildrenCount = 0;
|
int nonFlexibleChildrenCount = 0;
|
||||||
|
|
||||||
// Use the line loop to position children in the main axis for as long
|
// Use the line loop to position children in the main axis for as long
|
||||||
// as they are using a simple stacking behaviour. Children that are
|
// as they are using a simple stacking behaviour. Children that are
|
||||||
// immediately stacked in the initial loop will not be touched again
|
// immediately stacked in the initial loop will not be touched again
|
||||||
@@ -352,30 +352,30 @@ public class LayoutEngine {
|
|||||||
(isMainDimDefined && justifyContent == CSSJustify.FLEX_START) ||
|
(isMainDimDefined && justifyContent == CSSJustify.FLEX_START) ||
|
||||||
(!isMainDimDefined && justifyContent != CSSJustify.CENTER);
|
(!isMainDimDefined && justifyContent != CSSJustify.CENTER);
|
||||||
int firstComplexMain = (isSimpleStackMain ? childCount : startLine);
|
int firstComplexMain = (isSimpleStackMain ? childCount : startLine);
|
||||||
|
|
||||||
// Use the initial line loop to position children in the cross axis for
|
// Use the initial line loop to position children in the cross axis for
|
||||||
// as long as they are relatively positioned with alignment STRETCH or
|
// as long as they are relatively positioned with alignment STRETCH or
|
||||||
// FLEX_START. Children that are immediately stacked in the initial loop
|
// FLEX_START. Children that are immediately stacked in the initial loop
|
||||||
// will not be touched again in <Loop D>.
|
// will not be touched again in <Loop D>.
|
||||||
boolean isSimpleStackCross = true;
|
boolean isSimpleStackCross = true;
|
||||||
int firstComplexCross = childCount;
|
int firstComplexCross = childCount;
|
||||||
|
|
||||||
CSSNode firstFlexChild = null;
|
CSSNode firstFlexChild = null;
|
||||||
CSSNode currentFlexChild = null;
|
CSSNode currentFlexChild = null;
|
||||||
|
|
||||||
float mainDim = leadingPaddingAndBorderMain;
|
float mainDim = leadingPaddingAndBorderMain;
|
||||||
float crossDim = 0;
|
float crossDim = 0;
|
||||||
|
|
||||||
float maxWidth;
|
float maxWidth;
|
||||||
for (i = startLine; i < childCount; ++i) {
|
for (i = startLine; i < childCount; ++i) {
|
||||||
child = node.getChildAt(i);
|
child = node.getChildAt(i);
|
||||||
child.lineIndex = linesCount;
|
child.lineIndex = linesCount;
|
||||||
|
|
||||||
child.nextAbsoluteChild = null;
|
child.nextAbsoluteChild = null;
|
||||||
child.nextFlexChild = null;
|
child.nextFlexChild = null;
|
||||||
|
|
||||||
CSSAlign alignItem = getAlignItem(node, child);
|
CSSAlign alignItem = getAlignItem(node, child);
|
||||||
|
|
||||||
// Pre-fill cross axis dimensions when the child is using stretch before
|
// Pre-fill cross axis dimensions when the child is using stretch before
|
||||||
// we call the recursive layout pass
|
// we call the recursive layout pass
|
||||||
if (alignItem == CSSAlign.STRETCH &&
|
if (alignItem == CSSAlign.STRETCH &&
|
||||||
@@ -398,7 +398,7 @@ public class LayoutEngine {
|
|||||||
currentAbsoluteChild.nextAbsoluteChild = child;
|
currentAbsoluteChild.nextAbsoluteChild = child;
|
||||||
}
|
}
|
||||||
currentAbsoluteChild = child;
|
currentAbsoluteChild = child;
|
||||||
|
|
||||||
// Pre-fill dimensions when using absolute position and both offsets for the axis are defined (either both
|
// Pre-fill dimensions when using absolute position and both offsets for the axis are defined (either both
|
||||||
// left and right or top and bottom).
|
// left and right or top and bottom).
|
||||||
for (ii = 0; ii < 2; ii++) {
|
for (ii = 0; ii < 2; ii++) {
|
||||||
@@ -419,15 +419,15 @@ public class LayoutEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float nextContentDim = 0;
|
float nextContentDim = 0;
|
||||||
|
|
||||||
// It only makes sense to consider a child flexible if we have a computed
|
// It only makes sense to consider a child flexible if we have a computed
|
||||||
// dimension for the node.
|
// dimension for the node.
|
||||||
if (isMainDimDefined && (child.style.positionType == CSSPositionType.RELATIVE && child.style.flex > 0)) {
|
if (isMainDimDefined && (child.style.positionType == CSSPositionType.RELATIVE && child.style.flex > 0)) {
|
||||||
flexibleChildrenCount++;
|
flexibleChildrenCount++;
|
||||||
totalFlexible += child.style.flex;
|
totalFlexible += child.style.flex;
|
||||||
|
|
||||||
// Store a private linked list of flexible children so that we can
|
// Store a private linked list of flexible children so that we can
|
||||||
// efficiently traverse them later.
|
// efficiently traverse them later.
|
||||||
if (firstFlexChild == null) {
|
if (firstFlexChild == null) {
|
||||||
@@ -437,14 +437,14 @@ public class LayoutEngine {
|
|||||||
currentFlexChild.nextFlexChild = child;
|
currentFlexChild.nextFlexChild = child;
|
||||||
}
|
}
|
||||||
currentFlexChild = child;
|
currentFlexChild = child;
|
||||||
|
|
||||||
// Even if we don't know its exact size yet, we already know the padding,
|
// Even if we don't know its exact size yet, we already know the padding,
|
||||||
// border and margin. We'll use this partial information, which represents
|
// border and margin. We'll use this partial information, which represents
|
||||||
// the smallest possible size for the child, to compute the remaining
|
// the smallest possible size for the child, to compute the remaining
|
||||||
// available space.
|
// available space.
|
||||||
nextContentDim = ((child.style.padding.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + child.style.border.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis])) + (child.style.padding.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]) + child.style.border.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]))) +
|
nextContentDim = ((child.style.padding.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + child.style.border.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis])) + (child.style.padding.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]) + child.style.border.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]))) +
|
||||||
(child.style.margin.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + child.style.margin.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]));
|
(child.style.margin.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + child.style.margin.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
maxWidth = CSSConstants.UNDEFINED;
|
maxWidth = CSSConstants.UNDEFINED;
|
||||||
if (!isMainRowDirection) {
|
if (!isMainRowDirection) {
|
||||||
@@ -457,12 +457,12 @@ public class LayoutEngine {
|
|||||||
paddingAndBorderAxisResolvedRow;
|
paddingAndBorderAxisResolvedRow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is the main recursive call. We layout non flexible children.
|
// This is the main recursive call. We layout non flexible children.
|
||||||
if (alreadyComputedNextLayout == 0) {
|
if (alreadyComputedNextLayout == 0) {
|
||||||
layoutNode(layoutContext, child, maxWidth, direction);
|
layoutNode(layoutContext, child, maxWidth, direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Absolute positioned elements do not take part of the layout, so we
|
// Absolute positioned elements do not take part of the layout, so we
|
||||||
// don't use them to compute mainContentDim
|
// don't use them to compute mainContentDim
|
||||||
if (child.style.positionType == CSSPositionType.RELATIVE) {
|
if (child.style.positionType == CSSPositionType.RELATIVE) {
|
||||||
@@ -471,7 +471,7 @@ public class LayoutEngine {
|
|||||||
nextContentDim = (child.layout.dimensions[dim[mainAxis]] + child.style.margin.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + child.style.margin.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]));
|
nextContentDim = (child.layout.dimensions[dim[mainAxis]] + child.style.margin.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + child.style.margin.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The element we are about to add would make us go to the next line
|
// The element we are about to add would make us go to the next line
|
||||||
if (isNodeFlexWrap &&
|
if (isNodeFlexWrap &&
|
||||||
isMainDimDefined &&
|
isMainDimDefined &&
|
||||||
@@ -483,7 +483,7 @@ public class LayoutEngine {
|
|||||||
alreadyComputedNextLayout = 1;
|
alreadyComputedNextLayout = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable simple stacking in the main axis for the current line as
|
// Disable simple stacking in the main axis for the current line as
|
||||||
// we found a non-trivial child. The remaining children will be laid out
|
// we found a non-trivial child. The remaining children will be laid out
|
||||||
// in <Loop C>.
|
// in <Loop C>.
|
||||||
@@ -492,7 +492,7 @@ public class LayoutEngine {
|
|||||||
isSimpleStackMain = false;
|
isSimpleStackMain = false;
|
||||||
firstComplexMain = i;
|
firstComplexMain = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable simple stacking in the cross axis for the current line as
|
// Disable simple stacking in the cross axis for the current line as
|
||||||
// we found a non-trivial child. The remaining children will be laid out
|
// we found a non-trivial child. The remaining children will be laid out
|
||||||
// in <Loop D>.
|
// in <Loop D>.
|
||||||
@@ -503,37 +503,37 @@ public class LayoutEngine {
|
|||||||
isSimpleStackCross = false;
|
isSimpleStackCross = false;
|
||||||
firstComplexCross = i;
|
firstComplexCross = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSimpleStackMain) {
|
if (isSimpleStackMain) {
|
||||||
child.layout.position[pos[mainAxis]] += mainDim;
|
child.layout.position[pos[mainAxis]] += mainDim;
|
||||||
if (isMainDimDefined) {
|
if (isMainDimDefined) {
|
||||||
child.layout.position[trailing[mainAxis]] = node.layout.dimensions[dim[mainAxis]] - child.layout.dimensions[dim[mainAxis]] - child.layout.position[pos[mainAxis]];
|
child.layout.position[trailing[mainAxis]] = node.layout.dimensions[dim[mainAxis]] - child.layout.dimensions[dim[mainAxis]] - child.layout.position[pos[mainAxis]];
|
||||||
}
|
}
|
||||||
|
|
||||||
mainDim += (child.layout.dimensions[dim[mainAxis]] + child.style.margin.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + child.style.margin.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]));
|
mainDim += (child.layout.dimensions[dim[mainAxis]] + child.style.margin.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + child.style.margin.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]));
|
||||||
crossDim = Math.max(crossDim, boundAxis(child, crossAxis, (child.layout.dimensions[dim[crossAxis]] + child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + child.style.margin.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]))));
|
crossDim = Math.max(crossDim, boundAxis(child, crossAxis, (child.layout.dimensions[dim[crossAxis]] + child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + child.style.margin.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]))));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSimpleStackCross) {
|
if (isSimpleStackCross) {
|
||||||
child.layout.position[pos[crossAxis]] += linesCrossDim + leadingPaddingAndBorderCross;
|
child.layout.position[pos[crossAxis]] += linesCrossDim + leadingPaddingAndBorderCross;
|
||||||
if (isCrossDimDefined) {
|
if (isCrossDimDefined) {
|
||||||
child.layout.position[trailing[crossAxis]] = node.layout.dimensions[dim[crossAxis]] - child.layout.dimensions[dim[crossAxis]] - child.layout.position[pos[crossAxis]];
|
child.layout.position[trailing[crossAxis]] = node.layout.dimensions[dim[crossAxis]] - child.layout.dimensions[dim[crossAxis]] - child.layout.position[pos[crossAxis]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
alreadyComputedNextLayout = 0;
|
alreadyComputedNextLayout = 0;
|
||||||
mainContentDim += nextContentDim;
|
mainContentDim += nextContentDim;
|
||||||
endLine = i + 1;
|
endLine = i + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <Loop B> Layout flexible children and allocate empty space
|
// <Loop B> Layout flexible children and allocate empty space
|
||||||
|
|
||||||
// In order to position the elements in the main axis, we have two
|
// In order to position the elements in the main axis, we have two
|
||||||
// controls. The space between the beginning and the first element
|
// controls. The space between the beginning and the first element
|
||||||
// and the space between each two elements.
|
// and the space between each two elements.
|
||||||
float leadingMainDim = 0;
|
float leadingMainDim = 0;
|
||||||
float betweenMainDim = 0;
|
float betweenMainDim = 0;
|
||||||
|
|
||||||
// The remaining available space that needs to be allocated
|
// The remaining available space that needs to be allocated
|
||||||
float remainingMainDim = 0;
|
float remainingMainDim = 0;
|
||||||
if (isMainDimDefined) {
|
if (isMainDimDefined) {
|
||||||
@@ -541,14 +541,14 @@ public class LayoutEngine {
|
|||||||
} else {
|
} else {
|
||||||
remainingMainDim = Math.max(mainContentDim, 0) - mainContentDim;
|
remainingMainDim = Math.max(mainContentDim, 0) - mainContentDim;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there are flexible children in the mix, they are going to fill the
|
// If there are flexible children in the mix, they are going to fill the
|
||||||
// remaining space
|
// remaining space
|
||||||
if (flexibleChildrenCount != 0) {
|
if (flexibleChildrenCount != 0) {
|
||||||
float flexibleMainDim = remainingMainDim / totalFlexible;
|
float flexibleMainDim = remainingMainDim / totalFlexible;
|
||||||
float baseMainDim;
|
float baseMainDim;
|
||||||
float boundMainDim;
|
float boundMainDim;
|
||||||
|
|
||||||
// If the flex share of remaining space doesn't meet min/max bounds,
|
// If the flex share of remaining space doesn't meet min/max bounds,
|
||||||
// remove this child from flex calculations.
|
// remove this child from flex calculations.
|
||||||
currentFlexChild = firstFlexChild;
|
currentFlexChild = firstFlexChild;
|
||||||
@@ -556,22 +556,22 @@ public class LayoutEngine {
|
|||||||
baseMainDim = flexibleMainDim * currentFlexChild.style.flex +
|
baseMainDim = flexibleMainDim * currentFlexChild.style.flex +
|
||||||
((currentFlexChild.style.padding.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + currentFlexChild.style.border.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis])) + (currentFlexChild.style.padding.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]) + currentFlexChild.style.border.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis])));
|
((currentFlexChild.style.padding.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + currentFlexChild.style.border.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis])) + (currentFlexChild.style.padding.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]) + currentFlexChild.style.border.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis])));
|
||||||
boundMainDim = boundAxis(currentFlexChild, mainAxis, baseMainDim);
|
boundMainDim = boundAxis(currentFlexChild, mainAxis, baseMainDim);
|
||||||
|
|
||||||
if (baseMainDim != boundMainDim) {
|
if (baseMainDim != boundMainDim) {
|
||||||
remainingMainDim -= boundMainDim;
|
remainingMainDim -= boundMainDim;
|
||||||
totalFlexible -= currentFlexChild.style.flex;
|
totalFlexible -= currentFlexChild.style.flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentFlexChild = currentFlexChild.nextFlexChild;
|
currentFlexChild = currentFlexChild.nextFlexChild;
|
||||||
}
|
}
|
||||||
flexibleMainDim = remainingMainDim / totalFlexible;
|
flexibleMainDim = remainingMainDim / totalFlexible;
|
||||||
|
|
||||||
// The non flexible children can overflow the container, in this case
|
// The non flexible children can overflow the container, in this case
|
||||||
// we should just assume that there is no space available.
|
// we should just assume that there is no space available.
|
||||||
if (flexibleMainDim < 0) {
|
if (flexibleMainDim < 0) {
|
||||||
flexibleMainDim = 0;
|
flexibleMainDim = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentFlexChild = firstFlexChild;
|
currentFlexChild = firstFlexChild;
|
||||||
while (currentFlexChild != null) {
|
while (currentFlexChild != null) {
|
||||||
// At this point we know the final size of the element in the main
|
// At this point we know the final size of the element in the main
|
||||||
@@ -580,7 +580,7 @@ public class LayoutEngine {
|
|||||||
flexibleMainDim * currentFlexChild.style.flex +
|
flexibleMainDim * currentFlexChild.style.flex +
|
||||||
((currentFlexChild.style.padding.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + currentFlexChild.style.border.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis])) + (currentFlexChild.style.padding.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]) + currentFlexChild.style.border.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis])))
|
((currentFlexChild.style.padding.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + currentFlexChild.style.border.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis])) + (currentFlexChild.style.padding.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]) + currentFlexChild.style.border.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis])))
|
||||||
);
|
);
|
||||||
|
|
||||||
maxWidth = CSSConstants.UNDEFINED;
|
maxWidth = CSSConstants.UNDEFINED;
|
||||||
if ((!Float.isNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] > 0.0)) {
|
if ((!Float.isNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] > 0.0)) {
|
||||||
maxWidth = node.layout.dimensions[dim[resolvedRowAxis]] -
|
maxWidth = node.layout.dimensions[dim[resolvedRowAxis]] -
|
||||||
@@ -590,15 +590,15 @@ public class LayoutEngine {
|
|||||||
(node.style.margin.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis]) + node.style.margin.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis])) -
|
(node.style.margin.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis]) + node.style.margin.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis])) -
|
||||||
paddingAndBorderAxisResolvedRow;
|
paddingAndBorderAxisResolvedRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
// And we recursively call the layout algorithm for this child
|
// And we recursively call the layout algorithm for this child
|
||||||
layoutNode(layoutContext, currentFlexChild, maxWidth, direction);
|
layoutNode(layoutContext, currentFlexChild, maxWidth, direction);
|
||||||
|
|
||||||
child = currentFlexChild;
|
child = currentFlexChild;
|
||||||
currentFlexChild = currentFlexChild.nextFlexChild;
|
currentFlexChild = currentFlexChild.nextFlexChild;
|
||||||
child.nextFlexChild = null;
|
child.nextFlexChild = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We use justifyContent to figure out how to allocate the remaining
|
// We use justifyContent to figure out how to allocate the remaining
|
||||||
// space available
|
// space available
|
||||||
} else if (justifyContent != CSSJustify.FLEX_START) {
|
} else if (justifyContent != CSSJustify.FLEX_START) {
|
||||||
@@ -621,18 +621,18 @@ public class LayoutEngine {
|
|||||||
leadingMainDim = betweenMainDim / 2;
|
leadingMainDim = betweenMainDim / 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// <Loop C> Position elements in the main axis and compute dimensions
|
// <Loop C> Position elements in the main axis and compute dimensions
|
||||||
|
|
||||||
// At this point, all the children have their dimensions set. We need to
|
// At this point, all the children have their dimensions set. We need to
|
||||||
// find their position. In order to do that, we accumulate data in
|
// find their position. In order to do that, we accumulate data in
|
||||||
// variables that are also useful to compute the total dimensions of the
|
// variables that are also useful to compute the total dimensions of the
|
||||||
// container!
|
// container!
|
||||||
mainDim += leadingMainDim;
|
mainDim += leadingMainDim;
|
||||||
|
|
||||||
for (i = firstComplexMain; i < endLine; ++i) {
|
for (i = firstComplexMain; i < endLine; ++i) {
|
||||||
child = node.getChildAt(i);
|
child = node.getChildAt(i);
|
||||||
|
|
||||||
if (child.style.positionType == CSSPositionType.ABSOLUTE &&
|
if (child.style.positionType == CSSPositionType.ABSOLUTE &&
|
||||||
!Float.isNaN(child.style.position[leading[mainAxis]])) {
|
!Float.isNaN(child.style.position[leading[mainAxis]])) {
|
||||||
// In case the child is position absolute and has left/top being
|
// In case the child is position absolute and has left/top being
|
||||||
@@ -645,12 +645,12 @@ public class LayoutEngine {
|
|||||||
// If the child is position absolute (without top/left) or relative,
|
// If the child is position absolute (without top/left) or relative,
|
||||||
// we put it at the current accumulated offset.
|
// we put it at the current accumulated offset.
|
||||||
child.layout.position[pos[mainAxis]] += mainDim;
|
child.layout.position[pos[mainAxis]] += mainDim;
|
||||||
|
|
||||||
// Define the trailing position accordingly.
|
// Define the trailing position accordingly.
|
||||||
if (isMainDimDefined) {
|
if (isMainDimDefined) {
|
||||||
child.layout.position[trailing[mainAxis]] = node.layout.dimensions[dim[mainAxis]] - child.layout.dimensions[dim[mainAxis]] - child.layout.position[pos[mainAxis]];
|
child.layout.position[trailing[mainAxis]] = node.layout.dimensions[dim[mainAxis]] - child.layout.dimensions[dim[mainAxis]] - child.layout.position[pos[mainAxis]];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now that we placed the element, we need to update the variables
|
// Now that we placed the element, we need to update the variables
|
||||||
// We only need to do that for relative elements. Absolute elements
|
// We only need to do that for relative elements. Absolute elements
|
||||||
// do not take part in that phase.
|
// do not take part in that phase.
|
||||||
@@ -664,7 +664,7 @@ public class LayoutEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float containerCrossAxis = node.layout.dimensions[dim[crossAxis]];
|
float containerCrossAxis = node.layout.dimensions[dim[crossAxis]];
|
||||||
if (!isCrossDimDefined) {
|
if (!isCrossDimDefined) {
|
||||||
containerCrossAxis = Math.max(
|
containerCrossAxis = Math.max(
|
||||||
@@ -675,11 +675,11 @@ public class LayoutEngine {
|
|||||||
paddingAndBorderAxisCross
|
paddingAndBorderAxisCross
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// <Loop D> Position elements in the cross axis
|
// <Loop D> Position elements in the cross axis
|
||||||
for (i = firstComplexCross; i < endLine; ++i) {
|
for (i = firstComplexCross; i < endLine; ++i) {
|
||||||
child = node.getChildAt(i);
|
child = node.getChildAt(i);
|
||||||
|
|
||||||
if (child.style.positionType == CSSPositionType.ABSOLUTE &&
|
if (child.style.positionType == CSSPositionType.ABSOLUTE &&
|
||||||
!Float.isNaN(child.style.position[leading[crossAxis]])) {
|
!Float.isNaN(child.style.position[leading[crossAxis]])) {
|
||||||
// In case the child is absolutely positionned and has a
|
// In case the child is absolutely positionned and has a
|
||||||
@@ -688,10 +688,10 @@ public class LayoutEngine {
|
|||||||
child.layout.position[pos[crossAxis]] = (Float.isNaN(child.style.position[leading[crossAxis]]) ? 0 : child.style.position[leading[crossAxis]]) +
|
child.layout.position[pos[crossAxis]] = (Float.isNaN(child.style.position[leading[crossAxis]]) ? 0 : child.style.position[leading[crossAxis]]) +
|
||||||
node.style.border.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) +
|
node.style.border.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) +
|
||||||
child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]);
|
child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
float leadingCrossDim = leadingPaddingAndBorderCross;
|
float leadingCrossDim = leadingPaddingAndBorderCross;
|
||||||
|
|
||||||
// For a relative children, we're either using alignItems (parent) or
|
// For a relative children, we're either using alignItems (parent) or
|
||||||
// alignSelf (child) in order to determine the position in the cross axis
|
// alignSelf (child) in order to determine the position in the cross axis
|
||||||
if (child.style.positionType == CSSPositionType.RELATIVE) {
|
if (child.style.positionType == CSSPositionType.RELATIVE) {
|
||||||
@@ -699,7 +699,7 @@ public class LayoutEngine {
|
|||||||
if (alignItem == CSSAlign.STRETCH) {
|
if (alignItem == CSSAlign.STRETCH) {
|
||||||
// You can only stretch if the dimension has not already been set
|
// You can only stretch if the dimension has not already been set
|
||||||
// previously.
|
// previously.
|
||||||
if (Float.isNaN(child.layout.dimensions[dim[crossAxis]])) {
|
if (!(!Float.isNaN(child.style.dimensions[dim[crossAxis]]) && child.style.dimensions[dim[crossAxis]] > 0.0)) {
|
||||||
child.layout.dimensions[dim[crossAxis]] = Math.max(
|
child.layout.dimensions[dim[crossAxis]] = Math.max(
|
||||||
boundAxis(child, crossAxis, containerCrossAxis -
|
boundAxis(child, crossAxis, containerCrossAxis -
|
||||||
paddingAndBorderAxisCross - (child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + child.style.margin.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]))),
|
paddingAndBorderAxisCross - (child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + child.style.margin.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]))),
|
||||||
@@ -712,7 +712,7 @@ public class LayoutEngine {
|
|||||||
// dimensions+margin.
|
// dimensions+margin.
|
||||||
float remainingCrossDim = containerCrossAxis -
|
float remainingCrossDim = containerCrossAxis -
|
||||||
paddingAndBorderAxisCross - (child.layout.dimensions[dim[crossAxis]] + child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + child.style.margin.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]));
|
paddingAndBorderAxisCross - (child.layout.dimensions[dim[crossAxis]] + child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + child.style.margin.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]));
|
||||||
|
|
||||||
if (alignItem == CSSAlign.CENTER) {
|
if (alignItem == CSSAlign.CENTER) {
|
||||||
leadingCrossDim += remainingCrossDim / 2;
|
leadingCrossDim += remainingCrossDim / 2;
|
||||||
} else { // CSSAlign.FLEX_END
|
} else { // CSSAlign.FLEX_END
|
||||||
@@ -720,23 +720,23 @@ public class LayoutEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// And we apply the position
|
// And we apply the position
|
||||||
child.layout.position[pos[crossAxis]] += linesCrossDim + leadingCrossDim;
|
child.layout.position[pos[crossAxis]] += linesCrossDim + leadingCrossDim;
|
||||||
|
|
||||||
// Define the trailing position accordingly.
|
// Define the trailing position accordingly.
|
||||||
if (isCrossDimDefined) {
|
if (isCrossDimDefined) {
|
||||||
child.layout.position[trailing[crossAxis]] = node.layout.dimensions[dim[crossAxis]] - child.layout.dimensions[dim[crossAxis]] - child.layout.position[pos[crossAxis]];
|
child.layout.position[trailing[crossAxis]] = node.layout.dimensions[dim[crossAxis]] - child.layout.dimensions[dim[crossAxis]] - child.layout.position[pos[crossAxis]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
linesCrossDim += crossDim;
|
linesCrossDim += crossDim;
|
||||||
linesMainDim = Math.max(linesMainDim, mainDim);
|
linesMainDim = Math.max(linesMainDim, mainDim);
|
||||||
linesCount += 1;
|
linesCount += 1;
|
||||||
startLine = endLine;
|
startLine = endLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <Loop E>
|
// <Loop E>
|
||||||
//
|
//
|
||||||
// Note(prenaux): More than one line, we need to layout the crossAxis
|
// Note(prenaux): More than one line, we need to layout the crossAxis
|
||||||
@@ -754,10 +754,10 @@ public class LayoutEngine {
|
|||||||
float nodeCrossAxisInnerSize = node.layout.dimensions[dim[crossAxis]] -
|
float nodeCrossAxisInnerSize = node.layout.dimensions[dim[crossAxis]] -
|
||||||
paddingAndBorderAxisCross;
|
paddingAndBorderAxisCross;
|
||||||
float remainingAlignContentDim = nodeCrossAxisInnerSize - linesCrossDim;
|
float remainingAlignContentDim = nodeCrossAxisInnerSize - linesCrossDim;
|
||||||
|
|
||||||
float crossDimLead = 0;
|
float crossDimLead = 0;
|
||||||
float currentLead = leadingPaddingAndBorderCross;
|
float currentLead = leadingPaddingAndBorderCross;
|
||||||
|
|
||||||
CSSAlign alignContent = node.style.alignContent;
|
CSSAlign alignContent = node.style.alignContent;
|
||||||
if (alignContent == CSSAlign.FLEX_END) {
|
if (alignContent == CSSAlign.FLEX_END) {
|
||||||
currentLead += remainingAlignContentDim;
|
currentLead += remainingAlignContentDim;
|
||||||
@@ -768,11 +768,11 @@ public class LayoutEngine {
|
|||||||
crossDimLead = (remainingAlignContentDim / linesCount);
|
crossDimLead = (remainingAlignContentDim / linesCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int endIndex = 0;
|
int endIndex = 0;
|
||||||
for (i = 0; i < linesCount; ++i) {
|
for (i = 0; i < linesCount; ++i) {
|
||||||
int startIndex = endIndex;
|
int startIndex = endIndex;
|
||||||
|
|
||||||
// compute the line's height and find the endIndex
|
// compute the line's height and find the endIndex
|
||||||
float lineHeight = 0;
|
float lineHeight = 0;
|
||||||
for (ii = startIndex; ii < childCount; ++ii) {
|
for (ii = startIndex; ii < childCount; ++ii) {
|
||||||
@@ -792,13 +792,13 @@ public class LayoutEngine {
|
|||||||
}
|
}
|
||||||
endIndex = ii;
|
endIndex = ii;
|
||||||
lineHeight += crossDimLead;
|
lineHeight += crossDimLead;
|
||||||
|
|
||||||
for (ii = startIndex; ii < endIndex; ++ii) {
|
for (ii = startIndex; ii < endIndex; ++ii) {
|
||||||
child = node.getChildAt(ii);
|
child = node.getChildAt(ii);
|
||||||
if (child.style.positionType != CSSPositionType.RELATIVE) {
|
if (child.style.positionType != CSSPositionType.RELATIVE) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSSAlign alignContentAlignItem = getAlignItem(node, child);
|
CSSAlign alignContentAlignItem = getAlignItem(node, child);
|
||||||
if (alignContentAlignItem == CSSAlign.FLEX_START) {
|
if (alignContentAlignItem == CSSAlign.FLEX_START) {
|
||||||
child.layout.position[pos[crossAxis]] = currentLead + child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]);
|
child.layout.position[pos[crossAxis]] = currentLead + child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]);
|
||||||
@@ -813,14 +813,14 @@ public class LayoutEngine {
|
|||||||
// (auto) crossAxis dimension.
|
// (auto) crossAxis dimension.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
currentLead += lineHeight;
|
currentLead += lineHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean needsMainTrailingPos = false;
|
boolean needsMainTrailingPos = false;
|
||||||
boolean needsCrossTrailingPos = false;
|
boolean needsCrossTrailingPos = false;
|
||||||
|
|
||||||
// If the user didn't specify a width or height, and it has not been set
|
// If the user didn't specify a width or height, and it has not been set
|
||||||
// by the container, then we set it via the children.
|
// by the container, then we set it via the children.
|
||||||
if (!isMainDimDefined) {
|
if (!isMainDimDefined) {
|
||||||
@@ -831,13 +831,13 @@ public class LayoutEngine {
|
|||||||
// We can never assign a width smaller than the padding and borders
|
// We can never assign a width smaller than the padding and borders
|
||||||
paddingAndBorderAxisMain
|
paddingAndBorderAxisMain
|
||||||
);
|
);
|
||||||
|
|
||||||
if (mainAxis == CSS_FLEX_DIRECTION_ROW_REVERSE ||
|
if (mainAxis == CSS_FLEX_DIRECTION_ROW_REVERSE ||
|
||||||
mainAxis == CSS_FLEX_DIRECTION_COLUMN_REVERSE) {
|
mainAxis == CSS_FLEX_DIRECTION_COLUMN_REVERSE) {
|
||||||
needsMainTrailingPos = true;
|
needsMainTrailingPos = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isCrossDimDefined) {
|
if (!isCrossDimDefined) {
|
||||||
node.layout.dimensions[dim[crossAxis]] = Math.max(
|
node.layout.dimensions[dim[crossAxis]] = Math.max(
|
||||||
// For the cross dim, we add both sides at the end because the value
|
// For the cross dim, we add both sides at the end because the value
|
||||||
@@ -846,28 +846,28 @@ public class LayoutEngine {
|
|||||||
boundAxis(node, crossAxis, linesCrossDim + paddingAndBorderAxisCross),
|
boundAxis(node, crossAxis, linesCrossDim + paddingAndBorderAxisCross),
|
||||||
paddingAndBorderAxisCross
|
paddingAndBorderAxisCross
|
||||||
);
|
);
|
||||||
|
|
||||||
if (crossAxis == CSS_FLEX_DIRECTION_ROW_REVERSE ||
|
if (crossAxis == CSS_FLEX_DIRECTION_ROW_REVERSE ||
|
||||||
crossAxis == CSS_FLEX_DIRECTION_COLUMN_REVERSE) {
|
crossAxis == CSS_FLEX_DIRECTION_COLUMN_REVERSE) {
|
||||||
needsCrossTrailingPos = true;
|
needsCrossTrailingPos = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// <Loop F> Set trailing position if necessary
|
// <Loop F> Set trailing position if necessary
|
||||||
if (needsMainTrailingPos || needsCrossTrailingPos) {
|
if (needsMainTrailingPos || needsCrossTrailingPos) {
|
||||||
for (i = 0; i < childCount; ++i) {
|
for (i = 0; i < childCount; ++i) {
|
||||||
child = node.getChildAt(i);
|
child = node.getChildAt(i);
|
||||||
|
|
||||||
if (needsMainTrailingPos) {
|
if (needsMainTrailingPos) {
|
||||||
child.layout.position[trailing[mainAxis]] = node.layout.dimensions[dim[mainAxis]] - child.layout.dimensions[dim[mainAxis]] - child.layout.position[pos[mainAxis]];
|
child.layout.position[trailing[mainAxis]] = node.layout.dimensions[dim[mainAxis]] - child.layout.dimensions[dim[mainAxis]] - child.layout.position[pos[mainAxis]];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needsCrossTrailingPos) {
|
if (needsCrossTrailingPos) {
|
||||||
child.layout.position[trailing[crossAxis]] = node.layout.dimensions[dim[crossAxis]] - child.layout.dimensions[dim[crossAxis]] - child.layout.position[pos[crossAxis]];
|
child.layout.position[trailing[crossAxis]] = node.layout.dimensions[dim[crossAxis]] - child.layout.dimensions[dim[crossAxis]] - child.layout.position[pos[crossAxis]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// <Loop G> Calculate dimensions for absolutely positioned elements
|
// <Loop G> Calculate dimensions for absolutely positioned elements
|
||||||
currentAbsoluteChild = firstAbsoluteChild;
|
currentAbsoluteChild = firstAbsoluteChild;
|
||||||
while (currentAbsoluteChild != null) {
|
while (currentAbsoluteChild != null) {
|
||||||
@@ -875,7 +875,7 @@ public class LayoutEngine {
|
|||||||
// the axis are defined (either both left and right or top and bottom).
|
// the axis are defined (either both left and right or top and bottom).
|
||||||
for (ii = 0; ii < 2; ii++) {
|
for (ii = 0; ii < 2; ii++) {
|
||||||
axis = (ii != 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN;
|
axis = (ii != 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN;
|
||||||
|
|
||||||
if (!Float.isNaN(node.layout.dimensions[dim[axis]]) &&
|
if (!Float.isNaN(node.layout.dimensions[dim[axis]]) &&
|
||||||
!(!Float.isNaN(currentAbsoluteChild.style.dimensions[dim[axis]]) && currentAbsoluteChild.style.dimensions[dim[axis]] > 0.0) &&
|
!(!Float.isNaN(currentAbsoluteChild.style.dimensions[dim[axis]]) && currentAbsoluteChild.style.dimensions[dim[axis]] > 0.0) &&
|
||||||
!Float.isNaN(currentAbsoluteChild.style.position[leading[axis]]) &&
|
!Float.isNaN(currentAbsoluteChild.style.position[leading[axis]]) &&
|
||||||
@@ -891,7 +891,7 @@ public class LayoutEngine {
|
|||||||
((currentAbsoluteChild.style.padding.getWithFallback(leadingSpacing[axis], leading[axis]) + currentAbsoluteChild.style.border.getWithFallback(leadingSpacing[axis], leading[axis])) + (currentAbsoluteChild.style.padding.getWithFallback(trailingSpacing[axis], trailing[axis]) + currentAbsoluteChild.style.border.getWithFallback(trailingSpacing[axis], trailing[axis])))
|
((currentAbsoluteChild.style.padding.getWithFallback(leadingSpacing[axis], leading[axis]) + currentAbsoluteChild.style.border.getWithFallback(leadingSpacing[axis], leading[axis])) + (currentAbsoluteChild.style.padding.getWithFallback(trailingSpacing[axis], trailing[axis]) + currentAbsoluteChild.style.border.getWithFallback(trailingSpacing[axis], trailing[axis])))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Float.isNaN(currentAbsoluteChild.style.position[trailing[axis]]) &&
|
if (!Float.isNaN(currentAbsoluteChild.style.position[trailing[axis]]) &&
|
||||||
!!Float.isNaN(currentAbsoluteChild.style.position[leading[axis]])) {
|
!!Float.isNaN(currentAbsoluteChild.style.position[leading[axis]])) {
|
||||||
currentAbsoluteChild.layout.position[leading[axis]] =
|
currentAbsoluteChild.layout.position[leading[axis]] =
|
||||||
@@ -900,7 +900,7 @@ public class LayoutEngine {
|
|||||||
(Float.isNaN(currentAbsoluteChild.style.position[trailing[axis]]) ? 0 : currentAbsoluteChild.style.position[trailing[axis]]);
|
(Float.isNaN(currentAbsoluteChild.style.position[trailing[axis]]) ? 0 : currentAbsoluteChild.style.position[trailing[axis]]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
child = currentAbsoluteChild;
|
child = currentAbsoluteChild;
|
||||||
currentAbsoluteChild = currentAbsoluteChild.nextAbsoluteChild;
|
currentAbsoluteChild = currentAbsoluteChild.nextAbsoluteChild;
|
||||||
child.nextAbsoluteChild = null;
|
child.nextAbsoluteChild = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user