- Revision
- 271555
- Author
- [email protected]
- Date
- 2021-01-16 06:28:39 -0800 (Sat, 16 Jan 2021)
Log Message
[LFC][IFC] Do not use LineBox::isConsideredEmpty when checking if inline box stretches the line box.
https://bugs.webkit.org/show_bug.cgi?id=220259
Reviewed by Antti Koivisto.
1. Inline box always have a strut in standards mode and it stretches the line box even when the inline box itself has no content.
<!DOCTYPE html><div>this is a ~100px tall line<span style="font-size: 100px;"></span></div>
2. except when the line is completely empty (the inline box still has a strut but it does not affect the line box).
<!DOCTYPE html><div><span style="font-size: 100px;"></span><span style="font-size: 200px;"></span></div>
3. but not empty like this:
<!DOCTYPE html><div><span style="font-size: 100px;"></span><br></div>
4. or this:
<!DOCTYPE html><div><span style="font-size: 100px;"></span><img src="" style="width: 0px; height: 0px;"></div>
While #2 produces a 0px tall line box, #1, #3 and #4 produce ~100px tall lines.
This change also enables us to remove LineBox:isConsideredEmpty().
* layout/inlineformatting/InlineFormattingContext.h:
* layout/inlineformatting/InlineFormattingContextGeometry.cpp:
(WebCore::Layout::LineBoxBuilder::build):
(WebCore::Layout::LineBoxBuilder::computeLineBoxHeightAndAlignInlineLevelBoxesVertically):
* layout/inlineformatting/InlineFormattingContextQuirks.cpp:
(WebCore::Layout::InlineFormattingContext::Quirks::inlineLevelBoxAffectsLineBox const):
* layout/inlineformatting/InlineLineBox.cpp:
(WebCore::Layout::LineBox::LineBox):
(WebCore::Layout::m_isConsideredEmpty): Deleted.
* layout/inlineformatting/InlineLineBox.h:
(WebCore::Layout::LineBox::horizontalAlignmentOffset const):
(WebCore::Layout::LineBox::isConsideredEmpty const): Deleted.
* layout/inlineformatting/InlineLineBuilder.cpp:
(WebCore::Layout::LineBuilder::layoutInlineContent):
* layout/inlineformatting/InlineLineBuilder.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (271554 => 271555)
--- trunk/Source/WebCore/ChangeLog 2021-01-16 07:57:56 UTC (rev 271554)
+++ trunk/Source/WebCore/ChangeLog 2021-01-16 14:28:39 UTC (rev 271555)
@@ -1,3 +1,41 @@
+2021-01-16 Zalan Bujtas <[email protected]>
+
+ [LFC][IFC] Do not use LineBox::isConsideredEmpty when checking if inline box stretches the line box.
+ https://bugs.webkit.org/show_bug.cgi?id=220259
+
+ Reviewed by Antti Koivisto.
+
+ 1. Inline box always have a strut in standards mode and it stretches the line box even when the inline box itself has no content.
+ <!DOCTYPE html><div>this is a ~100px tall line<span style="font-size: 100px;"></span></div>
+
+ 2. except when the line is completely empty (the inline box still has a strut but it does not affect the line box).
+ <!DOCTYPE html><div><span style="font-size: 100px;"></span><span style="font-size: 200px;"></span></div>
+
+ 3. but not empty like this:
+ <!DOCTYPE html><div><span style="font-size: 100px;"></span><br></div>
+
+ 4. or this:
+ <!DOCTYPE html><div><span style="font-size: 100px;"></span><img src="" style="width: 0px; height: 0px;"></div>
+
+ While #2 produces a 0px tall line box, #1, #3 and #4 produce ~100px tall lines.
+ This change also enables us to remove LineBox:isConsideredEmpty().
+
+ * layout/inlineformatting/InlineFormattingContext.h:
+ * layout/inlineformatting/InlineFormattingContextGeometry.cpp:
+ (WebCore::Layout::LineBoxBuilder::build):
+ (WebCore::Layout::LineBoxBuilder::computeLineBoxHeightAndAlignInlineLevelBoxesVertically):
+ * layout/inlineformatting/InlineFormattingContextQuirks.cpp:
+ (WebCore::Layout::InlineFormattingContext::Quirks::inlineLevelBoxAffectsLineBox const):
+ * layout/inlineformatting/InlineLineBox.cpp:
+ (WebCore::Layout::LineBox::LineBox):
+ (WebCore::Layout::m_isConsideredEmpty): Deleted.
+ * layout/inlineformatting/InlineLineBox.h:
+ (WebCore::Layout::LineBox::horizontalAlignmentOffset const):
+ (WebCore::Layout::LineBox::isConsideredEmpty const): Deleted.
+ * layout/inlineformatting/InlineLineBuilder.cpp:
+ (WebCore::Layout::LineBuilder::layoutInlineContent):
+ * layout/inlineformatting/InlineLineBuilder.h:
+
2021-01-15 Rob Buis <[email protected]>
https://bugs.webkit.org/show_bug.cgi?id=220224
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextGeometry.cpp (271554 => 271555)
--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextGeometry.cpp 2021-01-16 07:57:56 UTC (rev 271554)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextGeometry.cpp 2021-01-16 14:28:39 UTC (rev 271555)
@@ -158,8 +158,7 @@
auto& runs = lineContent.runs;
auto lineLogicalWidth = lineContent.lineLogicalWidth;
auto contentLogicalWidth = lineContent.contentLogicalWidth;
- auto isLineConsideredEmpty = lineContent.isLineConsideredEmpty ? LineBox::IsLineConsideredEmpty::Yes : LineBox::IsLineConsideredEmpty::No;
- auto lineBox = LineBox { lineContent.logicalTopLeft, contentLogicalWidth, isLineConsideredEmpty, runs.size() };
+ auto lineBox = LineBox { lineContent.logicalTopLeft, contentLogicalWidth, runs.size() };
if (auto horizontalAlignmentOffset = Layout::horizontalAlignmentOffset(runs, rootBox().style().textAlign(), lineLogicalWidth, contentLogicalWidth, lineContent.isLastLineWithInlineContent))
lineBox.setHorizontalAlignmentOffset(*horizontalAlignmentOffset);
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextQuirks.cpp (271554 => 271555)
--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextQuirks.cpp 2021-01-16 07:57:56 UTC (rev 271554)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextQuirks.cpp 2021-01-16 14:28:39 UTC (rev 271555)
@@ -66,7 +66,9 @@
}
}
auto inlineBoxHasImaginaryStrut = layoutState().inStandardsMode();
- return inlineBoxHasImaginaryStrut && !lineBox.isConsideredEmpty();
+ // Inline box with strut only stetches the line box when it has additional inline level boxes (not inline boxes) or the root inline box has content.
+ // e.g. <!DOCTYPE html><div"><span style="font-size: 100px;"></span><img src="" style="width: 0px; height: 0px;"></div>
+ return inlineBoxHasImaginaryStrut && (lineBox.hasNonInlineBox() || lineBox.rootInlineBox().hasContent());
}
if (inlineLevelBox.isAtomicInlineLevelBox()) {
if (inlineLevelBox.layoutBounds().height())
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.cpp (271554 => 271555)
--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.cpp 2021-01-16 07:57:56 UTC (rev 271554)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.cpp 2021-01-16 14:28:39 UTC (rev 271555)
@@ -83,9 +83,8 @@
return verticalAlignment == VerticalAlign::Top || verticalAlignment == VerticalAlign::Bottom;
}
-LineBox::LineBox(const InlineLayoutPoint& logicalTopleft, InlineLayoutUnit contentLogicalWidth, IsLineConsideredEmpty isLineConsideredEmpty, size_t numberOfRuns)
+LineBox::LineBox(const InlineLayoutPoint& logicalTopleft, InlineLayoutUnit contentLogicalWidth, size_t numberOfRuns)
: m_logicalRect(logicalTopleft, InlineLayoutSize { contentLogicalWidth, { } })
- , m_isConsideredEmpty(isLineConsideredEmpty == IsLineConsideredEmpty::Yes)
{
m_nonRootInlineLevelBoxList.reserveInitialCapacity(numberOfRuns);
m_inlineLevelBoxRectMap.reserveInitialCapacity(numberOfRuns);
@@ -99,7 +98,7 @@
void LineBox::addInlineLevelBox(std::unique_ptr<InlineLevelBox>&& inlineLevelBox)
{
- m_hasInlineBox = m_hasInlineBox || inlineLevelBox->isInlineBox();
+ m_boxTypes.add(inlineLevelBox->type());
m_inlineLevelBoxRectMap.set(&inlineLevelBox->layoutBox(), inlineLevelBox.get());
m_nonRootInlineLevelBoxList.append(WTFMove(inlineLevelBox));
}
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h (271554 => 271555)
--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h 2021-01-16 07:57:56 UTC (rev 271554)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h 2021-01-16 14:28:39 UTC (rev 271555)
@@ -90,13 +90,15 @@
bool isLineBreakBox() const { return m_type == Type::LineBreakBox; }
bool hasLineBoxRelativeAlignment() const;
- enum class Type {
- InlineBox,
- RootInlineBox,
- AtomicInlineLevelBox,
- LineBreakBox,
- GenericInlineLevelBox
+ enum class Type : uint8_t {
+ InlineBox = 1 << 0,
+ RootInlineBox = 1 << 1,
+ AtomicInlineLevelBox = 1 << 2,
+ LineBreakBox = 1 << 3,
+ GenericInlineLevelBox = 1 << 4
};
+ Type type() const { return m_type; }
+
InlineLevelBox(const Box&, InlineLayoutUnit logicalLeft, InlineLayoutSize, Type);
InlineLevelBox() = default;
@@ -128,8 +130,7 @@
Type m_type { Type::InlineBox };
};
- enum class IsLineConsideredEmpty { No, Yes };
- LineBox(const InlineLayoutPoint& logicalTopLeft, InlineLayoutUnit logicalWidth, IsLineConsideredEmpty, size_t numberOfRuns);
+ LineBox(const InlineLayoutPoint& logicalTopLeft, InlineLayoutUnit logicalWidth, size_t numberOfRuns);
const InlineRect& logicalRect() const { return m_logicalRect; }
InlineLayoutUnit logicalWidth() const { return logicalSize().width(); }
@@ -138,8 +139,8 @@
InlineLayoutSize logicalSize() const { return logicalRect().size(); }
Optional<InlineLayoutUnit> horizontalAlignmentOffset() const { return m_horizontalAlignmentOffset; }
- bool isConsideredEmpty() const { return m_isConsideredEmpty; }
- bool hasInlineBox() const { return m_hasInlineBox; }
+ 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 }); }
const InlineLevelBox& inlineLevelBoxForLayoutBox(const Box& layoutBox) const { return *m_inlineLevelBoxRectMap.get(&layoutBox); }
@@ -169,8 +170,7 @@
private:
InlineRect m_logicalRect;
Optional<InlineLayoutUnit> m_horizontalAlignmentOffset;
- bool m_isConsideredEmpty { true };
- bool m_hasInlineBox { false };
+ OptionSet<InlineLevelBox::Type> m_boxTypes;
std::unique_ptr<InlineLevelBox> m_rootInlineBox;
InlineLevelBoxList m_nonRootInlineLevelBoxList;
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp (271554 => 271555)
--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp 2021-01-16 07:57:56 UTC (rev 271554)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp 2021-01-16 14:28:39 UTC (rev 271555)
@@ -264,7 +264,6 @@
, m_lineLogicalRect.topLeft()
, m_lineLogicalRect.width()
, m_line.contentLogicalWidth()
- , m_line.isConsideredEmpty()
, isLastLine
, m_line.runs()};
}
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.h (271554 => 271555)
--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.h 2021-01-16 07:57:56 UTC (rev 271554)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.h 2021-01-16 14:28:39 UTC (rev 271555)
@@ -57,7 +57,6 @@
InlineLayoutPoint logicalTopLeft;
InlineLayoutUnit lineLogicalWidth;
InlineLayoutUnit contentLogicalWidth;
- bool isLineConsideredEmpty { true };
bool isLastLineWithInlineContent { true };
const Line::RunList& runs;
};