diff options
Diffstat (limited to 'components/layout_2020/style_ext.rs')
-rw-r--r-- | components/layout_2020/style_ext.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/components/layout_2020/style_ext.rs b/components/layout_2020/style_ext.rs index 8c145f23c6f..5748eac1b02 100644 --- a/components/layout_2020/style_ext.rs +++ b/components/layout_2020/style_ext.rs @@ -45,6 +45,9 @@ 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 inline_box_offsets_are_both_non_auto(&self) -> bool; fn box_offsets(&self) -> flow_relative::Sides<LengthPercentageOrAuto>; fn box_size(&self) -> flow_relative::Vec2<LengthPercentageOrAuto>; fn min_box_size(&self) -> flow_relative::Vec2<LengthPercentageOrAuto>; @@ -62,6 +65,39 @@ 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) + } + + fn inline_box_offsets_are_both_non_auto(&self) -> bool { + let position = self.get_position(); + let offsets = if self.writing_mode_is_horizontal() { + (position.left, position.right) + } else { + (position.top, position.bottom) + }; + matches!( + offsets, + ( + LengthPercentageOrAuto::LengthPercentage(_), + LengthPercentageOrAuto::LengthPercentage(_), + ) + ) + } + #[inline] fn box_offsets(&self) -> flow_relative::Sides<LengthPercentageOrAuto> { let position = self.get_position(); |