@@ -90,6 +90,8 @@ public static List<List<FlexItemInfo>> calculateChildrenRectangles(Rectangle fle
9090 FlexContainerRenderer flexContainerRenderer ) {
9191 Rectangle layoutBox = flexContainerBBox .clone ();
9292 flexContainerRenderer .applyMarginsBordersPaddings (layoutBox , false );
93+ // Currently only width is used in this method
94+ final float layoutBoxWidth = layoutBox .getWidth ();
9395
9496 // 9.2. Line Length Determination
9597
@@ -99,9 +101,9 @@ public static List<List<FlexItemInfo>> calculateChildrenRectangles(Rectangle fle
99101 // if that dimension of the flex container is being sized under a min or max-content constraint,
100102 // the available space in that dimension is that constraint;
101103
102- Float mainSize = flexContainerRenderer .retrieveWidth (layoutBox . getWidth () );
104+ Float mainSize = flexContainerRenderer .retrieveWidth (layoutBoxWidth );
103105 if (mainSize == null ) {
104- mainSize = layoutBox . getWidth () ;
106+ mainSize = layoutBoxWidth ;
105107 }
106108 // We need to have crossSize only if its value is definite.
107109 Float crossSize = flexContainerRenderer .retrieveHeight ();
@@ -408,20 +410,36 @@ static void resolveFlexibleLengths(List<List<FlexItemCalculationInfo>> lines, fl
408410 static void determineHypotheticalCrossSizeForFlexItems (List <List <FlexItemCalculationInfo >> lines ) {
409411 for (List <FlexItemCalculationInfo > line : lines ) {
410412 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 );
424439 }
440+ } else {
441+ logger .error (IoLogMessageConstant .FLEX_ITEM_LAYOUT_RESULT_IS_NOT_FULL );
442+ info .hypotheticalCrossSize = 0 ;
425443 }
426444 }
427445 }
0 commit comments