Skip to content

Commit

Permalink
[IFC][line-clamp] Add support for "more info" type of trailing link h…
Browse files Browse the repository at this point in the history
…andling

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

Reviewed by Antti Koivisto.

See explanation in addLineClampTrailingLinkBoxIfApplicable.

* Source/WebCore/layout/formattingContexts/inline/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::lineLayout):
(WebCore::Layout::InlineFormattingContext::createDisplayContentForLine):
(WebCore::Layout::InlineFormattingContext::createDisplayContentForLineFromCachedContent):
* Source/WebCore/layout/formattingContexts/inline/InlineFormattingContext.h:
* Source/WebCore/layout/formattingContexts/inline/InlineLayoutState.h:
(WebCore::Layout::InlineLayoutState::setClampedLineIndex):
(WebCore::Layout::InlineLayoutState::clampedLineIndex const):
* Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayBox.h:
(WebCore::InlineDisplay::Box::moveToLine):
* Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayLine.h:
(WebCore::InlineDisplay::Line::hasContentAfterEllipsisBox const):
(WebCore::InlineDisplay::Line::setHasContentAfterEllipsisBox):
(WebCore::InlineDisplay::Line::visibleRectIgnoringBlockDirection const):
* Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayLineBuilder.cpp:
(WebCore::Layout::InlineDisplayLineBuilder::addLineClampTrailingLinkBoxIfApplicable):
* Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayLineBuilder.h:
* Source/WebCore/layout/integration/LayoutIntegrationCoverage.cpp:
(WebCore::LayoutIntegration::printReason):
(WebCore::LayoutIntegration::canUseForStyle):
* Source/WebCore/layout/integration/LayoutIntegrationCoverage.h:

Canonical link: https://commits.webkit.org/267588@main
  • Loading branch information
