From 6e3f0c09719fc0e89fa199d2c2c6a5ff3b192be3 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Tue, 22 Oct 2024 22:09:31 +0000 Subject: [PATCH] Bug 1791226 - Don't paint line-clamped lines. r=layout-reviewers,dshin This matches the proposal in https://github.com/w3c/csswg-drafts/pull/10816, and creates much better behavior. Differential Revision: https://phabricator.services.mozilla.com/D157578 UltraBlame original commit: cf9f54eef33465d089f850a55da5734a911fdac4 --- layout/generic/TextOverflow.cpp | 6 +- layout/generic/nsBlockFrame.cpp | 295 ++++++++++++++---- layout/generic/nsBlockFrame.h | 54 ++++ layout/generic/nsFrameStateBits.h | 14 +- .../reference/webkit-line-clamp-040-ref.html | 6 - .../line-clamp/webkit-line-clamp-050.html | 36 --- 6 files changed, 293 insertions(+), 118 deletions(-) diff --git a/layout/generic/TextOverflow.cpp b/layout/generic/TextOverflow.cpp index 0b07131d6ff79..e8b0d8902c782 100644 --- a/layout/generic/TextOverflow.cpp +++ b/layout/generic/TextOverflow.cpp @@ -4719,9 +4719,8 @@ f f - > -HasAnyStateBits +HasLineClampEllipsis ( -NS_BLOCK_HAS_LINE_CLAMP_ELLIPSIS ) ; } @@ -4754,9 +4753,8 @@ return aBlockFrame - > -HasAnyStateBits +HasLineClampEllipsis ( -NS_BLOCK_HAS_LINE_CLAMP_ELLIPSIS ) ; } diff --git a/layout/generic/nsBlockFrame.cpp b/layout/generic/nsBlockFrame.cpp index e3e3a852acc7e..aaddc0ed7da7c 100644 --- a/layout/generic/nsBlockFrame.cpp +++ b/layout/generic/nsBlockFrame.cpp @@ -6454,8 +6454,6 @@ nsIFrame aFrame ) { -if -( const nsBlockFrame * @@ -6465,27 +6463,30 @@ do_QueryFrame ( aFrame ) -) -{ +; if ( ! block +| +| +block - > HasAnyStateBits ( +NS_FRAME_OUT_OF_FLOW +| NS_BLOCK_BFC ) ) { return -block +nullptr ; } -} return -nullptr +block ; } static @@ -7239,104 +7240,131 @@ aFrame { if ( -! aFrame - > -HasAnyStateBits +HasLineClampEllipsis ( -NS_BLOCK_HAS_LINE_CLAMP_ELLIPSIS ) ) { -for +MOZ_ASSERT ( -nsIFrame -* -f -: +! aFrame - > -PrincipalChildList +HasLineClampEllipsisDescendant ( ) ) -{ -if +; +aFrame +- +> +SetHasLineClampEllipsis ( -nsBlockFrame -* -child -= -GetAsLineClampDescendant +false +) +; +for +( +auto +& +line +: +aFrame +- +> +Lines ( -f ) ) { if ( -ClearLineClampEllipsis +line +. +HasLineClampEllipsis ( -child ) ) { -return -true +line +. +ClearHasLineClampEllipsis +( +) +; +break ; -} } } return -false +true ; } +if +( aFrame - > -RemoveStateBits +HasLineClampEllipsisDescendant ( -NS_BLOCK_HAS_LINE_CLAMP_ELLIPSIS +) +) +{ +aFrame +- +> +SetHasLineClampEllipsisDescendant +( +false ) ; for ( -auto -& -line +nsIFrame +* +f : aFrame - > -Lines +PrincipalChildList ( ) ) { if ( -line -. -HasLineClampEllipsis +nsBlockFrame +* +child += +GetAsLineClampDescendant ( +f ) ) { -line -. -ClearHasLineClampEllipsis +if +( +ClearLineClampEllipsis ( +child ) -; +) +{ return true ; } } +} +} return -true +false ; } void @@ -9496,6 +9524,19 @@ DrainOverflowLines ( ) ; +if +( +IsLineClampRoot +( +this +) +) +{ +ClearLineClampEllipsis +( +) +; +} bool blockStartMarginRoot blockEndMarginRoot @@ -10203,21 +10244,6 @@ PhysicalSize ; } } -if -( -aReflowInput -. -mStyleDisplay -- -> -mWebkitLineClamp -) -{ -ClearLineClampEllipsis -( -) -; -} CheckFloats ( state @@ -10354,9 +10380,8 @@ MOZ_ASSERT aFrame - > -HasAnyStateBits +HasLineClampEllipsis ( -NS_BLOCK_HAS_LINE_CLAMP_ELLIPSIS ) " Should @@ -10364,11 +10389,6 @@ have been removed earlier -in -nsBlockReflow -: -: -Reflow " ) ; @@ -10583,9 +10603,9 @@ SetHasLineClampEllipsis target - > -AddStateBits +SetHasLineClampEllipsis ( -NS_BLOCK_HAS_LINE_CLAMP_ELLIPSIS +true ) ; nscoord @@ -10618,6 +10638,45 @@ GetParent ) ) { +MOZ_ASSERT +( +f +- +> +IsBlockFrameOrSubclass +( +) +" +GetAsLineClampDescendant +guarantees +this +" +) +; +if +( +f +! += +target +) +{ +static_cast +< +nsBlockFrame +* +> +( +f +) +- +> +SetHasLineClampEllipsisDescendant +( +true +) +; +} if ( f @@ -37070,6 +37129,9 @@ aDepth int32_t & aDrawnLines +bool +& +aFoundLineClamp ) { # @@ -37225,6 +37287,60 @@ GetNextSibling } if ( +aFrame +- +> +HasLineClampEllipsisDescendant +( +) +& +& +! +aLineInLine +) +{ +if +( +nsBlockFrame +* +f += +GetAsLineClampDescendant +( +aLine +- +> +mFirstChild +) +) +{ +if +( +f +- +> +HasLineClampEllipsis +( +) +| +| +f +- +> +HasLineClampEllipsisDescendant +( +) +) +{ +aFoundLineClamp += +true +; +} +} +} +if +( aTextOverflow & & @@ -37697,6 +37813,16 @@ isSome | | backplateColor +| +| +HasLineClampEllipsis +( +) +| +| +HasLineClampEllipsisDescendant +( +) ) ? nullptr @@ -37731,6 +37857,11 @@ ptrOr nullptr ) ; +bool +foundClamp += +false +; if ( cursor @@ -37834,6 +37965,13 @@ nullptr 0 depth drawnLines +foundClamp +) +; +MOZ_ASSERT +( +! +foundClamp ) ; } @@ -37972,6 +38110,7 @@ textOverflowPtr lineCount depth drawnLines +foundClamp ) ; } @@ -38134,6 +38273,26 @@ lineBackplate } } } +foundClamp += +foundClamp +| +| +line +- +> +HasLineClampEllipsis +( +) +; +if +( +foundClamp +) +{ +break +; +} lineCount + + diff --git a/layout/generic/nsBlockFrame.h b/layout/generic/nsBlockFrame.h index e6b1477d3a3e2..61bca0eebb605 100644 --- a/layout/generic/nsBlockFrame.h +++ b/layout/generic/nsBlockFrame.h @@ -1906,6 +1906,60 @@ MaybeHasFloats ) const ; +bool +HasLineClampEllipsis +( +) +const +{ +return +HasAnyStateBits +( +NS_BLOCK_HAS_LINE_CLAMP_ELLIPSIS +) +; +} +bool +HasLineClampEllipsisDescendant +( +) +const +{ +return +HasAnyStateBits +( +NS_BLOCK_HAS_LINE_CLAMP_ELLIPSIS_DESCENDANT +) +; +} +void +SetHasLineClampEllipsis +( +bool +aValue +) +{ +AddOrRemoveStateBits +( +NS_BLOCK_HAS_LINE_CLAMP_ELLIPSIS +aValue +) +; +} +void +SetHasLineClampEllipsisDescendant +( +bool +aValue +) +{ +AddOrRemoveStateBits +( +NS_BLOCK_HAS_LINE_CLAMP_ELLIPSIS_DESCENDANT +aValue +) +; +} protected : nsBlockFrame diff --git a/layout/generic/nsFrameStateBits.h b/layout/generic/nsFrameStateBits.h index bdfd0c242410a..f9265a6ee77a1 100644 --- a/layout/generic/nsFrameStateBits.h +++ b/layout/generic/nsFrameStateBits.h @@ -679,25 +679,31 @@ NS_BLOCK_NEEDS_BIDI_RESOLUTION FRAME_STATE_BIT ( Block -60 +30 NS_BLOCK_HAS_LINE_CLAMP_ELLIPSIS ) FRAME_STATE_BIT ( Block -61 +31 +NS_BLOCK_HAS_LINE_CLAMP_ELLIPSIS_DESCENDANT +) +FRAME_STATE_BIT +( +Block +60 NS_BLOCK_LOOK_FOR_DIRTY_FRAMES ) FRAME_STATE_BIT ( Block -62 +61 NS_BLOCK_INTRINSICS_INFLATED ) FRAME_STATE_BIT ( Block -63 +62 NS_BLOCK_HAS_FIRST_LETTER_CHILD ) FRAME_STATE_GROUP diff --git a/testing/web-platform/tests/css/css-overflow/line-clamp/reference/webkit-line-clamp-040-ref.html b/testing/web-platform/tests/css/css-overflow/line-clamp/reference/webkit-line-clamp-040-ref.html index 211bece6d8d7a..595c27d2c8be4 100644 --- a/testing/web-platform/tests/css/css-overflow/line-clamp/reference/webkit-line-clamp-040-ref.html +++ b/testing/web-platform/tests/css/css-overflow/line-clamp/reference/webkit-line-clamp-040-ref.html @@ -69,12 +69,6 @@ 1 Line 2 -Line -3 -Line -4 -Line -5 < / div diff --git a/testing/web-platform/tests/css/css-overflow/line-clamp/webkit-line-clamp-050.html b/testing/web-platform/tests/css/css-overflow/line-clamp/webkit-line-clamp-050.html index 4dd01285adfd0..414e7b1a18890 100644 --- a/testing/web-platform/tests/css/css-overflow/line-clamp/webkit-line-clamp-050.html +++ b/testing/web-platform/tests/css/css-overflow/line-clamp/webkit-line-clamp-050.html @@ -158,28 +158,6 @@ 15px ; } -span -{ -/ -* -TODO -: -Remove -once -we -don -' -t -paint -clamped -lines -* -/ -color -: -transparent -; -} < / style @@ -200,27 +178,13 @@ < br > -< -span -> Line3 < / -span -> -< -/ div > -< -span -> Line4 < -/ -span -> -< div > Line5