Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Commit 0bb5550

Browse files
[LFC][IFC] Share code when constructing LineBox::InlineBox for the atomic inline-level box
https://bugs.webkit.org/show_bug.cgi?id=216338 Reviewed by Antti Koivisto. * layout/inlineformatting/InlineFormattingContext.cpp: (WebCore::Layout::InlineFormattingContext::createDisplayBoxesForLineContent): * layout/inlineformatting/InlineLineBox.cpp: (WebCore::Layout::LineBox::logicalRectForTextRun const): (WebCore::Layout::LineBox::constructInlineBoxes): (WebCore::Layout::LineBox::inlineRectForTextRun const): Deleted. * layout/inlineformatting/InlineLineBox.h: git-svn-id: http://svn.webkit.org/repository/webkit/trunk@266848 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 81131ef commit 0bb5550

File tree

4 files changed

+36
-26
lines changed

4 files changed

+36
-26
lines changed

Source/WebCore/ChangeLog

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
2020-09-10 Zalan Bujtas <[email protected]>
2+
3+
[LFC][IFC] Share code when constructing LineBox::InlineBox for the atomic inline-level box
4+
https://bugs.webkit.org/show_bug.cgi?id=216338
5+
6+
Reviewed by Antti Koivisto.
7+
8+
* layout/inlineformatting/InlineFormattingContext.cpp:
9+
(WebCore::Layout::InlineFormattingContext::createDisplayBoxesForLineContent):
10+
* layout/inlineformatting/InlineLineBox.cpp:
11+
(WebCore::Layout::LineBox::logicalRectForTextRun const):
12+
(WebCore::Layout::LineBox::constructInlineBoxes):
13+
(WebCore::Layout::LineBox::inlineRectForTextRun const): Deleted.
14+
* layout/inlineformatting/InlineLineBox.h:
15+
116
2020-09-10 Antti Koivisto <[email protected]>
217

318
Don't create event regions when the page has no subscrollers

Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ Display::InlineRect InlineFormattingContext::createDisplayBoxesForLineContent(co
485485
}
486486
return inkOverflow;
487487
};
488-
auto logicalRect = lineRun.isBox() ? lineBox.inlineBoxForLayoutBox(layoutBox).logicalRect() : lineBox.inlineRectForTextRun(lineRun);
488+
auto logicalRect = lineRun.isBox() ? lineBox.inlineBoxForLayoutBox(layoutBox).logicalRect() : lineBox.logicalRectForTextRun(lineRun);
489489
// Inline boxes are relative to the line box while final Display::Runs need to be relative to the parent Display:Box
490490
// FIXME: Shouldn't we just leave them be relative to the line box?
491491
logicalRect.moveBy({ lineLogicalRect.left(), lineLogicalRect.top() + lineBoxVerticalOffset });

Source/WebCore/layout/inlineformatting/InlineLineBox.cpp

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ LineBox::LineBox(const InlineFormattingContext& inlineFormattingContext, InlineL
137137
alignInlineBoxesVerticallyAndComputeLineBoxHeight();
138138
}
139139

