[LFC][IFC] Adjust current line with float constraints.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Oct 2018 14:40:00 +0000 (14:40 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Oct 2018 14:40:00 +0000 (14:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=190940

Reviewed by Antti Koivisto.

* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::initializeNewLine const):
(WebCore::Layout::InlineFormattingContext::layoutInlineContent const):
* layout/inlineformatting/InlineFormattingContext.h:
* layout/inlineformatting/InlineRun.h:
(WebCore::Layout::InlineRun::moveHorizontally):
* layout/inlineformatting/Line.cpp:
(WebCore::Layout::InlineFormattingContext::Line::adjustLogicalLeft):
(WebCore::Layout::InlineFormattingContext::Line::adjustLogicalRight):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237455 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp
Source/WebCore/layout/inlineformatting/InlineFormattingContext.h
Source/WebCore/layout/inlineformatting/InlineRun.h
Source/WebCore/layout/inlineformatting/Line.cpp

index 8835818..a804304 100644 (file)
@@ -1,5 +1,22 @@
 2018-10-26  Zalan Bujtas  <zalan@apple.com>
 
+        [LFC][IFC] Adjust current line with float constraints.
+        https://bugs.webkit.org/show_bug.cgi?id=190940
+
+        Reviewed by Antti Koivisto.
+
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::initializeNewLine const):
+        (WebCore::Layout::InlineFormattingContext::layoutInlineContent const):
+        * layout/inlineformatting/InlineFormattingContext.h:
+        * layout/inlineformatting/InlineRun.h:
+        (WebCore::Layout::InlineRun::moveHorizontally):
+        * layout/inlineformatting/Line.cpp:
+        (WebCore::Layout::InlineFormattingContext::Line::adjustLogicalLeft):
+        (WebCore::Layout::InlineFormattingContext::Line::adjustLogicalRight):
+
+2018-10-26  Zalan Bujtas  <zalan@apple.com>
+
         [LFC][IFC] Compute float box size and position
         https://bugs.webkit.org/show_bug.cgi?id=190938
 
index 4192096..63da2e4 100644 (file)
@@ -101,7 +101,7 @@ static bool trimLeadingRun(const InlineLineBreaker::Run& run)
     return run.content.style().collapseWhiteSpace();
 }
 
