Modified: trunk/Source/WebCore/layout/displaytree/DisplayRect.h (250341 => 250342)
--- trunk/Source/WebCore/layout/displaytree/DisplayRect.h 2019-09-25 14:23:03 UTC (rev 250341)
+++ trunk/Source/WebCore/layout/displaytree/DisplayRect.h 2019-09-25 14:33:02 UTC (rev 250342)
@@ -39,6 +39,7 @@
public:
Rect() = default;
Rect(LayoutUnit top, LayoutUnit left, LayoutUnit width, LayoutUnit height);
+ Rect(LayoutPoint topLeft, LayoutUnit width, LayoutUnit height);
LayoutUnit top() const;
LayoutUnit left() const;
@@ -109,6 +110,11 @@
#endif
}
+inline Rect::Rect(LayoutPoint topLeft, LayoutUnit width, LayoutUnit height)
+ : Rect(topLeft.y(), topLeft.x(), width, height)
+{
+}
+
#if !ASSERT_DISABLED
inline void Rect::invalidatePosition()
{
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp (250341 => 250342)
--- trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp 2019-09-25 14:23:03 UTC (rev 250341)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp 2019-09-25 14:33:02 UTC (rev 250342)
@@ -55,13 +55,13 @@
Line::Line(const InlineFormattingContext& inlineFormattingContext, const InitialConstraints& initialConstraints, SkipVerticalAligment skipVerticalAligment)
: m_inlineFormattingContext(inlineFormattingContext)
, m_content(makeUnique<Line::Content>())
- , m_logicalTopLeft(initialConstraints.logicalTopLeft)
- , m_baseline({ initialConstraints.heightAndBaseline.baselineOffset, initialConstraints.heightAndBaseline.height - initialConstraints.heightAndBaseline.baselineOffset })
, m_initialStrut(initialConstraints.heightAndBaseline.strut)
- , m_lineLogicalHeight(initialConstraints.heightAndBaseline.height)
, m_lineLogicalWidth(initialConstraints.availableLogicalWidth)
, m_skipVerticalAligment(skipVerticalAligment == SkipVerticalAligment::Yes)
{
+ auto lineRect = Display::Rect { initialConstraints.logicalTopLeft, { }, initialConstraints.heightAndBaseline.height };
+ auto baseline = LineBox::Baseline { initialConstraints.heightAndBaseline.baselineOffset, initialConstraints.heightAndBaseline.height - initialConstraints.heightAndBaseline.baselineOffset };
+ m_content->setLineBox(LineBox { lineRect, baseline, { } });
}
static bool isInlineContainerConsideredEmpty(const FormattingContext& formattingContext, const Box& layoutBox)
@@ -102,17 +102,18 @@
std::unique_ptr<Line::Content> Line::close()
{
removeTrailingTrimmableContent();
+ auto& lineBox = m_content->lineBox();
if (!m_skipVerticalAligment) {
if (isVisuallyEmpty()) {
- m_baseline.reset();
- m_baselineTop = { };
- m_lineLogicalHeight = { };
+ lineBox.baseline().reset();
+ lineBox.setBaselineOffset({ });
+ lineBox.setLogicalHeight({ });
}
// 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.setDescent({ });
+ lineBox.shrinkVertically(lineBox.baseline().descent());
+ lineBox.baseline().setDescent({ });
}
auto& layoutState = this->layoutState();
@@ -155,7 +156,6 @@
run->moveHorizontally(this->logicalLeft());
}
}
- m_content->setLineBox(LineBox { Display::Rect { logicalTop(), logicalLeft(), contentLogicalWidth(), logicalHeight() }, m_baseline, baselineOffset() });
return WTFMove(m_content);
}
@@ -168,7 +168,7 @@
trimmableRun->setTextIsCollapsed();
trimmableWidth += trimmableRun->logicalRect().width();
}
- m_contentLogicalWidth -= trimmableWidth;
+ m_content->lineBox().shrinkHorizontally(trimmableWidth);
}
void Line::moveLogicalLeft(LayoutUnit delta)
@@ -176,8 +176,7 @@
if (!delta)
return;
ASSERT(delta > 0);
- // Shrink the line and move the items.
- m_logicalTopLeft.move(delta, 0);
+ m_content->lineBox().moveHorizontally(delta);
m_lineLogicalWidth -= delta;
}
@@ -215,7 +214,7 @@
void Line::appendNonBreakableSpace(const InlineItem& inlineItem, const Display::Rect& logicalRect)
{
m_content->runs().append(makeUnique<Content::Run>(inlineItem, logicalRect));
- m_contentLogicalWidth += logicalRect.width();
+ m_content->lineBox().expandHorizontally(logicalRect.width());
}
void Line::appendInlineContainerStart(const InlineItem& inlineItem, LayoutUnit logicalWidth)
@@ -288,7 +287,8 @@
m_trimmableContent.add(lineItem.get());
m_content->runs().append(WTFMove(lineItem));
- m_contentLogicalWidth += isCompletelyCollapsed ? LayoutUnit() : logicalWidth;
+ if (!isCompletelyCollapsed)
+ m_content->lineBox().expandHorizontally(logicalWidth);
}
void Line::appendNonReplacedInlineBox(const InlineItem& inlineItem, LayoutUnit logicalWidth)
@@ -305,7 +305,7 @@
}
m_content->runs().append(makeUnique<Content::Run>(inlineItem, logicalRect));
- m_contentLogicalWidth += (logicalWidth + horizontalMargin.start + horizontalMargin.end);
+ m_content->lineBox().expandHorizontally(logicalWidth + horizontalMargin.start + horizontalMargin.end);
m_trimmableContent.clear();
}
@@ -332,6 +332,8 @@
ASSERT(!inlineItem.isContainerEnd());
auto& layoutBox = inlineItem.layoutBox();
auto& style = layoutBox.style();
+ auto& lineBox = m_content->lineBox();
+ auto& baseline = lineBox.baseline();
if (inlineItem.isContainerStart()) {
// Inline containers stretch the line by their font size.
@@ -342,14 +344,13 @@
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.setDescent(std::max(m_baseline.descent(), halfLeading.descent()));
+ baseline.setDescentIfGreater(halfLeading.descent());
if (halfLeading.ascent() > 0)
- m_baseline.setAscent(std::max(m_baseline.ascent(), halfLeading.ascent()));
- contentHeight = m_baseline.height();
+ baseline.setAscentIfGreater(halfLeading.ascent());
+ contentHeight = baseline.height();
} else
contentHeight = fontMetrics.height();
- m_lineLogicalHeight = std::max(m_lineLogicalHeight, contentHeight);
- m_baselineTop = std::max(m_baselineTop, m_lineLogicalHeight - m_baseline.height());
+ lineBox.setLogicalHeightIfGreater(contentHeight, LineBox::AdjustBaseline::Yes);
return;
}
@@ -358,10 +359,9 @@
// through the inline container (start) -see above. Normally the text content itself does not stretch the line.
if (!m_initialStrut)
return;
- 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());
+ baseline.setAscentIfGreater(m_initialStrut->ascent());
+ baseline.setDescentIfGreater(m_initialStrut->descent());
+ lineBox.setLogicalHeightIfGreater(baseline.height(), LineBox::AdjustBaseline::Yes);
m_initialStrut = { };
return;
}
@@ -377,23 +377,18 @@
ASSERT(!formattingState.lineBoxes().isEmpty());
newBaselineCandidate = formattingState.lineBoxes().last().baseline();
}
- 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());
+ baseline.setAscentIfGreater(newBaselineCandidate.ascent());
+ baseline.setDescentIfGreater(newBaselineCandidate.descent());
+ lineBox.setLogicalHeightIfGreater(std::max(runHeight, baseline.height()), LineBox::AdjustBaseline::Yes);
break;
}
case VerticalAlign::Top:
// Top align content never changes the baseline offset, it only pushes the bottom of the line further down.
- m_lineLogicalHeight = std::max(runHeight, m_lineLogicalHeight);
+ lineBox.setLogicalHeightIfGreater(runHeight, LineBox::AdjustBaseline::No);
break;
case VerticalAlign::Bottom:
// Bottom aligned, tall content pushes the baseline further down from the line top.
- if (runHeight > m_lineLogicalHeight) {
- m_baselineTop += (runHeight - m_lineLogicalHeight);
- m_lineLogicalHeight = runHeight;
- }
+ lineBox.setLogicalHeightIfGreater(runHeight, LineBox::AdjustBaseline::Yes);
break;
default:
ASSERT_NOT_IMPLEMENTED_YET();
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLine.h (250341 => 250342)
--- trunk/Source/WebCore/layout/inlineformatting/InlineLine.h 2019-09-25 14:23:03 UTC (rev 250341)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLine.h 2019-09-25 14:33:02 UTC (rev 250342)
@@ -95,6 +95,7 @@
using Runs = Vector<std::unique_ptr<Run>>;
const Runs& runs() const { return m_runs; }
const LineBox& lineBox() const { return m_lineBox; }
+ LineBox& lineBox() { return m_lineBox; }
private:
friend class Line;
@@ -116,21 +117,21 @@
void moveLogicalRight(LayoutUnit);
LayoutUnit availableWidth() const { return logicalWidth() - contentLogicalWidth(); }
- LayoutUnit contentLogicalRight() const { return logicalLeft() + contentLogicalWidth(); }
- LayoutUnit logicalTop() const { return m_logicalTopLeft.y(); }
- LayoutUnit logicalBottom() const { return logicalTop() + logicalHeight(); }
+ LayoutUnit contentLogicalRight() const { return m_content->lineBox().logicalRight(); }
+ LayoutUnit logicalTop() const { return m_content->lineBox().logicalTop(); }
+ LayoutUnit logicalBottom() const { return m_content->lineBox().logicalBottom(); }
static LineBox::Baseline halfLeadingMetrics(const FontMetrics&, LayoutUnit lineLogicalHeight);
private:
- LayoutUnit logicalLeft() const { return m_logicalTopLeft.x(); }
+ LayoutUnit logicalLeft() const { return m_content->lineBox().logicalLeft(); }
LayoutUnit logicalRight() const { return logicalLeft() + logicalWidth(); }
LayoutUnit logicalWidth() const { return m_lineLogicalWidth; }
- LayoutUnit logicalHeight() const { return m_lineLogicalHeight; }
+ LayoutUnit logicalHeight() const { return m_content->lineBox().logicalHeight(); }
- LayoutUnit contentLogicalWidth() const { return m_contentLogicalWidth; }
- LayoutUnit baselineOffset() const { return m_baseline.ascent() + m_baselineTop; }
+ LayoutUnit contentLogicalWidth() const { return m_content->lineBox().logicalWidth(); }
+ LayoutUnit baselineOffset() const { return m_content->lineBox().baselineOffset(); }
void appendNonBreakableSpace(const InlineItem&, const Display::Rect& logicalRect);
void appendTextContent(const InlineTextItem&, LayoutUnit logicalWidth);
@@ -153,14 +154,7 @@
std::unique_ptr<Content> m_content;
ListHashSet<Content::Run*> m_trimmableContent;
- LayoutPoint m_logicalTopLeft;
- LayoutUnit m_contentLogicalWidth;
-
- LineBox::Baseline m_baseline;
- LayoutUnit m_baselineTop;
-
Optional<LineBox::Baseline> m_initialStrut;
- LayoutUnit m_lineLogicalHeight;
LayoutUnit m_lineLogicalWidth;
bool m_skipVerticalAligment { false };
};
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h (250341 => 250342)
--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h 2019-09-25 14:23:03 UTC (rev 250341)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h 2019-09-25 14:33:02 UTC (rev 250342)
@@ -40,6 +40,9 @@
void setAscent(LayoutUnit);
void setDescent(LayoutUnit);
+ void setAscentIfGreater(LayoutUnit);
+ void setDescentIfGreater(LayoutUnit);
+
void reset();
LayoutUnit height() const { return ascent() + descent(); }
@@ -68,26 +71,45 @@
LayoutUnit logicalWidth() const { return m_rect.width(); }
LayoutUnit logicalHeight() const { return m_rect.height(); }
- Baseline baseline() const { return m_baseline; }
+ void setBaseline(Baseline);
+ const Baseline& baseline() const;
+ Baseline& baseline();
// Baseline offset from line logical top. Note that offset does not necessarily equal to ascent.
//
- // ------------------- line logical top
- // ^
- // |
- // ^ | baseline offset
- // | |
- // | ascent |
- // | |
- // v v
- // ----------------- baseline
- // ^
- // | descent
+ // ------------------- line logical top ------------------- (top align)
+ // ^ ^
+ // | ^ |
+ // ^ | baseline offset | | baseline offset
+ // | | | |
+ // | ascent | | ascent |
+ // | | v v
+ // v v ------------------- baseline
+ // ----------------- baseline ^
+ // ^ | descent
+ // | descent v
// v
- // ------------------- line logical bottom
+ // ------------------- line logical bottom -------------------
LayoutUnit baselineOffset() const;
+ void setBaselineOffset(LayoutUnit);
+ void setLogicalTopLeft(LayoutPoint logicalTopLeft) { m_rect.setTopLeft(logicalTopLeft); }
+ void setLogicalHeight(LayoutUnit logicalHeight) { m_rect.setHeight(logicalHeight); }
+
+ enum class AdjustBaseline { No, Yes };
+ void setLogicalHeightIfGreater(LayoutUnit logicalHeight, AdjustBaseline);
+ void setLogicalWidth(LayoutUnit logicalWidth) { m_rect.setWidth(logicalWidth); }
+
+ void moveHorizontally(LayoutUnit delta) { m_rect.moveHorizontally(delta); }
+
+ void expandHorizontally(LayoutUnit delta) { m_rect.expandHorizontally(delta); }
+ void shrinkHorizontally(LayoutUnit delta) { expandHorizontally(-delta); }
+
+ void expandVertically(LayoutUnit delta) { m_rect.expandVertically(delta); }
+ void shrinkVertically(LayoutUnit delta) { expandVertically(-delta); }
+
private:
#if !ASSERT_DISABLED
+ bool m_hasValidBaseline { false };
bool m_hasValidBaselineOffset { false };
#endif
Display::Rect m_rect;
@@ -101,10 +123,49 @@
, m_baselineOffset(baselineOffset)
{
#if !ASSERT_DISABLED
+ m_hasValidBaseline = true;
m_hasValidBaselineOffset = true;
#endif
}
+inline void LineBox::setLogicalHeightIfGreater(LayoutUnit logicalHeight, AdjustBaseline adjustBaseline)
+{
+ auto diff = logicalHeight - m_rect.height();
+ if (diff <= 0)
+ return;
+ if (adjustBaseline == AdjustBaseline::Yes)
+ setBaselineOffset(baselineOffset() + diff);
+ m_rect.setHeight(logicalHeight);
+}
+
+inline void LineBox::setBaseline(Baseline baseline)
+{
+#if !ASSERT_DISABLED
+ m_hasValidBaseline = true;
+#endif
+ m_baseline = baseline;
+}
+
+inline const LineBox::Baseline& LineBox::baseline() const
+{
+ ASSERT(m_hasValidBaseline);
+ return m_baseline;
+}
+
+inline LineBox::Baseline& LineBox::baseline()
+{
+ ASSERT(m_hasValidBaseline);
+ return m_baseline;
+}
+
+inline void LineBox::setBaselineOffset(LayoutUnit baselineOffset)
+{
+#if !ASSERT_DISABLED
+ m_hasValidBaselineOffset = true;
+#endif
+ m_baselineOffset = baselineOffset;
+}
+
inline LayoutUnit LineBox::baselineOffset() const
{
ASSERT(m_hasValidBaselineOffset);
@@ -137,6 +198,22 @@
m_descent = descent;
}
+inline void LineBox::Baseline::setAscentIfGreater(LayoutUnit ascent)
+{
+#if !ASSERT_DISABLED
+ m_hasValidAscent = true;
+#endif
+ m_ascent = std::max(ascent, m_ascent);
+}
+
+inline void LineBox::Baseline::setDescentIfGreater(LayoutUnit descent)
+{
+#if !ASSERT_DISABLED
+ m_hasValidDescent = true;
+#endif
+ m_descent = std::max(descent, m_descent);
+}
+
inline void LineBox::Baseline::reset()
{
#if !ASSERT_DISABLED