Skip to content

Commit

Permalink
[IFC][Cleanup] Populate inline layout state (using LayoutState)
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=262450

Reviewed by Antti Koivisto.

Let's not consult the global layout state (renaming is coming up soon) in core inline layout
but instead transfer the inline layout related bits to inline-layout-state.

* Source/WebCore/layout/LayoutState.cpp:
(WebCore::Layout::LayoutState::LayoutState):
(WebCore::Layout::LayoutState::formattingStateForFormattingContext const):
(WebCore::Layout::LayoutState::formattingStateForFlexFormattingContext const):
(WebCore::Layout::LayoutState::ensureFlexFormattingState):
(WebCore::Layout::LayoutState::shouldNotSynthesizeInlineBlockBaseline const): Deleted.
* Source/WebCore/layout/LayoutState.h:
(WebCore::Layout::LayoutState::isInlineFormattingContextIntegration const): Deleted.
(WebCore::Layout::LayoutState::isFlexFormattingContextIntegration const): Deleted.
* Source/WebCore/layout/formattingContexts/inline/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::initializeLayoutState):
* Source/WebCore/layout/formattingContexts/inline/InlineFormattingGeometry.cpp:
(WebCore::Layout::InlineFormattingGeometry::inlineLevelBoxAffectsLineBox const):
(WebCore::Layout::InlineFormattingGeometry::initialLineHeight const):
(WebCore::Layout::InlineFormattingGeometry::inlineLayoutState const):
* Source/WebCore/layout/formattingContexts/inline/InlineFormattingGeometry.h:
* Source/WebCore/layout/formattingContexts/inline/InlineLayoutState.h:
(WebCore::Layout::InlineLayoutState::setInStandardsMode):
(WebCore::Layout::InlineLayoutState::inStandardsMode const):
(WebCore::Layout::InlineLayoutState::setShouldSynthesizeInlineBlockBaseline):
(WebCore::Layout::InlineLayoutState::shouldSynthesizeInlineBlockBaseline const):
* Source/WebCore/layout/formattingContexts/inline/InlineLineBoxBuilder.cpp:
(WebCore::Layout::LineBoxBuilder::setVerticalPropertiesForInlineLevelBox const):
(WebCore::Layout::LineBoxBuilder::constructInlineLevelBoxes):
* Source/WebCore/layout/formattingContexts/inline/InlineLineBoxBuilder.h:
(WebCore::Layout::LineBoxBuilder::blockLayoutState const):
(WebCore::Layout::LineBoxBuilder::layoutState const): Deleted.
* Source/WebCore/layout/formattingContexts/inline/InlineLineBoxVerticalAligner.cpp:
(WebCore::Layout::LineBoxVerticalAligner::computeLogicalHeightAndAlign const):
* Source/WebCore/layout/formattingContexts/inline/InlineLineBoxVerticalAligner.h:
(WebCore::Layout::LineBoxVerticalAligner::inlineLayoutState const):
(WebCore::Layout::LineBoxVerticalAligner::layoutState const): Deleted.
* Source/WebCore/layout/formattingContexts/inline/InlineQuirks.cpp:
(WebCore::Layout::InlineQuirks::initialLineHeight const):
(WebCore::Layout::InlineQuirks::inlineBoxAffectsLineBox const):
* Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayLineBuilder.cpp:
(WebCore::Layout::InlineDisplayLineBuilder::collectEnclosingLineGeometry const):
* Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayLineBuilder.h:
(WebCore::Layout::InlineDisplayLineBuilder::root const):
(WebCore::Layout::InlineDisplayLineBuilder::layoutState const): Deleted.
* Source/WebCore/rendering/RenderView.cpp:
(WebCore::RenderView::RenderView):

Canonical link: https://commits.webkit.org/268788@main
  • Loading branch information
