Skip to content

Commit

Permalink
[IFC][Cleanup] Move members from TextOnlySimpleLineBuilder/LineBuilde…
Browse files Browse the repository at this point in the history
…r to parent class (AbstractLineBuilder)

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

Reviewed by Antti Koivisto.

* Source/WebCore/layout/formattingContexts/inline/AbstractLineBuilder.cpp:
(WebCore::Layout::AbstractLineBuilder::AbstractLineBuilder):
(WebCore::Layout::AbstractLineBuilder::reset):
(WebCore::Layout::AbstractLineBuilder::root const):
(WebCore::Layout::AbstractLineBuilder::rootStyle const):
(WebCore::Layout::AbstractLineBuilder::layoutState const):
(WebCore::Layout::AbstractLineBuilder::layoutState):
* Source/WebCore/layout/formattingContexts/inline/AbstractLineBuilder.h:
(WebCore::Layout::AbstractLineBuilder::isFirstFormattedLine const):
(WebCore::Layout::AbstractLineBuilder::formattingContext):
(WebCore::Layout::AbstractLineBuilder::formattingContext const):
(WebCore::Layout::AbstractLineBuilder::rootHorizontalConstraints const):
(WebCore::Layout::AbstractLineBuilder::blockLayoutState const):
* Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.cpp:
(WebCore::Layout::LineBuilder::LineBuilder):
(WebCore::Layout::LineBuilder::initialize):
(WebCore::Layout::LineBuilder::tryPlacingFloatBox):
(WebCore::Layout::LineBuilder::root const): Deleted.
(WebCore::Layout::LineBuilder::rootStyle const): Deleted.
(WebCore::Layout::LineBuilder::layoutState const): Deleted.
(WebCore::Layout::LineBuilder::layoutState): Deleted.
* Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.h:
(WebCore::Layout::LineBuilder::isLineConstrainedByFloat const):
(WebCore::Layout::LineBuilder::isFirstFormattedLine const): Deleted.
(WebCore::Layout::LineBuilder::formattingContext): Deleted.
(WebCore::Layout::LineBuilder::formattingContext const): Deleted.
(WebCore::Layout::LineBuilder::blockLayoutState const): Deleted.
* Source/WebCore/layout/formattingContexts/inline/TextOnlySimpleLineBuilder.cpp:
(WebCore::Layout::TextOnlySimpleLineBuilder::TextOnlySimpleLineBuilder):
(WebCore::Layout::TextOnlySimpleLineBuilder::initialize):
(WebCore::Layout::TextOnlySimpleLineBuilder::commitCandidateContent):
(WebCore::Layout::TextOnlySimpleLineBuilder::handleOverflowingTextContent):
(WebCore::Layout::TextOnlySimpleLineBuilder::revertToLastNonOverflowingItem):
(WebCore::Layout::TextOnlySimpleLineBuilder::root const): Deleted.
* Source/WebCore/layout/formattingContexts/inline/TextOnlySimpleLineBuilder.h:
(WebCore::Layout::TextOnlySimpleLineBuilder::isFirstFormattedLine const): Deleted.
(WebCore::Layout::TextOnlySimpleLineBuilder::formattingContext const): Deleted.

Canonical link: https://commits.webkit.org/270950@main
  • Loading branch information
alanbaradlay committed Nov 19, 2023
1 parent be6ad68 commit 77cb22c
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,26 @@

#include "FontCascade.h"
#include "InlineContentBreaker.h"
#include "InlineFormattingContext.h"

