[LFC][IFC] Add line logical top and bottom
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Oct 2018 14:34:54 +0000 (14:34 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Oct 2018 14:34:54 +0000 (14:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=190934

Reviewed by Antti Koivisto.

* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::initializeNewLine const):
(WebCore::Layout::InlineFormattingContext::layoutInlineContent const):
* layout/inlineformatting/InlineFormattingContext.h:
(WebCore::Layout::InlineFormattingContext::Line::isFirstLine const):
(WebCore::Layout::InlineFormattingContext::Line::logicalTop const):
(WebCore::Layout::InlineFormattingContext::Line::logicalBottom const):
* layout/inlineformatting/Line.cpp:
(WebCore::Layout::InlineFormattingContext::Line::init):
(WebCore::Layout::InlineFormattingContext::Line::contentLogicalRight):
(WebCore::Layout::InlineFormattingContext::Line::close):

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

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

index 44ce664..f9bb691 100644 (file)
@@ -1,5 +1,24 @@
 2018-10-26  Zalan Bujtas  <zalan@apple.com>
 
+        [LFC][IFC] Add line logical top and bottom
+        https://bugs.webkit.org/show_bug.cgi?id=190934
+
+        Reviewed by Antti Koivisto.
+
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::initializeNewLine const):
+        (WebCore::Layout::InlineFormattingContext::layoutInlineContent const):
+        * layout/inlineformatting/InlineFormattingContext.h:
+        (WebCore::Layout::InlineFormattingContext::Line::isFirstLine const):
+        (WebCore::Layout::InlineFormattingContext::Line::logicalTop const):
+        (WebCore::Layout::InlineFormattingContext::Line::logicalBottom const):
+        * layout/inlineformatting/Line.cpp:
+        (WebCore::Layout::InlineFormattingContext::Line::init):
+        (WebCore::Layout::InlineFormattingContext::Line::contentLogicalRight):
+        (WebCore::Layout::InlineFormattingContext::Line::close):
+
+2018-10-26  Zalan Bujtas  <zalan@apple.com>
+
         [LFC][IFC] Find floating constraints for a given vertical position
         https://bugs.webkit.org/show_bug.cgi?id=190928
 
index 61b7a62..6f1ab72 100644 (file)
@@ -101,17 +101,30 @@ static bool trimLeadingRun(const InlineLineBreaker::Run& run)
     return run.content.style().collapseWhiteSpace();
 }
 
