Title: [272116] trunk/Source/WebCore
Revision
272116
Author
[email protected]
Date
2021-01-30 04:57:47 -0800 (Sat, 30 Jan 2021)

Log Message

[LFC][IFC] Adjust the line box stretching (quirky) <br> behavior
https://bugs.webkit.org/show_bug.cgi?id=221173

Reviewed by Antti Koivisto.

In quirks mode when the <br> is nested in an inline box (e.g. <span><br></span>) and it's taller than the root inline box, it
may stretch the line box. See InlineFormattingContext::Quirks::inlineLevelBoxAffectsLineBox for details.

* layout/inlineformatting/InlineFormattingContextQuirks.cpp:
(WebCore::Layout::InlineFormattingContext::Quirks::inlineLevelBoxAffectsLineBox const):
* layout/inlineformatting/InlineLineBox.h:
(WebCore::Layout::LineBox::hasAtomicInlineLevelBox const):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (272115 => 272116)


--- trunk/Source/WebCore/ChangeLog	2021-01-30 12:44:06 UTC (rev 272115)
+++ trunk/Source/WebCore/ChangeLog	2021-01-30 12:57:47 UTC (rev 272116)
@@ -1,5 +1,20 @@
 2021-01-30  Zalan Bujtas  <[email protected]>
 
+        [LFC][IFC] Adjust the line box stretching (quirky) <br> behavior
+        https://bugs.webkit.org/show_bug.cgi?id=221173
+
+        Reviewed by Antti Koivisto.
+
+        In quirks mode when the <br> is nested in an inline box (e.g. <span><br></span>) and it's taller than the root inline box, it
+        may stretch the line box. See InlineFormattingContext::Quirks::inlineLevelBoxAffectsLineBox for details.
+
+        * layout/inlineformatting/InlineFormattingContextQuirks.cpp:
+        (WebCore::Layout::InlineFormattingContext::Quirks::inlineLevelBoxAffectsLineBox const):
+        * layout/inlineformatting/InlineLineBox.h:
+        (WebCore::Layout::LineBox::hasAtomicInlineLevelBox const):
+
+2021-01-30  Zalan Bujtas  <[email protected]>
+
         [LFC][IFC] Remove redundant LineBoxBuilder::isRootLayoutBox function
         https://bugs.webkit.org/show_bug.cgi?id=221170
 

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextQuirks.cpp (272115 => 272116)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextQuirks.cpp	2021-01-30 12:44:06 UTC (rev 272115)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextQuirks.cpp	2021-01-30 12:57:47 UTC (rev 272116)
@@ -47,14 +47,25 @@
     if (inlineLevelBox.isLineBreakBox()) {
         if (layoutState().inStandardsMode())
             return true;
-        // In quirks mode linebreak boxes (<br>) affect the line box when they are inside a non-root inline box (<span></span>) or when
-        // the line has no other inline level box.
-        // e.g <div><img><br></div> should produce a line with no descent.
-        auto& parentInlineBox = lineBox.inlineLevelBoxForLayoutBox(inlineLevelBox.layoutBox().parent());
-        if (!parentInlineBox.isRootInlineBox())
+        // In quirks mode linebreak boxes (<br>) stop affecting the line box when (assume <br> is nested e.g. <span style="font-size: 100px"><br></span>)
+        // 1. the root inline box has content <div>content<br>/div>
+        // 2. there's at least one atomic inline level box on the line e.g <div><img><br></div> or <div><span><img></span><br></div>
+        // 3. there's at least one inline box with content e.g. <div><span>content</span><br></div>
+        if (lineBox.rootInlineBox().hasContent())
+            return false;
+        if (lineBox.hasAtomicInlineLevelBox())
+            return false;
+        // At this point we either have only the <br> on the line or inline boxes with or without content.
+        auto& inlineLevelBoxes = lineBox.nonRootInlineLevelBoxes();
+        ASSERT(!inlineLevelBoxes.isEmpty());
+        if (inlineLevelBoxes.size() == 1)
             return true;
-        // is <br> the only inline level box on the line?
-        return lineBox.nonRootInlineLevelBoxes().size() == 1;
+        for (auto& inlineLevelBox : lineBox.nonRootInlineLevelBoxes()) {
+            // Filter out empty inline boxes e.g. <div><span></span><span></span><br></div>
+            if (inlineLevelBox->isInlineBox() && inlineLevelBox->hasContent())
+                return false;
+        }
+        return true;
     }
     if (inlineLevelBox.isInlineBox()) {
         // Inline boxes (e.g. root inline box or <span>) affects line boxes either through the strut or actual content.

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h (272115 => 272116)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h	2021-01-30 12:44:06 UTC (rev 272115)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h	2021-01-30 12:57:47 UTC (rev 272116)
@@ -144,6 +144,7 @@
     bool hasContent() const { return m_hasContent; }
     bool hasInlineBox() const { return m_boxTypes.contains(InlineLevelBox::Type::InlineBox); }
     bool hasNonInlineBox() const { return m_boxTypes.containsAny({ InlineLevelBox::Type::AtomicInlineLevelBox, InlineLevelBox::Type::LineBreakBox, InlineLevelBox::Type::GenericInlineLevelBox }); }
+    bool hasAtomicInlineLevelBox() const { return m_boxTypes.contains(InlineLevelBox::Type::AtomicInlineLevelBox); }
 
     const InlineLevelBox& inlineLevelBoxForLayoutBox(const Box& layoutBox) const { return *m_inlineLevelBoxRectMap.get(&layoutBox); }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to