Title: [246158] trunk/Source/WebCore
Revision
246158
Author
[email protected]
Date
2019-06-06 09:53:29 -0700 (Thu, 06 Jun 2019)

Log Message

[LFC][IFC] Move baseline and line height computation to a dedicated function
https://bugs.webkit.org/show_bug.cgi?id=198611
<rdar://problem/51482708>

Reviewed by Antti Koivisto.

This is in preparation for adding vertical aligment.

* layout/inlineformatting/InlineLine.cpp:
(WebCore::Layout::Line::appendInlineContainerStart):
(WebCore::Layout::Line::appendNonReplacedInlineBox):
(WebCore::Layout::Line::adjustBaselineAndLineHeight):
* layout/inlineformatting/InlineLine.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (246157 => 246158)


--- trunk/Source/WebCore/ChangeLog	2019-06-06 16:50:49 UTC (rev 246157)
+++ trunk/Source/WebCore/ChangeLog	2019-06-06 16:53:29 UTC (rev 246158)
@@ -1,3 +1,19 @@
+2019-06-06  Zalan Bujtas  <[email protected]>
+
+        [LFC][IFC] Move baseline and line height computation to a dedicated function
+        https://bugs.webkit.org/show_bug.cgi?id=198611
+        <rdar://problem/51482708>
+
+        Reviewed by Antti Koivisto.
+
+        This is in preparation for adding vertical aligment.
+
+        * layout/inlineformatting/InlineLine.cpp:
+        (WebCore::Layout::Line::appendInlineContainerStart):
+        (WebCore::Layout::Line::appendNonReplacedInlineBox):
+        (WebCore::Layout::Line::adjustBaselineAndLineHeight):
+        * layout/inlineformatting/InlineLine.h:
+
 2019-06-06  Antti Koivisto  <[email protected]>
 
         Position fixed is buggy with overflow:auto scrolling inside iframes

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp (246157 => 246158)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp	2019-06-06 16:50:49 UTC (rev 246157)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp	2019-06-06 16:53:29 UTC (rev 246158)
@@ -121,22 +121,13 @@
 
 void Line::appendInlineContainerStart(const InlineItem& inlineItem, InlineItemSize runSize)
 {
+    if (runSize.logicalHeight)
+        adjustBaselineAndLineHeight(inlineItem, *runSize.logicalHeight);
+
     auto& layoutBox = inlineItem.layoutBox();
-    auto& style = layoutBox.style();
-    auto& fontMetrics = style.fontMetrics();
+    auto& fontMetrics = layoutBox.style().fontMetrics();
+    auto& displayBox = m_layoutState.displayBoxForLayoutBox(layoutBox);
 
-    auto alignAndAdjustLineHeight = [&] {
-        LayoutUnit inlineBoxHeight = style.computedLineHeight();
-
-        auto halfLeading = halfLeadingMetrics(fontMetrics, inlineBoxHeight);
-        if (halfLeading.depth > 0)
-            m_logicalHeight.depth = std::max(m_logicalHeight.depth, halfLeading.depth);
-        if (halfLeading.height > 0)
-            m_logicalHeight.height = std::max(m_logicalHeight.height, halfLeading.height);
-    };
-
-    alignAndAdjustLineHeight();
-    auto& displayBox = m_layoutState.displayBoxForLayoutBox(layoutBox);
     auto logicalTop = -fontMetrics.ascent() - displayBox.borderTop() - displayBox.paddingTop().valueOr(0);
     auto logicalRect = Display::Rect { logicalTop, contentLogicalRight(), runSize.logicalWidth, runSize.logicalHeight.valueOr(0) };
     appendNonBreakableSpace(inlineItem, logicalRect);
@@ -191,23 +182,10 @@
 
 void Line::appendNonReplacedInlineBox(const InlineItem& inlineItem, InlineItemSize runSize)
 {
+    if (runSize.logicalHeight)
+        adjustBaselineAndLineHeight(inlineItem, *runSize.logicalHeight);
+
     auto inlineBoxHeight = runSize.logicalHeight.valueOr(0);
-    auto alignAndAdjustLineHeight = [&] {
-        // FIXME: We need to look inside the inline-block's formatting context and check the lineboxes (if any) to be able to baseline align.
-        if (inlineItem.layoutBox().establishesInlineFormattingContext()) {
-            if (inlineBoxHeight == logicalHeight())
-                return;
-            // FIXME: This fails when the line height difference comes from font-size diff.
-            m_logicalHeight.depth = std::max<LayoutUnit>(0, m_logicalHeight.depth);
-            m_logicalHeight.height = std::max(inlineBoxHeight, m_logicalHeight.height);
-            return;
-        }
-        // 0 descent -> baseline aligment for now.
-        m_logicalHeight.depth = std::max<LayoutUnit>(0, m_logicalHeight.depth);
-        m_logicalHeight.height = std::max(inlineBoxHeight, m_logicalHeight.height);
-    };
-
-    alignAndAdjustLineHeight();
     auto& displayBox = m_layoutState.displayBoxForLayoutBox(inlineItem.layoutBox());
     auto logicalTop = -inlineBoxHeight;
     auto horizontalMargin = displayBox.horizontalMargin();
@@ -231,6 +209,36 @@
     m_content->runs().append(std::make_unique<Content::Run>(Display::Run { logicalRect }, inlineItem, false, false));
 }
 
+void Line::adjustBaselineAndLineHeight(const InlineItem& inlineItem, LayoutUnit runHeight)
+{
+    ASSERT(!inlineItem.isContainerEnd() && !inlineItem.isText());
+    auto& layoutBox = inlineItem.layoutBox();
+    auto& style = layoutBox.style();
+
+    if (inlineItem.isContainerStart()) {
+        auto& fontMetrics = style.fontMetrics();
+        auto halfLeading = halfLeadingMetrics(fontMetrics, style.computedLineHeight());
+        if (halfLeading.depth > 0)
+            m_logicalHeight.depth = std::max(m_logicalHeight.depth, halfLeading.depth);
+        if (halfLeading.height > 0)
+            m_logicalHeight.height = std::max(m_logicalHeight.height, halfLeading.height);
+        return;
+    }
+    // Replaced and non-replaced inline level box.
+    // FIXME: We need to look inside the inline-block's formatting context and check the lineboxes (if any) to be able to baseline align.
+    if (layoutBox.establishesInlineFormattingContext()) {
+        if (runHeight == logicalHeight())
+            return;
+        // FIXME: This fails when the line height difference comes from font-size diff.
+        m_logicalHeight.depth = std::max<LayoutUnit>(0, m_logicalHeight.depth);
+        m_logicalHeight.height = std::max(runHeight, m_logicalHeight.height);
+        return;
+    }
+    // 0 descent -> baseline aligment for now.
+    m_logicalHeight.depth = std::max<LayoutUnit>(0, m_logicalHeight.depth);
+    m_logicalHeight.height = std::max(runHeight, m_logicalHeight.height);
+}
+
 Line::UsedHeightAndDepth Line::halfLeadingMetrics(const FontMetrics& fontMetrics, LayoutUnit lineLogicalHeight)
 {
     auto ascent = fontMetrics.ascent();

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLine.h (246157 => 246158)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLine.h	2019-06-06 16:50:49 UTC (rev 246157)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLine.h	2019-06-06 16:53:29 UTC (rev 246158)
@@ -116,6 +116,8 @@
     void appendNonBreakableSpace(const InlineItem&, const Display::Rect& logicalRect);
     void removeTrailingTrimmableContent();
 
+    void adjustBaselineAndLineHeight(const InlineItem&, LayoutUnit runHeight);
+
     const LayoutState& m_layoutState;
     std::unique_ptr<Content> m_content;
     ListHashSet<Content::Run*> m_trimmableContent;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to