@@ -90,6 +90,8 @@ public static List<List<FlexItemInfo>> calculateChildrenRectangles(Rectangle fle
90
90
FlexContainerRenderer flexContainerRenderer ) {
91
91
Rectangle layoutBox = flexContainerBBox .clone ();
92
92
flexContainerRenderer .applyMarginsBordersPaddings (layoutBox , false );
93
+ // Currently only width is used in this method
94
+ final float layoutBoxWidth = layoutBox .getWidth ();
93
95
94
96
// 9.2. Line Length Determination
95
97
@@ -99,9 +101,9 @@ public static List<List<FlexItemInfo>> calculateChildrenRectangles(Rectangle fle
99
101
// if that dimension of the flex container is being sized under a min or max-content constraint,
100
102
// the available space in that dimension is that constraint;
101
103
102
- Float mainSize = flexContainerRenderer .retrieveWidth (layoutBox . getWidth () );
104
+ Float mainSize = flexContainerRenderer .retrieveWidth (layoutBoxWidth );
103
105
if (mainSize == null ) {
104
- mainSize = layoutBox . getWidth () ;
106
+ mainSize = layoutBoxWidth ;
105
107
}
106
108
// We need to have crossSize only if its value is definite.
107
109
Float crossSize = flexContainerRenderer .retrieveHeight ();
@@ -408,20 +410,36 @@ static void resolveFlexibleLengths(List<List<FlexItemCalculationInfo>> lines, fl
408
410
static void determineHypotheticalCrossSizeForFlexItems (List <List <FlexItemCalculationInfo >> lines ) {
409
411
for (List <FlexItemCalculationInfo > line : lines ) {
410
412
for (FlexItemCalculationInfo info : line ) {
411
- UnitValue prevWidth = info .renderer .<UnitValue >replaceOwnProperty (Property .WIDTH ,
412
- UnitValue .createPointValue (info .mainSize ));
413
- UnitValue prevMinWidth = info .renderer .<UnitValue >replaceOwnProperty (Property .MIN_WIDTH , null );
414
- LayoutResult result = info .renderer .layout (new LayoutContext (
415
- new LayoutArea (0 , new Rectangle (AbstractRenderer .INF , AbstractRenderer .INF ))));
416
- info .renderer .returnBackOwnProperty (Property .MIN_WIDTH , prevMinWidth );
417
- info .renderer .returnBackOwnProperty (Property .WIDTH , prevWidth );
418
- // Since main size is clamped with min-width, we do expect the result to be full
419
- if (result .getStatus () == LayoutResult .FULL ) {
420
- info .hypotheticalCrossSize = info .getInnerCrossSize (result .getOccupiedArea ().getBBox ().getHeight ());
421
- } else {
422
- logger .error (IoLogMessageConstant .FLEX_ITEM_LAYOUT_RESULT_IS_NOT_FULL );
423
- info .hypotheticalCrossSize = 0 ;
413
+ determineHypotheticalCrossSizeForFlexItem (info );
414
+ }
415
+ }
416
+ }
417
+
418
+ private static void determineHypotheticalCrossSizeForFlexItem (FlexItemCalculationInfo info ) {
419
+ if (info .renderer instanceof FlexContainerRenderer &&
420
+ ((FlexContainerRenderer ) info .renderer ).getHypotheticalCrossSize (info .mainSize ) != null ) {
421
+ // Take from cache
422
+ info .hypotheticalCrossSize = ((FlexContainerRenderer ) info .renderer )
423
+ .getHypotheticalCrossSize (info .mainSize ).floatValue ();
424
+ } else {
425
+ UnitValue prevWidth = info .renderer .<UnitValue >replaceOwnProperty (Property .WIDTH ,
426
+ UnitValue .createPointValue (info .mainSize ));
427
+ UnitValue prevMinWidth = info .renderer .<UnitValue >replaceOwnProperty (Property .MIN_WIDTH , null );
428
+ LayoutResult result = info .renderer .layout (new LayoutContext (
429
+ new LayoutArea (0 , new Rectangle (AbstractRenderer .INF , AbstractRenderer .INF ))));
430
+ info .renderer .returnBackOwnProperty (Property .MIN_WIDTH , prevMinWidth );
431
+ info .renderer .returnBackOwnProperty (Property .WIDTH , prevWidth );
432
+ // Since main size is clamped with min-width, we do expect the result to be full
433
+ if (result .getStatus () == LayoutResult .FULL ) {
434
+ info .hypotheticalCrossSize = info .getInnerCrossSize (result .getOccupiedArea ().getBBox ().getHeight ());
435
+ // Cache hypotheticalCrossSize for FlexContainerRenderer
436
+ if (info .renderer instanceof FlexContainerRenderer ) {
437
+ ((FlexContainerRenderer ) info .renderer ).setHypotheticalCrossSize (info .mainSize ,
438
+ info .hypotheticalCrossSize );
424
439
}
440
+ } else {
441
+ logger .error (IoLogMessageConstant .FLEX_ITEM_LAYOUT_RESULT_IS_NOT_FULL );
442
+ info .hypotheticalCrossSize = 0 ;
425
443
}
426
444
}
427
445
}
0 commit comments