alanbaradlay committed Oct 3, 2023
1 parent eae66f4 commit 5c15562
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 62 deletions.
31 changes: 1 addition & 30 deletions Source/WebCore/layout/LayoutState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ namespace Layout {

WTF_MAKE_ISO_ALLOCATED_IMPL(LayoutState);

LayoutState::LayoutState(const Document& document, const ElementBox& rootContainer, std::optional<FormattingContextIntegrationType> formattingContextIntegrationType)
LayoutState::LayoutState(const Document& document, const ElementBox& rootContainer)
: m_rootContainer(rootContainer)
, m_formattingContextIntegrationType(formattingContextIntegrationType)
{
// It makes absolutely no sense to construct a dedicated layout state for a non-formatting context root (layout would be a no-op).
ASSERT(root().establishesFormattingContext());
Expand Down Expand Up @@ -99,20 +98,12 @@ FormattingState& LayoutState::formattingStateForFormattingContext(const ElementB
{
ASSERT(formattingContextRoot.establishesFormattingContext());

if (isFlexFormattingContextIntegration()) {
ASSERT(&formattingContextRoot == m_rootContainer.ptr());
return *m_rootFlexFormattingStateForIntegration;
}

if (formattingContextRoot.establishesBlockFormattingContext())
return formattingStateForBlockFormattingContext(formattingContextRoot);

if (formattingContextRoot.establishesTableFormattingContext())
return formattingStateForTableFormattingContext(formattingContextRoot);

if (formattingContextRoot.establishesFlexFormattingContext())
return formattingStateForFlexFormattingContext(formattingContextRoot);

CRASH();
}

Expand All @@ -131,12 +122,6 @@ TableFormattingState& LayoutState::formattingStateForTableFormattingContext(cons
FlexFormattingState& LayoutState::formattingStateForFlexFormattingContext(const ElementBox& flexFormattingContextRoot) const
{
ASSERT(flexFormattingContextRoot.establishesFlexFormattingContext());

if (isFlexFormattingContextIntegration()) {
ASSERT(&flexFormattingContextRoot == m_rootContainer.ptr());
return *m_rootFlexFormattingStateForIntegration;
}

return *m_flexFormattingStates.get(&flexFormattingContextRoot);
}

Expand All @@ -161,15 +146,6 @@ TableFormattingState& LayoutState::ensureTableFormattingState(const ElementBox&
FlexFormattingState& LayoutState::ensureFlexFormattingState(const ElementBox& formattingContextRoot)
{
ASSERT(formattingContextRoot.establishesFlexFormattingContext());

if (isFlexFormattingContextIntegration()) {
if (!m_rootFlexFormattingStateForIntegration) {
ASSERT(&formattingContextRoot == m_rootContainer.ptr());
m_rootFlexFormattingStateForIntegration = makeUnique<FlexFormattingState>(*this);
}
return *m_rootFlexFormattingStateForIntegration;
}

return *m_flexFormattingStates.ensure(&formattingContextRoot, [&] { return makeUnique<FlexFormattingState>(*this); }).iterator->value;
}

Expand All @@ -185,11 +161,6 @@ void LayoutState::destroyInlineContentCache(const ElementBox& formattingContextR
m_inlineContentCaches.remove(&formattingContextRoot);
}

bool LayoutState::shouldNotSynthesizeInlineBlockBaseline() const
{
return isInlineFormattingContextIntegration();
}

}
}

15 changes: 1 addition & 14 deletions Source/WebCore/layout/LayoutState.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ class LayoutState : public CanMakeWeakPtr<LayoutState> {
WTF_MAKE_NONCOPYABLE(LayoutState);
WTF_MAKE_ISO_ALLOCATED(LayoutState);
public:
enum class FormattingContextIntegrationType {
Inline,
Flex
};
LayoutState(const Document&, const ElementBox& rootContainer, std::optional<FormattingContextIntegrationType> = std::nullopt);
LayoutState(const Document&, const ElementBox& rootContainer);
~LayoutState();

void updateQuirksMode(const Document&);
Expand Down Expand Up @@ -92,12 +88,6 @@ class LayoutState : public CanMakeWeakPtr<LayoutState> {

const ElementBox& root() const { return m_rootContainer; }

// LFC integration only. Full LFC has proper ICB access.
bool isInlineFormattingContextIntegration() const { return m_formattingContextIntegrationType && *m_formattingContextIntegrationType == FormattingContextIntegrationType::Inline; }
bool isFlexFormattingContextIntegration() const { return m_formattingContextIntegrationType && *m_formattingContextIntegrationType == FormattingContextIntegrationType::Flex; }

bool shouldNotSynthesizeInlineBlockBaseline() const;

private:
void setQuirksMode(QuirksMode quirksMode) { m_quirksMode = quirksMode; }
BoxGeometry& ensureGeometryForBoxSlow(const Box&);
Expand All @@ -117,9 +107,6 @@ class LayoutState : public CanMakeWeakPtr<LayoutState> {
QuirksMode m_quirksMode { QuirksMode::No };

CheckedRef<const ElementBox> m_rootContainer;

// LFC integration only.
std::optional<FormattingContextIntegrationType> m_formattingContextIntegrationType;
};

inline bool LayoutState::hasBoxGeometry(const Box& layoutBox) const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,14 @@ bool InlineFormattingContext::createDisplayContentForLineFromCachedContent(const

void InlineFormattingContext::initializeLayoutState()
{
auto& inlineLayoutState = this->inlineLayoutState();

if (auto limitLinesValue = root().style().hyphenationLimitLines(); limitLinesValue != RenderStyle::initialHyphenationLimitLines())
inlineLayoutState().setHyphenationLimitLines(limitLinesValue);
inlineLayoutState.setHyphenationLimitLines(limitLinesValue);
// FIXME: Remove when IFC takes care of running layout on inline-blocks.
inlineLayoutState.setShouldNotSynthesizeInlineBlockBaseline();
if (layoutState().inStandardsMode())
inlineLayoutState.setInStandardsMode();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ bool InlineFormattingGeometry::inlineLevelBoxAffectsLineBox(const InlineLevelBox
if (inlineLevelBox.isListMarker())
return true;
if (inlineLevelBox.isInlineBox())
return layoutState().inStandardsMode() ? true : formattingContext().quirks().inlineBoxAffectsLineBox(inlineLevelBox);
return inlineLayoutState().inStandardsMode() ? true : formattingContext().quirks().inlineBoxAffectsLineBox(inlineLevelBox);
if (inlineLevelBox.isAtomicInlineLevelBox())
return !inlineLevelBox.layoutBox().isRubyAnnotationBox();
return false;
Expand Down Expand Up @@ -212,7 +212,7 @@ InlineLayoutUnit InlineFormattingGeometry::computedTextIndent(IsIntrinsicWidthMo

InlineLayoutUnit InlineFormattingGeometry::initialLineHeight(bool isFirstLine) const
{
if (layoutState().inStandardsMode())
if (inlineLayoutState().inStandardsMode())
return isFirstLine ? formattingContext().root().firstLineStyle().computedLineHeight() : formattingContext().root().style().computedLineHeight();
return formattingContext().quirks().initialLineHeight();
}
Expand Down Expand Up @@ -527,6 +527,10 @@ size_t InlineFormattingGeometry::nextWrapOpportunity(size_t startIndex, const In
return layoutRange.endIndex();
}

const InlineLayoutState& InlineFormattingGeometry::inlineLayoutState() const
{
return formattingContext().inlineLayoutState();
}

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class InlineFormattingGeometry : public FormattingGeometry {
InlineLayoutUnit contentLeftAfterLastLine(const ConstraintsForInFlowContent&, std::optional<InlineLayoutUnit> lastLineLogicalBottom, const FloatingContext&) const;

const InlineFormattingContext& formattingContext() const { return downcast<InlineFormattingContext>(FormattingGeometry::formattingContext()); }

const InlineLayoutState& inlineLayoutState() const;
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,14 @@ class InlineLayoutState {
void resetSuccessiveHyphenatedLineCount() { m_successiveHyphenatedLineCount = 0; }
bool isHyphenationDisabled() const { return m_hyphenationLimitLines && *m_hyphenationLimitLines <= m_successiveHyphenatedLineCount; }

void setInStandardsMode() { m_inStandardsMode = true; }
bool inStandardsMode() const { return m_inStandardsMode; }

// Integration codepath
void setNestedListMarkerOffsets(HashMap<const ElementBox*, LayoutUnit>&& nestedListMarkerOffsets) { m_nestedListMarkerOffsets = WTFMove(nestedListMarkerOffsets); }
LayoutUnit nestedListMarkerOffset(const ElementBox& listMarkerBox) const { return m_nestedListMarkerOffsets.get(&listMarkerBox); }
void setShouldNotSynthesizeInlineBlockBaseline() { m_shouldNotSynthesizeInlineBlockBaseline = true; }
bool shouldNotSynthesizeInlineBlockBaseline() const { return m_shouldNotSynthesizeInlineBlockBaseline; }

private:
BlockLayoutState& m_parentBlockLayoutState;
Expand All @@ -69,6 +74,8 @@ class InlineLayoutState {
// FIXME: This is required by the integaration codepath.
HashMap<const ElementBox*, LayoutUnit> m_nestedListMarkerOffsets;
AvailableLineWidthOverride m_availableLineWidthOverride;
bool m_shouldNotSynthesizeInlineBlockBaseline { false };
bool m_inStandardsMode { false };
};

inline InlineLayoutState::InlineLayoutState(BlockLayoutState& parentBlockLayoutState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ void LineBoxBuilder::setVerticalPropertiesForInlineLevelBox(const LineBox& lineB
auto& inlineLevelBoxGeometry = formattingContext().geometryForBox(layoutBox);
auto marginBoxHeight = inlineLevelBoxGeometry.marginBoxHeight();
auto ascent = [&]() -> InlineLayoutUnit {
if (layoutState().shouldNotSynthesizeInlineBlockBaseline())
if (inlineLayoutState().shouldNotSynthesizeInlineBlockBaseline())
return downcast<ElementBox>(layoutBox).baselineForIntegration().value_or(marginBoxHeight);

if (layoutBox.isInlineBlockBox()) {
Expand Down Expand Up @@ -426,7 +426,7 @@ void LineBoxBuilder::constructInlineLevelBoxes(LineBox& lineBox)
setVerticalPropertiesForInlineLevelBox(lineBox, lineBreakBox);
lineBox.addInlineLevelBox(WTFMove(lineBreakBox));

if (layoutState().inStandardsMode() || InlineQuirks::lineBreakBoxAffectsParentInlineBox(lineBox))
if (inlineLayoutState().inStandardsMode() || InlineQuirks::lineBreakBoxAffectsParentInlineBox(lineBox))
lineBox.parentInlineBox(run).setHasContent();
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class LineBoxBuilder {

const InlineLayoutState& inlineLayoutState() const { return formattingContext().inlineLayoutState(); }
const BlockLayoutState& blockLayoutState() const { return inlineLayoutState().parentBlockLayoutState(); }
const LayoutState& layoutState() const { return formattingContext().layoutState(); }

private:
const InlineFormattingContext& m_inlineFormattingContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ InlineLayoutUnit LineBoxVerticalAligner::computeLogicalHeightAndAlign(LineBox& l
if (rootBox().style().lineBoxContain() != RenderStyle::initialLineBoxContain())
return false;
auto& rootInlineBox = lineBox.rootInlineBox();
if (!layoutState().inStandardsMode() || !rootInlineBox.isPreferredLineHeightFontMetricsBased() || rootInlineBox.verticalAlign().type != VerticalAlign::Baseline)
if (!inlineLayoutState().inStandardsMode() || !rootInlineBox.isPreferredLineHeightFontMetricsBased() || rootInlineBox.verticalAlign().type != VerticalAlign::Baseline)
return false;
if (rootInlineBox.hasAnnotation())
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class LineBoxVerticalAligner {
const InlineFormattingGeometry& formattingGeometry() const { return m_inlineFormattingGeometry; }
const InlineFormattingContext& formattingContext() const { return m_inlineFormattingContext; }
const ElementBox& rootBox() const { return formattingContext().root(); }
const LayoutState& layoutState() const { return formattingContext().layoutState(); }
const InlineLayoutState& inlineLayoutState() const { return formattingContext().inlineLayoutState(); }

private:
const InlineFormattingContext& m_inlineFormattingContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bool InlineQuirks::trailingNonBreakingSpaceNeedsAdjustment(bool isInIntrinsicWid

InlineLayoutUnit InlineQuirks::initialLineHeight() const
{
ASSERT(!formattingContext().layoutState().inStandardsMode());
ASSERT(!formattingContext().inlineLayoutState().inStandardsMode());
return 0.f;
}

Expand Down Expand Up @@ -77,7 +77,7 @@ bool InlineQuirks::lineBreakBoxAffectsParentInlineBox(const LineBox& lineBox)

bool InlineQuirks::inlineBoxAffectsLineBox(const InlineLevelBox& inlineLevelBox) const
{
ASSERT(!formattingContext().layoutState().inStandardsMode());
ASSERT(!formattingContext().inlineLayoutState().inStandardsMode());
ASSERT(inlineLevelBox.isInlineBox());
// Inline boxes (e.g. root inline box or <span>) affects line boxes either through the strut or actual content.
if (inlineLevelBox.hasContent())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,9 @@ InlineDisplayLineBuilder::EnclosingLineGeometry InlineDisplayLineBuilder::collec
borderBox.moveBy(lineBoxRect.topLeft());
} else if (inlineLevelBox.isInlineBox()) {
auto& boxGeometry = formattingContext().geometryForBox(layoutBox);
auto isContentful = [&] {
// In standards mode, inline boxes always start with an imaginary strut.
return layoutState().inStandardsMode() || inlineLevelBox.hasContent() || boxGeometry.horizontalBorder() || (boxGeometry.horizontalPadding() && boxGeometry.horizontalPadding().value());
};
if (!isContentful())
// In standards mode, inline boxes always start with an imaginary strut.
auto isContentful = formattingContext().inlineLayoutState().inStandardsMode() || inlineLevelBox.hasContent() || boxGeometry.horizontalBorder() || (boxGeometry.horizontalPadding() && boxGeometry.horizontalPadding().value());
if (!isContentful)
continue;
borderBox = lineBox.logicalBorderBoxForInlineBox(layoutBox, boxGeometry);
borderBox.moveBy(lineBoxRect.topLeft());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class InlineDisplayLineBuilder {
const InlineFormattingContext& formattingContext() const { return m_inlineFormattingContext; }
InlineFormattingContext& formattingContext() { return m_inlineFormattingContext; }
const Box& root() const { return formattingContext().root(); }
const LayoutState& layoutState() const { return formattingContext().layoutState(); }

private:
InlineFormattingContext& m_inlineFormattingContext;
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/rendering/RenderView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ RenderView::RenderView(Document& document, RenderStyle&& style)
: RenderBlockFlow(Type::View, document, WTFMove(style))
, m_frameView(*document.view())
, m_initialContainingBlock(makeUniqueRef<Layout::InitialContainingBlock>(RenderStyle::clone(this->style())))
, m_layoutState(makeUniqueRef<Layout::LayoutState>(document, *m_initialContainingBlock, Layout::LayoutState::FormattingContextIntegrationType::Inline))
, m_layoutState(makeUniqueRef<Layout::LayoutState>(document, *m_initialContainingBlock))
, m_selection(*this)
, m_lazyRepaintTimer(*this, &RenderView::lazyRepaintTimerFired)
{
Expand Down

0 comments on commit 5c15562

Please sign in to comment.