mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Move LengthOrNumber to style/values and implement GeckoStyleCoordConvertible
This commit is contained in:
parent
9a2ef2e6ef
commit
7720fe4d9c
7 changed files with 131 additions and 90 deletions
|
@ -5,7 +5,7 @@
|
|||
use app_units::Au;
|
||||
use ordered_float::NotNaN;
|
||||
use std::fmt;
|
||||
use super::{ToComputedValue, Context};
|
||||
use super::{Number, ToComputedValue, Context};
|
||||
use values::{CSSFloat, LocalToCss, specified};
|
||||
|
||||
pub use cssparser::Color as CSSColor;
|
||||
|
@ -506,3 +506,53 @@ impl ::cssparser::ToCss for LengthOrNone {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum LengthOrNumber {
|
||||
Length(Length),
|
||||
Number(Number),
|
||||
}
|
||||
|
||||
impl fmt::Debug for LengthOrNumber {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
LengthOrNumber::Length(length) => write!(f, "{:?}", length),
|
||||
LengthOrNumber::Number(number) => write!(f, "{:?}", number),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for specified::LengthOrNumber {
|
||||
type ComputedValue = LengthOrNumber;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> LengthOrNumber {
|
||||
match *self {
|
||||
specified::LengthOrNumber::Length(len) =>
|
||||
LengthOrNumber::Length(len.to_computed_value(context)),
|
||||
specified::LengthOrNumber::Number(number) =>
|
||||
LengthOrNumber::Number(number.to_computed_value(context)),
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &LengthOrNumber) -> Self {
|
||||
match *computed {
|
||||
LengthOrNumber::Length(len) =>
|
||||
specified::LengthOrNumber::Length(ToComputedValue::from_computed_value(&len)),
|
||||
LengthOrNumber::Number(number) =>
|
||||
specified::LengthOrNumber::Number(ToComputedValue::from_computed_value(&number)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ::cssparser::ToCss for LengthOrNumber {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
LengthOrNumber::Length(len) => len.to_css(dest),
|
||||
LengthOrNumber::Number(number) => number.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type Length = Au;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue