diff --git a/components/layout_2020/geom.rs b/components/layout_2020/geom.rs index d58fec63fbb..74171278e57 100644 --- a/components/layout_2020/geom.rs +++ b/components/layout_2020/geom.rs @@ -622,10 +622,10 @@ impl ToLogicalWithContainingBlock> for PhysicalRect { } } -/// The possible keywords accepted by the sizing properties. +/// The possible values accepted by the sizing properties. /// #[derive(Clone)] -pub(crate) enum SizeKeyword { +pub(crate) enum Size { /// Represents an `auto` value for the preferred and minimum size properties, /// or `none` for the maximum size properties. /// @@ -639,38 +639,32 @@ pub(crate) enum SizeKeyword { FitContent, /// Stretch, -} - -/// The possible values accepted by the sizing properties, -/// with numeric `` resolved as a `T`. -/// -#[derive(Clone)] -pub(crate) enum Size { - Keyword(SizeKeyword), + /// Represents a numeric ``, but resolved as a `T`. + /// Numeric(T), } impl Default for Size { #[inline] fn default() -> Self { - Self::Keyword(SizeKeyword::Initial) + Self::Initial } } impl Size { #[inline] pub(crate) fn fit_content() -> Self { - Self::Keyword(SizeKeyword::FitContent) + Self::FitContent } #[inline] pub(crate) fn is_keyword(&self) -> bool { - matches!(self, Self::Keyword(_)) + !matches!(self, Self::Numeric(_)) } #[inline] pub(crate) fn is_initial(&self) -> bool { - matches!(self, Self::Keyword(SizeKeyword::Initial)) + matches!(self, Self::Initial) } } @@ -678,8 +672,8 @@ impl Size { #[inline] pub(crate) fn to_numeric(&self) -> Option { match self { - Self::Keyword(_) => None, Self::Numeric(numeric) => Some(numeric).cloned(), + _ => None, } } @@ -692,7 +686,11 @@ impl Size { #[inline] pub fn map(&self, f: impl FnOnce(T) -> U) -> Size { match self { - Size::Keyword(keyword) => Size::Keyword(keyword.clone()), + Size::Initial => Size::Initial, + Size::MinContent => Size::MinContent, + Size::MaxContent => Size::MaxContent, + Size::FitContent => Size::FitContent, + Size::Stretch => Size::Stretch, Size::Numeric(numeric) => Size::Numeric(f(numeric.clone())), } } @@ -700,8 +698,8 @@ impl Size { #[inline] pub fn maybe_map(&self, f: impl FnOnce(T) -> Option) -> Option> { Some(match self { - Size::Keyword(keyword) => Size::Keyword(keyword.clone()), Size::Numeric(numeric) => Size::Numeric(f(numeric.clone())?), + _ => self.map(|_| unreachable!("This shouldn't be called for keywords")), }) } } @@ -710,11 +708,11 @@ impl From for Size { fn from(size: StyleSize) -> Self { match size { StyleSize::LengthPercentage(length) => Size::Numeric(length.0), - StyleSize::Auto => Size::Keyword(SizeKeyword::Initial), - StyleSize::MinContent => Size::Keyword(SizeKeyword::MinContent), - StyleSize::MaxContent => Size::Keyword(SizeKeyword::MaxContent), - StyleSize::FitContent => Size::Keyword(SizeKeyword::FitContent), - StyleSize::Stretch => Size::Keyword(SizeKeyword::Stretch), + StyleSize::Auto => Size::Initial, + StyleSize::MinContent => Size::MinContent, + StyleSize::MaxContent => Size::MaxContent, + StyleSize::FitContent => Size::FitContent, + StyleSize::Stretch => Size::Stretch, } } } @@ -723,11 +721,11 @@ impl From for Size { fn from(max_size: StyleMaxSize) -> Self { match max_size { StyleMaxSize::LengthPercentage(length) => Size::Numeric(length.0), - StyleMaxSize::None => Size::Keyword(SizeKeyword::Initial), - StyleMaxSize::MinContent => Size::Keyword(SizeKeyword::MinContent), - StyleMaxSize::MaxContent => Size::Keyword(SizeKeyword::MaxContent), - StyleMaxSize::FitContent => Size::Keyword(SizeKeyword::FitContent), - StyleMaxSize::Stretch => Size::Keyword(SizeKeyword::Stretch), + StyleMaxSize::None => Size::Initial, + StyleMaxSize::MinContent => Size::MinContent, + StyleMaxSize::MaxContent => Size::MaxContent, + StyleMaxSize::FitContent => Size::FitContent, + StyleMaxSize::Stretch => Size::Stretch, } } } @@ -803,13 +801,11 @@ impl Size { get_content_size: &mut impl FnMut() -> ContentSizes, ) -> Option { match self { - Self::Keyword(SizeKeyword::Initial) => None, - Self::Keyword(SizeKeyword::MinContent) => Some(get_content_size().min_content), - Self::Keyword(SizeKeyword::MaxContent) => Some(get_content_size().max_content), - Self::Keyword(SizeKeyword::FitContent) => { - Some(get_content_size().shrink_to_fit(stretch_size)) - }, - Self::Keyword(SizeKeyword::Stretch) => Some(stretch_size), + Self::Initial => None, + Self::MinContent => Some(get_content_size().min_content), + Self::MaxContent => Some(get_content_size().max_content), + Self::FitContent => Some(get_content_size().shrink_to_fit(stretch_size)), + Self::Stretch => Some(stretch_size), Self::Numeric(numeric) => Some(*numeric), } } @@ -826,13 +822,8 @@ impl Size { #[inline] pub(crate) fn maybe_resolve_extrinsic(&self, stretch_size: Option) -> Option { match self { - Self::Keyword(keyword) => match keyword { - SizeKeyword::Initial | - SizeKeyword::MinContent | - SizeKeyword::MaxContent | - SizeKeyword::FitContent => None, - SizeKeyword::Stretch => stretch_size, - }, + Self::Initial | Self::MinContent | Self::MaxContent | Self::FitContent => None, + Self::Stretch => stretch_size, Self::Numeric(numeric) => Some(*numeric), } } diff --git a/components/layout_2020/style_ext.rs b/components/layout_2020/style_ext.rs index 8fbe2bd68d9..4d9797a4c77 100644 --- a/components/layout_2020/style_ext.rs +++ b/components/layout_2020/style_ext.rs @@ -29,7 +29,7 @@ use crate::dom_traversal::Contents; use crate::fragment_tree::FragmentFlags; use crate::geom::{ AuOrAuto, LengthPercentageOrAuto, LogicalSides, LogicalVec2, PhysicalSides, PhysicalSize, - PhysicalVec, Size, SizeKeyword, + PhysicalVec, Size, }; use crate::{ContainingBlock, IndefiniteContainingBlock}; @@ -528,7 +528,7 @@ impl ComputedValuesExt for ComputedValues { // TODO: We are assuming that Size::Initial doesn't stretch. However, it may actually // stretch flex and grid items depending on the CSS Align properties, in that case // the caller needs to take care of it. - Size::Keyword(SizeKeyword::Stretch) => true, + Size::Stretch => true, Size::Numeric(length_percentage) => length_percentage.has_percentage(), _ => false, } diff --git a/components/layout_2020/table/layout.rs b/components/layout_2020/table/layout.rs index 24d5058b9ad..5ce34111ef7 100644 --- a/components/layout_2020/table/layout.rs +++ b/components/layout_2020/table/layout.rs @@ -35,7 +35,7 @@ use crate::fragment_tree::{ }; use crate::geom::{ AuOrAuto, LogicalRect, LogicalSides, LogicalVec2, PhysicalPoint, PhysicalRect, PhysicalSides, - Size, SizeKeyword, ToLogical, ToLogicalWithContainingBlock, + Size, ToLogical, ToLogicalWithContainingBlock, }; use crate::positioned::{relative_adjustement, PositioningContext, PositioningContextLength}; use crate::sizing::{ContentSizes, InlineContentSizesResult}; @@ -252,7 +252,7 @@ impl<'a> TableLayout<'a> { TableLayoutMode::Fixed && !matches!( self.table.style.box_size(writing_mode).inline, - Size::Keyword(SizeKeyword::Initial | SizeKeyword::MaxContent) + Size::Initial | Size::MaxContent ); let row_measures = vec![LogicalVec2::zero(); self.table.size.width]; self.cell_measures = vec![row_measures; self.table.size.height];