mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Add a predefined Number type.
This commit is contained in:
parent
d71e5c8b3d
commit
3255bb809e
2 changed files with 39 additions and 1 deletions
|
@ -1476,6 +1476,43 @@ pub mod specified {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, HeapSizeOf)]
|
||||||
|
pub struct Number(pub CSSFloat);
|
||||||
|
|
||||||
|
impl Number {
|
||||||
|
pub fn parse(input: &mut Parser) -> Result<Number, ()> {
|
||||||
|
parse_number(input).map(Number)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_with_minimum(input: &mut Parser, min: CSSFloat) -> Result<Number, ()> {
|
||||||
|
match parse_number(input) {
|
||||||
|
Ok(value) if value < min => Err(()),
|
||||||
|
value => value.map(Number),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse_non_negative(input: &mut Parser) -> Result<Number, ()> {
|
||||||
|
Number::parse_with_minimum(input, 0.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse_at_least_one(input: &mut Parser) -> Result<Number, ()> {
|
||||||
|
Number::parse_with_minimum(input, 1.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToComputedValue for Number {
|
||||||
|
type ComputedValue = CSSFloat;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn to_computed_value<Cx: TContext>(&self, _: &Cx) -> CSSFloat { self.0 }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToCss for Number {
|
||||||
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
|
self.0.to_css(dest)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, HeapSizeOf)]
|
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, HeapSizeOf)]
|
||||||
pub struct Opacity(pub CSSFloat);
|
pub struct Opacity(pub CSSFloat);
|
||||||
|
|
||||||
|
@ -2117,5 +2154,6 @@ pub mod computed {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub type Length = Au;
|
pub type Length = Au;
|
||||||
|
pub type Number = CSSFloat;
|
||||||
pub type Opacity = CSSFloat;
|
pub type Opacity = CSSFloat;
|
||||||
}
|
}
|
||||||
|
|
|
@ -295,7 +295,7 @@ impl Debug for ${style_struct.gecko_ffi_name} {
|
||||||
# These are booleans.
|
# These are booleans.
|
||||||
force_stub += ["page-break-after", "page-break-before"]
|
force_stub += ["page-break-after", "page-break-before"]
|
||||||
|
|
||||||
simple_types = ["Opacity"]
|
simple_types = ["Number", "Opacity"]
|
||||||
|
|
||||||
keyword_longhands = [x for x in longhands if x.keyword and not x.name in force_stub]
|
keyword_longhands = [x for x in longhands if x.keyword and not x.name in force_stub]
|
||||||
simple_longhands = [x for x in longhands
|
simple_longhands = [x for x in longhands
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue