From f884aa8dd494f15b5c8fa9de6ebd83cd76d5319b Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Tue, 22 Oct 2024 22:09:26 +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: c6ce92301ca11292a5dd25f07a80243592c94e5a --- layout/generic/TextOverflow.cpp | 6 +- layout/generic/nsBlockFrame.cpp | 293 ++++++++++++++---- layout/generic/nsBlockFrame.h | 126 ++++++++ layout/generic/nsFrameStateBits.h | 70 +---- .../reference/webkit-line-clamp-040-ref.html | 6 - .../line-clamp/webkit-line-clamp-050.html | 36 --- 6 files changed, 377 insertions(+), 160 deletions(-) diff --git a/layout/generic/TextOverflow.cpp b/layout/generic/TextOverflow.cpp index ab2b46e4aa2f4..371ee7b8668b5 100644 --- a/layout/generic/TextOverflow.cpp +++ b/layout/generic/TextOverflow.cpp @@ -5602,9 +5602,8 @@ f f - > -HasAnyStateBits +HasLineClampEllipsis ( -NS_BLOCK_HAS_LINE_CLAMP_ELLIPSIS ) ; } @@ -5637,9 +5636,8 @@ return aBlockFrame - > -HasAnyStateBits +HasLineClampEllipsis ( -NS_BLOCK_HAS_LINE_CLAMP_ELLIPSIS ) ; } diff --git a/layout/generic/nsBlockFrame.cpp b/layout/generic/nsBlockFrame.cpp index 90a7f7d14b42c..8f79d6ff250f0 100644 --- a/layout/generic/nsBlockFrame.cpp +++ b/layout/generic/nsBlockFrame.cpp @@ -8248,7 +8248,10 @@ aFrame if it is -a +an +in +- +flow non - BFC @@ -8294,8 +8297,6 @@ nsIFrame aFrame ) { -if -( const nsBlockFrame * @@ -8305,29 +8306,51 @@ do_QueryFrame ( aFrame ) +; +if +( +! +block ) { +return +nullptr +; +} if ( -! block - > -HasAnyStateBits +HasAllStateBits ( -NS_BLOCK_BFC +NS_FRAME_OUT_OF_FLOW ) ) { return -block +nullptr ; } -} +if +( +block +- +> +HasAllStateBits +( +NS_BLOCK_BFC +) +) +{ return nullptr ; } +return +block +; +} static nsBlockFrame * @@ -9421,102 +9444,127 @@ aFrame { if ( -! aFrame - > -HasAnyStateBits +HasLineClampEllipsis ( -NS_BLOCK_HAS_LINE_CLAMP_ELLIPSIS ) ) { +MOZ_ASSERT +( +! +aFrame +- +> +HasLineClampEllipsisDescendant +( +) +) +; for ( -nsIFrame -* -f +auto +& +line : aFrame - > -PrincipalChildList +Lines ( ) ) { if ( -nsBlockFrame -* -child -= -GetAsLineClampDescendant +line +. +HasLineClampEllipsis ( -f ) ) { -if -( -ClearLineClampEllipsis +line +. +ClearHasLineClampEllipsis ( -child ) +; +aFrame +- +> +SetHasLineClampEllipsis +( +false ) -{ +; return true ; } } } -return -false -; -} +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 ; } } +} +} / / We @@ -9538,7 +9586,7 @@ deleted already . return -true +false ; } void @@ -14821,21 +14869,10 @@ line clamp ellipsis . -if -( -aReflowInput -. -mStyleDisplay -- -> -mWebkitLineClamp -) -{ ClearLineClampEllipsis ( ) ; -} CheckFloats ( state @@ -14988,9 +15025,8 @@ MOZ_ASSERT aFrame - > -HasAnyStateBits +HasLineClampEllipsis ( -NS_BLOCK_HAS_LINE_CLAMP_ELLIPSIS ) " Should @@ -15326,9 +15362,9 @@ SetHasLineClampEllipsis target - > -AddStateBits +SetHasLineClampEllipsis ( -NS_BLOCK_HAS_LINE_CLAMP_ELLIPSIS +true ) ; / @@ -15379,6 +15415,45 @@ GetParent ) ) { +MOZ_ASSERT +( +f +- +> +IsBlockFrameOrSubclass +( +) +" +GetAsLineClampDescendant +guarantees +this +" +) +; +if +( +f +! += +target +) +{ +static_cast +< +nsBlockFrame +* +> +( +f +) +- +> +SetHasLineClampEllipsisDescendant +( +true +) +; +} if ( f @@ -58014,6 +58089,9 @@ aDepth int32_t & aDrawnLines +bool +& +aFoundLineClamp ) { # @@ -58237,6 +58315,60 @@ GetNextSibling } if ( +aFrame +- +> +HasLineClampEllipsisDescendant +( +) +& +& +! +aLineInLine +) +{ +if +( +nsBlockFrame +* +f += +GetAsLineClampDescendant +( +aLine +- +> +mFirstChild +) +) +{ +if +( +f +- +> +HasLineClampEllipsis +( +) +| +| +f +- +> +HasLineClampEllipsisDescendant +( +) +) +{ +aFoundLineClamp += +true +; +} +} +} +if +( aTextOverflow & & @@ -59095,6 +59227,16 @@ isSome | | backplateColor +| +| +HasLineClampEllipsis +( +) +| +| +HasLineClampEllipsisDescendant +( +) ) ? nullptr @@ -59129,6 +59271,11 @@ ptrOr nullptr ) ; +bool +foundClamp += +false +; if ( cursor @@ -59267,6 +59414,13 @@ nullptr 0 depth drawnLines +foundClamp +) +; +MOZ_ASSERT +( +! +foundClamp ) ; } @@ -59482,6 +59636,7 @@ textOverflowPtr lineCount depth drawnLines +foundClamp ) ; } @@ -59683,6 +59838,26 @@ lineBackplate } } } +foundClamp += +foundClamp +| +| +line +- +> +HasLineClampEllipsis +( +) +; +if +( +foundClamp +) +{ +break +; +} lineCount + + diff --git a/layout/generic/nsBlockFrame.h b/layout/generic/nsBlockFrame.h index d7326c961ac06..6837074174a69 100644 --- a/layout/generic/nsBlockFrame.h +++ b/layout/generic/nsBlockFrame.h @@ -4995,6 +4995,132 @@ MaybeHasFloats ) const ; +/ +* +* +* +This +indicates +that +exactly +one +line +in +this +block +has +the +* +LineClampEllipsis +flag +set +and +that +such +a +line +must +be +found +* +and +have +that +flag +cleared +when +reflowing +this +element +' +s +nearest +legacy +box +* +container +. +* +/ +bool +HasLineClampEllipsis +( +) +const +{ +return +HasAnyStateBits +( +NS_BLOCK_HAS_LINE_CLAMP_ELLIPSIS +) +; +} +/ +* +* +* +This +indicates +that +we +have +a +descendant +in +our +block +formatting +context +* +that +has +such +a +line +. +* +/ +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 4ea0036b612c0..91a989f616f06 100644 --- a/layout/generic/nsFrameStateBits.h +++ b/layout/generic/nsFrameStateBits.h @@ -5045,64 +5045,24 @@ NS_BLOCK_NEEDS_BIDI_RESOLUTION ) / / -bits -30 -and -31 -free -. -/ -/ -NS_BLOCK_HAS_LINE_CLAMP_ELLIPSIS -indicates -that -exactly -one -line -in -this -/ -/ -block -has -the -LineClampEllipsis -flag -set -and -that -such -a -line -must -be -found -/ -/ -and -have -that -flag -cleared -when -reflowing -this -element -' -s -nearest -legacy -box -/ -/ -container +See +nsBlockFrame . +h +for +docs FRAME_STATE_BIT ( Block -60 +30 NS_BLOCK_HAS_LINE_CLAMP_ELLIPSIS ) +FRAME_STATE_BIT +( +Block +31 +NS_BLOCK_HAS_LINE_CLAMP_ELLIPSIS_DESCENDANT +) / / This @@ -5142,7 +5102,7 @@ dirty FRAME_STATE_BIT ( Block -61 +60 NS_BLOCK_LOOK_FOR_DIRTY_FRAMES ) / @@ -5243,7 +5203,7 @@ enabled FRAME_STATE_BIT ( Block -62 +61 NS_BLOCK_INTRINSICS_INFLATED ) / @@ -5313,7 +5273,7 @@ only FRAME_STATE_BIT ( Block -63 +62 NS_BLOCK_HAS_FIRST_LETTER_CHILD ) / 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