- a/Source/WebCore/layout/integration/inline/LayoutIntegrationLineLayout.cpp -1 / +1 lines
Lines 304-310 std::pair<LayoutUnit, LayoutUnit> LineLayout::computeIntrinsicWidthConstraints() a/Source/WebCore/layout/integration/inline/LayoutIntegrationLineLayout.cpp_sec1
304
static inline std::optional<Layout::BlockLayoutState::LineClamp> lineClamp(const RenderBlockFlow& rootRenderer)
304
static inline std::optional<Layout::BlockLayoutState::LineClamp> lineClamp(const RenderBlockFlow& rootRenderer)
305
{
305
{
306
    auto& layoutState = *rootRenderer.view().frameView().layoutContext().layoutState();
306
    auto& layoutState = *rootRenderer.view().frameView().layoutContext().layoutState();
307
    if (auto lineClamp = layoutState.lineClamp())
307
    if (auto lineClamp = layoutState.legacyLineClamp())
308
        return Layout::BlockLayoutState::LineClamp { lineClamp->maximumLineCount, lineClamp->currentLineCount };
308
        return Layout::BlockLayoutState::LineClamp { lineClamp->maximumLineCount, lineClamp->currentLineCount };
309
    return { };
309
    return { };
310
}
310
}
- a/Source/WebCore/page/LocalFrameViewLayoutContext.cpp -5 / +5 lines
Lines 604-610 bool LocalFrameViewLayoutContext::pushLayoutState(RenderBox& renderer, const Lay a/Source/WebCore/page/LocalFrameViewLayoutContext.cpp_sec1
604
            , offset
604
            , offset
605
            , pageHeight
605
            , pageHeight
606
            , pageHeightChanged
606
            , pageHeightChanged
607
            , layoutState ? layoutState->lineClamp() : std::nullopt
607
            , layoutState ? layoutState->legacyLineClamp() : std::nullopt
608
            , layoutState ? layoutState->textBoxTrim() : RenderLayoutState::TextBoxTrim()));
608
            , layoutState ? layoutState->textBoxTrim() : RenderLayoutState::TextBoxTrim()));
609
        return true;
609
        return true;
610
    }
610
    }
Lines 616-630 void LocalFrameViewLayoutContext::popLayoutState() a/Source/WebCore/page/LocalFrameViewLayoutContext.cpp_sec2
616
    if (!layoutState())
616
    if (!layoutState())
617
        return;
617
        return;
618
618
619
    auto currentLineClamp = layoutState()->lineClamp();
619
    auto currentLineClamp = layoutState()->legacyLineClamp();
620
620
621
    m_layoutStateStack.removeLast();
621
    m_layoutStateStack.removeLast();
622
622
623
    if (currentLineClamp) {
623
    if (currentLineClamp) {
624
        // Propagates the current line clamp state to the parent.
624
        // Propagates the current line clamp state to the parent.
625
        if (auto* layoutState = this->layoutState(); layoutState && layoutState->lineClamp()) {
625
        if (auto* layoutState = this->layoutState(); layoutState && layoutState->legacyLineClamp()) {
626
            ASSERT(layoutState->lineClamp()->maximumLineCount == currentLineClamp->maximumLineCount);
626
            ASSERT(layoutState->legacyLineClamp()->maximumLineCount == currentLineClamp->maximumLineCount);
627
            layoutState->setLineClamp(currentLineClamp);
627
            layoutState->setLegacyLineClamp(currentLineClamp);
628
        }
628
        }
629
    }
629
    }
630
}
630
}
- a/Source/WebCore/rendering/RenderBlockFlow.cpp -10 / +10 lines
Lines 443-449 void RenderBlockFlow::layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalH a/Source/WebCore/rendering/RenderBlockFlow.cpp_sec1
443
    if (recomputeLogicalWidthAndColumnWidth())
443
    if (recomputeLogicalWidthAndColumnWidth())
444
        relayoutChildren = true;
444
        relayoutChildren = true;
445
445
446
    if (auto* layoutState = view().frameView().layoutContext().layoutState(); layoutState && layoutState->lineClamp())
446
    if (auto* layoutState = view().frameView().layoutContext().layoutState(); layoutState && layoutState->legacyLineClamp())
447
        relayoutChildren = true;
447
        relayoutChildren = true;
448
448
449
    rebuildFloatingObjectSetFromIntrudingFloats();
