From f56e8a5163739004de47488597c15a9618d7e6ee Mon Sep 17 00:00:00 2001 From: Emil Sjolander Date: Mon, 21 Nov 2016 11:03:56 -0800 Subject: [PATCH] Move measure code for empty containers out of main layout function Summary: Try to move more code out of the main measure function Reviewed By: gkassabli Differential Revision: D4213313 fbshipit-source-id: 2061a809202f7f948bff1b3ee8dc4c230692a223 --- CSSLayout/CSSLayout.c | 57 ++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/CSSLayout/CSSLayout.c b/CSSLayout/CSSLayout.c index 00b03ef6..2b8e2d61 100644 --- a/CSSLayout/CSSLayout.c +++ b/CSSLayout/CSSLayout.c @@ -1247,6 +1247,34 @@ static void setMeasuredDimensionsForNodeWithMeasureFunc(const CSSNodeRef node, } } +// For nodes with no children, use the available values if they were provided, +// or the minimum size as indicated by the padding and border sizes. +static void setMeasuredDimensionsForEmptyContainer(const CSSNodeRef node, + const float availableWidth, + const float availableHeight, + const CSSMeasureMode widthMeasureMode, + const CSSMeasureMode heightMeasureMode) { + const float paddingAndBorderAxisRow = getPaddingAndBorderAxis(node, CSSFlexDirectionRow); + const float paddingAndBorderAxisColumn = getPaddingAndBorderAxis(node, CSSFlexDirectionColumn); + const float marginAxisRow = getMarginAxis(node, CSSFlexDirectionRow); + const float marginAxisColumn = getMarginAxis(node, CSSFlexDirectionColumn); + + node->layout.measuredDimensions[CSSDimensionWidth] = + boundAxis(node, + CSSFlexDirectionRow, + (widthMeasureMode == CSSMeasureModeUndefined || + widthMeasureMode == CSSMeasureModeAtMost) + ? paddingAndBorderAxisRow + : availableWidth - marginAxisRow); + node->layout.measuredDimensions[CSSDimensionHeight] = + boundAxis(node, + CSSFlexDirectionColumn, + (heightMeasureMode == CSSMeasureModeUndefined || + heightMeasureMode == CSSMeasureModeAtMost) + ? paddingAndBorderAxisColumn + : availableHeight - marginAxisColumn); +} + // // This is the main routine that implements a subset of the flexbox layout // algorithm @@ -1375,11 +1403,6 @@ static void layoutNodeImpl(const CSSNodeRef node, "availableHeight is indefinite so heightMeasureMode must be " "CSSMeasureModeUndefined"); - const float paddingAndBorderAxisRow = getPaddingAndBorderAxis(node, CSSFlexDirectionRow); - const float paddingAndBorderAxisColumn = getPaddingAndBorderAxis(node, CSSFlexDirectionColumn); - const float marginAxisRow = getMarginAxis(node, CSSFlexDirectionRow); - const float marginAxisColumn = getMarginAxis(node, CSSFlexDirectionColumn); - // Set the resolved resolution in the node's layout. const CSSDirection direction = resolveDirection(node, parentDirection); node->layout.direction = direction; @@ -1390,28 +1413,18 @@ static void layoutNodeImpl(const CSSNodeRef node, return; } - // For nodes with no children, use the available values if they were provided, - // or - // the minimum size as indicated by the padding and border sizes. const uint32_t childCount = CSSNodeListCount(node->children); if (childCount == 0) { - node->layout.measuredDimensions[CSSDimensionWidth] = - boundAxis(node, - CSSFlexDirectionRow, - (widthMeasureMode == CSSMeasureModeUndefined || - widthMeasureMode == CSSMeasureModeAtMost) - ? paddingAndBorderAxisRow - : availableWidth - marginAxisRow); - node->layout.measuredDimensions[CSSDimensionHeight] = - boundAxis(node, - CSSFlexDirectionColumn, - (heightMeasureMode == CSSMeasureModeUndefined || - heightMeasureMode == CSSMeasureModeAtMost) - ? paddingAndBorderAxisColumn - : availableHeight - marginAxisColumn); + setMeasuredDimensionsForEmptyContainer( + node, availableWidth, availableHeight, widthMeasureMode, heightMeasureMode); return; } + const float paddingAndBorderAxisRow = getPaddingAndBorderAxis(node, CSSFlexDirectionRow); + const float paddingAndBorderAxisColumn = getPaddingAndBorderAxis(node, CSSFlexDirectionColumn); + const float marginAxisRow = getMarginAxis(node, CSSFlexDirectionRow); + const float marginAxisColumn = getMarginAxis(node, CSSFlexDirectionColumn); + // If we're not being asked to perform a full layout, we can handle a number // of common // cases here without incurring the cost of the remaining function.