alanbaradlay committed Sep 2, 2023
1 parent 28241a0 commit bf48ac6
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 79 deletions.
40 changes: 20 additions & 20 deletions LayoutTests/platform/ios/fast/overflow/line-clamp-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ layer at (0,0) size 800x600
RenderText {#text} at (208,263) size 4x19
text run at (208,263) width 4: " "
RenderText {#text} at (0,0) size 0x0
layer at (8,63) size 102x81 clip at (9,64) size 100x79 scrollHeight 159
RenderDeprecatedFlexibleBox {DIV} at (0,55) size 102x81 [border: (1px solid #808080)]
RenderBlock (anonymous) at (1,1) size 100x79
layer at (8,62) size 102x82 clip at (9,63) size 100x80 scrollHeight 160
RenderDeprecatedFlexibleBox {DIV} at (0,54) size 102x82 [border: (1px solid #808080)]
RenderBlock (anonymous) at (1,1) size 100x80
RenderText {#text} at (0,0) size 83x159
text run at (0,0) width 30: "50%"
text run at (0,20) width 69: "truncation."
Expand All @@ -38,12 +38,12 @@ layer at (8,63) size 102x81 clip at (9,64) size 100x79 scrollHeight 159
text run at (0,120) width 64: "multi-line"
text run at (0,140) width 28: "text."
RenderInline {A} at (0,0) size 36x19 [color=#0000EE]
RenderText {#text} at (27,140) size 36x19
text run at (27,140) width 36: "More"
RenderText {#text} at (61,60) size 36x19
text run at (61,60) width 36: "More"
RenderText {#text} at (0,0) size 0x0
layer at (114,123) size 102x21 clip at (115,124) size 100x19 scrollHeight 119
RenderDeprecatedFlexibleBox {DIV} at (106,115) size 102x21 [border: (1px solid #808080)]
RenderBlock (anonymous) at (1,1) size 100x19
layer at (114,122) size 102x22 clip at (115,123) size 100x20 scrollHeight 120
RenderDeprecatedFlexibleBox {DIV} at (106,114) size 102x22 [border: (1px solid #808080)]
RenderBlock (anonymous) at (1,1) size 100x20
RenderText {#text} at (0,0) size 100x119
text run at (0,0) width 95: "0% truncation."
text run at (0,20) width 86: "This does the"
Expand All @@ -52,12 +52,12 @@ layer at (114,123) size 102x21 clip at (115,124) size 100x19 scrollHeight 119
text run at (0,80) width 94: "truncating to 1"
text run at (0,100) width 28: "line."
RenderInline {A} at (0,0) size 36x19 [color=#0000EE]
RenderText {#text} at (27,100) size 36x19
text run at (27,100) width 36: "More"
RenderText {#text} at (62,0) size 35x19
text run at (62,0) width 35: "More"
RenderText {#text} at (0,0) size 0x0
layer at (220,103) size 102x41 clip at (221,104) size 100x39 scrollHeight 119
RenderDeprecatedFlexibleBox {DIV} at (212,95) size 102x41 [border: (1px solid #808080)]
RenderBlock (anonymous) at (1,1) size 100x39
layer at (220,102) size 102x42 clip at (221,103) size 100x40 scrollHeight 120
RenderDeprecatedFlexibleBox {DIV} at (212,94) size 102x42 [border: (1px solid #808080)]
RenderBlock (anonymous) at (1,1) size 100x40
RenderText {#text} at (0,0) size 94x119
text run at (0,0) width 51: "2 lines. "
text run at (50,0) width 44: "This is"
Expand All @@ -67,12 +67,12 @@ layer at (220,103) size 102x41 clip at (221,104) size 100x39 scrollHeight 119
text run at (0,80) width 64: "multi-line"
text run at (0,100) width 28: "text."
RenderInline {A} at (0,0) size 36x19 [color=#0000EE]
RenderText {#text} at (27,100) size 36x19
text run at (27,100) width 36: "More"
RenderText {#text} at (60,20) size 35x19
text run at (60,20) width 35: "More"
RenderText {#text} at (0,0) size 0x0
layer at (326,83) size 102x61 clip at (327,84) size 100x59 scrollHeight 179
RenderDeprecatedFlexibleBox {DIV} at (318,75) size 102x61 [border: (1px solid #808080)]
RenderBlock (anonymous) at (1,1) size 100x59
layer at (326,82) size 102x62 clip at (327,83) size 100x60 scrollHeight 180
RenderDeprecatedFlexibleBox {DIV} at (318,74) size 102x62 [border: (1px solid #808080)]
RenderBlock (anonymous) at (1,1) size 100x60
RenderText {#text} at (0,0) size 85x179
text run at (0,0) width 72: "Backwards"
text run at (0,20) width 72: "compatible"
Expand All @@ -86,8 +86,8 @@ layer at (326,83) size 102x61 clip at (327,84) size 100x59 scrollHeight 179
text run at (0,140) width 71: "versions of"
text run at (0,160) width 54: "WebKit."
RenderInline {A} at (0,0) size 36x19 [color=#0000EE]
RenderText {#text} at (53,160) size 36x19
text run at (53,160) width 36: "More"
RenderText {#text} at (63,40) size 36x19
text run at (63,40) width 36: "More"
RenderText {#text} at (0,0) size 0x0
layer at (432,102) size 102x42 clip at (433,103) size 100x40 scrollHeight 160
RenderDeprecatedFlexibleBox {DIV} at (424,94) size 102x42 [border: (1px solid #808080)]
Expand Down
16 changes: 8 additions & 8 deletions LayoutTests/platform/mac/fast/overflow/line-clamp-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ layer at (8,57) size 102x74 clip at (9,58) size 100x72 scrollHeight 144
text run at (0,108) width 64: "multi-line"
text run at (0,126) width 28: "text."
RenderInline {A} at (0,0) size 36x18 [color=#0000EE]
RenderText {#text} at (27,126) size 36x18
text run at (27,126) width 36: "More"
RenderText {#text} at (61,54) size 36x18
text run at (61,54) width 36: "More"
RenderText {#text} at (0,0) size 0x0
layer at (114,111) size 102x20 clip at (115,112) size 100x18 scrollHeight 108
RenderDeprecatedFlexibleBox {DIV} at (106,103) size 102x20 [border: (1px solid #808080)]
Expand All @@ -52,8 +52,8 @@ layer at (114,111) size 102x20 clip at (115,112) size 100x18 scrollHeight 108
text run at (0,72) width 94: "truncating to 1"
text run at (0,90) width 28: "line."
RenderInline {A} at (0,0) size 36x18 [color=#0000EE]
RenderText {#text} at (27,90) size 36x18
text run at (27,90) width 36: "More"
RenderText {#text} at (62,0) size 35x18
text run at (62,0) width 35: "More"
RenderText {#text} at (0,0) size 0x0
layer at (220,93) size 102x38 clip at (221,94) size 100x36 scrollHeight 108
RenderDeprecatedFlexibleBox {DIV} at (212,85) size 102x38 [border: (1px solid #808080)]
Expand All @@ -67,8 +67,8 @@ layer at (220,93) size 102x38 clip at (221,94) size 100x36 scrollHeight 108
text run at (0,72) width 64: "multi-line"
text run at (0,90) width 28: "text."
RenderInline {A} at (0,0) size 36x18 [color=#0000EE]
RenderText {#text} at (27,90) size 36x18
text run at (27,90) width 36: "More"
RenderText {#text} at (60,18) size 35x18
text run at (60,18) width 35: "More"
RenderText {#text} at (0,0) size 0x0
layer at (326,75) size 102x56 clip at (327,76) size 100x54 scrollHeight 162
RenderDeprecatedFlexibleBox {DIV} at (318,67) size 102x56 [border: (1px solid #808080)]
Expand All @@ -86,8 +86,8 @@ layer at (326,75) size 102x56 clip at (327,76) size 100x54 scrollHeight 162
text run at (0,126) width 71: "versions of"
text run at (0,144) width 54: "WebKit."
RenderInline {A} at (0,0) size 36x18 [color=#0000EE]
RenderText {#text} at (53,144) size 36x18
text run at (53,144) width 36: "More"
RenderText {#text} at (63,36) size 36x18
text run at (63,36) width 36: "More"
RenderText {#text} at (0,0) size 0x0
layer at (432,93) size 102x38 clip at (433,94) size 100x36 scrollHeight 144
RenderDeprecatedFlexibleBox {DIV} at (424,85) size 102x38 [border: (1px solid #808080)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ InlineLayoutResult InlineFormattingContext::lineLayout(AbstractLineBuilder& line
previousLine = PreviousLine { lineIndex, lineLayoutResult.contentGeometry.trailingOverflowingContentWidth, !lineLayoutResult.inlineContent.isEmpty() && lineLayoutResult.inlineContent.last().isLineBreak(), lineLayoutResult.directionality.inlineBaseDirection, WTFMove(lineLayoutResult.floatContent.suspendedFloats) };
previousLineEnd = lineContentEnd;
}
InlineDisplayLineBuilder::addLineClampTrailingLinkBoxIfApplicable(*this, inlineLayoutState, layoutResult.displayContent);
return layoutResult;
}

Expand Down Expand Up @@ -252,7 +253,7 @@ static LineEndingEllipsisPolicy lineEndingEllipsisPolicy(const RenderStyle& root
return LineEndingEllipsisPolicy::No;
}

InlineRect InlineFormattingContext::createDisplayContentForLine(size_t lineIndex, const LineLayoutResult& lineLayoutResult, const ConstraintsForInlineContent& constraints, const InlineLayoutState& inlineLayoutState, InlineDisplay::Content& displayContent)
InlineRect InlineFormattingContext::createDisplayContentForLine(size_t lineIndex, const LineLayoutResult& lineLayoutResult, const ConstraintsForInlineContent& constraints, InlineLayoutState& inlineLayoutState, InlineDisplay::Content& displayContent)
{
auto numberOfVisibleLinesAllowed = [&] () -> std::optional<size_t> {
if (auto lineClamp = inlineLayoutState.parentBlockLayoutState().lineClamp())
Expand All @@ -265,8 +266,11 @@ InlineRect InlineFormattingContext::createDisplayContentForLine(size_t lineIndex
auto lineBox = LineBoxBuilder { *this, inlineLayoutState, lineLayoutResult }.build(lineIndex);
auto displayLine = InlineDisplayLineBuilder { constraints, *this }.build(lineLayoutResult, lineBox, lineIsFullyTruncatedInBlockDirection);
auto boxes = InlineDisplayContentBuilder { constraints, *this, formattingState(), displayLine, lineIndex }.build(lineLayoutResult, lineBox);
if (auto ellipsisRect = InlineDisplayLineBuilder::trailingEllipsisVisualRectAfterTruncation(ellipsisPolicy, displayLine, boxes, lineLayoutResult.isFirstLast.isLastLineWithInlineContent))
if (auto ellipsisRect = InlineDisplayLineBuilder::trailingEllipsisVisualRectAfterTruncation(ellipsisPolicy, displayLine, boxes, lineLayoutResult.isFirstLast.isLastLineWithInlineContent)) {
displayLine.setEllipsisVisualRect(*ellipsisRect);
if (ellipsisPolicy == LineEndingEllipsisPolicy::WhenContentOverflowsInBlockDirection)
inlineLayoutState.setClampedLineIndex(lineIndex);
}

displayContent.boxes.appendVector(WTFMove(boxes));
displayContent.lines.append(displayLine);
Expand Down Expand Up @@ -304,7 +308,7 @@ void InlineFormattingContext::resetGeometryForClampedContent(const InlineItemRan
}
}

bool InlineFormattingContext::createDisplayContentForLineFromCachedContent(const ConstraintsForInlineContent& constraints, const InlineLayoutState& inlineLayoutState, InlineLayoutResult& layoutResult)
bool InlineFormattingContext::createDisplayContentForLineFromCachedContent(const ConstraintsForInlineContent& constraints, InlineLayoutState& inlineLayoutState, InlineLayoutResult& layoutResult)
{
auto& inlineFormattingState = formattingState();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ class InlineFormattingContext final : public FormattingContext {
void layoutFloatContentOnly(const ConstraintsForInlineContent&, FloatingState&);

void collectContentIfNeeded();
InlineRect createDisplayContentForLine(size_t lineIndex, const LineLayoutResult&, const ConstraintsForInlineContent&, const InlineLayoutState&, InlineDisplay::Content&);
InlineRect createDisplayContentForLine(size_t lineIndex, const LineLayoutResult&, const ConstraintsForInlineContent&, InlineLayoutState&, InlineDisplay::Content&);
void resetGeometryForClampedContent(const InlineItemRange& needsDisplayContentRange, const LineLayoutResult::SuspendedFloatList& suspendedFloats, LayoutPoint topleft);
bool createDisplayContentForLineFromCachedContent(const ConstraintsForInlineContent&, const InlineLayoutState&, InlineLayoutResult&);
bool createDisplayContentForLineFromCachedContent(const ConstraintsForInlineContent&, InlineLayoutState&, InlineLayoutResult&);

InlineFormattingState& formattingState() { return downcast<InlineFormattingState>(FormattingContext::formattingState()); }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ class InlineLayoutState {
void setAvailableLineWidthOverride(AvailableLineWidthOverride availableLineWidthOverride) { m_availableLineWidthOverride = availableLineWidthOverride; }
const AvailableLineWidthOverride& availableLineWidthOverride() const { return m_availableLineWidthOverride; }

void setClampedLineIndex(size_t lineIndex) { m_clampedLineIndex = lineIndex; }
std::optional<size_t> clampedLineIndex() const { return m_clampedLineIndex; }

private:
BlockLayoutState& m_parentBlockLayoutState;
InlineLayoutUnit m_clearGapBeforeFirstLine { 0.f };
InlineLayoutUnit m_clearGapAfterLastLine { 0.f };
std::optional<size_t> m_clampedLineIndex { };
// FIXME: This is required by the integaration codepath.
HashMap<const ElementBox*, LayoutUnit> m_nestedListMarkerOffsets;
AvailableLineWidthOverride m_availableLineWidthOverride;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ struct Box {
const Layout::Box& layoutBox() const { return m_layoutBox; }
const RenderStyle& style() const { return !lineIndex() ? layoutBox().firstLineStyle() : layoutBox().style(); }

void moveToLine(unsigned lineIndex) { m_lineIndex = lineIndex; }
size_t lineIndex() const { return m_lineIndex; }
// These functions tell you whether this display box is the first/last for the associated inline level box (Layout::Box) and not whether it's the first/last box on the line.
// (e.g. always true for atomic boxes, but inline boxes spanning over multiple lines can produce individual first/last boxes).
Expand All @@ -201,7 +202,7 @@ struct Box {
FloatRect m_unflippedVisualRect;
FloatRect m_inkOverflow;

const unsigned m_lineIndex { 0 };
unsigned m_lineIndex { 0 };

float m_horizontalExpansion { 0 };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ class Line {
void moveVertically(float offset);
void setEllipsisVisualRect(const FloatRect& ellipsisVisualRect) { m_ellipsisVisualRect = ellipsisVisualRect; }

bool hasContentAfterEllipsisBox() const { return m_hasContentAfterEllipsisBox; }
void setHasContentAfterEllipsisBox() { m_hasContentAfterEllipsisBox = true; }

void setFirstBoxIndex(size_t firstBoxIndex) { m_firstBoxIndex = firstBoxIndex; }
void setBoxCount(size_t boxCount) { m_boxCount = boxCount; }
void setIsFirstAfterPageBreak() { m_isFirstAfterPageBreak = true; }
Expand Down Expand Up @@ -125,6 +128,7 @@ class Line {
bool m_isHorizontal : 1 { true };
bool m_isFirstAfterPageBreak : 1 { false };
bool m_isTruncatedInBlockDirection : 1 { false };
bool m_hasContentAfterEllipsisBox : 1 { false };
// This is visual rect ignoring block direction.
std::optional<FloatRect> m_ellipsisVisualRect { };
};
Expand Down Expand Up @@ -162,7 +166,7 @@ inline FloatRect Line::visibleRectIgnoringBlockDirection() const
{
if (m_isTruncatedInBlockDirection)
return { };
if (!hasEllipsis())
if (!hasEllipsis() || hasContentAfterEllipsisBox())
return m_inkOverflow;
if (m_isLeftToRightDirection) {
auto visibleLineBoxRight = std::min(m_lineBoxRect.maxX(), m_ellipsisVisualRect->maxX());
Expand Down
Loading

0 comments on commit bf48ac6

Please sign in to comment.