449
    rebuildFloatingObjectSetFromIntrudingFloats();
Lines 3945-3974 void RenderBlockFlow::layoutModernLines(bool relayoutChildren, LayoutUnit& repai a/Source/WebCore/rendering/RenderBlockFlow.cpp_sec2
3945
3945
3946
    setLogicalHeight(newBorderBoxBottom);
3946
    setLogicalHeight(newBorderBoxBottom);
3947
    auto updateLineClampStateAndLogicalHeightIfApplicable = [&] {
3947
    auto updateLineClampStateAndLogicalHeightIfApplicable = [&] {
3948
        auto lineClamp = layoutState.lineClamp();
3948
        auto legacyLineClamp = layoutState.legacyLineClamp();
3949
        if (!lineClamp || isFloatingOrOutOfFlowPositioned())
3949
        if (!legacyLineClamp || isFloatingOrOutOfFlowPositioned())
3950
            return;
3950
            return;
3951
        lineClamp->currentLineCount += layoutFormattingContextLineLayout.lineCount();
3951
        legacyLineClamp->currentLineCount += layoutFormattingContextLineLayout.lineCount();
3952
        if (lineClamp->clampedRenderer) {
3952
        if (legacyLineClamp->clampedRenderer) {
3953
            // We've already clamped this flex container at a previous flex item.
3953
            // We've already clamped this flex container at a previous flex item.
3954
            layoutState.setLineClamp(*lineClamp);
3954
            layoutState.setLegacyLineClamp(*legacyLineClamp);
3955
            return;
3955
            return;
3956
        }
3956
        }
3957
        auto clampedContentHeight = [&]() -> std::optional<LayoutUnit> {
3957
        auto clampedContentHeight = [&]() -> std::optional<LayoutUnit> {
3958
            if (auto clampedHeight = layoutFormattingContextLineLayout.clampedContentLogicalHeight())
3958
            if (auto clampedHeight = layoutFormattingContextLineLayout.clampedContentLogicalHeight())
3959
                return clampedHeight;
3959
                return clampedHeight;
3960
            if (lineClamp->currentLineCount == lineClamp->maximumLineCount) {
3960
            if (legacyLineClamp->currentLineCount == legacyLineClamp->maximumLineCount) {
3961
                // Even if we did not truncate the content, this might be our clamping position.
3961
                // Even if we did not truncate the content, this might be our clamping position.
3962
                return computeContentHeight();
3962
                return computeContentHeight();
3963
            }
3963
            }
3964
            return { };
3964
            return { };
3965
        };
3965
        };
3966
        if (auto logicalHeight = clampedContentHeight()) {
3966
        if (auto logicalHeight = clampedContentHeight()) {
3967
            lineClamp->clampedContentLogicalHeight = logicalHeight;
3967
            legacyLineClamp->clampedContentLogicalHeight = logicalHeight;
3968
            lineClamp->clampedRenderer = this;
3968
            legacyLineClamp->clampedRenderer = this;
3969
            setLogicalHeight(borderAndPaddingBefore() + *logicalHeight + borderAndPaddingAfter() + scrollbarLogicalHeight());
3969
            setLogicalHeight(borderAndPaddingBefore() + *logicalHeight + borderAndPaddingAfter() + scrollbarLogicalHeight());
3970
        }
3970
        }
3971
        layoutState.setLineClamp(*lineClamp);
3971
        layoutState.setLegacyLineClamp(*legacyLineClamp);
3972
    };
3972
    };
3973
    updateLineClampStateAndLogicalHeightIfApplicable();
3973
    updateLineClampStateAndLogicalHeightIfApplicable();
3974
}
3974
}
- a/Source/WebCore/rendering/RenderDeprecatedFlexibleBox.cpp -4 / +4 lines
Lines 989-997 std::optional<RenderDeprecatedFlexibleBox::ClampedContent> RenderDeprecatedFlexi a/Source/WebCore/rendering/RenderDeprecatedFlexibleBox.cpp_sec1
989
        return { };
989
        return { };
990
990
991
    auto& layoutState = *view().frameView().layoutContext().layoutState();
991
    auto& layoutState = *view().frameView().layoutContext().layoutState();
992
    auto ancestorLineClamp = layoutState.lineClamp();
992
    auto ancestorLineClamp = layoutState.legacyLineClamp();