-void InlineFormattingContext::initializeNewLine(const LayoutContext& layoutContext, Line& line) const
+void InlineFormattingContext::initializeNewLine(const LayoutContext& layoutContext, InlineFormattingState& inlineFormattingState, Line& line) const
 {
     auto& formattingRoot = downcast<Container>(root());
     auto& formattingRootDisplayBox = layoutContext.displayBoxForLayoutBox(formattingRoot);
@@ -110,6 +110,31 @@ void InlineFormattingContext::initializeNewLine(const LayoutContext& layoutConte
     auto lineLogicalTop = line.isFirstLine() ? formattingRootDisplayBox.contentBoxTop() : line.logicalBottom();
     auto availableWidth = formattingRootDisplayBox.contentBoxWidth();
 
+    // Check for intruding floats and adjust logical left/available width for this line accordingly.
+    auto& floatingState = inlineFormattingState.floatingState();
+    if (!floatingState.isEmpty()) {
+        auto floatConstraints = floatingState.constraints(lineLogicalTop, formattingRoot);
+        // Check if these constraints actually put limitation on the line.
+        if (floatConstraints.left && *floatConstraints.left <= formattingRootDisplayBox.contentBoxLeft())
+            floatConstraints.left = { };
+
+        if (floatConstraints.right && *floatConstraints.right >= formattingRootDisplayBox.contentBoxRight())
+            floatConstraints.right = { };
+
+        if (floatConstraints.left && floatConstraints.right) {
+            ASSERT(*floatConstraints.left < *floatConstraints.right);
+            availableWidth = *floatConstraints.right - *floatConstraints.left;
+            lineLogicalLeft = *floatConstraints.left;
+        } else if (floatConstraints.left) {
+            ASSERT(*floatConstraints.left > lineLogicalLeft);
+            availableWidth -= (*floatConstraints.left - lineLogicalLeft);
+            lineLogicalLeft = *floatConstraints.left;
+        } else if (floatConstraints.right) {
+            ASSERT(*floatConstraints.right > lineLogicalLeft);
+            availableWidth = *floatConstraints.right - lineLogicalLeft;
+        }
+    }
+
     Display::Box::Rect logicalRect;
     logicalRect.setTop(lineLogicalTop);
     logicalRect.setLeft(lineLogicalLeft);
@@ -124,7 +149,7 @@ void InlineFormattingContext::layoutInlineContent(const LayoutContext& layoutCon
     auto previousRunPositionIsLineEnd = false;
 
     Line line(inlineFormattingState, root());
-    initializeNewLine(layoutContext, line);
+    initializeNewLine(layoutContext, inlineFormattingState, line);
 
     InlineLineBreaker lineBreaker(layoutContext, inlineFormattingState.inlineContent(), inlineRunProvider.runs());
     while (auto run = lineBreaker.nextRun(line.contentLogicalRight(), line.availableWidth(), !line.hasContent())) {
@@ -135,7 +160,7 @@ void InlineFormattingContext::layoutInlineContent(const LayoutContext& layoutCon
             // Previous run ended up being at the line end. Adjust the line accordingly.
             if (!previousRunPositionIsLineEnd) {
                 line.close();
-                initializeNewLine(layoutContext, line);
+                initializeNewLine(layoutContext, inlineFormattingState, line);
             }
             // Skip leading whitespace.
             if (!trimLeadingRun(*run))
@@ -149,7 +174,7 @@ void InlineFormattingContext::layoutInlineContent(const LayoutContext& layoutCon
             line.appendContent(*run);
             // Move over to the next line.
             line.close();
-            initializeNewLine(layoutContext, line);
+            initializeNewLine(layoutContext, inlineFormattingState, line);
             continue;
         }
 
index 89ca7f7..faf5f7f 100644 (file)
@@ -55,6 +55,10 @@ private:
         void init(const Display::Box::Rect&);
 
         void appendContent(const InlineLineBreaker::Run&);
+
+        void adjustLogicalLeft(LayoutUnit delta);
+        void adjustLogicalRight(LayoutUnit delta);
+
         enum class LastLine { No, Yes };
         void close(LastLine = LastLine::No);
 
@@ -90,7 +94,7 @@ private:
     };
 
     void layoutInlineContent(const LayoutContext&, InlineFormattingState&, const InlineRunProvider&) const;
-    void initializeNewLine(const LayoutContext&, Line&) const;
+    void initializeNewLine(const LayoutContext&, InlineFormattingState&, Line&) const;
 
     void computeWidthAndHeight(LayoutContext&, const Box&) const;
     void computeFloatPosition(const LayoutContext&, const FloatingContext&, Line&, const Box&) const;
index 4aba427..28d3276 100644 (file)
@@ -43,6 +43,7 @@ struct InlineRun {
     void setWidth(LayoutUnit width) { m_width = width; }
     void setLogicalLeft(LayoutUnit logicalLeft) { m_logicalLeft = logicalLeft; }
     void setLogicalRight(LayoutUnit logicalRight) { m_width -= (this->logicalRight() - logicalRight); }
+    void moveHorizontally(LayoutUnit delta) { m_logicalLeft += delta; }
 
     struct ExpansionOpportunity {
         unsigned count { 0 };
index 0ba20ad..be51353 100644 (file)
@@ -51,6 +51,25 @@ void InlineFormattingContext::Line::init(const Display::Box::Rect& logicalRect)
     m_trailingTrimmableContent = { };
 }
 
+void InlineFormattingContext::Line::adjustLogicalLeft(LayoutUnit delta)
+{
+    m_availableWidth -= delta;
+    m_logicalRect.shiftLeftTo(m_logicalRect.left() + delta);
+
+    if (!m_firstRunIndex)
+        return;
+
+    auto& inlineRuns = m_formattingState.inlineRuns();
+    for (auto runIndex = *m_firstRunIndex; runIndex < inlineRuns.size(); ++runIndex)
+        inlineRuns[runIndex].moveHorizontally(delta);
+}
+
+void InlineFormattingContext::Line::adjustLogicalRight(LayoutUnit delta)
+{
+    m_availableWidth -= delta;
+    m_logicalRect.shiftRightTo(m_logicalRect.right() - delta);
+}
+
 static LayoutUnit adjustedLineLogicalLeft(TextAlignMode align, LayoutUnit lineLogicalLeft, LayoutUnit remainingWidth)
 {
     switch (align) {