Skip to content
Permalink
Browse files
[LFC][IFC][Floats] Incorrect content placement when first-line style …
…is present in non-quirks mode

https://bugs.webkit.org/show_bug.cgi?id=245917

Reviewed by Antti Koivisto.

Use the first line style to compute the initial line height of the first line.

* LayoutTests/fast/inline/tall-first-line-with-multiple-floats-expected.html: Added.
* LayoutTests/fast/inline/tall-first-line-with-multiple-floats.html: Added.
* Source/WebCore/layout/formattingContexts/inline/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::lineLayout):
* Source/WebCore/layout/formattingContexts/inline/InlineFormattingGeometry.cpp:
(WebCore::Layout::InlineFormattingGeometry::initialLineHeight const):
* Source/WebCore/layout/formattingContexts/inline/InlineFormattingGeometry.h:
* Source/WebCore/layout/formattingContexts/inline/InlineFormattingQuirks.cpp:
(WebCore::Layout::InlineFormattingQuirks::initialLineHeight const):
* Source/WebCore/layout/formattingContexts/inline/InlineFormattingQuirks.h:

Canonical link: https://commits.webkit.org/255069@main
  • Loading branch information
alanbaradlay committed Oct 2, 2022
1 parent a8f81aa commit 73f3eb85f0fd6cb01d2f6cf4294d554b41916b0b
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 8 deletions.
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<style>
.container {
line-height: 190px;
}

img {
background: blue;
width: 50px;
height: 50px;
}

.narrowfloat {
float: left;
width: 50px;
height: 50px;
background-color: green;
}

.widefloat {
float: left;
clear: left;
width: 100px;
height: 50px;
background-color: green;
}
</style>
<div class="container"><div class="narrowfloat"></div><div class="widefloat"></div><img></div>
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<style>
.container:first-line {
line-height: 190px;
}

img {
background: blue;
width: 50px;
height: 50px;
}

.narrowfloat {
float: left;
width: 50px;
height: 50px;
background-color: green;
}

.widefloat {
float: left;
clear: left;
width: 100px;
height: 50px;
background-color: green;
}
</style>
<div class="container"><div class="narrowfloat"></div><div class="widefloat"></div><img></div>
@@ -228,7 +228,7 @@ void InlineFormattingContext::lineLayout(InlineItems& inlineItems, const LineBui
auto lineBuilder = LineBuilder { *this, floatingState, constraints.horizontal(), inlineItems };
while (true) {

auto lineInitialRect = InlineRect { lineLogicalTop, constraints.horizontal().logicalLeft, constraints.horizontal().logicalWidth, formattingGeometry().initialLineHeight() };
auto lineInitialRect = InlineRect { lineLogicalTop, constraints.horizontal().logicalLeft, constraints.horizontal().logicalWidth, formattingGeometry().initialLineHeight(!previousLine.has_value()) };
auto lineContent = lineBuilder.layoutInlineContent({ firstInlineItemNeedsLayout, needsLayoutRange.end }, lineInitialRect, previousLine);
auto lineLogicalRect = computeGeometryForLineContent(lineContent);
if (lineContent.isLastLineWithInlineContent)
@@ -283,11 +283,11 @@ LayoutPoint InlineFormattingGeometry::staticPositionForOutOfFlowBlockLevelBox(co
return { currentLine.left(), currentLine.bottom() };
}

InlineLayoutUnit InlineFormattingGeometry::initialLineHeight() const
InlineLayoutUnit InlineFormattingGeometry::initialLineHeight(bool isFirstLine) const
{
if (layoutState().inStandardsMode())
return formattingContext().root().style().computedLineHeight();
return formattingContext().formattingQuirks().initialLineHeight();
return isFirstLine ? formattingContext().root().firstLineStyle().computedLineHeight() : formattingContext().root().style().computedLineHeight();
return formattingContext().formattingQuirks().initialLineHeight(isFirstLine);
}

std::optional<HorizontalConstraints> InlineFormattingGeometry::floatConstraintsForLine(const InlineRect& lineLogicalRect, const FloatingContext& floatingContext) const
@@ -48,7 +48,7 @@ class InlineFormattingGeometry : public FormattingGeometry {

bool inlineLevelBoxAffectsLineBox(const InlineLevelBox&, const LineBox&) const;

InlineLayoutUnit initialLineHeight() const;
InlineLayoutUnit initialLineHeight(bool isFirstLine) const;

std::optional<HorizontalConstraints> floatConstraintsForLine(const InlineRect& lineLogicalRect, const FloatingContext&) const;

@@ -67,11 +67,11 @@ bool InlineFormattingQuirks::trailingNonBreakingSpaceNeedsAdjustment(bool isInIn
return rootStyle.nbspMode() == NBSPMode::Space && (whiteSpace == WhiteSpace::Normal || whiteSpace == WhiteSpace::PreWrap || whiteSpace == WhiteSpace::PreLine);
}

InlineLayoutUnit InlineFormattingQuirks::initialLineHeight() const
InlineLayoutUnit InlineFormattingQuirks::initialLineHeight(bool isFirstLine) const
{
ASSERT(!layoutState().inStandardsMode());
// Negative lineHeight value means the line-height is not set
auto& rootStyle = formattingContext().root().style();
auto& rootStyle = isFirstLine ? formattingContext().root().firstLineStyle() : formattingContext().root().style();
return rootStyle.lineHeight().isNegative() ? rootStyle.metricsOfPrimaryFont().floatHeight() : rootStyle.computedLineHeight();
}

@@ -39,7 +39,7 @@ class InlineFormattingQuirks : public FormattingQuirks {

bool shouldPreserveTrailingWhitespace(bool isInIntrinsicWidthMode, bool lineHasBidiContent, bool lineHasOverflow, bool lineEndWithLineBreak) const;
bool trailingNonBreakingSpaceNeedsAdjustment(bool isInIntrinsicWidthMode, bool lineHasOverflow) const;
InlineLayoutUnit initialLineHeight() const;
InlineLayoutUnit initialLineHeight(bool isFirstLine) const;
bool inlineLevelBoxAffectsLineBox(const InlineLevelBox&, const LineBox&) const;
};

0 comments on commit 73f3eb8

Please sign in to comment.