From 65fbb16bb4857c2d25c6f560f32cce60fddebe58 Mon Sep 17 00:00:00 2001 From: Oriol Brufau Date: Wed, 21 Dec 2022 01:04:05 +0000 Subject: [PATCH] style: Partial fix for container units in pseudo-elements When apply_declarations is used for a pseudo-element, make it pass the parent_style as the originating_element_style for container queries. This requires changing some parameters from Option<&Arc> to Option<&ComputedValues>. It's not a complete solution, since e.g. parent_style is not the style of the originating element of a ::backdrop. But here it's not as simple as in D164908, so leaving these details for later. Differential Revision: https://phabricator.services.mozilla.com/D164977 --- components/style/properties/cascade.rs | 3 ++- .../style/stylesheets/container_rule.rs | 21 ++++++++----------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/components/style/properties/cascade.rs b/components/style/properties/cascade.rs index 0035a5a53fc..3edee32237a 100644 --- a/components/style/properties/cascade.rs +++ b/components/style/properties/cascade.rs @@ -281,7 +281,8 @@ where }; let is_root_element = pseudo.is_none() && element.map_or(false, |e| e.is_root()); - let container_size_query = ContainerSizeQuery::for_option_element(element, None); + let container_size_query = + ContainerSizeQuery::for_option_element(element, pseudo.and(parent_style)); let mut context = computed::Context::new( // We'd really like to own the rules here to avoid refcount traffic, but diff --git a/components/style/stylesheets/container_rule.rs b/components/style/stylesheets/container_rule.rs index 0720cde1366..9b06066e1ea 100644 --- a/components/style/stylesheets/container_rule.rs +++ b/components/style/stylesheets/container_rule.rs @@ -135,14 +135,14 @@ enum TraversalResult { Done(T), } -fn traverse_container( +fn traverse_container( mut e: E, - originating_element_style: Option<&Arc>, + originating_element_style: Option<&S>, evaluator: F, ) -> Option<(E, R)> where E: TElement, - F: Fn(E, Option<&Arc>) -> TraversalResult, + F: Fn(E, Option<&S>) -> TraversalResult, { if originating_element_style.is_some() { match evaluator(e, originating_element_style) { @@ -479,7 +479,7 @@ pub enum ContainerSizeQuery<'a> { impl<'a> ContainerSizeQuery<'a> { fn evaluate_potential_size_container( e: E, - originating_element_style: Option<&Arc>, + originating_element_style: Option<&ComputedValues>, ) -> TraversalResult where E: TElement, @@ -492,7 +492,7 @@ impl<'a> ContainerSizeQuery<'a> { Some(d) => d, None => return TraversalResult::InProgress, }; - data.styles.primary() + &**data.styles.primary() }, }; if !style @@ -533,7 +533,7 @@ impl<'a> ContainerSizeQuery<'a> { /// Find the query container size for a given element. Meant to be used as a callback for new(). fn lookup( element: E, - originating_element_style: Option<&Arc>, + originating_element_style: Option<&ComputedValues>, ) -> ContainerSizeQueryResult where E: TElement + 'a, @@ -558,10 +558,7 @@ impl<'a> ContainerSizeQuery<'a> { } /// Create a new instance of the container size query for given element, with a deferred lookup callback. - pub fn for_element( - element: E, - originating_element_style: Option<&'a Arc>, - ) -> Self + pub fn for_element(element: E, originating_element_style: Option<&'a ComputedValues>) -> Self where E: TElement + 'a, { @@ -576,7 +573,7 @@ impl<'a> ContainerSizeQuery<'a> { None => return Self::none(), }; data = parent.borrow_data(); - data.as_ref().map(|data| data.styles.primary()) + data.as_ref().map(|data| &**data.styles.primary()) }, }; let should_traverse = match style { @@ -596,7 +593,7 @@ impl<'a> ContainerSizeQuery<'a> { /// Create a new instance, but with optional element. pub fn for_option_element( element: Option, - originating_element_style: Option<&'a Arc>, + originating_element_style: Option<&'a ComputedValues>, ) -> Self where E: TElement + 'a,