Skip to content

Commit 917da36

Browse files
author
Eugene Bochilo
committed
Support collapsing margins for flex container
DEVSIX-5137
1 parent 76cead4 commit 917da36

File tree

170 files changed

+93
-100
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+93
-100
lines changed

src/main/java/com/itextpdf/html2pdf/attach/impl/DefaultHtmlProcessor.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,6 @@ public List<com.itextpdf.layout.element.IElement> processElements(INode root) {
220220
for (IPropertyContainer propertyContainer : bodyDiv.getChildren()) {
221221
if (propertyContainer instanceof com.itextpdf.layout.element.IElement) {
222222
setConvertedRootElementProperties(body.getStyles(), context, propertyContainer);
223-
// TODO DEVSIX-5087 remove this when working on a ticket
224-
if (((IElement) propertyContainer).getRenderer() instanceof FlexContainerRenderer) {
225-
propertyContainer.setProperty(Property.COLLAPSING_MARGINS, null);
226-
}
227223
elements.add((com.itextpdf.layout.element.IElement) propertyContainer);
228224
}
229225
}

src/main/java/com/itextpdf/html2pdf/css/apply/impl/DisplayFlexTagCssApplier.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public void apply(ProcessorContext context, IStylesContainer stylesContainer, IT
6161
if (container != null) {
6262
FlexApplierUtil.applyFlexContainerProperties(stylesContainer.getStyles(), container);
6363
//TODO DEVSIX-5087 remove these lines when working on a ticket
64-
container.setProperty(Property.COLLAPSING_MARGINS, null);
6564
container.deleteOwnProperty(Property.FLOAT);
6665
container.deleteOwnProperty(Property.CLEAR);
6766
container.deleteOwnProperty(Property.OVERFLOW_X);

src/main/java/com/itextpdf/html2pdf/css/apply/util/FlexApplierUtil.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ private FlexApplierUtil() {
7171
*/
7272
public static void applyFlexItemProperties(Map<String, String> cssProps, ProcessorContext context,
7373
IPropertyContainer element) {
74+
element.setProperty(Property.COLLAPSING_MARGINS, null);
7475
final String flexGrow = cssProps.get(CommonCssConstants.FLEX_GROW);
7576
if (flexGrow != null) {
7677
final Float flexGrowValue = CssDimensionParsingUtils.parseFloat(flexGrow);

src/test/java/com/itextpdf/html2pdf/css/DisplayFlexTest.java

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ This file is part of the iText (R) project.
2727
import com.itextpdf.html2pdf.HtmlConverter;
2828
import com.itextpdf.html2pdf.attach.impl.layout.HtmlPageBreak;
2929
import com.itextpdf.html2pdf.attach.impl.layout.form.element.TextArea;
30+
import com.itextpdf.io.LogMessageConstant;
3031
import com.itextpdf.layout.element.Div;
3132
import com.itextpdf.layout.element.IElement;
3233
import com.itextpdf.layout.element.Image;
@@ -35,6 +36,8 @@ This file is part of the iText (R) project.
3536
import com.itextpdf.layout.property.Property;
3637
import com.itextpdf.layout.property.UnitValue;
3738
import com.itextpdf.layout.renderer.FlexContainerRenderer;
39+
import com.itextpdf.test.annotations.LogMessage;
40+
import com.itextpdf.test.annotations.LogMessages;
3841
import com.itextpdf.test.annotations.type.IntegrationTest;
3942

4043
import java.io.FileInputStream;
@@ -323,9 +326,6 @@ public void tempDisablePropertiesTest() throws IOException {
323326
Assert.assertFalse(elements.get(0).hasProperty(Property.OVERFLOW_Y));
324327
Assert.assertFalse(elements.get(0).hasProperty(Property.FLOAT));
325328
Assert.assertFalse(elements.get(0).hasProperty(Property.CLEAR));
326-
327-
Assert.assertTrue(elements.get(0).hasProperty(Property.COLLAPSING_MARGINS));
328-
Assert.assertNull(elements.get(0).<Object>getProperty(Property.COLLAPSING_MARGINS));
329329
}
330330

331331
@Test
@@ -362,7 +362,6 @@ public void flexItemPropertiesTest() throws IOException {
362362
}
363363

364364
@Test
365-
// TODO DEVSIX-5137 flex: support margin collapse
366365
public void flexGrowTest() throws IOException, InterruptedException {
367366
String name = "flexGrow";
368367
convertToPdfAndCompare(name, SOURCE_FOLDER, DESTINATION_FOLDER);
@@ -395,7 +394,6 @@ public void floatAtFlexItemNestedTest() throws IOException, InterruptedException
395394
}
396395

397396
@Test
398-
// TODO DEVSIX-5135 flex item with nested floating element processed incorrectly
399397
public void flexContainerHeightTest() throws IOException, InterruptedException {
400398
convertToPdfAndCompare("flexContainerHeight", SOURCE_FOLDER, DESTINATION_FOLDER);
401399
}
@@ -426,7 +424,6 @@ public void flexAlignItemsStretchTest() throws IOException, InterruptedException
426424
}
427425

428426
@Test
429-
// TODO DEVSIX-5137 flex: support margin collapse
430427
public void checkboxTest() throws IOException, InterruptedException {
431428
convertToPdfAndCompare("checkbox", SOURCE_FOLDER, DESTINATION_FOLDER);
432429
}
@@ -487,6 +484,39 @@ public void smallHeightAndBigMaxHeightOnContainerAnonymousFlexItemTest() throws
487484
SOURCE_FOLDER, DESTINATION_FOLDER);
488485
}
489486

487+
@Test
488+
public void marginsCollapseFlexContainerAndFlexItemStretchTest() throws IOException, InterruptedException {
489+
convertToPdfAndCompare("marginsCollapseFlexContainerAndFlexItemStretch", SOURCE_FOLDER, DESTINATION_FOLDER);
490+
}
491+
492+
@Test
493+
public void marginsCollapseFlexContainerAndSiblingsTest() throws IOException, InterruptedException {
494+
convertToPdfAndCompare("marginsCollapseFlexContainerAndSiblings", SOURCE_FOLDER, DESTINATION_FOLDER);
495+
}
496+
497+
498+
@Test
499+
@LogMessages(messages = @LogMessage(messageTemplate = LogMessageConstant.CLIP_ELEMENT))
500+
public void marginsCollapseFlexContainerAndParentTest() throws IOException, InterruptedException {
501+
convertToPdfAndCompare("marginsCollapseFlexContainerAndParent", SOURCE_FOLDER, DESTINATION_FOLDER);
502+
}
503+
504+
@Test
505+
public void marginsCollapseInsideFlexContainerTest() throws IOException, InterruptedException {
506+
convertToPdfAndCompare("marginsCollapseInsideFlexContainer", SOURCE_FOLDER, DESTINATION_FOLDER);
507+
}
508+
509+
@Test
510+
public void marginsCollapseFlexContainerAndItsChildTest() throws IOException, InterruptedException {
511+
convertToPdfAndCompare("marginsCollapseFlexContainerAndItsChild", SOURCE_FOLDER, DESTINATION_FOLDER);
512+
}
513+
514+
@Test
515+
// TODO DEVSIX-5196 Support collapsing margins for flex item's children
516+
public void marginsCollapseInsideFlexItemTest() throws IOException, InterruptedException {
517+
convertToPdfAndCompare("marginsCollapseInsideFlexItem", SOURCE_FOLDER, DESTINATION_FOLDER);
518+
}
519+
490520
private static void assertDiv(IElement element, String text) {
491521
Assert.assertTrue(element instanceof Div);
492522
Assert.assertEquals(1, ((Div) element).getChildren().size());

src/test/java/com/itextpdf/html2pdf/css/w3c/css_flexbox/AlignItems001Test.java

Lines changed: 0 additions & 1 deletion
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.html2pdf.css.w3c.W3CCssTest;
2626

27-
//TODO DEVSIX-5137 support margin collapse
2827
public class AlignItems001Test extends W3CCssTest {
2928
@Override
3029
protected String getHtmlFileName() {

src/test/java/com/itextpdf/html2pdf/css/w3c/css_flexbox/AlignItems002Test.java

Lines changed: 0 additions & 1 deletion
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.html2pdf.css.w3c.W3CCssTest;
2626

27-
//TODO DEVSIX-5137 support margin collapse
2827
public class AlignItems002Test extends W3CCssTest {
2928
@Override
3029
protected String getHtmlFileName() {

src/test/java/com/itextpdf/html2pdf/css/w3c/css_flexbox/AlignItems003Test.java

Lines changed: 0 additions & 1 deletion
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.html2pdf.css.w3c.W3CCssTest;
2626

27-
//TODO DEVSIX-5137 support margin collapse
2827
public class AlignItems003Test extends W3CCssTest {
2928
@Override
3029
protected String getHtmlFileName() {

src/test/java/com/itextpdf/html2pdf/css/w3c/css_flexbox/AlignItems004Test.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ This file is part of the iText (R) project.
2525
import com.itextpdf.html2pdf.css.w3c.W3CCssTest;
2626

2727
//TODO DEVSIX-5096 support flex-flow property
28-
//TODO DEVSIX-5137 support margin collapse
2928
public class AlignItems004Test extends W3CCssTest {
3029
@Override
3130
protected String getHtmlFileName() {

src/test/java/com/itextpdf/html2pdf/css/w3c/css_flexbox/AlignItems005Test.java

Lines changed: 0 additions & 1 deletion
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.html2pdf.css.w3c.W3CCssTest;
2626

27-
//TODO DEVSIX-5137 support margin collapse
2827
public class AlignItems005Test extends W3CCssTest {
2928
@Override
3029
protected String getHtmlFileName() {

src/test/java/com/itextpdf/html2pdf/css/w3c/css_flexbox/AlignItems006Test.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ This file is part of the iText (R) project.
2525
import com.itextpdf.html2pdf.css.w3c.W3CCssTest;
2626

2727
//TODO DEVSIX-5096 support flex-direction: column
28-
//TODO DEVSIX-5137 support margin collapse
2928
public class AlignItems006Test extends W3CCssTest {
3029
@Override
3130
protected String getHtmlFileName() {

0 commit comments

Comments
 (0)