style: Make content-visibility: auto forces contain-intrinsic-size to gain an auto value

When the content having `content-visibility: auto` and the specific value for `contain-intrinsic-size` is slightly out of the viewport,
its computed value keeps changing.
This patch makes `content-visibilty: auto` forces `contain-intrinsic-size` to gain an auto value to solve this issue.

Differential Revision: https://phabricator.services.mozilla.com/D174583
This commit is contained in:
Jihye Hong 2023-06-05 20:46:25 +00:00 committed by Martin Robinson
parent dcbeb2f1ab
commit 9e223342e7
2 changed files with 41 additions and 0 deletions

View file

@ -532,6 +532,32 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
.set_effective_containment(new_contain);
}
/// content-visibility: auto should force contain-intrinsic-size to gain
/// an auto value
///
/// <https://github.com/w3c/csswg-drafts/issues/8407>
fn adjust_for_contain_intrinsic_size(&mut self) {
let content_visibility = self.style.get_box().clone_content_visibility();
if content_visibility != ContentVisibility::Auto {
return;
}
let pos = self.style.get_position();
let new_width = pos.clone_contain_intrinsic_width().add_auto_if_needed();
let new_height = pos.clone_contain_intrinsic_height().add_auto_if_needed();
if new_width.is_none() && new_height.is_none() {
return;
}
let pos = self.style.mutate_position();
if let Some(width) = new_width {
pos.set_contain_intrinsic_width(width);
}
if let Some(height) = new_height {
pos.set_contain_intrinsic_height(height);
}
}
/// Handles the relevant sections in:
///
/// https://drafts.csswg.org/css-display/#unbox-html
@ -952,6 +978,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
self.adjust_for_webkit_line_clamp();
self.adjust_for_position();
self.adjust_for_overflow();
self.adjust_for_contain_intrinsic_size();
#[cfg(feature = "gecko")]
{
self.adjust_for_contain();

View file

@ -25,6 +25,20 @@ pub type VerticalAlign = GenericVerticalAlign<LengthPercentage>;
/// A computed value for the `contain-intrinsic-size` property.
pub type ContainIntrinsicSize = GenericContainIntrinsicSize<NonNegativeLength>;
impl ContainIntrinsicSize {
/// Converts contain-intrinsic-size to auto style.
pub fn add_auto_if_needed(&self) -> Option<Self> {
use crate::Zero;
// TODO: support contain-intrinsic-size: auto none, see
// https://bugzilla.mozilla.org/show_bug.cgi?id=1835813
Some(match *self {
Self::None => Self::AutoLength(Zero::zero()),
Self::Length(ref l) => Self::AutoLength(*l),
Self::AutoLength(..) => return None,
})
}
}
/// A computed value for the `line-clamp` property.
pub type LineClamp = GenericLineClamp<Integer>;