diff --git a/components/layout_2020/lib.rs b/components/layout_2020/lib.rs index 09013578308..dd589e1819b 100644 --- a/components/layout_2020/lib.rs +++ b/components/layout_2020/lib.rs @@ -4,6 +4,7 @@ #![deny(unsafe_code)] #![feature(exact_size_is_empty)] +#![feature(matches_macro)] pub mod context; pub mod data; diff --git a/components/layout_2020/style_ext.rs b/components/layout_2020/style_ext.rs index e6d4537f47c..6bd2e91a2f9 100644 --- a/components/layout_2020/style_ext.rs +++ b/components/layout_2020/style_ext.rs @@ -43,6 +43,8 @@ pub(crate) enum DisplayInside { pub(crate) trait ComputedValuesExt { fn writing_mode(&self) -> (WritingMode, Direction); + fn writing_mode_is_horizontal(&self) -> bool; + fn inline_size_is_auto(&self) -> bool; fn box_offsets(&self) -> flow_relative::Sides; fn box_size(&self) -> flow_relative::Vec2; fn padding(&self) -> flow_relative::Sides; @@ -58,6 +60,23 @@ impl ComputedValuesExt for ComputedValues { (writing_mode, direction) } + fn writing_mode_is_horizontal(&self) -> bool { + match self.get_inherited_box().writing_mode { + WritingMode::HorizontalTb => true, + WritingMode::VerticalLr | WritingMode::VerticalRl => false, + } + } + + fn inline_size_is_auto(&self) -> bool { + let position = self.get_position(); + let size = if self.writing_mode_is_horizontal() { + position.width + } else { + position.height + }; + matches!(size, Size::Auto) + } + #[inline] fn box_offsets(&self) -> flow_relative::Sides { let position = self.get_position();