Skip to content

Commit

Permalink
[IFC][Integration] Move inline content dimension update from RenderBl…
Browse files Browse the repository at this point in the history
…ockFlow to LineLayout

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

Reviewed by Antti Koivisto.

This ensures that when preferred width computation and line layout are in synch with updating the layout boxes' dimensions.
(Out of sync can lead to inconsistent state where line layout relies on certain structures (BoxGeometry) which are supposed to be constructed by whoever runs layout first (preferred width or actual line layout)).

* Source/WebCore/layout/integration/inline/LayoutIntegrationLineLayout.cpp:
(WebCore::LayoutIntegration::LineLayout::updateInlineContentDimensions):
* Source/WebCore/layout/integration/inline/LayoutIntegrationLineLayout.h:
* Source/WebCore/rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::layoutModernLines):
(WebCore::RenderBlockFlow::tryComputePreferredWidthsUsingModernPath):

Canonical link: https://commits.webkit.org/255800@main
  • Loading branch information
alanbaradlay committed Oct 20, 2022
1 parent f7d70aa commit 037ca44
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "InlineFormattingContext.h"
#include "InlineFormattingState.h"
#include "InlineInvalidation.h"
#include "InlineWalker.h"
#include "LayoutBoxGeometry.h"
#include "LayoutIntegrationCoverage.h"
#include "LayoutIntegrationInlineContentBuilder.h"
Expand Down Expand Up @@ -358,6 +359,42 @@ void LineLayout::updateInlineBoxDimensions(const RenderInline& renderInline)
boxGeometry.setPadding(logicalPadding(renderInline, isLeftToRightInlineDirection, writingMode, !shouldNotRetainBorderPaddingAndMarginStart, !shouldNotRetainBorderPaddingAndMarginEnd));
}

void LineLayout::updateInlineContentDimensions()
{
for (auto walker = InlineWalker(flow()); !walker.atEnd(); walker.advance()) {
auto& renderer = *walker.current();

if (is<RenderReplaced>(renderer)) {
updateReplacedDimensions(downcast<RenderReplaced>(renderer));
continue;
}
if (is<RenderTable>(renderer)) {
updateInlineTableDimensions(downcast<RenderTable>(renderer));
continue;
}
if (is<RenderListMarker>(renderer)) {
updateListMarkerDimensions(downcast<RenderListMarker>(renderer));
continue;
}
if (is<RenderListItem>(renderer)) {
updateListItemDimensions(downcast<RenderListItem>(renderer));
continue;
}
if (is<RenderBlock>(renderer)) {
updateInlineBlockDimensions(downcast<RenderBlock>(renderer));
continue;
}
if (is<RenderLineBreak>(renderer)) {
updateLineBreakBoxDimensions(downcast<RenderLineBreak>(renderer));
continue;
}
if (is<RenderInline>(renderer)) {
updateInlineBoxDimensions(downcast<RenderInline>(renderer));
continue;
}
}
}

