mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +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
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue