Skip to content

Commit 7992046

Browse files
committed
Replace grid track sizing algorithm with ported code from chromium
* Also implement 5th point from grid track sizing algroithm DEVSIX-8387
1 parent fc414da commit 7992046

File tree

8 files changed

+727
-281
lines changed

8 files changed

+727
-281
lines changed

layout/src/main/java/com/itextpdf/layout/exceptions/LayoutExceptionMessageConstant.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ public final class LayoutExceptionMessageConstant {
6060
public static final String GRID_AUTO_REPEAT_CAN_BE_USED_ONLY_ONCE
6161
= "Automatic repetitions in the grid template are allowed only once per template.";
6262
public static final String GRID_AUTO_REPEAT_CANNOT_BE_COMBINED_WITH_INDEFINITE_SIZES
63-
= "Automatic repetitions in the grid template cannot be combined with intrinsic or flexible sizes.";
63+
= "Automatic repetitions in the grid template cannot be combined with intrinsic or flexible sizes.";
64+
public static final String FLEXIBLE_ARENT_ALLOWED_AS_MINIMUM_IN_MINMAX
65+
= "Flexible values aren't allowed as minimum in minmax grid function.";
6466

6567
private LayoutExceptionMessageConstant(){}
6668
}

layout/src/main/java/com/itextpdf/layout/renderer/GridContainerRenderer.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,8 @@ private static Grid constructGrid(GridContainerRenderer renderer, Rectangle actu
345345
float rowGap = rowGapProp == null ? 0f : (float) rowGapProp;
346346

347347
// Resolving repeats
348-
GridTemplateResolver rowRepeatResolver
349-
= new GridTemplateResolver(actualBBox.getHeight(), rowGap);
350-
GridTemplateResolver columnRepeatResolver
351-
= new GridTemplateResolver(actualBBox.getWidth(), columnGap);
348+
GridTemplateResolver rowRepeatResolver = new GridTemplateResolver(actualBBox.getHeight(), rowGap);
349+
GridTemplateResolver columnRepeatResolver = new GridTemplateResolver(actualBBox.getWidth(), columnGap);
352350
List<GridValue> templateRows = rowRepeatResolver.resolveTemplate(
353351
renderer.<List<TemplateValue>>getProperty(Property.GRID_TEMPLATE_ROWS));
354352
List<GridValue> templateColumns = columnRepeatResolver.resolveTemplate(

layout/src/main/java/com/itextpdf/layout/renderer/GridSizer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ This file is part of the iText (R) project.
2424

2525
import com.itextpdf.kernel.geom.Rectangle;
2626
import com.itextpdf.layout.properties.grid.AutoValue;
27-
import com.itextpdf.layout.properties.grid.FlexValue;
2827
import com.itextpdf.layout.properties.grid.GridValue;
2928
import com.itextpdf.layout.renderer.Grid.GridOrder;
3029
import com.itextpdf.layout.renderer.GridTrackSizer.TrackSizingResult;
@@ -178,7 +177,7 @@ private void resolveGridColumns() {
178177
} else if (columnAutoWidth != null) {
179178
colsValues.add(columnAutoWidth);
180179
} else {
181-
colsValues.add(new FlexValue(1f));
180+
colsValues.add(AutoValue.VALUE);
182181
}
183182
}
184183
GridTrackSizer gridTrackSizer = new GridTrackSizer(grid, colsValues, columnGap,

layout/src/main/java/com/itextpdf/layout/renderer/GridTemplateResolver.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ This file is part of the iText (R) project.
3030
import com.itextpdf.layout.properties.grid.PercentValue;
3131
import com.itextpdf.layout.properties.grid.PointValue;
3232
import com.itextpdf.layout.properties.grid.TemplateValue;
33+
import com.itextpdf.layout.properties.grid.TemplateValue.ValueType;
3334

3435
import java.util.ArrayList;
3536
import java.util.List;
@@ -136,9 +137,15 @@ private float processValue(TemplateValue value) {
136137
// or as its minimum track sizing function otherwise
137138
// if encountered intrinsic or flexible before, then it doesn't matter what to process
138139
boolean currentValue = containsIntrinsicOrFlexible;
139-
float length = processValue(((MinMaxValue)value).getMax());
140+
final MinMaxValue minMaxValue = (MinMaxValue) value;
141+
if (minMaxValue.getMin().getType() == ValueType.FLEX) {
142+
// A future level of CSS Grid spec may allow <flex> minimums, but not now
143+
throw new IllegalStateException(
144+
LayoutExceptionMessageConstant.FLEXIBLE_ARENT_ALLOWED_AS_MINIMUM_IN_MINMAX);
145+
}
146+
float length = processValue(minMaxValue.getMax());
140147
if (containsIntrinsicOrFlexible) {
141-
length = processValue(((MinMaxValue)value).getMin());
148+
length = processValue(minMaxValue.getMin());
142149
}
143150
containsIntrinsicOrFlexible = currentValue;
144151
result.setFreeze(false);

0 commit comments

Comments
 (0)