140-
Display::InlineRect LineBox::inlineRectForTextRun(const Line::Run& run) const
140+
Display::InlineRect LineBox::logicalRectForTextRun(const Line::Run& run) const
141141
{
142142
ASSERT(run.isText() || run.isLineBreak());
143143
auto& parentInlineBox = inlineBoxForLayoutBox(run.layoutBox().parent());
@@ -161,15 +161,13 @@ void LineBox::constructInlineBoxes(const Line::RunList& runs)
161161
constructRootInlineBox();
162162

163163
for (auto& run : runs) {
164-
auto& layoutBox = run.layoutBox();
164+
auto& inlineLevelBox = run.layoutBox();
165165
if (run.isBox()) {
166-
auto& boxGeometry = formattingContext().geometryForBox(layoutBox);
167-
auto inlineBoxLogicalLeft = m_horizontalAlignmentOffset.valueOr(InlineLayoutUnit { }) + run.logicalLeft();
168-
if (layoutBox.isInlineBlockBox() && layoutBox.establishesInlineFormattingContext()) {
169-
auto& formattingState = layoutState().establishedInlineFormattingState(downcast<ContainerBox>(layoutBox));
170-
// Spec makes us generate at least one line -even if it is empty.
171-
auto& lastLine = formattingState.displayInlineContent()->lines.last();
172-
auto inlineBlockBaseline = lastLine.top() + lastLine.baseline();
166+
auto logicalLeft = m_horizontalAlignmentOffset.valueOr(InlineLayoutUnit { }) + run.logicalLeft();
167+
auto& inlineLevelBoxGeometry = formattingContext().geometryForBox(inlineLevelBox);
168+
auto logicalHeight = inlineLevelBoxGeometry.marginBoxHeight();
169+
auto baseline = logicalHeight;
170+
if (inlineLevelBox.isInlineBlockBox() && inlineLevelBox.establishesInlineFormattingContext()) {
173171
// The inline-block's baseline offset is relative to its content box. Let's convert it relative to the margin box.
174172
// _______________ <- margin box
175173
// |
@@ -182,32 +180,29 @@ void LineBox::constructInlineBoxes(const Line::RunList& runs)
182180
// text | | | v text
183181
// -----|-|-|---------- <- baseline
184182
//
185-
auto adjustedBaseline = boxGeometry.marginBefore() + boxGeometry.borderTop() + boxGeometry.paddingTop().valueOr(0) + inlineBlockBaseline;
186-
auto inlineBoxRect = Display::InlineRect { { }, inlineBoxLogicalLeft, run.logicalWidth(), boxGeometry.marginBoxHeight() };
187-
auto inlineBox = makeUnique<InlineBox>(layoutBox, inlineBoxRect, adjustedBaseline, InlineLayoutUnit { }, InlineBox::IsConsideredEmpty::No);
188-
m_inlineBoxRectMap.set(&layoutBox, inlineBox.get());
189-
m_inlineBoxList.append(WTFMove(inlineBox));
190-
} else {
191-
auto runHeight = boxGeometry.marginBoxHeight();
192-
auto inlineBoxRect = Display::InlineRect { { }, inlineBoxLogicalLeft, run.logicalWidth(), runHeight };
193-
auto inlineBox = makeUnique<InlineBox>(layoutBox, inlineBoxRect, runHeight, InlineLayoutUnit { }, InlineBox::IsConsideredEmpty::No);
194-
m_inlineBoxRectMap.set(&layoutBox, inlineBox.get());
195-
m_inlineBoxList.append(WTFMove(inlineBox));
183+
auto& formattingState = layoutState().establishedInlineFormattingState(downcast<ContainerBox>(inlineLevelBox));
184+
auto& lastLine = formattingState.displayInlineContent()->lines.last();
185+
auto inlineBlockBaseline = lastLine.top() + lastLine.baseline();
186+
baseline = inlineLevelBoxGeometry.marginBefore() + inlineLevelBoxGeometry.borderTop() + inlineLevelBoxGeometry.paddingTop().valueOr(0) + inlineBlockBaseline;
196187
}
188+
auto rect = Display::InlineRect { { }, logicalLeft, run.logicalWidth(), logicalHeight };
189+
auto inlineBox = makeUnique<InlineBox>(inlineLevelBox, rect, baseline, InlineLayoutUnit { }, InlineBox::IsConsideredEmpty::No);
190+
m_inlineBoxRectMap.set(&inlineLevelBox, inlineBox.get());
191+
m_inlineBoxList.append(WTFMove(inlineBox));
197192
} else if (run.isContainerStart()) {
198193
auto inlineBoxLogicalLeft = m_horizontalAlignmentOffset.valueOr(InlineLayoutUnit { }) + run.logicalLeft();
199194
auto initialWidth = logicalWidth() - run.logicalLeft();
200195
ASSERT(initialWidth >= 0);
201-
auto& fontMetrics = layoutBox.style().fontMetrics();
196+
auto& fontMetrics = inlineLevelBox.style().fontMetrics();
202197
InlineLayoutUnit logicalHeight = fontMetrics.height();
203198
InlineLayoutUnit baseline = fontMetrics.ascent();
204199
auto inlineBoxRect = Display::InlineRect { { }, inlineBoxLogicalLeft, initialWidth, logicalHeight };
205-
auto inlineBox = makeUnique<InlineBox>(layoutBox, inlineBoxRect, baseline, logicalHeight - baseline, InlineBox::IsConsideredEmpty::Yes);
206-
m_inlineBoxRectMap.set(&layoutBox, inlineBox.get());
200+
auto inlineBox = makeUnique<InlineBox>(inlineLevelBox, inlineBoxRect, baseline, logicalHeight - baseline, InlineBox::IsConsideredEmpty::Yes);
201+
m_inlineBoxRectMap.set(&inlineLevelBox, inlineBox.get());
207202
m_inlineBoxList.append(WTFMove(inlineBox));
208203
} else if (run.isContainerEnd()) {
209204
// Adjust the logical width when the inline level container closes on this line.
210-
auto& inlineBox = *m_inlineBoxRectMap.get(&layoutBox);
205+
auto& inlineBox = *m_inlineBoxRectMap.get(&inlineLevelBox);
211206
inlineBox.setLogicalWidth(run.logicalRight() - inlineBox.logicalLeft());
212207
} else if ((run.isText() || run.isLineBreak())) {
213208
auto& containerBox = run.layoutBox().parent();

Source/WebCore/layout/inlineformatting/InlineLineBox.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class LineBox {
105105
bool isLineVisuallyEmpty() const { return m_isLineVisuallyEmpty; }
106106

107107
const InlineBox& inlineBoxForLayoutBox(const Box& layoutBox) const { return *m_inlineBoxRectMap.get(&layoutBox); }
108-
Display::InlineRect inlineRectForTextRun(const Line::Run&) const;
108+
Display::InlineRect logicalRectForTextRun(const Line::Run&) const;
109109

110110
InlineLayoutUnit alignmentBaseline() const { return m_rootInlineBox.logicalTop() + m_rootInlineBox.baseline(); }
111111

0 commit comments

Comments
 (0)