Diff
Modified: trunk/Source/WebCore/ChangeLog (246233 => 246234)
--- trunk/Source/WebCore/ChangeLog 2019-06-08 18:31:26 UTC (rev 246233)
+++ trunk/Source/WebCore/ChangeLog 2019-06-08 18:48:41 UTC (rev 246234)
@@ -1,3 +1,32 @@
+2019-06-08 Zalan Bujtas <[email protected]>
+
+ [LFC][IFC] Introduce Baseline to LineBox
+ https://bugs.webkit.org/show_bug.cgi?id=198686
+ <rdar://problem/51545175>
+
+ Reviewed by Antti Koivisto.
+
+ Make baselines alignment explicit in Line.
+ This is in preparation for adding non-baseline vertical alignment support.
+
+ * layout/inlineformatting/InlineFormattingContextLineLayout.cpp:
+ (WebCore::Layout::InlineFormattingContext::LineLayout::placeInlineItems const):
+ (WebCore::Layout::InlineFormattingContext::LineLayout::createDisplayRuns const):
+ * layout/inlineformatting/InlineLine.cpp:
+ (WebCore::Layout::Line::Line):
+ (WebCore::Layout::Line::close):
+ (WebCore::Layout::Line::adjustBaselineAndLineHeight):
+ (WebCore::Layout::Line::halfLeadingMetrics):
+ * layout/inlineformatting/InlineLine.h:
+ (WebCore::Layout::Line::Content::baseline const):
+ (WebCore::Layout::Line::Content::setBaseline):
+ (WebCore::Layout::Line::logicalHeight const):
+ (WebCore::Layout::Line::baselineAlignedContentHeight const):
+ (WebCore::Layout::Line::baselineOffset const):
+ * layout/inlineformatting/InlineLineBox.h:
+ (WebCore::Layout::LineBox::baseline const):
+ (WebCore::Layout::LineBox::LineBox):
+
2019-06-07 Said Abou-Hallawa <[email protected]>
REGRESSION (r244182) [WK1]: Page updates should always scheduleCompositingLayerFlush() immediately
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp (246233 => 246234)
--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp 2019-06-08 18:31:26 UTC (rev 246233)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp 2019-06-08 18:48:41 UTC (rev 246234)
@@ -130,8 +130,8 @@
std::unique_ptr<Line> line;
if (lineInput.skipVerticalAligment == LineInput::SkipVerticalAligment::No) {
auto mimimumLineHeight = m_formattingRoot.style().computedLineHeight();
- auto baselineOffset = Line::halfLeadingMetrics(m_formattingRoot.style().fontMetrics(), mimimumLineHeight).height;
- line = std::make_unique<Line>(layoutState(), lineInput.horizontalConstraint.logicalTopLeft, lineInput.horizontalConstraint.availableLogicalWidth, mimimumLineHeight, baselineOffset);
+ auto initialBaselineOffset = Line::halfLeadingMetrics(m_formattingRoot.style().fontMetrics(), mimimumLineHeight).offset;
+ line = std::make_unique<Line>(layoutState(), lineInput.horizontalConstraint.logicalTopLeft, lineInput.horizontalConstraint.availableLogicalWidth, mimimumLineHeight, initialBaselineOffset);
} else
line = std::make_unique<Line>(layoutState(), lineInput.horizontalConstraint.logicalTopLeft.x(), lineInput.horizontalConstraint.availableLogicalWidth);
@@ -301,7 +301,7 @@
if (lineContent.isEmpty()) {
// Spec tells us to create a zero height, empty line box.
auto lineBox = Display::Rect { lineContent.logicalTop(), lineContent.logicalLeft(), 0 , 0 };
- m_formattingState.addLineBox({ lineBox });
+ m_formattingState.addLineBox({ lineBox, lineContent.baseline() });
return;
}
@@ -311,7 +311,7 @@
// A line box is always tall enough for all of the boxes it contains.
// Ignore the initial strut.
- auto lineBox = Display::Rect { lineContent.logicalTop(), lineContent.logicalLeft(), 0 , !lineContent.isVisuallyEmpty() ? lineContent.logicalHeight() : LayoutUnit { } };
+ auto lineBox = Display::Rect { lineContent.logicalTop(), lineContent.logicalLeft(), 0, !lineContent.isVisuallyEmpty() ? lineContent.logicalHeight() : LayoutUnit { } };
// Create final display runs.
auto& lineRuns = lineContent.runs();
for (unsigned index = 0; index < lineRuns.size(); ++index) {
@@ -392,7 +392,7 @@
}
}
// FIXME linebox needs to be ajusted after content alignment.
- m_formattingState.addLineBox({ lineBox });
+ m_formattingState.addLineBox({ lineBox, lineContent.baseline() });
if (!lineContent.isVisuallyEmpty())
alignRuns(m_formattingRoot.style().textAlign(), previousLineLastRunIndex.valueOr(-1) + 1, widthConstraint - lineContent.logicalWidth());
}
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp (246233 => 246234)
--- trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp 2019-06-08 18:31:26 UTC (rev 246233)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp 2019-06-08 18:48:41 UTC (rev 246234)
@@ -69,7 +69,8 @@
: m_layoutState(layoutState)
, m_content(std::make_unique<Line::Content>())
, m_logicalTopLeft(topLeft)
- , m_logicalHeight({ baselineOffset, minimumHeight - baselineOffset })
+ , m_baseline({ baselineOffset, minimumHeight - baselineOffset, { } })
+ , m_contentLogicalHeight(minimumHeight)
, m_lineLogicalWidth(availableWidth)
{
}
@@ -80,11 +81,12 @@
if (!m_skipVerticalAligment) {
// Convert inline run geometry from relative to the baseline to relative to logical top.
for (auto& run : m_content->runs()) {
- auto adjustedLogicalTop = run->logicalRect.top() + m_logicalHeight.height + m_logicalTopLeft.y();
+ auto adjustedLogicalTop = run->logicalRect.top() + baselineOffset();
run->logicalRect.setTop(adjustedLogicalTop);
}
}
m_content->setLogicalRect({ logicalTop(), logicalLeft(), contentLogicalWidth(), logicalHeight() });
+ m_content->setBaseline(m_baseline);
return WTFMove(m_content);
}
@@ -245,10 +247,11 @@
if (inlineItem.isContainerStart()) {
auto& fontMetrics = style.fontMetrics();
auto halfLeading = halfLeadingMetrics(fontMetrics, style.computedLineHeight());
- if (halfLeading.depth > 0)
- m_logicalHeight.depth = std::max(m_logicalHeight.depth, halfLeading.depth);
- if (halfLeading.height > 0)
- m_logicalHeight.height = std::max(m_logicalHeight.height, halfLeading.height);
+ 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);
+ m_contentLogicalHeight = std::max(m_contentLogicalHeight, baselineAlignedContentHeight());
return;
}
// Replaced and non-replaced inline level box.
@@ -257,13 +260,15 @@
if (runHeight == logicalHeight())
return;
// FIXME: This fails when the line height difference comes from font-size diff.
- m_logicalHeight.depth = std::max<LayoutUnit>(0, m_logicalHeight.depth);
- m_logicalHeight.height = std::max(runHeight, m_logicalHeight.height);
+ m_baseline.descent = std::max<LayoutUnit>(0, m_baseline.descent);
+ m_baseline.ascent = std::max(runHeight, m_baseline.ascent);
+ m_contentLogicalHeight = std::max(m_contentLogicalHeight, baselineAlignedContentHeight());
return;
}
// 0 descent -> baseline aligment for now.
- m_logicalHeight.depth = std::max<LayoutUnit>(0, m_logicalHeight.depth);
- m_logicalHeight.height = std::max(runHeight, m_logicalHeight.height);
+ m_baseline.descent = std::max<LayoutUnit>(0, m_baseline.descent);
+ m_baseline.ascent = std::max(runHeight, m_baseline.ascent);
+ m_contentLogicalHeight = std::max(m_contentLogicalHeight, baselineAlignedContentHeight());
}
LayoutUnit Line::inlineItemHeight(const InlineItem& inlineItem) const
@@ -290,7 +295,7 @@
return displayBox.height();
}
-Line::UsedHeightAndDepth Line::halfLeadingMetrics(const FontMetrics& fontMetrics, LayoutUnit lineLogicalHeight)
+LineBox::Baseline Line::halfLeadingMetrics(const FontMetrics& fontMetrics, LayoutUnit lineLogicalHeight)
{
auto ascent = fontMetrics.ascent();
auto descent = fontMetrics.descent();
@@ -299,7 +304,7 @@
// Inline tree is all integer based.
auto adjustedAscent = std::max((ascent + leading / 2).floor(), 0);
auto adjustedDescent = std::max((descent + leading / 2).ceil(), 0);
- return { adjustedAscent, adjustedDescent };
+ return { adjustedAscent, adjustedDescent, adjustedAscent };
}
}
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLine.h (246233 => 246234)
--- trunk/Source/WebCore/layout/inlineformatting/InlineLine.h 2019-06-08 18:31:26 UTC (rev 246233)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLine.h 2019-06-08 18:48:41 UTC (rev 246234)
@@ -69,14 +69,17 @@
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; }
private:
friend class Line;
void setLogicalRect(const Display::Rect& logicalRect) { m_logicalRect = logicalRect; }
+ void setBaseline(LineBox::Baseline baseline) { m_baseline = baseline; }
Runs& runs() { return m_runs; }
Display::Rect m_logicalRect;
+ LineBox::Baseline m_baseline;
Runs m_runs;
};
std::unique_ptr<Content> close();
@@ -100,11 +103,7 @@
LayoutUnit logicalTop() const { return m_logicalTopLeft.y(); }
LayoutUnit logicalBottom() const { return logicalTop() + logicalHeight(); }
- struct UsedHeightAndDepth {
- LayoutUnit height;
- LayoutUnit depth;
- };
- static UsedHeightAndDepth halfLeadingMetrics(const FontMetrics&, LayoutUnit lineLogicalHeight);
+ static LineBox::Baseline halfLeadingMetrics(const FontMetrics&, LayoutUnit lineLogicalHeight);
private:
LayoutUnit logicalLeft() const { return m_logicalTopLeft.x(); }
@@ -111,9 +110,11 @@
LayoutUnit logicalRight() const { return logicalLeft() + logicalWidth(); }
LayoutUnit logicalWidth() const { return m_lineLogicalWidth; }
- LayoutUnit logicalHeight() const { return m_logicalHeight.height + m_logicalHeight.depth; }
+ LayoutUnit logicalHeight() const { return m_contentLogicalHeight; }
LayoutUnit contentLogicalWidth() const { return m_contentLogicalWidth; }
+ LayoutUnit baselineAlignedContentHeight() const { return m_baseline.ascent + m_baseline.descent; }
+ LayoutUnit baselineOffset() const { return m_baseline.offset; }
void appendNonBreakableSpace(const InlineItem&, const Display::Rect& logicalRect);
void removeTrailingTrimmableContent();
@@ -128,7 +129,8 @@
LayoutPoint m_logicalTopLeft;
LayoutUnit m_contentLogicalWidth;
- UsedHeightAndDepth m_logicalHeight;
+ LineBox::Baseline m_baseline;
+ LayoutUnit m_contentLogicalHeight;
LayoutUnit m_lineLogicalWidth;
bool m_skipVerticalAligment { false };
};
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h (246233 => 246234)
--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h 2019-06-08 18:31:26 UTC (rev 246233)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h 2019-06-08 18:48:41 UTC (rev 246234)
@@ -34,7 +34,12 @@
class LineBox {
public:
- LineBox(Display::Rect);
+ struct Baseline {
+ LayoutUnit ascent;
+ LayoutUnit descent;
+ LayoutUnit offset; // baseline offset from line logical top. Note that offset does not necessarily equal to ascent.
+ };
+ LineBox(Display::Rect, const Baseline&);
LayoutPoint logicalTopLeft() const { return m_rect.topLeft(); }
@@ -46,12 +51,16 @@
LayoutUnit logicalWidth() const { return m_rect.width(); }
LayoutUnit logicalHeight() const { return m_rect.height(); }
+ Baseline baseline() const { return m_baseline; }
+
private:
Display::Rect m_rect;
+ Baseline m_baseline;
};
-inline LineBox::LineBox(Display::Rect rect)
+inline LineBox::LineBox(Display::Rect rect, const Baseline& baseline)
: m_rect(rect)
+ , m_baseline(baseline)
{
}