993
    auto restoreAncestorLineClamp = makeScopeExit([&] {
993
    auto restoreAncestorLineClamp = makeScopeExit([&] {
994
        layoutState.setLineClamp(ancestorLineClamp);
994
        layoutState.setLegacyLineClamp(ancestorLineClamp);
995
    });
995
    });
996
996
997
    auto lineCountForLineClamp = [&]() -> size_t {
997
    auto lineCountForLineClamp = [&]() -> size_t {
Lines 1013-1019 std::optional<RenderDeprecatedFlexibleBox::ClampedContent> RenderDeprecatedFlexi a/Source/WebCore/rendering/RenderDeprecatedFlexibleBox.cpp_sec2
1013
        return std::max<size_t>(1, (numberOfLines + 1) * lineClamp.value() / 100.f);
1013
        return std::max<size_t>(1, (numberOfLines + 1) * lineClamp.value() / 100.f);
1014
    };
1014
    };
1015
1015
1016
    layoutState.setLineClamp(RenderLayoutState::LineClamp { lineCountForLineClamp(), { }, { }, { } });
1016
    layoutState.setLegacyLineClamp(RenderLayoutState::LegacyLineClamp { lineCountForLineClamp(), { }, { }, { } });
1017
    for (auto* child = iterator.first(); child; child = iterator.next()) {
1017
    for (auto* child = iterator.first(); child; child = iterator.next()) {
1018
        if (childDoesNotAffectWidthOrFlexing(child))
1018
        if (childDoesNotAffectWidthOrFlexing(child))
1019
            continue;
1019
            continue;
Lines 1021-1027 std::optional<RenderDeprecatedFlexibleBox::ClampedContent> RenderDeprecatedFlexi a/Source/WebCore/rendering/RenderDeprecatedFlexibleBox.cpp_sec3
1021
        child->layoutIfNeeded();
1021
        child->layoutIfNeeded();
1022
    }
1022
    }
1023
1023
1024
    auto lineClamp = *layoutState.lineClamp();
1024
    auto lineClamp = *layoutState.legacyLineClamp();
1025
    if (!lineClamp.clampedContentLogicalHeight) {
1025
    if (!lineClamp.clampedContentLogicalHeight) {
1026
        // We've managed to run line clamping but it came back with no clamped content (i.e. there are fewer lines than the line-clamp limit).
1026
        // We've managed to run line clamping but it came back with no clamped content (i.e. there are fewer lines than the line-clamp limit).
1027
        return RenderDeprecatedFlexibleBox::ClampedContent { };
1027
        return RenderDeprecatedFlexibleBox::ClampedContent { };
- a/Source/WebCore/rendering/RenderLayoutState.cpp -2 / +2 lines
Lines 66-72 RenderLayoutState::RenderLayoutState(RenderElement& renderer) a/Source/WebCore/rendering/RenderLayoutState.cpp_sec1
66
    }
66
    }
67
}
67
}
68
68
69
RenderLayoutState::RenderLayoutState(const LocalFrameViewLayoutContext::LayoutStateStack& layoutStateStack, RenderBox& renderer, const LayoutSize& offset, LayoutUnit pageLogicalHeight, bool pageLogicalHeightChanged, std::optional<LineClamp> lineClamp, std::optional<TextBoxTrim> textBoxTrim)
69
RenderLayoutState::RenderLayoutState(const LocalFrameViewLayoutContext::LayoutStateStack& layoutStateStack, RenderBox& renderer, const LayoutSize& offset, LayoutUnit pageLogicalHeight, bool pageLogicalHeightChanged, std::optional<LegacyLineClamp> legacyLineClamp, std::optional<TextBoxTrim> textBoxTrim)
70
    : m_clipped(false)
70
    : m_clipped(false)
71
    , m_isPaginated(false)
71
    , m_isPaginated(false)
72
    , m_pageLogicalHeightChanged(false)
72
    , m_pageLogicalHeightChanged(false)
