Title: [268825] trunk/Source/WebCore
Revision
268825
Author
[email protected]
Date
2020-10-21 14:24:06 -0700 (Wed, 21 Oct 2020)

Log Message

[LFC][Integration] Add content dependent vertical line snapping
https://bugs.webkit.org/show_bug.cgi?id=218034

Reviewed by Antti Koivisto.

This patch ensures that IFC integration line snapping matches the legacy line layout snapping behavior (e.g. images prevent line snapping).

* layout/inlineformatting/InlineLineBox.h:
(WebCore::Layout::LineBox::InlineLevelBox::isAtomicInlineLevelBox const):
* layout/integration/LayoutIntegrationLineLayout.cpp:
(WebCore::LayoutIntegration::LineLayout::constructContent):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (268824 => 268825)


--- trunk/Source/WebCore/ChangeLog	2020-10-21 21:23:52 UTC (rev 268824)
+++ trunk/Source/WebCore/ChangeLog	2020-10-21 21:24:06 UTC (rev 268825)
@@ -1,5 +1,19 @@
 2020-10-21  Zalan Bujtas  <[email protected]>
 
+        [LFC][Integration] Add content dependent vertical line snapping
+        https://bugs.webkit.org/show_bug.cgi?id=218034
+
+        Reviewed by Antti Koivisto.
+
+        This patch ensures that IFC integration line snapping matches the legacy line layout snapping behavior (e.g. images prevent line snapping).
+
+        * layout/inlineformatting/InlineLineBox.h:
+        (WebCore::Layout::LineBox::InlineLevelBox::isAtomicInlineLevelBox const):
+        * layout/integration/LayoutIntegrationLineLayout.cpp:
+        (WebCore::LayoutIntegration::LineLayout::constructContent):
+
+2020-10-21  Zalan Bujtas  <[email protected]>
+
         [LFC][IFC] Apply font line-spacing to <br> inline level box
         https://bugs.webkit.org/show_bug.cgi?id=218043
 

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h (268824 => 268825)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h	2020-10-21 21:23:52 UTC (rev 268824)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h	2020-10-21 21:24:06 UTC (rev 268825)
@@ -83,6 +83,7 @@
         const Box& layoutBox() const { return *m_layoutBox; }
 
         bool isInlineBox() const { return m_type == Type::InlineBox || m_type == Type::RootInlineBox; }
+        bool isAtomicInlineLevelBox() const { return m_type == Type::AtomicInlineLevelBox; }
         bool isLineBreakBox() const { return m_type == Type::LineBreakBox; }
         bool hasLineBoxRelativeAlignment() const;
 

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp (268824 => 268825)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp	2020-10-21 21:23:52 UTC (rev 268824)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp	2020-10-21 21:24:06 UTC (rev 268825)
@@ -138,8 +138,31 @@
 {
     auto& displayInlineContent = ensureInlineContent();
 
+    auto lineNeedsLegacyIntegralVerticalPosition = [&](size_t lineIndex) {
+        RELEASE_ASSERT(m_inlineFormattingState.lineBoxes().size() > lineIndex);
+        // InlineTree rounds y position to integral value for certain content (see InlineFlowBox::placeBoxesInBlockDirection).
+        auto inlineLevelBoxList = m_inlineFormattingState.lineBoxes()[lineIndex].inlineLevelBoxList();
+        if (inlineLevelBoxList.size() == 1) {
+            // This is text content only with root inline box.
+            return true;
+        }
+        // Text + <br> (or just <br> or text<span></span><br>) behaves like text.
+        for (auto& inlineLevelBox : inlineLevelBoxList) {
+            if (inlineLevelBox->isAtomicInlineLevelBox()) {
+                // Content like text<img> prevents legacy snapping.
+                return false;
+            }
+        }
+        return true;
+    };
+
     auto constructDisplayLineRuns = [&] {
         auto initialContaingBlockSize = m_layoutState.viewportSize();
+        struct LineLegacyVerticalPositionPolicy {
+            size_t lineIndex { 0 };
+            bool needsIntegralPosition { true }; 
+        };
+        auto lineLegacyVerticalPositionPolicy = LineLegacyVerticalPositionPolicy { 0, lineNeedsLegacyIntegralVerticalPosition(0) };
         for (auto& lineRun : m_inlineFormattingState.lineRuns()) {
             auto& layoutBox = lineRun.layoutBox();
             auto computedInkOverflow = [&] (auto runRect) {
@@ -164,9 +187,9 @@
             auto lineIndex = lineRun.lineIndex();
             auto lineBoxLogicalRect = m_inlineFormattingState.lines()[lineIndex].lineBoxLogicalRect();
             runRect.moveBy({ lineBoxLogicalRect.left(), lineBoxLogicalRect.top() });
-            // InlineTree rounds y position to integral value, see InlineFlowBox::placeBoxesInBlockDirection.
-            auto needsLegacyIntegralPosition = !layoutBox.isReplacedBox();
-            if (needsLegacyIntegralPosition)
+            if (lineIndex != lineLegacyVerticalPositionPolicy.lineIndex)
+                lineLegacyVerticalPositionPolicy = LineLegacyVerticalPositionPolicy { lineIndex, lineNeedsLegacyIntegralVerticalPosition(lineIndex) };
+            if (lineLegacyVerticalPositionPolicy.needsIntegralPosition)
                 runRect.setY(roundToInt(runRect.y()));
 
             WTF::Optional<Run::TextContent> textContent;
@@ -215,8 +238,8 @@
             auto lineRect = FloatRect { line.logicalRect() };
             // Painting code (specifically TextRun's xPos) needs the line box offset to be able to compute tab positions.
             lineRect.setX(lineBoxLogicalRect.left());
-            // InlineTree rounds y position to integral value, see InlineFlowBox::placeBoxesInBlockDirection.
-            lineRect.setY(roundToInt(lineRect.y()));
+            if (lineNeedsLegacyIntegralVerticalPosition(lineIndex))
+                lineRect.setY(roundToInt(lineRect.y()));
             displayInlineContent.lines.append({ firstRunIndex, runCount, lineRect, scrollableOverflowRect, lineInkOverflowRect, line.baseline(), line.horizontalAlignmentOffset() });
         }
     };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to