aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout/model.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/layout/model.rs')
-rw-r--r--components/layout/model.rs33
1 files changed, 28 insertions, 5 deletions
diff --git a/components/layout/model.rs b/components/layout/model.rs
index 83b3e3a8879..9aadc7083f8 100644
--- a/components/layout/model.rs
+++ b/components/layout/model.rs
@@ -12,7 +12,7 @@ use euclid::SideOffsets2D;
use serde::Serialize;
use style::logical_geometry::{LogicalMargin, WritingMode};
use style::properties::ComputedValues;
-use style::values::computed::{LengthPercentageOrAuto, MaxSize, Size};
+use style::values::computed::{Inset, LengthPercentageOrAuto, Margin, MaxSize, Size};
use crate::fragment::Fragment;
@@ -468,6 +468,29 @@ impl MaybeAuto {
}
#[inline]
+ pub fn from_inset(length: &Inset, containing_length: Au) -> MaybeAuto {
+ match length {
+ Inset::Auto => MaybeAuto::Auto,
+ Inset::LengthPercentage(ref lp) => {
+ MaybeAuto::Specified(lp.to_used_value(containing_length))
+ },
+ Inset::AnchorFunction(_) => unreachable!("anchor() should be disabled"),
+ Inset::AnchorSizeFunction(_) => unreachable!("anchor-size() should be disabled"),
+ }
+ }
+
+ #[inline]
+ pub fn from_margin(length: &Margin, containing_length: Au) -> MaybeAuto {
+ match length {
+ Margin::Auto => MaybeAuto::Auto,
+ Margin::LengthPercentage(ref lp) => {
+ MaybeAuto::Specified(lp.to_used_value(containing_length))
+ },
+ Margin::AnchorSizeFunction(_) => unreachable!("anchor-size() should be disabled"),
+ }
+ }
+
+ #[inline]
pub fn from_option(au: Option<Au>) -> MaybeAuto {
match au {
Some(l) => MaybeAuto::Specified(l),
@@ -562,10 +585,10 @@ pub fn specified_margin_from_style(
LogicalMargin::from_physical(
writing_mode,
SideOffsets2D::new(
- MaybeAuto::from_style(&margin_style.margin_top, Au(0)).specified_or_zero(),
- MaybeAuto::from_style(&margin_style.margin_right, Au(0)).specified_or_zero(),
- MaybeAuto::from_style(&margin_style.margin_bottom, Au(0)).specified_or_zero(),
- MaybeAuto::from_style(&margin_style.margin_left, Au(0)).specified_or_zero(),
+ MaybeAuto::from_margin(&margin_style.margin_top, Au(0)).specified_or_zero(),
+ MaybeAuto::from_margin(&margin_style.margin_right, Au(0)).specified_or_zero(),
+ MaybeAuto::from_margin(&margin_style.margin_bottom, Au(0)).specified_or_zero(),
+ MaybeAuto::from_margin(&margin_style.margin_left, Au(0)).specified_or_zero(),
),
)
}