Lines 75-81 RenderLayoutState::RenderLayoutState(const LocalFrameViewLayoutContext::LayoutSt a/Source/WebCore/rendering/RenderLayoutState.cpp_sec2
75
    , m_layoutDeltaYSaturated(false)
75
    , m_layoutDeltaYSaturated(false)
76
#endif
76
#endif
77
    , m_blockStartTrimming(Vector<bool>(0))
77
    , m_blockStartTrimming(Vector<bool>(0))
78
    , m_lineClamp(lineClamp)
78
    , m_legacyLineClamp(legacyLineClamp)
79
    , m_textBoxTrim(textBoxTrim)
79
    , m_textBoxTrim(textBoxTrim)
80
#if ASSERT_ENABLED
80
#if ASSERT_ENABLED
81
    , m_renderer(&renderer)
81
    , m_renderer(&renderer)
- a/Source/WebCore/rendering/RenderLayoutState.h -5 / +5 lines
Lines 49-55 public: a/Source/WebCore/rendering/RenderLayoutState.h_sec1
49
        TextEdge propagatedTextBoxEdge { };
49
        TextEdge propagatedTextBoxEdge { };
50
        SingleThreadWeakPtr<const RenderBlockFlow> lastFormattedLineRoot;
50
        SingleThreadWeakPtr<const RenderBlockFlow> lastFormattedLineRoot;
51
    };
51
    };
52
    struct LineClamp {
52
    struct LegacyLineClamp {
53
        size_t maximumLineCount { 0 };
53
        size_t maximumLineCount { 0 };
54
        size_t currentLineCount { 0 };
54
        size_t currentLineCount { 0 };
55
        std::optional<LayoutUnit> clampedContentLogicalHeight;
55
        std::optional<LayoutUnit> clampedContentLogicalHeight;
Lines 67-73 public: a/Source/WebCore/rendering/RenderLayoutState.h_sec2
67
        , m_blockStartTrimming(Vector<bool>(0))
67
        , m_blockStartTrimming(Vector<bool>(0))
68
    {
68
    {
69
    }
69
    }
70
    RenderLayoutState(const LocalFrameViewLayoutContext::LayoutStateStack&, RenderBox&, const LayoutSize& offset, LayoutUnit pageHeight, bool pageHeightChanged, std::optional<LineClamp>, std::optional<TextBoxTrim>);
70
    RenderLayoutState(const LocalFrameViewLayoutContext::LayoutStateStack&, RenderBox&, const LayoutSize& offset, LayoutUnit pageHeight, bool pageHeightChanged, std::optional<LegacyLineClamp>, std::optional<TextBoxTrim>);
71
    explicit RenderLayoutState(RenderElement&);
71
    explicit RenderLayoutState(RenderElement&);
72
72
73
    bool isPaginated() const { return m_isPaginated; }
73
    bool isPaginated() const { return m_isPaginated; }
Lines 102-109 public: a/Source/WebCore/rendering/RenderLayoutState.h_sec3
102
    bool layoutDeltaMatches(LayoutSize) const;
102
    bool layoutDeltaMatches(LayoutSize) const;
103
#endif
103
#endif
104
104
105
    void setLineClamp(std::optional<LineClamp> lineClamp) { m_lineClamp = lineClamp; }
105
    void setLegacyLineClamp(std::optional<LegacyLineClamp> legacyLineClamp) { m_legacyLineClamp = legacyLineClamp; }
106
    std::optional<LineClamp> lineClamp() const { return m_lineClamp; }
106
    std::optional<LegacyLineClamp> legacyLineClamp() const { return m_legacyLineClamp; }
107
107
108
    std::optional<TextBoxTrim> textBoxTrim() { return m_textBoxTrim; }
108
    std::optional<TextBoxTrim> textBoxTrim() { return m_textBoxTrim; }
109
    void setTextBoxTrim(std::optional<TextBoxTrim> textBoxTrim) { m_textBoxTrim = textBoxTrim; }
109
    void setTextBoxTrim(std::optional<TextBoxTrim> textBoxTrim) { m_textBoxTrim = textBoxTrim; }
Lines 161-167 private: a/Source/WebCore/rendering/RenderLayoutState.h_sec4
161
    LayoutSize m_pageOffset;
161
    LayoutSize m_pageOffset;
162
    LayoutSize m_lineGridOffset;
162
    LayoutSize m_lineGridOffset;
163
    LayoutSize m_lineGridPaginationOrigin;
163
    LayoutSize m_lineGridPaginationOrigin;
164
    std::optional<LineClamp> m_lineClamp;
164
    std::optional<LegacyLineClamp> m_legacyLineClamp;
165
    std::optional<TextBoxTrim> m_textBoxTrim;
165
    std::optional<TextBoxTrim> m_textBoxTrim;
166
#if ASSERT_ENABLED
166
#if ASSERT_ENABLED
167
    RenderElement* m_renderer { nullptr };
167
    RenderElement* m_renderer { nullptr };

Return to Bug 278826