Diff
Modified: trunk/Source/WebCore/ChangeLog (250298 => 250299)
--- trunk/Source/WebCore/ChangeLog 2019-09-24 14:58:49 UTC (rev 250298)
+++ trunk/Source/WebCore/ChangeLog 2019-09-24 15:30:17 UTC (rev 250299)
@@ -1,5 +1,52 @@
2019-09-24 Zalan Bujtas <[email protected]>
+ [LFC][IFC] Line::Content should use LineBox
+ https://bugs.webkit.org/show_bug.cgi?id=202128
+ <rdar://problem/55649079>
+
+ Reviewed by Antti Koivisto.
+
+ Replace Line::Content's m_logicalRect, m_baseline and m_baselineOffset with LineBox.
+
+ * layout/inlineformatting/InlineFormattingContextLineLayout.cpp:
+ (WebCore::Layout::InlineFormattingContext::InlineLayout::layout):
+ (WebCore::Layout::InlineFormattingContext::InlineLayout::computedIntrinsicWidth const):
+ (WebCore::Layout::InlineFormattingContext::InlineLayout::createDisplayRuns):
+ * layout/inlineformatting/InlineFormattingContextQuirks.cpp:
+ (WebCore::Layout::InlineFormattingContext::Quirks::lineDescentNeedsCollapsing const):
+ (WebCore::Layout::InlineFormattingContext::Quirks::lineHeightConstraints const):
+ * layout/inlineformatting/InlineLine.cpp:
+ (WebCore::Layout::Line::close):
+ (WebCore::Layout::Line::adjustBaselineAndLineHeight):
+ * layout/inlineformatting/InlineLine.h:
+ (WebCore::Layout::Line::Content::lineBox const):
+ (WebCore::Layout::Line::Content::setLineBox):
+ (WebCore::Layout::Line::baselineOffset const):
+ (WebCore::Layout::Line::Content::isEmpty const): Deleted.
+ (WebCore::Layout::Line::Content::logicalTop const): Deleted.
+ (WebCore::Layout::Line::Content::logicalLeft const): Deleted.
+ (WebCore::Layout::Line::Content::logicalRight const): Deleted.
+ (WebCore::Layout::Line::Content::logicalBottom const): Deleted.
+ (WebCore::Layout::Line::Content::logicalWidth const): Deleted.
+ (WebCore::Layout::Line::Content::logicalHeight const): Deleted.
+ (WebCore::Layout::Line::Content::baseline const): Deleted.
+ (WebCore::Layout::Line::Content::baselineOffset const): Deleted.
+ (WebCore::Layout::Line::Content::setLogicalRect): Deleted.
+ (WebCore::Layout::Line::Content::setBaseline): Deleted.
+ (WebCore::Layout::Line::Content::setBaselineOffset): Deleted.
+ * layout/inlineformatting/InlineLineBox.h:
+ (WebCore::Layout::LineBox::Baseline::height const):
+ (WebCore::Layout::LineBox::LineBox):
+ (WebCore::Layout::LineBox::baselineOffset const):
+ (WebCore::Layout::LineBox::Baseline::Baseline):
+ (WebCore::Layout::LineBox::Baseline::setAscent):
+ (WebCore::Layout::LineBox::Baseline::setDescent):
+ (WebCore::Layout::LineBox::Baseline::reset):
+ (WebCore::Layout::LineBox::Baseline::ascent const):
+ (WebCore::Layout::LineBox::Baseline::descent const):
+
+2019-09-24 Zalan Bujtas <[email protected]>
+
[LFC][IFC] Move line constraints computation to a dedicated function
https://bugs.webkit.org/show_bug.cgi?id=202121
<rdar://problem/55640742>
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp (250298 => 250299)
--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp 2019-09-24 14:58:49 UTC (rev 250298)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp 2019-09-24 15:30:17 UTC (rev 250299)
@@ -288,11 +288,10 @@
if (lineContent.lastCommitted) {
currentInlineItem = { lineContent.lastCommitted->index + 1, WTF::nullopt };
- lineLogicalTop = lineContent.runs->logicalBottom();
+ lineLogicalTop = lineContent.runs->lineBox().logicalBottom();
} else {
// Floats prevented us placing any content on the line.
ASSERT(lineInput.initialConstraints.lineIsConstrainedByFloat);
- ASSERT(lineContent.runs->isEmpty());
// Move the next line below the intrusive float.
auto floatingContext = FloatingContext { formattingRoot(), formattingContext(), formattingState().floatingState() };
auto floatConstraints = floatingContext.constraints({ lineLogicalTop });
@@ -353,7 +352,7 @@
LayoutUnit floatsWidth;
for (auto& floatItem : lineContent.floats)
floatsWidth += formattingContext.geometryForBox(floatItem->layoutBox()).marginBoxWidth();
- maximumLineWidth = std::max(maximumLineWidth, floatsWidth + lineContent.runs->logicalWidth());
+ maximumLineWidth = std::max(maximumLineWidth, floatsWidth + lineContent.runs->lineBox().logicalWidth());
}
return maximumLineWidth;
}
@@ -369,24 +368,17 @@
auto& floatBox = floatItem->layoutBox();
auto& displayBox = formattingState.displayBox(floatBox);
// Set static position first.
- displayBox.setTopLeft({ lineContent.logicalLeft(), lineContent.logicalTop() });
+ auto& lineBox = lineContent.lineBox();
+ displayBox.setTopLeft({ lineBox.logicalLeft(), lineBox.logicalTop() });
// Float it.
displayBox.setTopLeft(floatingContext.positionForFloat(floatBox));
floatingContext.append(floatBox);
}
- if (lineContent.isEmpty()) {
- // Spec tells us to create a zero height, empty line box.
- auto lineBoxRect = Display::Rect { lineContent.logicalTop(), lineContent.logicalLeft(), 0 , 0 };
- formattingState.addLineBox({ lineBoxRect, lineContent.baseline(), lineContent.baselineOffset() });
- return;
- }
-
auto& inlineDisplayRuns = formattingState.inlineRuns();
- Optional<unsigned> previousLineLastRunIndex = inlineDisplayRuns.isEmpty() ? Optional<unsigned>() : inlineDisplayRuns.size() - 1;
+ auto previousLineLastRunIndex = Optional<unsigned> { inlineDisplayRuns.isEmpty() ? Optional<unsigned>() : inlineDisplayRuns.size() - 1 };
// 9.4.2 Inline formatting contexts
// A line box is always tall enough for all of the boxes it contains.
- auto lineBoxRect = Display::Rect { lineContent.logicalTop(), lineContent.logicalLeft(), 0, lineContent.logicalHeight()};
// Create final display runs.
auto& lineRuns = lineContent.runs();
auto geometry = formattingContext.geometry();
@@ -410,7 +402,6 @@
if (layoutBox.isInFlowPositioned())
topLeft += geometry.inFlowPositionedPositionOffset(layoutBox, m_usedHorizontalValues);
displayBox.setTopLeft(topLeft);
- lineBoxRect.expandHorizontally(logicalRect.width());
formattingState.addInlineRun(makeUnique<Display::Run>(logicalRect));
continue;
}
@@ -418,7 +409,6 @@
// Inline level container start (<span>)
if (lineRun->isContainerStart()) {
displayBox.setTopLeft(logicalRect.topLeft());
- lineBoxRect.expandHorizontally(logicalRect.width());
continue;
}
@@ -434,7 +424,6 @@
// FIXME fix it for multiline.
displayBox.setContentBoxWidth(contentBoxWidth);
displayBox.setContentBoxHeight(logicalRect.height());
- lineBoxRect.expandHorizontally(logicalRect.width());
continue;
}
@@ -452,7 +441,6 @@
lastDisplayRun->expandHorizontally(logicalRect.width());
lastDisplayRun->textContext()->expand(textContext->length);
}
- lineBoxRect.expandHorizontally(logicalRect.width());
}
// FIXME take content breaking into account when part of the layout box is on the previous line.
auto firstInlineRunForLayoutBox = !previousLineRun || &previousLineRun->layoutBox() != &layoutBox;
@@ -467,8 +455,8 @@
}
}
// FIXME linebox needs to be ajusted after content alignment.
- formattingState.addLineBox({ lineBoxRect, lineContent.baseline(), lineContent.baselineOffset() });
- alignRuns(formattingRoot().style().textAlign(), inlineDisplayRuns, previousLineLastRunIndex.valueOr(-1) + 1, widthConstraint() - lineContent.logicalWidth());
+ formattingState.addLineBox(lineContent.lineBox());
+ alignRuns(formattingRoot().style().textAlign(), inlineDisplayRuns, previousLineLastRunIndex.valueOr(-1) + 1, widthConstraint() - lineContent.lineBox().logicalWidth());
}
static Optional<LayoutUnit> horizontalAdjustmentForAlignment(TextAlignMode align, LayoutUnit remainingWidth)
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextQuirks.cpp (250298 => 250299)
--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextQuirks.cpp 2019-09-24 14:58:49 UTC (rev 250298)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextQuirks.cpp 2019-09-24 15:30:17 UTC (rev 250299)
@@ -69,7 +69,7 @@
auto& formattingState = downcast<InlineFormattingState>(layoutState.establishedFormattingState(downcast<Container>(layoutBox)));
ASSERT(!formattingState.lineBoxes().isEmpty());
auto inlineBlockBaseline = formattingState.lineBoxes().last().baseline();
- if (inlineBlockBaseline.descent)
+ if (inlineBlockBaseline.descent())
return false;
}
break;
@@ -87,18 +87,18 @@
// computedLineHeight takes font-size into account when line-height is not set.
// Strut is the imaginary box that we put on every line. It sets the initial vertical constraints for each new line.
auto strutHeight = formattingRoot.style().computedLineHeight();
- auto strutBaselineOffset = Line::halfLeadingMetrics(formattingRoot.style().fontMetrics(), strutHeight).ascent;
+ auto strutBaselineOffset = Line::halfLeadingMetrics(formattingRoot.style().fontMetrics(), strutHeight).ascent();
if (layoutState().inNoQuirksMode())
return { strutHeight, strutBaselineOffset, { } };
auto lineHeight = formattingRoot.style().lineHeight();
if (lineHeight.isPercentOrCalculated()) {
- auto initialBaselineOffset = Line::halfLeadingMetrics(formattingRoot.style().fontMetrics(), { }).ascent;
+ auto initialBaselineOffset = Line::halfLeadingMetrics(formattingRoot.style().fontMetrics(), { }).ascent();
return { initialBaselineOffset, initialBaselineOffset, LineBox::Baseline { strutBaselineOffset, strutHeight - strutBaselineOffset } };
}
// FIXME: The only reason why we use intValue() here is to match current inline tree (integral)behavior.
auto initialLineHeight = LayoutUnit { lineHeight.intValue() };
- auto initialBaselineOffset = Line::halfLeadingMetrics(formattingRoot.style().fontMetrics(), initialLineHeight).ascent;
+ auto initialBaselineOffset = Line::halfLeadingMetrics(formattingRoot.style().fontMetrics(), initialLineHeight).ascent();
return { initialLineHeight, initialBaselineOffset, LineBox::Baseline { strutBaselineOffset, strutHeight - strutBaselineOffset } };
}
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp (250298 => 250299)
--- trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp 2019-09-24 14:58:49 UTC (rev 250298)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp 2019-09-24 15:30:17 UTC (rev 250299)
@@ -104,7 +104,7 @@
removeTrailingTrimmableContent();
if (!m_skipVerticalAligment) {
if (isVisuallyEmpty()) {
- m_baseline = { };
+ m_baseline.reset();
m_baselineTop = { };
m_lineLogicalHeight = { };
}
@@ -111,8 +111,8 @@
// Remove descent when all content is baseline aligned but none of them have descent.
if (formattingContext().quirks().lineDescentNeedsCollapsing(*m_content)) {
- m_lineLogicalHeight -= m_baseline.descent;
- m_baseline.descent = { };
+ m_lineLogicalHeight -= m_baseline.descent();
+ m_baseline.setDescent({ });
}
auto& layoutState = this->layoutState();
@@ -135,7 +135,7 @@
// Spec makes us generate at least one line -even if it is empty.
ASSERT(!formattingState.lineBoxes().isEmpty());
auto inlineBlockBaseline = formattingState.lineBoxes().last().baseline();
- logicalTop = baselineOffset() - inlineBlockBaseline.ascent;
+ logicalTop = baselineOffset() - inlineBlockBaseline.ascent();
} else
logicalTop = baselineOffset() - run->logicalRect().height();
break;
@@ -155,9 +155,7 @@
run->moveHorizontally(this->logicalLeft());
}
}
- m_content->setLogicalRect({ logicalTop(), logicalLeft(), contentLogicalWidth(), logicalHeight() });
- m_content->setBaseline(m_baseline);
- m_content->setBaselineOffset(baselineOffset());
+ m_content->setLineBox(LineBox { Display::Rect { logicalTop(), logicalLeft(), contentLogicalWidth(), logicalHeight() }, m_baseline, baselineOffset() });
return WTFMove(m_content);
}
@@ -343,10 +341,10 @@
if (style.verticalAlign() == VerticalAlign::Baseline) {
auto halfLeading = halfLeadingMetrics(fontMetrics, style.computedLineHeight());
// Both halfleading ascent and descent could be negative (tall font vs. small line-height value)
- if (halfLeading.descent > 0)
- m_baseline.descent = std::max(m_baseline.descent, halfLeading.descent);
- if (halfLeading.ascent > 0)
- m_baseline.ascent = std::max(m_baseline.ascent, halfLeading.ascent);
+ if (halfLeading.descent() > 0)
+ m_baseline.setDescent(std::max(m_baseline.descent(), halfLeading.descent()));
+ if (halfLeading.ascent() > 0)
+ m_baseline.setAscent(std::max(m_baseline.ascent(), halfLeading.ascent()));
contentHeight = m_baseline.height();
} else
contentHeight = fontMetrics.height();
@@ -360,8 +358,8 @@
// through the inline container (start) -see above. Normally the text content itself does not stretch the line.
if (!m_initialStrut)
return;
- m_baseline.ascent = std::max(m_initialStrut->ascent, m_baseline.ascent);
- m_baseline.descent = std::max(m_initialStrut->descent, m_baseline.descent);
+ m_baseline.setAscent(std::max(m_initialStrut->ascent(), m_baseline.ascent()));
+ m_baseline.setDescent(std::max(m_initialStrut->descent(), m_baseline.descent()));
m_lineLogicalHeight = std::max(m_lineLogicalHeight, m_baseline.height());
m_baselineTop = std::max(m_baselineTop, m_lineLogicalHeight - m_baseline.height());
m_initialStrut = { };
@@ -379,8 +377,8 @@
ASSERT(!formattingState.lineBoxes().isEmpty());
newBaselineCandidate = formattingState.lineBoxes().last().baseline();
}
- m_baseline.ascent = std::max(newBaselineCandidate.ascent, m_baseline.ascent);
- m_baseline.descent = std::max(newBaselineCandidate.descent, m_baseline.descent);
+ m_baseline.setAscent(std::max(newBaselineCandidate.ascent(), m_baseline.ascent()));
+ m_baseline.setDescent(std::max(newBaselineCandidate.descent(), m_baseline.descent()));
m_lineLogicalHeight = std::max(std::max(m_lineLogicalHeight, runHeight), m_baseline.height());
// Baseline ascent/descent never shrink -> max.
m_baselineTop = std::max(m_baselineTop, m_lineLogicalHeight - m_baseline.height());
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLine.h (250298 => 250299)
--- trunk/Source/WebCore/layout/inlineformatting/InlineLine.h 2019-09-24 14:58:49 UTC (rev 250298)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLine.h 2019-09-24 15:30:17 UTC (rev 250299)
@@ -94,28 +94,15 @@
};
using Runs = Vector<std::unique_ptr<Run>>;
const Runs& runs() const { return m_runs; }
- bool isEmpty() const { return m_runs.isEmpty(); }
+ const LineBox& lineBox() const { return m_lineBox; }
- LayoutUnit logicalTop() const { return m_logicalRect.top(); }
- LayoutUnit logicalLeft() const { return m_logicalRect.left(); }
- LayoutUnit logicalRight() const { return logicalLeft() + logicalWidth(); }
- LayoutUnit logicalBottom() const { return logicalTop() + logicalHeight(); }
- LayoutUnit logicalWidth() const { return m_logicalRect.width(); }
- LayoutUnit logicalHeight() const { return m_logicalRect.height(); }
- LineBox::Baseline baseline() const { return m_baseline; }
- LayoutUnit baselineOffset() const { return m_baselineOffset; }
-
private:
friend class Line;
- void setLogicalRect(const Display::Rect& logicalRect) { m_logicalRect = logicalRect; }
- void setBaseline(LineBox::Baseline baseline) { m_baseline = baseline; }
- void setBaselineOffset(LayoutUnit baselineOffset) { m_baselineOffset = baselineOffset; }
+ void setLineBox(const LineBox& lineBox) { m_lineBox = lineBox; }
Runs& runs() { return m_runs; }
- Display::Rect m_logicalRect;
- LineBox::Baseline m_baseline;
- LayoutUnit m_baselineOffset;
+ LineBox m_lineBox;
Runs m_runs;
};
std::unique_ptr<Content> close();
@@ -143,7 +130,7 @@
LayoutUnit logicalHeight() const { return m_lineLogicalHeight; }
LayoutUnit contentLogicalWidth() const { return m_contentLogicalWidth; }
- LayoutUnit baselineOffset() const { return m_baseline.ascent + m_baselineTop; }
+ LayoutUnit baselineOffset() const { return m_baseline.ascent() + m_baselineTop; }
void appendNonBreakableSpace(const InlineItem&, const Display::Rect& logicalRect);
void appendTextContent(const InlineTextItem&, LayoutUnit logicalWidth);
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h (250298 => 250299)
--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h 2019-09-24 14:58:49 UTC (rev 250298)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h 2019-09-24 15:30:17 UTC (rev 250299)
@@ -35,12 +35,28 @@
class LineBox {
public:
struct Baseline {
- LayoutUnit height() const { return ascent + descent; }
+ Baseline(LayoutUnit ascent, LayoutUnit descent);
+ Baseline() = default;
- LayoutUnit ascent;
- LayoutUnit descent;
+ void setAscent(LayoutUnit);
+ void setDescent(LayoutUnit);
+ void reset();
+
+ LayoutUnit height() const { return ascent() + descent(); }
+ LayoutUnit ascent() const;
+ LayoutUnit descent() const;
+
+ private:
+#if !ASSERT_DISABLED
+ bool m_hasValidAscent { false };
+ bool m_hasValidDescent { false };
+#endif
+ LayoutUnit m_ascent;
+ LayoutUnit m_descent;
};
+
LineBox(Display::Rect, const Baseline&, LayoutUnit baselineOffset);
+ LineBox() = default;
LayoutPoint logicalTopLeft() const { return m_rect.topLeft(); }
@@ -68,9 +84,12 @@
// | descent
// v
// ------------------- line logical bottom
- LayoutUnit baselineOffset() const { return m_baselineOffset; }
+ LayoutUnit baselineOffset() const;
private:
+#if !ASSERT_DISABLED
+ bool m_hasValidBaselineOffset { false };
+#endif
Display::Rect m_rect;
Baseline m_baseline;
LayoutUnit m_baselineOffset;
@@ -81,9 +100,66 @@
, m_baseline(baseline)
, m_baselineOffset(baselineOffset)
{
+#if !ASSERT_DISABLED
+ m_hasValidBaselineOffset = true;
+#endif
}
+inline LayoutUnit LineBox::baselineOffset() const
+{
+ ASSERT(m_hasValidBaselineOffset);
+ return m_baselineOffset;
}
+
+inline LineBox::Baseline::Baseline(LayoutUnit ascent, LayoutUnit descent)
+ : m_ascent(ascent)
+ , m_descent(descent)
+{
+#if !ASSERT_DISABLED
+ m_hasValidAscent = true;
+ m_hasValidDescent = true;
+#endif
}
+inline void LineBox::Baseline::setAscent(LayoutUnit ascent)
+{
+#if !ASSERT_DISABLED
+ m_hasValidAscent = true;
#endif
+ m_ascent = ascent;
+}
+
+inline void LineBox::Baseline::setDescent(LayoutUnit descent)
+{
+#if !ASSERT_DISABLED
+ m_hasValidDescent = true;
+#endif
+ m_descent = descent;
+}
+
+inline void LineBox::Baseline::reset()
+{
+#if !ASSERT_DISABLED
+ m_hasValidAscent = true;
+ m_hasValidDescent = true;
+#endif
+ m_ascent = { };
+ m_descent = { };
+}
+
+inline LayoutUnit LineBox::Baseline::ascent() const
+{
+ ASSERT(m_hasValidAscent);
+ return m_ascent;
+}
+
+inline LayoutUnit LineBox::Baseline::descent() const
+{
+ ASSERT(m_hasValidDescent);
+ return m_descent;
+}
+
+}
+}
+
+#endif