style: Add an API to parse an absolute length without any other context

This should allow making these work on canvas.

Differential Revision: https://phabricator.services.mozilla.com/D177074
This commit is contained in:
Emilio Cobos Álvarez 2023-05-10 23:07:31 +00:00 committed by Martin Robinson
parent a69578993a
commit d9d865e8c9

View file

@ -1085,7 +1085,7 @@ impl NoCalcLength {
#[inline]
pub fn to_computed_pixel_length_without_context(&self) -> Result<CSSFloat, ()> {
match *self {
NoCalcLength::Absolute(len) => Ok(CSSPixelLength::new(len.to_px()).finite().px()),
Self::Absolute(len) => Ok(CSSPixelLength::new(len.to_px()).finite().px()),
_ => Err(()),
}
}
@ -1344,6 +1344,14 @@ impl Length {
pub fn from_px(px_value: CSSFloat) -> Length {
Length::NoCalc(NoCalcLength::from_px(px_value))
}
/// Get a px value without context.
pub fn to_computed_pixel_length_without_context(&self) -> Result<CSSFloat, ()> {
match *self {
Self::NoCalc(ref l) => l.to_computed_pixel_length_without_context(),
Self::Calc(ref l) => l.to_computed_pixel_length_without_context(),
}
}
}
impl Parse for Length {