From 5cbb81a0df8d6f24732fe5aa1c5c0f6a62fee412 Mon Sep 17 00:00:00 2001 From: David Shin Date: Mon, 17 Oct 2022 17:26:13 +0000 Subject: [PATCH] style: Flag computed styles of elements with `container-type: *size` set & propagate them to their descendants Low-hanging fruit optimization that enables short-circuit exit of container query lookups. Differential Revision: https://phabricator.services.mozilla.com/D158056 --- .../style/properties/computed_value_flags.rs | 7 ++++++- components/style/style_adjuster.rs | 15 +++++++++++---- components/style/values/specified/box.rs | 7 +++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/components/style/properties/computed_value_flags.rs b/components/style/properties/computed_value_flags.rs index 01c23ba73ad..1cfaee084df 100644 --- a/components/style/properties/computed_value_flags.rs +++ b/components/style/properties/computed_value_flags.rs @@ -101,6 +101,10 @@ bitflags! { /// Whether the style depends on viewport units. const USES_VIEWPORT_UNITS = 1 << 20; + + /// A flag used to mark styles which have `container-type` of `size` or + /// `inline-size`, or under one. + const SELF_OR_ANCESTOR_HAS_SIZE_CONTAINER_TYPE = 1 << 21; } } @@ -113,7 +117,8 @@ impl ComputedValueFlags { Self::IS_IN_PSEUDO_ELEMENT_SUBTREE | Self::HAS_TEXT_DECORATION_LINES | Self::IS_IN_OPACITY_ZERO_SUBTREE | - Self::SELF_OR_ANCESTOR_HAS_CONTAIN_STYLE + Self::SELF_OR_ANCESTOR_HAS_CONTAIN_STYLE | + Self::SELF_OR_ANCESTOR_HAS_SIZE_CONTAINER_TYPE } /// Flags that may be propagated to descendants. diff --git a/components/style/style_adjuster.rs b/components/style/style_adjuster.rs index 3305b757292..2912f0676b6 100644 --- a/components/style/style_adjuster.rs +++ b/components/style/style_adjuster.rs @@ -250,7 +250,8 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { /// Compute a few common flags for both text and element's style. fn set_bits(&mut self) { - let display = self.style.get_box().clone_display(); + let box_style = self.style.get_box(); + let display = box_style.clone_display(); if !display.is_contents() { if !self @@ -280,9 +281,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { } #[cfg(feature = "gecko")] - if self - .style - .get_box() + if box_style .clone_contain() .contains(SpecifiedValue::STYLE) { @@ -290,6 +289,14 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { .add_flags(ComputedValueFlags::SELF_OR_ANCESTOR_HAS_CONTAIN_STYLE); } + if box_style + .clone_container_type() + .is_size_container_type() + { + self.style + .add_flags(ComputedValueFlags::SELF_OR_ANCESTOR_HAS_SIZE_CONTAINER_TYPE); + } + if self.style.get_parent_column().is_multicol() { self.style.add_flags(ComputedValueFlags::CAN_BE_FRAGMENTED); } diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs index 0faf01bc778..9e8c3e85340 100644 --- a/components/style/values/specified/box.rs +++ b/components/style/values/specified/box.rs @@ -1509,6 +1509,13 @@ bitflags! { } } +impl ContainerType { + /// Is this type containing size in any way? + pub fn is_size_container_type(&self) -> bool { + self.intersects(ContainerType::SIZE | ContainerType::INLINE_SIZE) + } +} + /// https://drafts.csswg.org/css-contain-3/#container-name #[repr(transparent)] #[derive(