Skip to content

Commit

Permalink
[IFC][Cleanup] Move LineBuilder's m_successiveHyphenatedLineCount to …
Browse files Browse the repository at this point in the history
…InlineLayoutState

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

Reviewed by Antti Koivisto.

When m_successiveHyphenatedLineCount was introduced, we did not have InlineLayoutState yet
(but that's where it belongs).

* Source/WebCore/layout/formattingContexts/flex/FlexLayout.cpp:
(WebCore::Layout::FlexLayout::hypotheticalCrossSizeForFlexItems const):
* Source/WebCore/layout/formattingContexts/inline/InlineContentBalancer.cpp:
(WebCore::Layout::InlineContentBalancer::initialize):
* Source/WebCore/layout/formattingContexts/inline/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::lineLayout):
(WebCore::Layout::InlineFormattingContext::updateInlineLayoutStateWithLineLayoutResult):
* Source/WebCore/layout/formattingContexts/inline/InlineFormattingContext.h:
* Source/WebCore/layout/formattingContexts/inline/InlineLayoutState.h:
(WebCore::Layout::InlineLayoutState::incrementSuccessiveHyphenatedLineCount):
(WebCore::Layout::InlineLayoutState::resetSuccessiveHyphenatedLineCount):
(WebCore::Layout::InlineLayoutState::isHyphenationDisabled const):
(WebCore::Layout::InlineLayoutState::InlineLayoutState):
* Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.cpp:
(WebCore::Layout::LineBuilder::layoutInlineContent):
(WebCore::Layout::LineBuilder::initialize):
(WebCore::Layout::LineBuilder::placeInlineAndFloatContent):
(WebCore::Layout::LineBuilder::handleInlineContent):
(WebCore::Layout::shouldDisableHyphenation): Deleted.
* Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.h:
(WebCore::Layout::LineBuilder::inlineLayoutState const):
* Source/WebCore/layout/formattingContexts/inline/IntrinsicWidthHandler.cpp:
(WebCore::Layout::IntrinsicWidthHandler::computedIntrinsicSizes):
(WebCore::Layout::IntrinsicWidthHandler::maximumContentSize):
* Source/WebCore/layout/formattingContexts/inline/LineLayoutResult.h:
* Source/WebCore/layout/formattingContexts/inline/TextOnlySimpleLineBuilder.cpp:
(WebCore::Layout::TextOnlySimpleLineBuilder::layoutInlineContent):
* Source/WebCore/layout/integration/inline/LayoutIntegrationLineLayout.cpp:
(WebCore::LayoutIntegration::LineLayout::layout):

Canonical link: https://commits.webkit.org/268060@main
  • Loading branch information
