Bug 1865065 - Do not apply content-visibility to frames with NS_FRAME_SVG_LAYOUT set. r=emilio,firefox-style-system-reviewers

The CSS containment spec [1] indicates that `content-visibility` applies
to "elements for which size containment can apply" and additionally
(1) "in the case of SVG2, the `contain` property only applies to `<svg>`
elements that have an associated CSS layout box".
(2) "size containment has no effect" for misc cases on CSS boxes.

Currently, we properly do (1) (via the NS_FRAME_SVG_LAYOUT flag)
and (2) (via the `PrecludesSizeContainmentOrContentVisibilityWithFrame`)
for size containment, but only exclude the latter for
`content-visibility`. This patch makes sure also do (1) and update
comments to refer to relevant text from the spec.

Differential Revision: https://phabricator.services.mozilla.com/D194995
This commit is contained in:
Frederic Wang 2023-11-30 13:04:55 +00:00
Родитель d54719e325
Коммит f486db48e0
2 изменённых файлов: 18 добавлений и 11 удалений

Просмотреть файл

@ -3494,8 +3494,22 @@ nscoord StyleCalcLengthPercentage::Resolve(nscoord aBasis,
bool nsStyleDisplay::PrecludesSizeContainmentOrContentVisibilityWithFrame(
const nsIFrame& aFrame) const {
// Note: The spec for size containment says it should have no effect on
// non-atomic, inline-level boxes.
// The spec says that in the case of SVG, the contain property only applies
// to <svg> elements that have an associated CSS layout box.
// https://drafts.csswg.org/css-contain/#contain-property
// Internal SVG elements do not use the standard CSS box model, and wouldn't
// be affected by size containment. By disabling it we prevent them from
// becoming query containers for size features.
if (aFrame.HasAnyStateBits(NS_FRAME_SVG_LAYOUT)) {
return true;
}
// Note: The spec for size containment says it should have no effect
// - on non-atomic, inline-level boxes.
// - on internal ruby boxes.
// - if inner display type is table.
// - on internal table boxes.
// https://drafts.csswg.org/css-contain/#containment-size
bool isNonReplacedInline = aFrame.IsLineParticipant() && !aFrame.IsReplaced();
return isNonReplacedInline || IsInternalRubyDisplayType() ||
DisplayInside() == mozilla::StyleDisplayInside::Table ||
@ -3513,13 +3527,6 @@ ContainSizeAxes nsStyleDisplay::GetContainSizeAxes(
return ContainSizeAxes(false, false);
}
// Internal SVG elements do not use the standard CSS box model, and wouldn't
// be affected by size containment. By disabling it we prevent them from
// becoming query containers for size features.
if (aFrame.HasAnyStateBits(NS_FRAME_SVG_LAYOUT)) {
return ContainSizeAxes(false, false);
}
// https://drafts.csswg.org/css-contain-2/#content-visibility
// If this content skips its content via content-visibility, it always has
// size containment.
@ -3538,6 +3545,8 @@ StyleContentVisibility nsStyleDisplay::ContentVisibility(
if (MOZ_LIKELY(mContentVisibility == StyleContentVisibility::Visible)) {
return StyleContentVisibility::Visible;
}
// content-visibility applies to elements for which size containment applies.
// https://drafts.csswg.org/css-contain/#content-visibility
if (PrecludesSizeContainmentOrContentVisibilityWithFrame(aFrame)) {
return StyleContentVisibility::Visible;
}

Просмотреть файл

@ -1,2 +0,0 @@
[content-visibility-on-g.html]
expected: FAIL