Title: [287244] trunk/Source/WebCore
Revision
287244
Author
[email protected]
Date
2021-12-19 11:44:48 -0800 (Sun, 19 Dec 2021)

Log Message

[LFC][IFC] text-indent is treated as a margin applied to the start edge of the line box.
https://bugs.webkit.org/show_bug.cgi?id=234460

Reviewed by Antti Koivisto.

See https://drafts.csswg.org/css-text/#text-indent-property
This is also in preparation for adjusting the display line geometry when the inline axis direction is rtl.

* layout/formattingContexts/inline/InlineLineBuilder.cpp:
(WebCore::Layout::LineBuilder::layoutInlineContent):
(WebCore::Layout::LineBuilder::initialize):
(WebCore::Layout::LineBuilder::initialConstraintsForLine const):
* layout/formattingContexts/inline/InlineLineBuilder.h:
* layout/formattingContexts/inline/InlineRect.h:
(WebCore::Layout::InlineRect::moveLeftBy):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (287243 => 287244)


--- trunk/Source/WebCore/ChangeLog	2021-12-19 18:52:49 UTC (rev 287243)
+++ trunk/Source/WebCore/ChangeLog	2021-12-19 19:44:48 UTC (rev 287244)
@@ -1,3 +1,21 @@
+2021-12-19  Alan Bujtas  <[email protected]>
+
+        [LFC][IFC] text-indent is treated as a margin applied to the start edge of the line box.
+        https://bugs.webkit.org/show_bug.cgi?id=234460
+
+        Reviewed by Antti Koivisto.
+
+        See https://drafts.csswg.org/css-text/#text-indent-property
+        This is also in preparation for adjusting the display line geometry when the inline axis direction is rtl.
+
+        * layout/formattingContexts/inline/InlineLineBuilder.cpp:
+        (WebCore::Layout::LineBuilder::layoutInlineContent):
+        (WebCore::Layout::LineBuilder::initialize):
+        (WebCore::Layout::LineBuilder::initialConstraintsForLine const):
+        * layout/formattingContexts/inline/InlineLineBuilder.h:
+        * layout/formattingContexts/inline/InlineRect.h:
+        (WebCore::Layout::InlineRect::moveLeftBy):
+
 2021-12-19  Simon Fraser  <[email protected]>
 
         Keyboard shortcut to scroll to top when already at the top of the page moves to the bottom

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBoxBuilder.cpp (287243 => 287244)


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBoxBuilder.cpp	2021-12-19 18:52:49 UTC (rev 287243)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBoxBuilder.cpp	2021-12-19 19:44:48 UTC (rev 287244)
@@ -112,7 +112,7 @@
     auto lineBoxLogicalHeight = constructAndAlignInlineLevelBoxes(lineBox, lineContent.runs, lineIndex);
 
     auto line = [&] {
-        auto lineBoxLogicalRect = InlineRect { lineContent.logicalTopLeft, lineContent.lineLogicalWidth, lineBoxLogicalHeight };
+        auto lineBoxLogicalRect = InlineRect { lineContent.lineLogicalTopLeft, lineContent.lineLogicalWidth, lineBoxLogicalHeight };
         auto scrollableOverflowRect = lineBoxLogicalRect;
         auto& rootInlineBox = lineBox.rootInlineBox();
         auto enclosingTopAndBottom = InlineDisplay::Line::EnclosingTopAndBottom { lineBoxLogicalRect.top() + rootInlineBox.logicalTop(), lineBoxLogicalRect.top() + rootInlineBox.logicalBottom() };

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.cpp (287243 => 287244)


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.cpp	2021-12-19 18:52:49 UTC (rev 287243)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.cpp	2021-12-19 19:44:48 UTC (rev 287244)
@@ -288,6 +288,11 @@
 {
 }
 
+struct UsedConstraints {
+    InlineRect logicalRect;
+    InlineLayoutUnit marginStart { 0 };
+    bool isConstrainedByFloat { false };
+};
 LineBuilder::LineContent LineBuilder::layoutInlineContent(const InlineItemRange& needsLayoutRange, size_t partialLeadingContentLength, std::optional<InlineLayoutUnit> overflowingLogicalWidth, const InlineRect& initialLineLogicalRect, bool isFirstLine)
 {
     initialize(initialConstraintsForLine(initialLineLogicalRect, isFirstLine), isFirstLine, needsLayoutRange.start, partialLeadingContentLength, overflowingLogicalWidth);
@@ -332,6 +337,7 @@
         , committedContent.overflowLogicalWidth
         , m_floats
         , m_contentIsConstrainedByFloat
+        , m_lineMarginStart
         , m_lineLogicalRect.topLeft()
         , m_lineLogicalRect.width()
         , m_line.contentLogicalWidth()
@@ -351,7 +357,7 @@
 
     auto committedContent = placeInlineContent(needsLayoutRange);
     auto committedRange = close(needsLayoutRange, committedContent);
-    auto lineWidth = lineConstraints.logicalRect.left() + m_line.contentLogicalWidth();
+    auto lineWidth = lineConstraints.logicalRect.left() + lineConstraints.marginStart + m_line.contentLogicalWidth();
     return { committedRange, lineWidth, m_floats };
 }
 
@@ -395,7 +401,12 @@
     createLineSpanningInlineBoxes();
     m_line.initialize(m_lineSpanningInlineBoxes);
 
+    m_lineMarginStart = lineConstraints.marginStart;
     m_lineLogicalRect = lineConstraints.logicalRect;
+    m_lineLogicalRect.moveHorizontally(m_lineMarginStart);
+    // While negative margins normally don't expand the available space, preferred width computation gets confused by negative text-indent
+    // (shrink the space needed for the content) which we have to balance it here.
+    m_lineLogicalRect.expandHorizontally(-m_lineMarginStart);
     m_contentIsConstrainedByFloat = lineConstraints.isConstrainedByFloat;
 
     if (partialLeadingContentLength) {
@@ -547,7 +558,7 @@
     return HorizontalConstraints { toLayoutUnit(lineLogicalLeft), toLayoutUnit(lineLogicalRight - lineLogicalLeft) };
 }
 
-LineBuilder::UsedConstraints LineBuilder::initialConstraintsForLine(const InlineRect& initialLineLogicalRect, bool isFirstLine) const
+UsedConstraints LineBuilder::initialConstraintsForLine(const InlineRect& initialLineLogicalRect, bool isFirstLine) const
 {
     auto lineLogicalLeft = initialLineLogicalRect.left();
     auto lineLogicalRight = initialLineLogicalRect.right();
@@ -598,8 +609,7 @@
         }
         return { minimumValueForLength(textIndent, initialLineLogicalRect.width()) };
     };