namespace WebCore {
namespace Layout {

AbstractLineBuilder::AbstractLineBuilder(InlineFormattingContext& inlineFormattingContext, HorizontalConstraints rootHorizontalConstraints, const InlineItemList& inlineItemList)
: m_line(inlineFormattingContext)
, m_inlineItemList(inlineItemList)
, m_inlineFormattingContext(inlineFormattingContext)
, m_rootHorizontalConstraints(rootHorizontalConstraints)
{
}

void AbstractLineBuilder::reset()
{
m_wrapOpportunityList = { };
m_partialLeadingTextItem = { };
m_previousLine = { };
}

std::optional<InlineLayoutUnit> AbstractLineBuilder::eligibleOverflowWidthAsLeading(const InlineContentBreaker::ContinuousContent::RunList& candidateRuns, const InlineContentBreaker::Result& lineBreakingResult, bool isFirstFormattedLine) const
{
auto eligibleTrailingRunIndex = [&]() -> std::optional<size_t> {
Expand Down Expand Up @@ -79,5 +95,25 @@ void AbstractLineBuilder::setIntrinsicWidthMode(IntrinsicWidthMode intrinsicWidt
m_inlineContentBreaker.setIsMinimumInIntrinsicWidthMode(m_intrinsicWidthMode == IntrinsicWidthMode::Minimum);
}

const ElementBox& AbstractLineBuilder::root() const
{
return formattingContext().root();
}

const RenderStyle& AbstractLineBuilder::rootStyle() const
{
return isFirstFormattedLine() ? root().firstLineStyle() : root().style();
}

const InlineLayoutState& AbstractLineBuilder::layoutState() const
{
return formattingContext().layoutState();
}

InlineLayoutState& AbstractLineBuilder::layoutState()
{
return formattingContext().layoutState();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@

#pragma once

#include "FormattingConstraints.h"
#include "InlineContentBreaker.h"
#include "InlineLayoutState.h"
#include "InlineLine.h"
#include "InlineLineTypes.h"
#include "LineLayoutResult.h"

namespace WebCore {
Expand All @@ -44,17 +48,42 @@ class AbstractLineBuilder {
void setIntrinsicWidthMode(IntrinsicWidthMode);

protected:
AbstractLineBuilder(InlineFormattingContext&, HorizontalConstraints rootHorizontalConstraints, const InlineItemList&);

void reset();

std::optional<InlineLayoutUnit> eligibleOverflowWidthAsLeading(const InlineContentBreaker::ContinuousContent::RunList&, const InlineContentBreaker::Result&, bool) const;

std::optional<IntrinsicWidthMode> intrinsicWidthMode() const { return m_intrinsicWidthMode; }
bool isInIntrinsicWidthMode() const { return !!intrinsicWidthMode(); }

bool isFirstFormattedLine() const { return !m_previousLine.has_value(); }

InlineContentBreaker& inlineContentBreaker() { return m_inlineContentBreaker; }

InlineFormattingContext& formattingContext() { return m_inlineFormattingContext; }
const InlineFormattingContext& formattingContext() const { return m_inlineFormattingContext; }
const HorizontalConstraints& rootHorizontalConstraints() const { return m_rootHorizontalConstraints; }
const InlineLayoutState& layoutState() const;
InlineLayoutState& layoutState();
const BlockLayoutState& blockLayoutState() const { return layoutState().parentBlockLayoutState(); }
const ElementBox& root() const;
const RenderStyle& rootStyle() const;

protected:
Line m_line;
InlineRect m_lineLogicalRect;
const InlineItemList& m_inlineItemList;
Vector<const InlineItem*> m_wrapOpportunityList;
std::optional<InlineTextItem> m_partialLeadingTextItem;
std::optional<PreviousLine> m_previousLine { };

private:
InlineFormattingContext& m_inlineFormattingContext;
HorizontalConstraints m_rootHorizontalConstraints;

InlineContentBreaker m_inlineContentBreaker;
std::optional<IntrinsicWidthMode> m_intrinsicWidthMode;

};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,8 @@ inline void LineCandidate::reset()


LineBuilder::LineBuilder(InlineFormattingContext& inlineFormattingContext, HorizontalConstraints rootHorizontalConstraints, const InlineItemList& inlineItemList)
: m_inlineFormattingContext(inlineFormattingContext)
, m_rootHorizontalConstraints(rootHorizontalConstraints)
, m_line(inlineFormattingContext)
: AbstractLineBuilder(inlineFormattingContext, rootHorizontalConstraints, inlineItemList)
, m_floatingContext(inlineFormattingContext.floatingContext())
, m_inlineItemList(inlineItemList)
{
}

Expand Down Expand Up @@ -275,12 +272,12 @@ LineLayoutResult LineBuilder::layoutInlineContent(const LineInput& lineInput, co
void LineBuilder::initialize(const InlineRect& initialLineLogicalRect, const UsedConstraints& lineConstraints, const InlineItemRange& needsLayoutRange, const std::optional<PreviousLine>& previousLine)
{
ASSERT(!needsLayoutRange.isEmpty() || (previousLine && !previousLine->suspendedFloats.isEmpty()));
reset();

m_previousLine = previousLine;
m_placedFloats.clear();
m_suspendedFloats.clear();
m_lineSpanningInlineBoxes.clear();
m_wrapOpportunityList.clear();
m_overflowingLogicalWidth = { };
m_partialLeadingTextItem = { };
m_initialLetterClearGap = { };
Expand Down Expand Up @@ -444,7 +441,7 @@ LineContent LineBuilder::placeInlineAndFloatContent(const InlineItemRange& needs
};
layoutInlineAndFloatContent();

auto comutePlacedInlineItemRange = [&] {
auto computePlacedInlineItemRange = [&] {
lineContent.range = { needsLayoutRange.start, { needsLayoutRange.startIndex() + placedInlineItemCount, { } } };
if (!placedInlineItemCount || placedInlineItemCount == m_placedFloats.size() || !lineContent.partialTrailingContentLength)
return;
Expand All @@ -454,7 +451,7 @@ LineContent LineBuilder::placeInlineAndFloatContent(const InlineItemRange& needs
ASSERT(lineContent.partialTrailingContentLength && lineContent.partialTrailingContentLength < overflowingInlineTextItemLength);
lineContent.range.end = { trailingInlineItemIndex, overflowingInlineTextItemLength - lineContent.partialTrailingContentLength };
};
comutePlacedInlineItemRange();
computePlacedInlineItemRange();

ASSERT(lineContent.range.endIndex() <= needsLayoutRange.endIndex());

Expand Down Expand Up @@ -929,7 +926,7 @@ bool LineBuilder::tryPlacingFloatBox(const Box& floatBox, MayOverConstrainLine m
staticPosition.move(boxGeometry.marginStart(), boxGeometry.marginBefore());
boxGeometry.setTopLeft(staticPosition);
// Compute float position by running float layout.
auto floatingPosition = floatingContext.positionForFloat(floatBox, boxGeometry, *m_rootHorizontalConstraints);
auto floatingPosition = floatingContext.positionForFloat(floatBox, boxGeometry, rootHorizontalConstraints());
boxGeometry.setTopLeft(floatingPosition);
};
computeFloatBoxPosition();
Expand Down Expand Up @@ -1231,26 +1228,6 @@ bool LineBuilder::isLastLineWithInlineContent(const LineContent& lineContent, si
return false;
}

const ElementBox& LineBuilder::root() const
{
return formattingContext().root();
}

const RenderStyle& LineBuilder::rootStyle() const
{
return isFirstFormattedLine() ? root().firstLineStyle() : root().style();
}

const InlineLayoutState& LineBuilder::layoutState() const
{
return formattingContext().layoutState();
}

InlineLayoutState& LineBuilder::layoutState()
{
return formattingContext().layoutState();
}

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@

#include "AbstractLineBuilder.h"
#include "FloatingContext.h"
#include "FormattingConstraints.h"
#include "InlineLayoutState.h"
#include "InlineLine.h"
#include "InlineLineTypes.h"

namespace WebCore {
namespace Layout {
Expand Down Expand Up @@ -89,36 +85,17 @@ class LineBuilder : public AbstractLineBuilder {
bool shouldTryToPlaceFloatBox(const Box& floatBox, LayoutUnit floatBoxMarginBoxWidth, MayOverConstrainLine) const;

bool isLineConstrainedByFloat() const { return !m_lineIsConstrainedByFloat.isEmpty(); }
bool isFirstFormattedLine() const { return !m_previousLine.has_value(); }

InlineFormattingContext& formattingContext() { return m_inlineFormattingContext; }
const InlineFormattingContext& formattingContext() const { return m_inlineFormattingContext; }
const FloatingContext& floatingContext() const { return m_floatingContext; }

const InlineLayoutState& layoutState() const;
InlineLayoutState& layoutState();
const BlockLayoutState& blockLayoutState() const { return layoutState().parentBlockLayoutState(); }
const ElementBox& root() const;
const RenderStyle& rootStyle() const;

private:
std::optional<PreviousLine> m_previousLine { };
InlineFormattingContext& m_inlineFormattingContext;
std::optional<HorizontalConstraints> m_rootHorizontalConstraints;

Line m_line;
const FloatingContext& m_floatingContext;
InlineRect m_lineInitialLogicalRect;
InlineRect m_lineLogicalRect;
InlineLayoutUnit m_lineMarginStart { 0.f };
InlineLayoutUnit m_initialIntrusiveFloatsWidth { 0.f };
InlineLayoutUnit m_candidateContentMaximumHeight { 0.f };
const InlineItemList& m_inlineItemList;
LineLayoutResult::PlacedFloatList m_placedFloats;
LineLayoutResult::SuspendedFloatList m_suspendedFloats;
std::optional<InlineTextItem> m_partialLeadingTextItem;
std::optional<InlineLayoutUnit> m_overflowingLogicalWidth;
Vector<const InlineItem*> m_wrapOpportunityList;
Vector<InlineItem> m_lineSpanningInlineBoxes;
OptionSet<UsedFloat> m_lineIsConstrainedByFloat { };
std::optional<InlineLayoutUnit> m_initialLetterClearGap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,8 @@ static inline bool consumeTrailingLineBreakIfApplicable(const TextOnlyLineBreakR
return true;
}

TextOnlySimpleLineBuilder::TextOnlySimpleLineBuilder(const InlineFormattingContext& inlineFormattingContext, HorizontalConstraints rootHorizontalConstraints, const InlineItemList& inlineItemList)
: m_inlineFormattingContext(inlineFormattingContext)
, m_rootHorizontalConstraints(rootHorizontalConstraints)
, m_line(inlineFormattingContext)
, m_inlineItemList(inlineItemList)
TextOnlySimpleLineBuilder::TextOnlySimpleLineBuilder(InlineFormattingContext& inlineFormattingContext, HorizontalConstraints rootHorizontalConstraints, const InlineItemList& inlineItemList)
: AbstractLineBuilder(inlineFormattingContext, rootHorizontalConstraints, inlineItemList)
, m_isWrappingAllowed(TextUtil::isWrappingAllowed(root().style()))
{
}
Expand Down Expand Up @@ -127,6 +124,8 @@ LineLayoutResult TextOnlySimpleLineBuilder::layoutInlineContent(const LineInput&

void TextOnlySimpleLineBuilder::initialize(const InlineItemRange& layoutRange, const InlineRect& initialLogicalRect, const std::optional<PreviousLine>& previousLine)
{
reset();

ASSERT(!layoutRange.isEmpty() || (previousLine && !previousLine->suspendedFloats.isEmpty()));
auto partialLeadingTextItem = [&]() -> std::optional<InlineTextItem> {
if (!previousLine || !layoutRange.start.offset)
Expand All @@ -146,7 +145,6 @@ void TextOnlySimpleLineBuilder::initialize(const InlineItemRange& layoutRange, c
m_line.initialize({ }, isFirstFormattedLine());
m_previousLine = previousLine;
m_lineLogicalRect = initialLogicalRect;
m_wrapOpportunityList = { };
m_trimmedTrailingWhitespaceWidth = { };
m_overflowContentLogicalWidth = { };
}
Expand Down Expand Up @@ -279,7 +277,7 @@ TextOnlyLineBreakResult TextOnlySimpleLineBuilder::commitCandidateContent(const
}

if (m_line.hasContentOrListMarker())
m_wrapOpportunityList.append(&downcast<InlineTextItem>(m_inlineItemList[candidateContent.endIndex - 1]));
m_wrapOpportunityList.append(&m_inlineItemList[candidateContent.endIndex - 1]);
return { InlineContentBreaker::IsEndOfLine::No, candidateContent.endIndex - candidateContent.startIndex };
}

Expand Down Expand Up @@ -313,7 +311,7 @@ TextOnlyLineBreakResult TextOnlySimpleLineBuilder::handleOverflowingTextContent(
for (auto& run : committedRuns)
m_line.appendTextFast(downcast<InlineTextItem>(run.inlineItem), run.style, run.logicalWidth);
if (m_line.hasContentOrListMarker())
m_wrapOpportunityList.append(&downcast<InlineTextItem>(committedRuns.last().inlineItem));
m_wrapOpportunityList.append(&committedRuns.last().inlineItem);
return { lineBreakingResult.isEndOfLine, committedRuns.size() };
}

Expand Down Expand Up @@ -368,7 +366,7 @@ TextOnlyLineBreakResult TextOnlySimpleLineBuilder::handleOverflowingTextContent(
}

if (lineBreakingResult.action == InlineContentBreaker::Result::Action::RevertToLastWrapOpportunity)
return { InlineContentBreaker::IsEndOfLine::Yes, revertToTrailingItem(layoutRange, *m_wrapOpportunityList.last()), { }, { }, true };
return { InlineContentBreaker::IsEndOfLine::Yes, revertToTrailingItem(layoutRange, downcast<InlineTextItem>(*m_wrapOpportunityList.last())), { }, { }, true };

if (lineBreakingResult.action == InlineContentBreaker::Result::Action::RevertToLastNonOverflowingWrapOpportunity)
return { InlineContentBreaker::IsEndOfLine::Yes, revertToLastNonOverflowingItem(layoutRange), { }, { }, true };
Expand Down Expand Up @@ -419,7 +417,7 @@ size_t TextOnlySimpleLineBuilder::revertToLastNonOverflowingItem(const InlineIte
{
// Revert all the way back to a wrap opportunity when either a soft hyphen fits or no hyphen is required.
for (auto i = m_wrapOpportunityList.size(); i--;) {
auto committedCount = revertToTrailingItem(layoutRange, *m_wrapOpportunityList[i]);
auto committedCount = revertToTrailingItem(layoutRange, downcast<InlineTextItem>(*m_wrapOpportunityList[i]));
auto trailingSoftHyphenWidth = m_line.trailingSoftHyphenWidth();

auto hasRevertedEnough = [&] {
Expand All @@ -443,11 +441,6 @@ InlineLayoutUnit TextOnlySimpleLineBuilder::availableWidth() const
return (m_lineLogicalRect.width() + LayoutUnit::epsilon()) - (!std::isnan(contentLogicalRight) ? contentLogicalRight : 0.f);
}

const ElementBox& TextOnlySimpleLineBuilder::root() const
{
return formattingContext().root();
}

bool TextOnlySimpleLineBuilder::isEligibleForSimplifiedTextOnlyInlineLayout(const ElementBox& rootBox, const InlineContentCache& inlineContentCache, const PlacedFloats* placedFloats)
{
if (placedFloats && !placedFloats->isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
#pragma once

#include "AbstractLineBuilder.h"
#include "FormattingConstraints.h"
#include "InlineLine.h"
#include "InlineLineBuilder.h"
#include "InlineLineTypes.h"

namespace WebCore {
namespace Layout {
Expand All @@ -41,7 +37,7 @@ struct TextOnlyLineBreakResult;

class TextOnlySimpleLineBuilder : public AbstractLineBuilder {
public:
TextOnlySimpleLineBuilder(const InlineFormattingContext&, HorizontalConstraints rootHorizontalConstraints, const InlineItemList&);
TextOnlySimpleLineBuilder(InlineFormattingContext&, HorizontalConstraints rootHorizontalConstraints, const InlineItemList&);
LineLayoutResult layoutInlineContent(const LineInput&, const std::optional<PreviousLine>&) final;

static bool isEligibleForSimplifiedTextOnlyInlineLayout(const ElementBox& root, const InlineContentCache&, const PlacedFloats* = nullptr);
Expand All @@ -58,26 +54,10 @@ class TextOnlySimpleLineBuilder : public AbstractLineBuilder {
InlineLayoutUnit availableWidth() const;
bool isWrappingAllowed() const { return m_isWrappingAllowed; }

bool isFirstFormattedLine() const { return !m_previousLine.has_value(); }

const InlineFormattingContext& formattingContext() const { return m_inlineFormattingContext; }
const ElementBox& root() const;

private:
std::optional<PreviousLine> m_previousLine { };
std::optional<IntrinsicWidthMode> m_intrinsicWidthMode;
const InlineFormattingContext& m_inlineFormattingContext;
std::optional<HorizontalConstraints> m_rootHorizontalConstraints;

Line m_line;
InlineRect m_lineLogicalRect;
const InlineItemList& m_inlineItemList;
Vector<const InlineTextItem*> m_wrapOpportunityList;
bool m_isWrappingAllowed { false };
InlineLayoutUnit m_trimmedTrailingWhitespaceWidth { 0.f };
std::optional<InlineLayoutUnit> m_overflowContentLogicalWidth { };

std::optional<InlineTextItem> m_partialLeadingTextItem;
};

}
Expand Down

0 comments on commit 77cb22c

Please sign in to comment.