Title: [268133] trunk
Revision
268133
Author
za...@apple.com
Date
2020-10-07 11:02:52 -0700 (Wed, 07 Oct 2020)

Log Message

[LFC][IFC] Adjust the inline formatting context root's content height when the last line has float clear
https://bugs.webkit.org/show_bug.cgi?id=217432

Reviewed by Antti Koivisto.

Source/WebCore:

This patch expands the support for inline content to clear floats (r268122) by taking the clear gap into
account when it occurs after the last line (e.g. <div>foobar<br clear=left"></div>).
In such cases the inline formatting context's content height needs to be adjusted with the computed clear
gap value.

Test: fast/layoutformattingcontext/float-avoiding-br-last-line.html

* layout/FormattingContextGeometry.cpp:
(WebCore::Layout::FormattingContext::Geometry::contentHeightForFormattingContextRoot const):
* layout/blockformatting/BlockFormattingContextGeometry.cpp:
(WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMargin):
* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::lineLayout):
* layout/inlineformatting/InlineFormattingState.h:
(WebCore::Layout::InlineFormattingState::setClearGapAfterLastLine):
(WebCore::Layout::InlineFormattingState::clearGapAfterLastLine const):
(WebCore::Layout::InlineFormattingState::clearLineAndRuns):

LayoutTests:

* fast/layoutformattingcontext/float-avoiding-br-last-line-expected.html: Added.
* fast/layoutformattingcontext/float-avoiding-br-last-line.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (268132 => 268133)


--- trunk/LayoutTests/ChangeLog	2020-10-07 17:09:13 UTC (rev 268132)
+++ trunk/LayoutTests/ChangeLog	2020-10-07 18:02:52 UTC (rev 268133)
@@ -1,3 +1,13 @@
+2020-10-07  Zalan Bujtas  <za...@apple.com>
+
+        [LFC][IFC] Adjust the inline formatting context root's content height when the last line has float clear
+        https://bugs.webkit.org/show_bug.cgi?id=217432
+
+        Reviewed by Antti Koivisto.
+
+        * fast/layoutformattingcontext/float-avoiding-br-last-line-expected.html: Added.
+        * fast/layoutformattingcontext/float-avoiding-br-last-line.html: Added.
+
 2020-10-07  Youenn Fablet  <you...@apple.com>
 
         Add support for MediaRecorder pause/resume

Added: trunk/LayoutTests/fast/layoutformattingcontext/float-avoiding-br-last-line-expected.html (0 => 268133)


--- trunk/LayoutTests/fast/layoutformattingcontext/float-avoiding-br-last-line-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/layoutformattingcontext/float-avoiding-br-last-line-expected.html	2020-10-07 18:02:52 UTC (rev 268133)
@@ -0,0 +1,14 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ internal:LayoutFormattingContextEnabled=true internal:LayoutFormattingContextIntegrationEnabled=false ] -->
+<style>
+.float_like {
+  position: absolute;
+  background-color: blue;
+  width: 50px;
+  height: 50px;
+}
+</style>
+<div style="width: 300px; height: 170px; background-color: green;"></div>
+<div class=float_like style="top: 8px; left: 8px;"></div>
+<div class=float_like style="top: 58px; left: 258px; height: 60px;"></div>
+<div class=float_like style="top: 118px; left: 258px; height: 60px"></div>
+<div class=float_like style="top: 118px; left: 8px;"></div>

Added: trunk/LayoutTests/fast/layoutformattingcontext/float-avoiding-br-last-line.html (0 => 268133)


--- trunk/LayoutTests/fast/layoutformattingcontext/float-avoiding-br-last-line.html	                        (rev 0)
+++ trunk/LayoutTests/fast/layoutformattingcontext/float-avoiding-br-last-line.html	2020-10-07 18:02:52 UTC (rev 268133)
@@ -0,0 +1,27 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ internal:LayoutFormattingContextEnabled=true internal:LayoutFormattingContextIntegrationEnabled=false ] -->
+<style>
+.float {
+  float: left; 
+  width: 50px;
+  height: 50px;
+  background-color: blue;
+}
+.container {
+  font-family: Ahem;
+  font-size: 10px;
+  color: green;
+  background-color: green;
+  width: 300px;
+}
+</style>
+<div style="width: 300px;">
+<div class="float"></div>
+<div class=container>foobar<br style="clear: left"></div>
+
+<div class="float" style="float: right; height: 60px;"></div>
+<div class=container>foobar<br style="clear: right"></div>
+
+<div class="float"></div>
+<div class="float" style="float: right; height: 60px;"></div>
+<div class=container>foobar<br style="clear: both"></div>
+</div>

Modified: trunk/Source/WebCore/ChangeLog (268132 => 268133)


--- trunk/Source/WebCore/ChangeLog	2020-10-07 17:09:13 UTC (rev 268132)
+++ trunk/Source/WebCore/ChangeLog	2020-10-07 18:02:52 UTC (rev 268133)
@@ -1,3 +1,28 @@
+2020-10-07  Zalan Bujtas  <za...@apple.com>
+
+        [LFC][IFC] Adjust the inline formatting context root's content height when the last line has float clear
+        https://bugs.webkit.org/show_bug.cgi?id=217432
+
+        Reviewed by Antti Koivisto.
+
+        This patch expands the support for inline content to clear floats (r268122) by taking the clear gap into
+        account when it occurs after the last line (e.g. <div>foobar<br clear=left"></div>).
+        In such cases the inline formatting context's content height needs to be adjusted with the computed clear
+        gap value.
+
+        Test: fast/layoutformattingcontext/float-avoiding-br-last-line.html
+
+        * layout/FormattingContextGeometry.cpp:
+        (WebCore::Layout::FormattingContext::Geometry::contentHeightForFormattingContextRoot const):
+        * layout/blockformatting/BlockFormattingContextGeometry.cpp:
+        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMargin):
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::lineLayout):
+        * layout/inlineformatting/InlineFormattingState.h:
+        (WebCore::Layout::InlineFormattingState::setClearGapAfterLastLine):
+        (WebCore::Layout::InlineFormattingState::clearGapAfterLastLine const):
+        (WebCore::Layout::InlineFormattingState::clearLineAndRuns):
+
 2020-10-07  Youenn Fablet  <you...@apple.com>
 
         Add support for MediaRecorder pause/resume

Modified: trunk/Source/WebCore/layout/FormattingContextGeometry.cpp (268132 => 268133)


--- trunk/Source/WebCore/layout/FormattingContextGeometry.cpp	2020-10-07 17:09:13 UTC (rev 268132)
+++ trunk/Source/WebCore/layout/FormattingContextGeometry.cpp	2020-10-07 18:02:52 UTC (rev 268133)
@@ -193,11 +193,12 @@
     auto top = borderAndPaddingTop;
     auto bottom = borderAndPaddingTop;
     if (formattingContextRoot.establishesInlineFormattingContext()) {
-        auto& lines = layoutState.establishedInlineFormattingState(formattingContextRoot).lines();
-        // Even empty containers generate one line. 
+        auto& inlineFormattingState = layoutState.establishedInlineFormattingState(formattingContextRoot);
+        auto& lines = inlineFormattingState.lines();
+        // Even empty containers generate one line.
         ASSERT(!lines.isEmpty());
         top = lines.first().logicalTop();
-        bottom = lines.last().logicalBottom();
+        bottom = lines.last().logicalBottom() + inlineFormattingState.clearGapAfterLastLine();
     } else if (formattingContextRoot.establishesFlexFormattingContext()) {
         auto& lines = layoutState.establishedFlexFormattingState(formattingContextRoot).lines();
         ASSERT(!lines.isEmpty());

Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp (268132 => 268133)


--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp	2020-10-07 17:09:13 UTC (rev 268132)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp	2020-10-07 18:02:52 UTC (rev 268133)
@@ -77,10 +77,11 @@
         // 1. the bottom edge of the last line box, if the box establishes a inline formatting context with one or more lines
         auto& layoutContainer = downcast<ContainerBox>(layoutBox);
         if (layoutContainer.establishesInlineFormattingContext()) {
-            auto& lines = layoutState().establishedInlineFormattingState(layoutContainer).lines();
+            auto& inlineFormattingState = layoutState().establishedInlineFormattingState(layoutContainer);
+            auto& lines = inlineFormattingState.lines();
             // Even empty containers generate one line. 
             ASSERT(!lines.isEmpty());
-            return { toLayoutUnit(lines.last().logicalBottom()) - borderAndPaddingTop, nonCollapsedMargin };
+            return { toLayoutUnit(lines.last().logicalBottom() + inlineFormattingState.clearGapAfterLastLine()) - borderAndPaddingTop, nonCollapsedMargin };
         }
 
         // 2. the bottom edge of the bottom (possibly collapsed) margin of its last in-flow child, if the child's bottom margin...

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp (268132 => 268133)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2020-10-07 17:09:13 UTC (rev 268132)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2020-10-07 18:02:52 UTC (rev 268133)
@@ -166,6 +166,10 @@
             ASSERT(needsLayoutRange.start < lineContentRange.end);
             isFirstLine = false;
             lineLogicalTop = geometry().logicalTopForNextLine(lineContent, lineLogicalRect.bottom(), floatingContext);
+            if (lineContent.isLastLineWithInlineContent) {
+                // The final content height of this inline formatting context should include the cleared floats as well.
+                formattingState().setClearGapAfterLastLine(lineLogicalTop - lineLogicalRect.bottom());
+            }
             // When the trailing content is partial, we need to reuse the last InlineTextItem.
             auto lastInlineItemNeedsPartialLayout = lineContent.partialTrailingContentLength;
             if (lastInlineItemNeedsPartialLayout) {

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingState.h (268132 => 268133)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingState.h	2020-10-07 17:09:13 UTC (rev 268132)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingState.h	2020-10-07 18:02:52 UTC (rev 268133)
@@ -64,6 +64,9 @@
     InlineLineRuns& lineRuns() { return m_lineRuns; }
     void addLineRun(const LineRun& run) { m_lineRuns.append(run); }
 
+    void setClearGapAfterLastLine(InlineLayoutUnit verticalGap);
+    InlineLayoutUnit clearGapAfterLastLine() const { return m_clearGapAfterLastLine; }
+
     void clearLineAndRuns();
     void shrinkToFit();
 
@@ -73,13 +76,21 @@
     InlineLines m_lines;
     InlineLineBoxes m_lineBoxes;
     InlineLineRuns m_lineRuns;
+    InlineLayoutUnit m_clearGapAfterLastLine { 0 };
 };
 
+inline void InlineFormattingState::setClearGapAfterLastLine(InlineLayoutUnit verticalGap)
+{
+    ASSERT(verticalGap >= 0);
+    m_clearGapAfterLastLine = verticalGap;
+}
+
 inline void InlineFormattingState::clearLineAndRuns()
 {
     m_lines.clear();
     m_lineBoxes.clear();
     m_lineRuns.clear();
+    m_clearGapAfterLastLine = { };
 }
 
 inline void InlineFormattingState::shrinkToFit()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to