From 647d813c6b480b8f3f97d1447e20b2c844d0db83 Mon Sep 17 00:00:00 2001 From: Oriol Brufau Date: Tue, 6 Dec 2022 12:57:50 +0000 Subject: [PATCH] style: @container(width:0) shouldn't match elements with no box Depends on D163879 Differential Revision: https://phabricator.services.mozilla.com/D163844 --- components/style/dom.rs | 2 +- components/style/gecko/wrapper.rs | 9 ++++---- .../style/stylesheets/container_rule.rs | 22 +++++++++---------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/components/style/dom.rs b/components/style/dom.rs index e89c662f89c..98246ae562c 100644 --- a/components/style/dom.rs +++ b/components/style/dom.rs @@ -944,7 +944,7 @@ pub trait TElement: -> &::BorrowedNamespaceUrl; /// Returns the size of the primary box of the element. - fn primary_content_box_size(&self) -> euclid::default::Size2D; + fn primary_content_box_size(&self) -> euclid::default::Size2D>; } /// TNode and TElement aren't Send because we want to be careful and explicit diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index 86a8d31d1d1..e7afd518c0b 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -1041,9 +1041,9 @@ impl<'le> TElement for GeckoElement<'le> { } #[inline] - fn primary_content_box_size(&self) -> Size2D { + fn primary_content_box_size(&self) -> Size2D> { if !self.as_node().is_connected() { - return Size2D::zero(); + return Size2D::new(None, None) } unsafe { @@ -1056,12 +1056,13 @@ impl<'le> TElement for GeckoElement<'le> { .mPrimaryFrame .as_ref(); if frame.is_null() { - return Size2D::zero(); + return Size2D::new(None, None) } let mut width = 0; let mut height = 0; bindings::Gecko_ContentSize(*frame, &mut width, &mut height); - Size2D::new(Au(width), Au(height)) + // FIXME: Should use None if there isn't size containment. + Size2D::new(Some(Au(width)), Some(Au(height))) } } diff --git a/components/style/stylesheets/container_rule.rs b/components/style/stylesheets/container_rule.rs index 9c12043b789..aab9e64d56d 100644 --- a/components/style/stylesheets/container_rule.rs +++ b/components/style/stylesheets/container_rule.rs @@ -258,25 +258,25 @@ impl ContainerCondition { /// Information needed to evaluate an individual container query. #[derive(Copy, Clone)] pub struct ContainerInfo { - size: Size2D, + size: Size2D>, wm: WritingMode, } fn eval_width(context: &Context) -> Option { let info = context.container_info.as_ref()?; - Some(CSSPixelLength::new(info.size.width.to_f32_px())) + Some(CSSPixelLength::new(info.size.width?.to_f32_px())) } fn eval_height(context: &Context) -> Option { let info = context.container_info.as_ref()?; - Some(CSSPixelLength::new(info.size.height.to_f32_px())) + Some(CSSPixelLength::new(info.size.height?.to_f32_px())) } fn eval_inline_size(context: &Context) -> Option { let info = context.container_info.as_ref()?; Some(CSSPixelLength::new( LogicalSize::from_physical(info.wm, info.size) - .inline + .inline? .to_f32_px(), )) } @@ -285,14 +285,14 @@ fn eval_block_size(context: &Context) -> Option { let info = context.container_info.as_ref()?; Some(CSSPixelLength::new( LogicalSize::from_physical(info.wm, info.size) - .block + .block? .to_f32_px(), )) } fn eval_aspect_ratio(context: &Context) -> Option { let info = context.container_info.as_ref()?; - Some(Ratio::new(info.size.width.0 as f32, info.size.height.0 as f32)) + Some(Ratio::new(info.size.width?.0 as f32, info.size.height?.0 as f32)) } fn eval_orientation(context: &Context, value: Option) -> bool { @@ -466,11 +466,11 @@ impl<'a> ContainerSizeQuery<'a> { let container_type = box_style.clone_container_type(); let size = e.primary_content_box_size(); match container_type { - ContainerType::Size=> { + ContainerType::Size => { TraversalResult::Done( ContainerSizeQueryResult { - width: Some(size.width), - height: Some(size.height) + width: size.width, + height: size.height, } ) }, @@ -478,7 +478,7 @@ impl<'a> ContainerSizeQuery<'a> { if wm.is_horizontal() { TraversalResult::Done( ContainerSizeQueryResult { - width: Some(size.width), + width: size.width, height: None, } ) @@ -486,7 +486,7 @@ impl<'a> ContainerSizeQuery<'a> { TraversalResult::Done( ContainerSizeQueryResult { width: None, - height: Some(size.height), + height: size.height, } ) }