-    lineLogicalLeft += computedTextIndent();
-    return UsedConstraints { { initialLineLogicalRect.top(), lineLogicalLeft, lineLogicalRight - lineLogicalLeft, initialLineLogicalRect.height() }, lineIsConstrainedByFloat };
+    return UsedConstraints { { initialLineLogicalRect.top(), lineLogicalLeft, lineLogicalRight - lineLogicalLeft, initialLineLogicalRect.height() }, computedTextIndent(), lineIsConstrainedByFloat };
 }
 
 void LineBuilder::candidateContentForLine(LineCandidate& lineCandidate, size_t currentInlineItemIndex, const InlineItemRange& layoutRange, InlineLayoutUnit currentLogicalRight)

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.h (287243 => 287244)


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.h	2021-12-19 18:52:49 UTC (rev 287243)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.h	2021-12-19 19:44:48 UTC (rev 287244)
@@ -37,6 +37,7 @@
 
 class FloatingContext;
 struct LineCandidate;
+struct UsedConstraints;
 
 class LineBuilder {
 public:
@@ -56,7 +57,8 @@
         std::optional<InlineLayoutUnit> overflowLogicalWidth;
         const FloatList& floats;
         bool hasIntrusiveFloat { false };
-        InlineLayoutPoint logicalTopLeft;
+        InlineLayoutUnit lineMarginStart { 0 };
+        InlineLayoutPoint lineLogicalTopLeft;
         InlineLayoutUnit lineLogicalWidth { 0 };
         InlineLayoutUnit contentLogicalWidth { 0 };
         InlineLayoutUnit hangingWhitespaceWidth { 0 };
@@ -88,10 +90,6 @@
         size_t partialTrailingContentLength { 0 };
         std::optional<InlineLayoutUnit> overflowLogicalWidth { };
     };
-    struct UsedConstraints {
-        InlineRect logicalRect;
-        bool isConstrainedByFloat { false };
-    };
     UsedConstraints initialConstraintsForLine(const InlineRect& initialLineLogicalRect, bool isFirstLine) const;
     std::optional<HorizontalConstraints> floatConstraints(const InlineRect& lineLogicalRect) const;
 
@@ -132,6 +130,7 @@
 
     Line m_line;
     InlineRect m_lineLogicalRect;
+    InlineLayoutUnit m_lineMarginStart { 0 };
     const InlineItems& m_inlineItems;
     FloatList m_floats;
     std::optional<InlineTextItem> m_partialLeadingTextItem;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to