void LineLayout::updateStyle(const RenderBoxModelObject& renderer, const RenderStyle& oldStyle)
{
auto invalidation = Layout::InlineInvalidation { ensureLineDamage() };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,7 @@ class LineLayout : public CanMakeCheckedPtr {
bool shouldSwitchToLegacyOnInvalidation() const;

void updateFormattingRootGeometryAndInvalidate();
void updateReplacedDimensions(const RenderBox&);
void updateInlineBlockDimensions(const RenderBlock&);
void updateLineBreakBoxDimensions(const RenderLineBreak&);
void updateInlineBoxDimensions(const RenderInline&);
void updateInlineTableDimensions(const RenderTable&);
void updateListItemDimensions(const RenderListItem&);
void updateListMarkerDimensions(const RenderListMarker&);
void updateInlineContentDimensions();
void updateStyle(const RenderBoxModelObject&, const RenderStyle& oldStyle);
void updateOverflow();

Expand Down Expand Up @@ -125,6 +119,14 @@ class LineLayout : public CanMakeCheckedPtr {
#endif

private:
void updateReplacedDimensions(const RenderBox&);
void updateInlineBlockDimensions(const RenderBlock&);
void updateLineBreakBoxDimensions(const RenderLineBreak&);
void updateInlineBoxDimensions(const RenderInline&);
void updateInlineTableDimensions(const RenderTable&);
void updateListItemDimensions(const RenderListItem&);
void updateListMarkerDimensions(const RenderListMarker&);

void prepareLayoutState();
void prepareFloatingState();
void constructContent();
Expand Down
43 changes: 3 additions & 40 deletions Source/WebCore/rendering/RenderBlockFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3627,34 +3627,6 @@ void RenderBlockFlow::layoutModernLines(bool relayoutChildren, LayoutUnit& repai
else if (!renderer.isOutOfFlowPositioned())
renderer.clearNeedsLayout();

if (is<RenderReplaced>(renderer)) {
layoutFormattingContextLineLayout.updateReplacedDimensions(downcast<RenderReplaced>(renderer));
continue;
}
if (is<RenderTable>(renderer)) {
layoutFormattingContextLineLayout.updateInlineTableDimensions(downcast<RenderTable>(renderer));
continue;
}
if (is<RenderListMarker>(renderer)) {
layoutFormattingContextLineLayout.updateListMarkerDimensions(downcast<RenderListMarker>(renderer));
continue;
}
if (is<RenderListItem>(renderer)) {
layoutFormattingContextLineLayout.updateListItemDimensions(downcast<RenderListItem>(renderer));
continue;
}
if (is<RenderBlock>(renderer)) {
layoutFormattingContextLineLayout.updateInlineBlockDimensions(downcast<RenderBlock>(renderer));
continue;
}
if (is<RenderLineBreak>(renderer)) {
layoutFormattingContextLineLayout.updateLineBreakBoxDimensions(downcast<RenderLineBreak>(renderer));
continue;
}
if (is<RenderInline>(renderer)) {
layoutFormattingContextLineLayout.updateInlineBoxDimensions(downcast<RenderInline>(renderer));
continue;
}
if (is<RenderCounter>(renderer)) {
// The counter content gets updated unconventionally by involving computePreferredLogicalWidths() (see RenderCounter::updateCounter())
// Here we assume that every time the content of a counter changes, we already handled the update by re-constructing the associated InlineTextBox (see BoxTree::buildTreeForInlineContent).
Expand All @@ -3664,6 +3636,8 @@ void RenderBlockFlow::layoutModernLines(bool relayoutChildren, LayoutUnit& repai
}
}

layoutFormattingContextLineLayout.updateInlineContentDimensions();

auto contentBoxTop = borderAndPaddingBefore();

auto computeContentHeight = [&] {
Expand Down Expand Up @@ -4496,18 +4470,7 @@ bool RenderBlockFlow::tryComputePreferredWidthsUsingModernPath(LayoutUnit& minLo
if (!modernLineLayout())
m_lineLayout = makeUnique<LayoutIntegration::LineLayout>(*this);

auto& layoutFormattingContextLineLayout = *this->modernLineLayout();
for (auto walker = InlineWalker(*this); !walker.atEnd(); walker.advance()) {
auto& renderer = *walker.current();
if (renderer.isText() || is<RenderLineBreak>(renderer))
continue;
if (is<RenderInline>(renderer)) {
layoutFormattingContextLineLayout.updateInlineBoxDimensions(downcast<RenderInline>(renderer));
continue;
}
// FIXME: Add other, inline level box cases.
ASSERT_NOT_IMPLEMENTED_YET();
}
modernLineLayout()->updateInlineContentDimensions();

std::tie(minLogicalWidth, maxLogicalWidth) = modernLineLayout()->computeIntrinsicWidthConstraints();
for (auto walker = InlineWalker(*this); !walker.atEnd(); walker.advance())
Expand Down

0 comments on commit 037ca44

Please sign in to comment.