alanbaradlay committed Sep 17, 2023
1 parent 61e2bf8 commit 6c5b713
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ FlexLayout::SizeList FlexLayout::hypotheticalCrossSizeForFlexItems(const Logical
// FIXME: Let it run through integration codepath.
auto floatingState = FloatingState { flexItemBox };
auto parentBlockLayoutState = BlockLayoutState { floatingState };
auto inlineLayoutState = InlineLayoutState { parentBlockLayoutState, { } };
auto inlineLayoutState = InlineLayoutState { parentBlockLayoutState, { }, { } };
auto& inlineFormattingState = flexFormattingContext().layoutState().ensureInlineFormattingState(flexItemBox);
auto inlineFormattingContext = InlineFormattingContext { flexItemBox, inlineFormattingState };
auto constraintsForInFlowContent = ConstraintsForInFlowContent { HorizontalConstraints { { }, flexItemsMainSizeList[flexItemIndex] }, { } };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void InlineContentBalancer::initialize()
InlineItemRange layoutRange = InlineItemRange { 0, m_inlineItems.size() };
auto floatingState = FloatingState { m_inlineFormattingContext.root() };
auto parentBlockLayoutState = BlockLayoutState { floatingState, { } };
auto inlineLayoutState = InlineLayoutState { parentBlockLayoutState, { } };
auto inlineLayoutState = InlineLayoutState { parentBlockLayoutState, { }, { } };
auto lineBuilder = LineBuilder { m_inlineFormattingContext, inlineLayoutState, floatingState, m_horizontalConstraints, m_inlineItems };
auto previousLineEnd = std::optional<InlineItemPosition> { };
auto previousLine = std::optional<PreviousLine> { };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,7 @@ InlineLayoutResult InlineFormattingContext::lineLayout(AbstractLineBuilder& line
auto lineIndex = previousLine ? (previousLine->lineIndex + 1) : 0lu;
auto lineLogicalRect = createDisplayContentForInlineContent(lineIndex, lineLayoutResult, constraints, inlineLayoutState, layoutResult.displayContent);
updateBoxGeometryForPlacedFloats(lineLayoutResult.floatContent.placedFloats);

if (auto firstLineGap = lineLayoutResult.lineGeometry.initialLetterClearGap) {
ASSERT(!inlineLayoutState.clearGapBeforeFirstLine());
inlineLayoutState.setClearGapBeforeFirstLine(*firstLineGap);
}

if (lineLayoutResult.isFirstLast.isLastLineWithInlineContent)
inlineLayoutState.setClearGapAfterLastLine(formattingGeometry().logicalTopForNextLine(lineLayoutResult, lineLogicalRect, floatingContext) - lineLogicalRect.bottom());
updateInlineLayoutStateWithLineLayoutResult(lineLayoutResult, inlineLayoutState, lineLogicalRect, floatingContext);

auto lineContentEnd = lineLayoutResult.inlineItemRange.end;
leadingInlineItemPosition = InlineFormattingGeometry::leadingInlineItemPositionForNextLine(lineContentEnd, previousLineEnd, needsLayoutRange.end);
Expand All @@ -205,9 +198,9 @@ InlineLayoutResult InlineFormattingContext::lineLayout(AbstractLineBuilder& line
break;
}

lineLogicalTop = formattingGeometry().logicalTopForNextLine(lineLayoutResult, lineLogicalRect, floatingContext);
previousLine = PreviousLine { lineIndex, lineLayoutResult.contentGeometry.trailingOverflowingContentWidth, !lineLayoutResult.inlineContent.isEmpty() && lineLayoutResult.inlineContent.last().isLineBreak(), lineLayoutResult.directionality.inlineBaseDirection, WTFMove(lineLayoutResult.floatContent.suspendedFloats) };
previousLineEnd = lineContentEnd;
lineLogicalTop = formattingGeometry().logicalTopForNextLine(lineLayoutResult, lineLogicalRect, floatingContext);
}
InlineDisplayLineBuilder::addLineClampTrailingLinkBoxIfApplicable(*this, inlineLayoutState, layoutResult.displayContent);
return layoutResult;
Expand Down Expand Up @@ -254,6 +247,19 @@ static LineEndingEllipsisPolicy lineEndingEllipsisPolicy(const RenderStyle& root
return LineEndingEllipsisPolicy::No;
}

void InlineFormattingContext::updateInlineLayoutStateWithLineLayoutResult(const LineLayoutResult& lineLayoutResult, InlineLayoutState& inlineLayoutState, const InlineRect& lineLogicalRect, const FloatingContext& floatingContext)
{
if (auto firstLineGap = lineLayoutResult.lineGeometry.initialLetterClearGap) {
ASSERT(!inlineLayoutState.clearGapBeforeFirstLine());
inlineLayoutState.setClearGapBeforeFirstLine(*firstLineGap);
}

if (lineLayoutResult.isFirstLast.isLastLineWithInlineContent)
inlineLayoutState.setClearGapAfterLastLine(formattingGeometry().logicalTopForNextLine(lineLayoutResult, lineLogicalRect, floatingContext) - lineLogicalRect.bottom());

lineLayoutResult.endsWithHyphen ? inlineLayoutState.incrementSuccessiveHyphenatedLineCount() : inlineLayoutState.resetSuccessiveHyphenatedLineCount();
}

void InlineFormattingContext::updateBoxGeometryForPlacedFloats(const LineLayoutResult::PlacedFloatList& placedFloats)
{
for (auto& floatItem : placedFloats) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class InlineFormattingContext final : public FormattingContext {

void collectContentIfNeeded();
InlineRect createDisplayContentForInlineContent(size_t lineIndex, const LineLayoutResult&, const ConstraintsForInlineContent&, InlineLayoutState&, InlineDisplay::Content&);
void updateInlineLayoutStateWithLineLayoutResult(const LineLayoutResult&, InlineLayoutState&, const InlineRect& lineLogicalRect, const FloatingContext&);
void updateBoxGeometryForPlacedFloats(const LineLayoutResult::PlacedFloatList&);
void resetGeometryForClampedContent(const InlineItemRange& needsDisplayContentRange, const LineLayoutResult::SuspendedFloatList& suspendedFloats, LayoutPoint topleft);
bool createDisplayContentForLineFromCachedContent(const ConstraintsForInlineContent&, InlineLayoutState&, InlineLayoutResult&);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@

#include "AvailableLineWidthOverride.h"
#include "BlockLayoutState.h"
#include "FloatingState.h"

namespace WebCore {
namespace Layout {

class InlineLayoutState {
public:
InlineLayoutState(BlockLayoutState&, HashMap<const ElementBox*, LayoutUnit>&& nestedListMarkerOffsets);
InlineLayoutState(BlockLayoutState&, HashMap<const ElementBox*, LayoutUnit>&& nestedListMarkerOffsets, std::optional<size_t> hyphenationLimitLines);

void setClearGapAfterLastLine(InlineLayoutUnit verticalGap);
InlineLayoutUnit clearGapAfterLastLine() const { return m_clearGapAfterLastLine; }
Expand All @@ -53,18 +52,25 @@ class InlineLayoutState {
void setClampedLineIndex(size_t lineIndex) { m_clampedLineIndex = lineIndex; }
std::optional<size_t> clampedLineIndex() const { return m_clampedLineIndex; }

void incrementSuccessiveHyphenatedLineCount() { ++m_successiveHyphenatedLineCount; }
void resetSuccessiveHyphenatedLineCount() { m_successiveHyphenatedLineCount = 0; }
bool isHyphenationDisabled() const { return m_hyphenationLimitLines && *m_hyphenationLimitLines <= m_successiveHyphenatedLineCount; }

private:
BlockLayoutState& m_parentBlockLayoutState;
InlineLayoutUnit m_clearGapBeforeFirstLine { 0.f };
InlineLayoutUnit m_clearGapAfterLastLine { 0.f };
std::optional<size_t> m_clampedLineIndex { };
const std::optional<size_t> m_hyphenationLimitLines { };
size_t m_successiveHyphenatedLineCount { 0 };
// FIXME: This is required by the integaration codepath.
HashMap<const ElementBox*, LayoutUnit> m_nestedListMarkerOffsets;
AvailableLineWidthOverride m_availableLineWidthOverride;
};

inline InlineLayoutState::InlineLayoutState(BlockLayoutState& parentBlockLayoutState, HashMap<const ElementBox*, LayoutUnit>&& nestedListMarkerOffsets)
inline InlineLayoutState::InlineLayoutState(BlockLayoutState& parentBlockLayoutState, HashMap<const ElementBox*, LayoutUnit>&& nestedListMarkerOffsets, std::optional<size_t> hyphenationLimitLines)
: m_parentBlockLayoutState(parentBlockLayoutState)
, m_hyphenationLimitLines(hyphenationLimitLines)
, m_nestedListMarkerOffsets(WTFMove(nestedListMarkerOffsets))
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace Layout {

struct LineContent {
InlineItemRange range;
bool endsWithHyphen { false };
size_t partialTrailingContentLength { 0 };
std::optional<InlineLayoutUnit> overflowLogicalWidth { };
};
Expand Down Expand Up @@ -259,6 +260,7 @@ LineLayoutResult LineBuilder::layoutInlineContent(const LineInput& lineInput, co
, { !result.isHangingTrailingContentWhitespace, result.hangingTrailingContentWidth }
, { WTFMove(visualOrderList), inlineBaseDirection }
, { isFirstFormattedLine() ? LineLayoutResult::IsFirstLast::FirstFormattedLine::WithinIFC : LineLayoutResult::IsFirstLast::FirstFormattedLine::No, isLastLine }
, lineContent.endsWithHyphen
, result.nonSpanningInlineLevelBoxCount
, { }
, lineContent.range.isEmpty() ? std::make_optional(m_lineLogicalRect.top() + m_candidateContentMaximumHeight) : std::nullopt
Expand All @@ -278,6 +280,7 @@ void LineBuilder::initialize(const InlineRect& initialLineLogicalRect, const Use
m_partialLeadingTextItem = { };
m_initialLetterClearGap = { };
m_candidateContentMaximumHeight = { };
inlineContentBreaker().setHyphenationDisabled(inlineLayoutState().isHyphenationDisabled());

auto createLineSpanningInlineBoxes = [&] {
auto isRootLayoutBox = [&](auto& elementBox) {
Expand Down Expand Up @@ -498,12 +501,10 @@ LineContent LineBuilder::placeInlineAndFloatContent(const InlineItemRange& needs
auto runsExpandHorizontally = !isInIntrinsicWidthMode() && (isLastLine ? rootStyle.textAlignLast() == TextAlignLast::Justify : rootStyle.textAlign() == TextAlignMode::Justify);
if (runsExpandHorizontally)
m_line.applyRunExpansion(horizontalAvailableSpace);
auto lineEndsWithHyphen = false;
if (m_line.hasContent()) {
auto& lastTextContent = m_line.runs().last().textContent();
lineEndsWithHyphen = lastTextContent && lastTextContent->needsHyphen;
lineContent.endsWithHyphen = lastTextContent && lastTextContent->needsHyphen;
}
m_successiveHyphenatedLineCount = lineEndsWithHyphen ? m_successiveHyphenatedLineCount + 1 : 0;
};
handleLineEnding();

Expand Down Expand Up @@ -686,12 +687,6 @@ void LineBuilder::candidateContentForLine(LineCandidate& lineCandidate, size_t c
lineCandidate.inlineContent.setHasTrailingSoftWrapOpportunity(hasTrailingSoftWrapOpportunity(softWrapOpportunityIndex, layoutRange.endIndex(), m_inlineItems));
}

static bool shouldDisableHyphenation(const RenderStyle& rootStyle, unsigned successiveHyphenatedLineCount)
{
unsigned limitLines = rootStyle.hyphenationLimitLines() == RenderStyle::initialHyphenationLimitLines() ? std::numeric_limits<unsigned>::max() : rootStyle.hyphenationLimitLines();
return successiveHyphenatedLineCount >= limitLines;
}

static inline InlineLayoutUnit availableWidth(const LineCandidate::InlineContent& candidateContent, const Line& line, InlineLayoutUnit lineWidth)
{
#if USE_FLOAT_AS_INLINE_LAYOUT_UNIT
Expand Down Expand Up @@ -977,7 +972,6 @@ LineBuilder::Result LineBuilder::handleInlineContent(const InlineItemRange& layo
lineIsConsideredContentful,
!m_wrapOpportunityList.isEmpty()
};
inlineContentBreaker().setHyphenationDisabled(shouldDisableHyphenation(root().style(), m_successiveHyphenatedLineCount));
lineBreakingResult = inlineContentBreaker().processInlineContent(continuousInlineContent, lineStatus);
}
auto lineGainsNewContent = lineBreakingResult.action == InlineContentBreaker::Result::Action::Keep || lineBreakingResult.action == InlineContentBreaker::Result::Action::Break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class LineBuilder : public AbstractLineBuilder {
bool isFirstFormattedLine() const { return !m_previousLine.has_value(); }

const InlineFormattingContext& formattingContext() const { return m_inlineFormattingContext; }
const InlineLayoutState& inlineLayoutState() const { return m_inlineLayoutState; }
const BlockLayoutState& blockLayoutState() const { return m_inlineLayoutState.parentBlockLayoutState(); }
FloatingState& floatingState() { return m_floatingState; }
const FloatingState& floatingState() const { return const_cast<LineBuilder&>(*this).floatingState(); }
Expand All @@ -118,7 +119,6 @@ class LineBuilder : public AbstractLineBuilder {
std::optional<InlineLayoutUnit> m_overflowingLogicalWidth;
Vector<const InlineItem*> m_wrapOpportunityList;
Vector<InlineItem> m_lineSpanningInlineBoxes;
unsigned m_successiveHyphenatedLineCount { 0 };
OptionSet<UsedFloat> m_lineIsConstrainedByFloat { };
std::optional<InlineLayoutUnit> m_initialLetterClearGap;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ IntrinsicWidthConstraints IntrinsicWidthHandler::computedIntrinsicSizes()

auto floatingState = FloatingState { root() };
auto parentBlockLayoutState = BlockLayoutState { floatingState, { } };
auto inlineLayoutState = InlineLayoutState { parentBlockLayoutState, { } };
auto inlineLayoutState = InlineLayoutState { parentBlockLayoutState, { }, { } };
auto lineBuilder = LineBuilder { formattingContext(), inlineLayoutState, floatingState, { }, inlineFormattingState.inlineItems() };
return { computedIntrinsicValue(IntrinsicWidthMode::Minimum, lineBuilder), computedIntrinsicValue(IntrinsicWidthMode::Maximum, lineBuilder) };
}
Expand All @@ -75,7 +75,7 @@ LayoutUnit IntrinsicWidthHandler::maximumContentSize()
auto& inlineFormattingState = formattingState();
auto floatingState = FloatingState { root() };
auto parentBlockLayoutState = BlockLayoutState { floatingState, { } };
auto inlineLayoutState = InlineLayoutState { parentBlockLayoutState, { } };
auto inlineLayoutState = InlineLayoutState { parentBlockLayoutState, { }, { } };
auto lineBuilder = LineBuilder { formattingContext(), inlineLayoutState, floatingState, { }, inlineFormattingState.inlineItems() };
lineBuilder.setIntrinsicWidthMode(IntrinsicWidthMode::Maximum);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ struct LineLayoutResult {
};
IsFirstLast isFirstLast { };
// Misc
bool endsWithHyphen { false };
size_t nonSpanningInlineLevelBoxCount { 0 };
InlineLayoutUnit trimmedTrailingWhitespaceWidth { 0.f }; // only used for line-break: after-white-space currently
std::optional<InlineLayoutUnit> hintForNextLineTopToAvoidIntrusiveFloat { }; // This is only used for cases when intrusive floats prevent any content placement at current vertical position.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ LineLayoutResult TextOnlySimpleLineBuilder::layoutInlineContent(const LineInput&
, { }
, { isFirstFormattedLine() ? LineLayoutResult::IsFirstLast::FirstFormattedLine::WithinIFC : LineLayoutResult::IsFirstLast::FirstFormattedLine::No, isLastLine }
, { }
, { }
, m_trimmedTrailingWhitespaceWidth
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,10 @@ std::optional<LayoutRect> LineLayout::layout()
return { constraintsForInFlowContent, m_inlineContentConstraints->visualLeft() };
}();
auto parentBlockLayoutState = Layout::BlockLayoutState { m_blockFormattingState.floatingState(), lineClamp(flow()), textBoxTrim(flow()), intrusiveInitialLetterBottom() };
auto inlineLayoutState = Layout::InlineLayoutState { parentBlockLayoutState, WTFMove(m_nestedListMarkerOffsets) };
auto hyphenationLimitLines = std::optional<size_t> { };
if (auto limitLinesValue = rootLayoutBox().style().hyphenationLimitLines(); limitLinesValue != RenderStyle::initialHyphenationLimitLines())
hyphenationLimitLines = limitLinesValue;
auto inlineLayoutState = Layout::InlineLayoutState { parentBlockLayoutState, WTFMove(m_nestedListMarkerOffsets), hyphenationLimitLines };
auto layoutResult = Layout::InlineFormattingContext { rootLayoutBox(), m_inlineFormattingState }.layout(inlineContentConstraints, inlineLayoutState, m_lineDamage.get());

auto repaintRect = LayoutRect { constructContent(inlineLayoutState, WTFMove(layoutResult)) };
Expand Down

0 comments on commit 6c5b713

Please sign in to comment.