@@ -86,9 +86,6 @@ public static List<List<FlexItemInfo>> calculateChildrenRectangles(Rectangle fle
86
86
Rectangle layoutBox = flexContainerBBox .clone ();
87
87
flexContainerRenderer .applyMarginsBordersPaddings (layoutBox , false );
88
88
89
- List <FlexItemCalculationInfo > flexItemCalculationInfos =
90
- createFlexItemCalculationInfos (flexContainerRenderer , layoutBox );
91
-
92
89
// 9.2. Line Length Determination
93
90
94
91
// 2. Determine the available main and cross space for the flex items.
@@ -106,7 +103,10 @@ public static List<List<FlexItemInfo>> calculateChildrenRectangles(Rectangle fle
106
103
Float minCrossSize = flexContainerRenderer .retrieveMinHeight ();
107
104
Float maxCrossSize = flexContainerRenderer .retrieveMaxHeight ();
108
105
109
- determineFlexBasisAndHypotheticalMainSizeForFlexItems (flexItemCalculationInfos , (float ) mainSize );
106
+ List <FlexItemCalculationInfo > flexItemCalculationInfos =
107
+ createFlexItemCalculationInfos (flexContainerRenderer , (float ) mainSize );
108
+
109
+ determineFlexBasisAndHypotheticalMainSizeForFlexItems (flexItemCalculationInfos );
110
110
111
111
// 9.3. Main Size Determination
112
112
@@ -182,17 +182,12 @@ public static List<List<FlexItemInfo>> calculateChildrenRectangles(Rectangle fle
182
182
}
183
183
184
184
static void determineFlexBasisAndHypotheticalMainSizeForFlexItems (
185
- List <FlexItemCalculationInfo > flexItemCalculationInfos , float mainSize ) {
185
+ List <FlexItemCalculationInfo > flexItemCalculationInfos ) {
186
186
for (FlexItemCalculationInfo info : flexItemCalculationInfos ) {
187
187
// 3. Determine the flex base size and hypothetical main size of each item:
188
188
189
- // Note: We assume that flex-basis: auto was resolved (set to either width or height) on some upper level
190
- assert null != info .flexBasis ;
191
-
192
189
// A. If the item has a definite used flex basis, that’s the flex base size.
193
- info .flexBaseSize = info .flexBasis .isPercentValue ()
194
- ? (info .flexBasis .getValue () * mainSize / 100 )
195
- : info .flexBasis .getValue ();
190
+ info .flexBaseSize = info .flexBasis ;
196
191
197
192
// TODO DEVSIX-5001 content as width are not supported
198
193
// TODO DEVSIX-5004 Implement method to check whether an element has an intrinsic aspect ratio
@@ -607,34 +602,64 @@ static boolean isZero(final float value) {
607
602
}
608
603
609
604
private static List <FlexItemCalculationInfo > createFlexItemCalculationInfos (
610
- FlexContainerRenderer flexContainerRenderer , Rectangle flexContainerBBox ) {
605
+ FlexContainerRenderer flexContainerRenderer , float flexContainerWidth ) {
611
606
final List <IRenderer > childRenderers = flexContainerRenderer .getChildRenderers ();
612
607
final List <FlexItemCalculationInfo > flexItems = new ArrayList <>();
613
608
for (final IRenderer renderer : childRenderers ) {
614
609
if (renderer instanceof AbstractRenderer ) {
615
610
AbstractRenderer abstractRenderer = (AbstractRenderer ) renderer ;
616
- float flexGrow = (float ) renderer .<Float >getProperty (Property .FLEX_GROW , FLEX_GROW_INITIAL_VALUE );
617
-
618
- float flexShrink = (float ) renderer .<Float >getProperty (Property .FLEX_SHRINK , FLEX_SHRINK_INITIAL_VALUE );
619
611
620
612
// TODO DEVSIX-5091 improve determining of the flex base size when flex-basis: content
621
- float maxWidth = abstractRenderer .getMinMaxWidth ().getMaxWidth ();
622
- maxWidth = abstractRenderer .applyMarginsBordersPaddings (new Rectangle (maxWidth , 0 ), false ).getWidth ();
613
+ float maxWidth = calculateMaxWidth (abstractRenderer , flexContainerWidth );
614
+ float flexBasis ;
615
+ if (renderer .<UnitValue >getProperty (Property .FLEX_BASIS ) == null ) {
616
+ flexBasis = maxWidth ;
617
+ } else {
618
+ flexBasis = (float ) abstractRenderer .retrieveUnitValue (flexContainerWidth , Property .FLEX_BASIS );
619
+ if (AbstractRenderer .isBorderBoxSizing (abstractRenderer )) {
620
+ flexBasis -= AbstractRenderer .calculatePaddingBorderWidth (abstractRenderer );
621
+ }
622
+ }
623
+ flexBasis = Math .max (flexBasis , 0 );
623
624
624
- UnitValue flexBasis = renderer .getProperty (Property .FLEX_BASIS , UnitValue .createPointValue (maxWidth ));
625
+ float flexGrow = (float ) renderer .<Float >getProperty (Property .FLEX_GROW , FLEX_GROW_INITIAL_VALUE );
626
+
627
+ float flexShrink = (float ) renderer .<Float >getProperty (Property .FLEX_SHRINK , FLEX_SHRINK_INITIAL_VALUE );
625
628
626
629
final FlexItemCalculationInfo flexItemInfo = new FlexItemCalculationInfo (
627
- (AbstractRenderer ) renderer , flexBasis , flexGrow , flexShrink , flexContainerBBox . getWidth () );
630
+ (AbstractRenderer ) renderer , flexBasis , flexGrow , flexShrink , flexContainerWidth );
628
631
629
632
flexItems .add (flexItemInfo );
630
633
}
631
634
}
632
635
return flexItems ;
633
636
}
634
637
638
+ private static float calculateMaxWidth (AbstractRenderer flexItemRenderer , float flexContainerWidth ) {
639
+ Float maxWidth ;
640
+ if (flexItemRenderer instanceof TableRenderer ) {
641
+ // TODO DEVSIX-5214 we can't call TableRenderer#retrieveWidth method as far as it can throw NPE
642
+ maxWidth = flexItemRenderer .getMinMaxWidth ().getMaxWidth ();
643
+ maxWidth = flexItemRenderer .applyMarginsBordersPaddings (
644
+ new Rectangle ((float ) maxWidth , 0 ), false ).getWidth ();
645
+ } else {
646
+ // We need to retrieve width and max-width manually because this methods take into account box-sizing
647
+ maxWidth = flexItemRenderer .retrieveWidth (flexContainerWidth );
648
+ if (maxWidth == null ) {
649
+ maxWidth = flexItemRenderer .retrieveMaxWidth (flexContainerWidth );
650
+ }
651
+ if (maxWidth == null ) {
652
+ maxWidth = flexItemRenderer .getMinMaxWidth ().getMaxWidth ();
653
+ maxWidth = flexItemRenderer .applyMarginsBordersPaddings (
654
+ new Rectangle ((float ) maxWidth , 0 ), false ).getWidth ();
655
+ }
656
+ }
657
+ return (float ) maxWidth ;
658
+ }
659
+
635
660
static class FlexItemCalculationInfo {
636
661
AbstractRenderer renderer ;
637
- UnitValue flexBasis ;
662
+ float flexBasis ;
638
663
float flexShrink ;
639
664
float flexGrow ;
640
665
float minContent ;
@@ -656,12 +681,9 @@ static class FlexItemCalculationInfo {
656
681
float hypotheticalMainSize ;
657
682
float hypotheticalCrossSize ;
658
683
659
- public FlexItemCalculationInfo (AbstractRenderer renderer , UnitValue flexBasis ,
684
+ public FlexItemCalculationInfo (AbstractRenderer renderer , float flexBasis ,
660
685
float flexGrow , float flexShrink , float areaWidth ) {
661
686
this .renderer = renderer ;
662
- if (null == flexBasis ) {
663
- throw new IllegalArgumentException (LayoutExceptionMessageConstant .FLEX_BASIS_CANNOT_BE_NULL );
664
- }
665
687
this .flexBasis = flexBasis ;
666
688
if (flexShrink < 0 ) {
667
689
throw new IllegalArgumentException (LayoutExceptionMessageConstant .FLEX_SHRINK_CANNOT_BE_NEGATIVE );
0 commit comments