mirror of
https://github.com/servo/servo.git
synced 2025-08-08 06:55:31 +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;
|
||||
|
|
|
@ -12,7 +12,7 @@ pub use cssparser::Color as CSSColor;
|
|||
pub use self::image::{EndingShape as GradientShape, Gradient, GradientKind, Image};
|
||||
pub use self::image::{LengthOrKeyword, LengthOrPercentageOrKeyword};
|
||||
pub use super::specified::{Angle, BorderStyle, Time, UrlExtraData, UrlOrNone};
|
||||
pub use self::length::{CalcLengthOrPercentage, LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||
pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||
pub use self::length::{LengthOrPercentageOrAutoOrContent, LengthOrPercentageOrNone, LengthOrNone};
|
||||
|
||||
pub mod basic_shape;
|
||||
|
@ -147,7 +147,5 @@ impl ::cssparser::ToCss for BorderRadiusSize {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
pub type Length = Au;
|
||||
pub type Number = CSSFloat;
|
||||
pub type Opacity = CSSFloat;
|
||||
|
|
|
@ -11,7 +11,7 @@ use std::cmp;
|
|||
use std::fmt;
|
||||
use std::ops::Mul;
|
||||
use style_traits::values::specified::AllowedNumericType;
|
||||
use super::{Angle, SimplifiedValueNode, SimplifiedSumNode, Time};
|
||||
use super::{Angle, Number, SimplifiedValueNode, SimplifiedSumNode, Time};
|
||||
use values::{CSSFloat, FONT_MEDIUM_PX, HasViewportPercentage, LocalToCss, computed};
|
||||
|
||||
pub use super::image::{AngleOrCorner, ColorStop, EndingShape as GradientEndingShape, Gradient};
|
||||
|
@ -1014,3 +1014,40 @@ impl LengthOrPercentageOrAutoOrContent {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum LengthOrNumber {
|
||||
Length(Length),
|
||||
Number(Number),
|
||||
}
|
||||
|
||||
impl HasViewportPercentage for LengthOrNumber {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
match *self {
|
||||
LengthOrNumber::Length(length) => length.has_viewport_percentage(),
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl 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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for LengthOrNumber {
|
||||
fn parse(input: &mut Parser) -> Result<Self, ()> {
|
||||
let length = input.try(Length::parse);
|
||||
if let Ok(len) = length {
|
||||
return Ok(LengthOrNumber::Length(len));
|
||||
}
|
||||
|
||||
let num = try!(Number::parse_non_negative(input));
|
||||
Ok(LengthOrNumber::Number(num))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@ pub use self::image::{AngleOrCorner, ColorStop, EndingShape as GradientEndingSha
|
|||
pub use self::image::{GradientKind, HorizontalDirection, Image, LengthOrKeyword, LengthOrPercentageOrKeyword};
|
||||
pub use self::image::{SizeKeyword, VerticalDirection};
|
||||
pub use self::length::{FontRelativeLength, ViewportPercentageLength, CharacterWidth, Length, CalcLengthOrPercentage};
|
||||
pub use self::length::{Percentage, LengthOrPercentage, LengthOrPercentageOrAuto, LengthOrPercentageOrNone};
|
||||
pub use self::length::{LengthOrNone, LengthOrPercentageOrAutoOrContent, CalcUnit};
|
||||
pub use self::length::{Percentage, LengthOrNone, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||
pub use self::length::{LengthOrPercentageOrNone, LengthOrPercentageOrAutoOrContent, CalcUnit};
|
||||
|
||||
pub mod basic_shape;
|
||||
pub mod image;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue