Title: [237456] trunk
Revision
237456
Author
[email protected]
Date
2018-10-26 07:42:06 -0700 (Fri, 26 Oct 2018)

Log Message

[LFC][IFC] Layout floats as part of the inline content
https://bugs.webkit.org/show_bug.cgi?id=190942

Reviewed by Antti Koivisto.

Source/WebCore:

Add float handling to InlineFormattingContext::layoutInlineContent.
Note that floats don't actually generate inline runs.

Test: fast/block/basic/inline-content-with-floating-image.html

* layout/blockformatting/BlockFormattingContext.cpp:
(WebCore::Layout::BlockFormattingContext::layoutFormattingContextRoot const):
* layout/floats/FloatAvoider.cpp:
(WebCore::Layout::FloatAvoider::FloatAvoider): Check if any mapping is needed.
* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::isTrimmableContent):
(WebCore::Layout::InlineFormattingContext::layoutInlineContent const):
(WebCore::Layout::trimLeadingRun): Deleted.
* layout/inlineformatting/InlineFormattingContext.h:
(WebCore::Layout::InlineFormattingContext::Line::isClosed const):
* layout/inlineformatting/Line.cpp:
(WebCore::Layout::InlineFormattingContext::Line::init):
(WebCore::Layout::InlineFormattingContext::Line::adjustLogicalLeft):
(WebCore::Layout::InlineFormattingContext::Line::adjustLogicalRight):
(WebCore::Layout::InlineFormattingContext::Line::appendContent):
(WebCore::Layout::InlineFormattingContext::Line::close):

Tools:

* LayoutReloaded/misc/LFC-passing-tests.txt:

LayoutTests:

* fast/block/basic/inline-content-with-floating-image-expected.txt: Added.
* fast/block/basic/inline-content-with-floating-image.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (237455 => 237456)


--- trunk/LayoutTests/ChangeLog	2018-10-26 14:40:00 UTC (rev 237455)
+++ trunk/LayoutTests/ChangeLog	2018-10-26 14:42:06 UTC (rev 237456)
@@ -1,3 +1,13 @@
+2018-10-26  Zalan Bujtas  <[email protected]>
+
+        [LFC][IFC] Layout floats as part of the inline content
+        https://bugs.webkit.org/show_bug.cgi?id=190942
+
+        Reviewed by Antti Koivisto.
+
+        * fast/block/basic/inline-content-with-floating-image-expected.txt: Added.
+        * fast/block/basic/inline-content-with-floating-image.html: Added.
+
 2018-10-26  Alicia Boya García  <[email protected]>
 
         [MSE][WTF][Media] Invalid MediaTime should be falsy

Added: trunk/LayoutTests/fast/block/basic/inline-content-with-floating-image-expected.txt (0 => 237456)


--- trunk/LayoutTests/fast/block/basic/inline-content-with-floating-image-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/block/basic/inline-content-with-floating-image-expected.txt	2018-10-26 14:42:06 UTC (rev 237456)
@@ -0,0 +1,31 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+layer at (8,8) size 300x72
+  RenderBlock {DIV} at (0,0) size 300x72
+    RenderImage {IMG} at (0,0) size 50x30
+    RenderText {#text} at (50,0) size 284x72
+      text run at (50,0) width 232: "long text with left floating box. long"
+      text run at (50,18) width 228: "text with left floating box. long text"
+      text run at (0,36) width 284: "with left floating box. text eventually breaks"
+      text run at (0,54) width 120: "below the floating."
+layer at (8,80) size 300x72
+  RenderBlock {DIV} at (0,72) size 300x72
+    RenderImage {IMG} at (250,0) size 50x30
+    RenderText {#text} at (0,0) size 292x72
+      text run at (0,0) width 241: "long text with right floating box. long"
+      text run at (0,18) width 236: "text with right floating box. long text"
+      text run at (0,36) width 292: "with right floating box. text eventually breaks"
+      text run at (0,54) width 120: "below the floating."
+layer at (8,152) size 300x90
+  RenderBlock {DIV} at (0,144) size 300x90
+    RenderImage {IMG} at (0,0) size 20x30
+    RenderImage {IMG} at (280,0) size 20x30
+    RenderText {#text} at (20,0) size 292x90
+      text run at (20,0) width 229: "long text with left and right floating"
+      text run at (20,18) width 208: "box. long text with left and right"
+      text run at (0,36) width 261: "floating box. long text with left and right"
+      text run at (0,54) width 292: "floating box. text eventually breaks below the"
+      text run at (0,72) width 60: "floatings."

Added: trunk/LayoutTests/fast/block/basic/inline-content-with-floating-image.html (0 => 237456)


--- trunk/LayoutTests/fast/block/basic/inline-content-with-floating-image.html	                        (rev 0)
+++ trunk/LayoutTests/fast/block/basic/inline-content-with-floating-image.html	2018-10-26 14:42:06 UTC (rev 237456)
@@ -0,0 +1,16 @@
+<div style="overflow: hidden; text-align: left; width: 300px;">
+<img style="float: left;" src="" height="30" width="50">
+long text with left floating box. long text with left floating box. long text with left floating box.
+text eventually breaks below the floating.</div>
+
+<div style="overflow: hidden; text-align: left; width: 300px;">
+<img style="float: right;" src="" height="30" width="50">
+long text with right floating box. long text with right floating box. long text with right floating box.
+text eventually breaks below the floating.</div>
+
+
+<div style="overflow: hidden; text-align: left; width: 300px;">
+<img style="float: left;" src="" height="30" width="20">
+<img style="float: right;" src="" height="30" width="20">
+long text with left and right floating box. long text with left and right floating box. long text with left and right floating box.
+text eventually breaks below the floatings.</div>

Modified: trunk/Source/WebCore/ChangeLog (237455 => 237456)


--- trunk/Source/WebCore/ChangeLog	2018-10-26 14:40:00 UTC (rev 237455)
+++ trunk/Source/WebCore/ChangeLog	2018-10-26 14:42:06 UTC (rev 237456)
@@ -1,5 +1,34 @@
 2018-10-26  Zalan Bujtas  <[email protected]>
 
+        [LFC][IFC] Layout floats as part of the inline content
+        https://bugs.webkit.org/show_bug.cgi?id=190942
+
+        Reviewed by Antti Koivisto.
+
+        Add float handling to InlineFormattingContext::layoutInlineContent.
+        Note that floats don't actually generate inline runs.
+
+        Test: fast/block/basic/inline-content-with-floating-image.html
+
+        * layout/blockformatting/BlockFormattingContext.cpp:
+        (WebCore::Layout::BlockFormattingContext::layoutFormattingContextRoot const):
+        * layout/floats/FloatAvoider.cpp:
+        (WebCore::Layout::FloatAvoider::FloatAvoider): Check if any mapping is needed.
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::isTrimmableContent):
+        (WebCore::Layout::InlineFormattingContext::layoutInlineContent const):
+        (WebCore::Layout::trimLeadingRun): Deleted.
+        * layout/inlineformatting/InlineFormattingContext.h:
+        (WebCore::Layout::InlineFormattingContext::Line::isClosed const):
+        * layout/inlineformatting/Line.cpp:
+        (WebCore::Layout::InlineFormattingContext::Line::init):
+        (WebCore::Layout::InlineFormattingContext::Line::adjustLogicalLeft):
+        (WebCore::Layout::InlineFormattingContext::Line::adjustLogicalRight):
+        (WebCore::Layout::InlineFormattingContext::Line::appendContent):
+        (WebCore::Layout::InlineFormattingContext::Line::close):
+
+2018-10-26  Zalan Bujtas  <[email protected]>
+
         [LFC][IFC] Adjust current line with float constraints.
         https://bugs.webkit.org/show_bug.cgi?id=190940
 

Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp (237455 => 237456)


--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp	2018-10-26 14:40:00 UTC (rev 237455)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp	2018-10-26 14:42:06 UTC (rev 237456)
@@ -145,8 +145,7 @@
     if (layoutBox.isFloatingPositioned()) {
         computeFloatingPosition(layoutContext, floatingContext, layoutBox);
         floatingContext.floatingState().append(layoutBox);
-    }
-    else if (layoutBox.hasFloatClear())
+    } else if (layoutBox.hasFloatClear())
         computeVerticalPositionForFloatClear(layoutContext, floatingContext, layoutBox);
     else if (layoutBox.establishesBlockFormattingContext())
         computePositionToAvoidFloats(layoutContext, floatingContext, layoutBox);

Modified: trunk/Source/WebCore/layout/floats/FloatAvoider.cpp (237455 => 237456)


--- trunk/Source/WebCore/layout/floats/FloatAvoider.cpp	2018-10-26 14:40:00 UTC (rev 237455)
+++ trunk/Source/WebCore/layout/floats/FloatAvoider.cpp	2018-10-26 14:42:06 UTC (rev 237456)
@@ -42,7 +42,7 @@
     : m_layoutBox(makeWeakPtr(layoutBox))
     , m_floatingState(floatingState)
     , m_absoluteDisplayBox(FormattingContext::mapBoxToAncestor(layoutContext, layoutBox, downcast<Container>(floatingState.root())))
-    , m_containingBlockAbsoluteDisplayBox(FormattingContext::mapBoxToAncestor(layoutContext, *layoutBox.containingBlock(), downcast<Container>(floatingState.root())))
+    , m_containingBlockAbsoluteDisplayBox(layoutBox.containingBlock() == &floatingState.root() ? Display::Box(layoutContext.displayBoxForLayoutBox(*layoutBox.containingBlock())) : FormattingContext::mapBoxToAncestor(layoutContext, *layoutBox.containingBlock(), downcast<Container>(floatingState.root())))
     , m_initialVerticalPosition(m_absoluteDisplayBox.top())
 {
     ASSERT(m_layoutBox->establishesBlockFormattingContext());

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp (237455 => 237456)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2018-10-26 14:40:00 UTC (rev 237455)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2018-10-26 14:42:06 UTC (rev 237456)
@@ -91,14 +91,9 @@
     LOG_WITH_STREAM(FormattingContextLayout, stream << "[End] -> inline formatting context -> layout context(" << &layoutContext << ") formatting root(" << &root() << ")");
 }
 
-static bool trimLeadingRun(const InlineLineBreaker::Run& run)
+static bool isTrimmableContent(const InlineLineBreaker::Run& run)
 {
-    ASSERT(run.position == InlineLineBreaker::Run::Position::LineBegin);
-
-    if (!run.content.isWhitespace())
-        return false;
-
-    return run.content.style().collapseWhiteSpace();
+    return run.content.isWhitespace() && run.content.style().collapseWhiteSpace();
 }
 
 void InlineFormattingContext::initializeNewLine(const LayoutContext& layoutContext, InlineFormattingState& inlineFormattingState, Line& line) const
@@ -146,7 +141,7 @@
 
 void InlineFormattingContext::layoutInlineContent(const LayoutContext& layoutContext, InlineFormattingState& inlineFormattingState, const InlineRunProvider& inlineRunProvider) const
 {
-    auto previousRunPositionIsLineEnd = false;
+    auto floatingContext = FloatingContext { inlineFormattingState.floatingState() };
 
     Line line(inlineFormattingState, root());
     initializeNewLine(layoutContext, inlineFormattingState, line);
@@ -153,34 +148,48 @@
 
     InlineLineBreaker lineBreaker(layoutContext, inlineFormattingState.inlineContent(), inlineRunProvider.runs());
     while (auto run = lineBreaker.nextRun(line.contentLogicalRight(), line.availableWidth(), !line.hasContent())) {
+        auto isFirstRun = run->position == InlineLineBreaker::Run::Position::LineBegin;
+        auto isLastRun = run->position == InlineLineBreaker::Run::Position::LineEnd;
+        auto generatesInlineRun = true;
 
-        if (run->position == InlineLineBreaker::Run::Position::LineBegin) {
-            // First run on line.
+        // Position float and adjust the runs on line.
+        if (run->content.isFloat()) {
+            auto& floatBox = run->content.inlineItem().layoutBox();
+            computeFloatPosition(layoutContext, floatingContext, line, floatBox);
+            inlineFormattingState.floatingState().append(floatBox);
 
-            // Previous run ended up being at the line end. Adjust the line accordingly.
-            if (!previousRunPositionIsLineEnd) {
-                line.close();
+            auto floatBoxWidth = layoutContext.displayBoxForLayoutBox(floatBox).width();
+            // Shrink availble space for current line and move existing inline runs.
+            floatBox.isLeftFloatingPositioned() ? line.adjustLogicalLeft(floatBoxWidth) : line.adjustLogicalRight(floatBoxWidth);
+
+            generatesInlineRun = false;
+        }
+
+        // 1. Initialize new line if needed.
+        // 2. Append inline run unless it is skipped.
+        // 3. Close current line if needed.
+        if (isFirstRun) {
+            // When the first run does not generate an actual inline run, the next run comes in first-run as well.
+            // No need to spend time on closing/initializing.
+            // Skip leading whitespace.
+            if (!generatesInlineRun || isTrimmableContent(*run))
+                continue;
+
+            if (line.hasContent()) {
+                // Previous run ended up being at the line end. Adjust the line accordingly.
+                if (!line.isClosed())
+                    line.close(Line::LastLine::No);
                 initializeNewLine(layoutContext, inlineFormattingState, line);
             }
-            // Skip leading whitespace.
-            if (!trimLeadingRun(*run))
-                line.appendContent(*run);
-            continue;
-        }
+         }
 
-        if (run->position == InlineLineBreaker::Run::Position::LineEnd) {
-            // Last run on line.
-            previousRunPositionIsLineEnd = true;
-            line.appendContent(*run);
-            // Move over to the next line.
-            line.close();
-            initializeNewLine(layoutContext, inlineFormattingState, line);
-            continue;
-        }
+        if (generatesInlineRun)
+             line.appendContent(*run);
 
-        // This may or may not be the last run on line -but definitely not the first one.
-        line.appendContent(*run);
+        if (isLastRun)
+            line.close(Line::LastLine::No);
     }
+
     line.close(Line::LastLine::Yes);
 }
 

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h (237455 => 237456)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h	2018-10-26 14:40:00 UTC (rev 237455)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h	2018-10-26 14:42:06 UTC (rev 237456)
@@ -63,6 +63,7 @@
         void close(LastLine = LastLine::No);
 
         bool hasContent() const { return m_firstRunIndex.has_value(); }
+        bool isClosed() const { return m_closed; }
         bool isFirstLine() const { return m_isFirstLine; }
         LayoutUnit contentLogicalRight();
         LayoutUnit availableWidth() const { return m_availableWidth; }
@@ -91,6 +92,7 @@
         std::optional<unsigned> m_firstRunIndex;
         bool m_alignmentIsJustify { false };
         bool m_isFirstLine { true };
+        bool m_closed { true };
     };
 
     void layoutInlineContent(const LayoutContext&, InlineFormattingState&, const InlineRunProvider&) const;

Modified: trunk/Source/WebCore/layout/inlineformatting/Line.cpp (237455 => 237456)


--- trunk/Source/WebCore/layout/inlineformatting/Line.cpp	2018-10-26 14:40:00 UTC (rev 237455)
+++ trunk/Source/WebCore/layout/inlineformatting/Line.cpp	2018-10-26 14:42:06 UTC (rev 237456)
@@ -49,10 +49,13 @@
     m_lastRunIsWhitespace = false;
     m_lastRunCanExpand = false;
     m_trailingTrimmableContent = { };
+    m_closed = false;
 }
 
 void InlineFormattingContext::Line::adjustLogicalLeft(LayoutUnit delta)
 {
+    ASSERT(delta > 0);
+
     m_availableWidth -= delta;
     m_logicalRect.shiftLeftTo(m_logicalRect.left() + delta);
 
@@ -66,6 +69,8 @@
 
 void InlineFormattingContext::Line::adjustLogicalRight(LayoutUnit delta)
 {
+    ASSERT(delta > 0);
+
     m_availableWidth -= delta;
     m_logicalRect.shiftRightTo(m_logicalRect.right() - delta);
 }
@@ -132,6 +137,8 @@
 
 void InlineFormattingContext::Line::appendContent(const InlineLineBreaker::Run& run)
 {
+    ASSERT(!isClosed());
+
     auto& content = run.content;
 
     // Append this text run to the end of the last text run, if the last run is continuous.
@@ -258,6 +265,7 @@
 
     alignRuns(textAlignment);
     m_isFirstLine = false;
+    m_closed = true;
 }
 
 }

Modified: trunk/Tools/ChangeLog (237455 => 237456)


--- trunk/Tools/ChangeLog	2018-10-26 14:40:00 UTC (rev 237455)
+++ trunk/Tools/ChangeLog	2018-10-26 14:42:06 UTC (rev 237456)
@@ -1,3 +1,12 @@
+2018-10-26  Zalan Bujtas  <[email protected]>
+
+        [LFC][IFC] Layout floats as part of the inline content
+        https://bugs.webkit.org/show_bug.cgi?id=190942
+
+        Reviewed by Antti Koivisto.
+
+        * LayoutReloaded/misc/LFC-passing-tests.txt:
+
 2018-10-26  Alicia Boya García  <[email protected]>
 
         [MSE][WTF][Media] Invalid MediaTime should be falsy

Modified: trunk/Tools/LayoutReloaded/misc/LFC-passing-tests.txt (237455 => 237456)


--- trunk/Tools/LayoutReloaded/misc/LFC-passing-tests.txt	2018-10-26 14:40:00 UTC (rev 237455)
+++ trunk/Tools/LayoutReloaded/misc/LFC-passing-tests.txt	2018-10-26 14:42:06 UTC (rev 237456)
@@ -62,3 +62,4 @@
 fast/block/block-only/absolute-position-min-max-height.html
 fast/block/block-only/float-min-max-height.html
 fast/block/block-only/min-max-height-percentage.html
+fast/block/basic/inline-content-with-floating-image.html
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to