From 9e223342e77147abbd5c1150df4d6237cac20d45 Mon Sep 17 00:00:00 2001 From: Jihye Hong Date: Mon, 5 Jun 2023 20:46:25 +0000 Subject: [PATCH] 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 --- components/style/style_adjuster.rs | 27 +++++++++++++++++++++++++ components/style/values/computed/box.rs | 14 +++++++++++++ 2 files changed, 41 insertions(+) diff --git a/components/style/style_adjuster.rs b/components/style/style_adjuster.rs index 5f169429949..c4bb7f3cea7 100644 --- a/components/style/style_adjuster.rs +++ b/components/style/style_adjuster.rs @@ -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 + /// + /// + 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(); diff --git a/components/style/values/computed/box.rs b/components/style/values/computed/box.rs index e25cd104894..5f1f68249da 100644 --- a/components/style/values/computed/box.rs +++ b/components/style/values/computed/box.rs @@ -25,6 +25,20 @@ pub type VerticalAlign = GenericVerticalAlign; /// A computed value for the `contain-intrinsic-size` property. pub type ContainIntrinsicSize = GenericContainIntrinsicSize; +impl ContainIntrinsicSize { + /// Converts contain-intrinsic-size to auto style. + pub fn add_auto_if_needed(&self) -> Option { + 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;