Title: [273815] trunk/Source/WebCore
Revision
273815
Author
za...@apple.com
Date
2021-03-03 08:34:03 -0800 (Wed, 03 Mar 2021)

Log Message

[LFC][IFC] Enable simplified vertical alignment for empty inline boxes
https://bugs.webkit.org/show_bug.cgi?id=222630

Reviewed by Antti Koivisto.

This patch enables the simplified vertical alignment for cases when the line has non-stretching empty inline boxes.
e.g.
<div>text<span></span>content</div>
but not
<div>text<span style="font-size: 100px"></span>content</div> (in standards mode the empty inline box starts with a strut, so this would be stretching the root inline box to ~100px).

* layout/inlineformatting/InlineFormattingContextGeometry.cpp:
(WebCore::Layout::LineBoxBuilder::constructAndAlignInlineLevelBoxes):
(WebCore::Layout::LineBoxBuilder::SimplifiedVerticalAlignment::canUseSimplifiedAlignment):
(WebCore::Layout::LineBoxBuilder::SimplifiedVerticalAlignment::align):
* layout/inlineformatting/InlineLineBox.h:
(WebCore::Layout::LineBox::InlineLevelBox::LayoutBounds::operator== const):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (273814 => 273815)


--- trunk/Source/WebCore/ChangeLog	2021-03-03 16:02:09 UTC (rev 273814)
+++ trunk/Source/WebCore/ChangeLog	2021-03-03 16:34:03 UTC (rev 273815)
@@ -1,3 +1,23 @@
+2021-03-03  Zalan Bujtas  <za...@apple.com>
+
+        [LFC][IFC] Enable simplified vertical alignment for empty inline boxes
+        https://bugs.webkit.org/show_bug.cgi?id=222630
+
+        Reviewed by Antti Koivisto.
+
+        This patch enables the simplified vertical alignment for cases when the line has non-stretching empty inline boxes.
+        e.g.
+        <div>text<span></span>content</div>
+        but not
+        <div>text<span style="font-size: 100px"></span>content</div> (in standards mode the empty inline box starts with a strut, so this would be stretching the root inline box to ~100px).
+
+        * layout/inlineformatting/InlineFormattingContextGeometry.cpp:
+        (WebCore::Layout::LineBoxBuilder::constructAndAlignInlineLevelBoxes):
+        (WebCore::Layout::LineBoxBuilder::SimplifiedVerticalAlignment::canUseSimplifiedAlignment):
+        (WebCore::Layout::LineBoxBuilder::SimplifiedVerticalAlignment::align):
+        * layout/inlineformatting/InlineLineBox.h:
+        (WebCore::Layout::LineBox::InlineLevelBox::LayoutBounds::operator== const):
+
 2021-03-02  Manuel Rego Casasnovas  <r...@igalia.com>
 
         [selectors] :focus-visible implementation

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextGeometry.cpp (273814 => 273815)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextGeometry.cpp	2021-03-03 16:02:09 UTC (rev 273814)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextGeometry.cpp	2021-03-03 16:34:03 UTC (rev 273815)
@@ -341,7 +341,6 @@
             auto inlineBox = LineBox::InlineLevelBox::createInlineBox(layoutBox, logicalLeft, initialLogicalWidth);
             setVerticalGeometryForInlineBox(*inlineBox);
             lineBox.addInlineLevelBox(WTFMove(inlineBox));
-            simplifiedVerticalAlignment.setEnabled(!lineHasContent);
             continue;
         }
         if (run.isInlineBoxEnd()) {
@@ -349,10 +348,11 @@
             auto& inlineBox = lineBox.inlineLevelBoxForLayoutBox(layoutBox);
             ASSERT(inlineBox.isInlineBox());
             // Inline box run is based on margin box. Let's convert it to border box.
-            auto marginEnd = std::max(0_lu, formattingContext().geometryForBox(layoutBox).marginEnd());
+            auto& inlineBoxGeometry = formattingContext().geometryForBox(layoutBox);
+            auto marginEnd = std::max(0_lu, inlineBoxGeometry.marginEnd());
             auto inlineBoxLogicalRight = logicalLeft + run.logicalWidth() - marginEnd;
             inlineBox.setLogicalWidth(inlineBoxLogicalRight - inlineBox.logicalLeft());
-            simplifiedVerticalAlignment.setEnabled(!lineHasContent);
+            simplifiedAlignVerticallyIfApplicable(inlineBox, inlineBoxGeometry);
             continue;
         }
         if (run.isText() || run.isSoftLineBreak()) {
@@ -638,16 +638,18 @@
     }
     if (inlineLevelBox.isLineBreakBox()) {
         // Baseline aligned, non-stretchy line breaks e.g. <div><span><br></span></div> but not <div><span style="font-size: 100px;"><br></span></div>.
-        auto& layoutBox = inlineLevelBox.layoutBox();
-        return layoutBox.style().verticalAlign() == VerticalAlign::Baseline
-            && inlineLevelBox.baseline() <= rootInlineBox.baseline();
+        return inlineLevelBox.layoutBox().style().verticalAlign() == VerticalAlign::Baseline && inlineLevelBox.baseline() <= rootInlineBox.baseline();
     }
+    if (inlineLevelBox.isInlineBox()) {
+        // Baseline aligned, non-stretchy inline boxes e.g. <div><span></span></div> but not <div><span style="font-size: 100px;"></span></div>.
+        return inlineLevelBox.layoutBox().style().verticalAlign() == VerticalAlign::Baseline && inlineLevelBox.layoutBounds() == rootInlineBox.layoutBounds();
+    }
     return false;
 }
 
 void LineBoxBuilder::SimplifiedVerticalAlignment::align(LineBox::InlineLevelBox& inlineLevelBox)
 {
-    if (inlineLevelBox.isAtomicInlineLevelBox() || inlineLevelBox.isLineBreakBox()) {
+    if (inlineLevelBox.isAtomicInlineLevelBox() || inlineLevelBox.isLineBreakBox() || inlineLevelBox.isInlineBox()) {
         // Only baseline alignment for now.
         inlineLevelBox.setLogicalTop(m_rootInlineBox.baseline() - inlineLevelBox.baseline());
         adjust(inlineLevelBox);

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h (273814 => 273815)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h	2021-03-03 16:02:09 UTC (rev 273814)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h	2021-03-03 16:34:03 UTC (rev 273815)
@@ -72,6 +72,7 @@
         // See https://www.w3.org/TR/css-inline-3/#layout-bounds
         struct LayoutBounds {
             InlineLayoutUnit height() const { return ascent + descent; }
+            bool operator==(const LayoutBounds& other) const { return ascent == other.ascent && descent == other.descent; }
 
             InlineLayoutUnit ascent { 0 };
             InlineLayoutUnit descent { 0 };
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to