-void InlineFormattingContext::layoutInlineContent(const LayoutContext& layoutContext, InlineFormattingState& inlineFormattingState, const InlineRunProvider& inlineRunProvider) const
+void InlineFormattingContext::initializeNewLine(const LayoutContext& layoutContext, Line& line) const
 {
     auto& formattingRoot = downcast<Container>(root());
     auto& formattingRootDisplayBox = layoutContext.displayBoxForLayoutBox(formattingRoot);
 
     auto lineLogicalLeft = formattingRootDisplayBox.contentBoxLeft();
+    auto lineLogicalTop = line.isFirstLine() ? formattingRootDisplayBox.contentBoxTop() : line.logicalBottom();
     auto availableWidth = formattingRootDisplayBox.contentBoxWidth();
+
+    Display::Box::Rect logicalRect;
+    logicalRect.setTop(lineLogicalTop);
+    logicalRect.setLeft(lineLogicalLeft);
+    logicalRect.setWidth(availableWidth);
+    logicalRect.setHeight(formattingRoot.style().computedLineHeight());
+
+    line.init(logicalRect);
+}
+
+void InlineFormattingContext::layoutInlineContent(const LayoutContext& layoutContext, InlineFormattingState& inlineFormattingState, const InlineRunProvider& inlineRunProvider) const
+{
     auto previousRunPositionIsLineEnd = false;
 
     Line line(inlineFormattingState, root());
-    line.init(lineLogicalLeft, availableWidth);
+    initializeNewLine(layoutContext, line);
 
     InlineLineBreaker lineBreaker(layoutContext, inlineFormattingState.inlineContent(), inlineRunProvider.runs());
     while (auto run = lineBreaker.nextRun(line.contentLogicalRight(), line.availableWidth(), !line.hasContent())) {
@@ -122,7 +135,7 @@ void InlineFormattingContext::layoutInlineContent(const LayoutContext& layoutCon
             // Previous run ended up being at the line end. Adjust the line accordingly.
             if (!previousRunPositionIsLineEnd) {
                 line.close();
-                line.init(lineLogicalLeft, availableWidth);
+                initializeNewLine(layoutContext, line);
             }
             // Skip leading whitespace.
             if (!trimLeadingRun(*run))
@@ -136,7 +149,7 @@ void InlineFormattingContext::layoutInlineContent(const LayoutContext& layoutCon
             line.appendContent(*run);
             // Move over to the next line.
             line.close();
-            line.init(lineLogicalLeft, availableWidth);
+            initializeNewLine(layoutContext, line);
             continue;
         }
 
index 0683f1c..8a80c39 100644 (file)
@@ -27,6 +27,7 @@
 
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
+#include "DisplayBox.h"
 #include "FormattingContext.h"
 #include "InlineLineBreaker.h"
 #include <wtf/IsoMalloc.h>
@@ -51,15 +52,20 @@ private:
     public:
         Line(InlineFormattingState&, const Box& formattingRoot);
 
-        void init(LayoutUnit lineLogicalLeft, LayoutUnit availableWidth);
+        void init(const Display::Box::Rect&);
+
         void appendContent(const InlineLineBreaker::Run&);
         enum class LastLine { No, Yes };
         void close(LastLine = LastLine::No);
 
         bool hasContent() const { return m_firstRunIndex.has_value(); }
+        bool isFirstLine() const { return m_isFirstLine; }
         LayoutUnit contentLogicalRight();
         LayoutUnit availableWidth() const { return m_availableWidth; }
 
+        LayoutUnit logicalTop() const { return m_logicalRect.top(); }
+        LayoutUnit logicalBottom() const { return m_logicalRect.bottom(); }
+
     private:
         void justifyRuns();
         void computeExpansionOpportunities(const InlineLineBreaker::Run&);
@@ -75,15 +81,16 @@ private:
         InlineFormattingState& m_formattingState;
         const Box& m_formattingRoot;
 
-        LayoutUnit m_lineLogicalLeft;
+        Display::Box::Rect m_logicalRect;
         LayoutUnit m_availableWidth;
-        LayoutUnit m_lineWidth;
 
         std::optional<unsigned> m_firstRunIndex;
         bool m_alignmentIsJustify { false };
+        bool m_isFirstLine { true };
     };
 
     void layoutInlineContent(const LayoutContext&, InlineFormattingState&, const InlineRunProvider&) const;
+    void initializeNewLine(const LayoutContext&, Line&) const;
 
     void computeWidthAndHeight(const LayoutContext&, const Box&) const;
     void computeStaticPosition(const LayoutContext&, const Box&) const override;
index 70c19f8..0ba20ad 100644 (file)
@@ -40,11 +40,10 @@ InlineFormattingContext::Line::Line(InlineFormattingState& formattingState, cons
 {
 }
 
-void InlineFormattingContext::Line::init(LayoutUnit lineLogicalLeft, LayoutUnit availableWidth)
+void InlineFormattingContext::Line::init(const Display::Box::Rect& logicalRect)
 {
-    m_lineLogicalLeft = lineLogicalLeft;
-    m_lineWidth = availableWidth;
-    m_availableWidth = availableWidth;
+    m_logicalRect = logicalRect;
+    m_availableWidth = logicalRect.width();
 
     m_firstRunIndex = { };
     m_lastRunIsWhitespace = false;
@@ -82,7 +81,7 @@ static bool isTrimmableContent(const InlineRunProvider::Run& inlineRun)
 LayoutUnit InlineFormattingContext::Line::contentLogicalRight()
 {
     if (!m_firstRunIndex.has_value())
-        return m_lineLogicalLeft;
+        return m_logicalRect.left();
 
     return m_formattingState.inlineRuns().last().logicalRight();
 }
@@ -214,12 +213,12 @@ void InlineFormattingContext::Line::close(LastLine isLastLine)
         if (!hasContent())
             return;
 
-        auto adjustedLogicalLeft = adjustedLineLogicalLeft(alignment, m_lineLogicalLeft, m_availableWidth);
-        if (m_lineLogicalLeft == adjustedLogicalLeft)
+        auto adjustedLogicalLeft = adjustedLineLogicalLeft(alignment, m_logicalRect.left(), m_availableWidth);
+        if (m_logicalRect.left() == adjustedLogicalLeft)
             return;
 
         auto& inlineRuns = m_formattingState.inlineRuns();
-        auto delta = adjustedLogicalLeft - m_lineLogicalLeft;
+        auto delta = adjustedLogicalLeft - m_logicalRect.left();
         for (auto runIndex = *m_firstRunIndex; runIndex < inlineRuns.size(); ++runIndex)
             inlineRuns[runIndex].setLogicalLeft(inlineRuns[runIndex].logicalLeft() + delta);
     };
@@ -237,7 +236,9 @@ void InlineFormattingContext::Line::close(LastLine isLastLine)
         }
         textAlignment = TextAlignMode::Left;
     }
+
     alignRuns(textAlignment);
+    m_isFirstLine = false;
 }
 
 }