mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #10957 - heycam:number, r=bholley
Support plain number-typed properties in geckolib r? @bholley <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10957) <!-- Reviewable:end -->
This commit is contained in:
commit
ddada69acb
9 changed files with 119 additions and 43 deletions
|
@ -46,10 +46,11 @@ class Keyword(object):
|
|||
|
||||
class Longhand(object):
|
||||
def __init__(self, style_struct, name, derived_from=None, keyword=None,
|
||||
custom_cascade=False, experimental=False, internal=False,
|
||||
predefined_type=None, custom_cascade=False, experimental=False, internal=False,
|
||||
need_clone=False, gecko_ffi_name=None):
|
||||
self.name = name
|
||||
self.keyword = keyword
|
||||
self.predefined_type = predefined_type
|
||||
self.ident = to_rust_ident(name)
|
||||
self.camel_case = to_camel_case(self.ident)
|
||||
self.style_struct = style_struct
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
</%def>
|
||||
|
||||
<%def name="predefined_type(name, type, initial_value, parse_method='parse', **kwargs)">
|
||||
<%call expr="longhand(name, **kwargs)">
|
||||
<%call expr="longhand(name, predefined_type=type, **kwargs)">
|
||||
#[allow(unused_imports)]
|
||||
use app_units::Au;
|
||||
pub type SpecifiedValue = specified::${type};
|
||||
|
|
|
@ -7,46 +7,9 @@
|
|||
// Box-shadow, etc.
|
||||
<% data.new_style_struct("Effects", inherited=False) %>
|
||||
|
||||
<%helpers:longhand name="opacity">
|
||||
use cssparser::ToCss;
|
||||
use std::fmt;
|
||||
use values::CSSFloat;
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
self.0.to_css(dest)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, HeapSizeOf)]
|
||||
pub struct SpecifiedValue(pub CSSFloat);
|
||||
pub mod computed_value {
|
||||
use values::CSSFloat;
|
||||
pub type T = CSSFloat;
|
||||
}
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
1.0
|
||||
}
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
type ComputedValue = computed_value::T;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value<Cx: TContext>(&self, _context: &Cx) -> computed_value::T {
|
||||
if self.0 < 0.0 {
|
||||
0.0
|
||||
} else if self.0 > 1.0 {
|
||||
1.0
|
||||
} else {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
}
|
||||
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
specified::parse_number(input).map(SpecifiedValue)
|
||||
}
|
||||
</%helpers:longhand>
|
||||
${helpers.predefined_type("opacity",
|
||||
"Opacity",
|
||||
"1.0")}
|
||||
|
||||
<%helpers:longhand name="box-shadow">
|
||||
use cssparser::{self, ToCss};
|
||||
|
|
|
@ -63,6 +63,11 @@
|
|||
// Flex container properties
|
||||
${helpers.single_keyword("flex-direction", "row row-reverse column column-reverse", experimental=True)}
|
||||
|
||||
// Flex item properties
|
||||
${helpers.predefined_type("flex-grow", "Number", "0.0", "parse_non_negative", products="gecko")}
|
||||
|
||||
${helpers.predefined_type("flex-shrink", "Number", "1.0", "parse_non_negative", products="gecko")}
|
||||
|
||||
// https://drafts.csswg.org/css-flexbox/#propdef-order
|
||||
<%helpers:longhand name="order">
|
||||
use values::computed::ComputedValueAsSpecified;
|
||||
|
|
|
@ -13,6 +13,14 @@ ${helpers.single_keyword("dominant-baseline",
|
|||
|
||||
${helpers.single_keyword("vector-effect", "none non-scaling-stroke", products="gecko")}
|
||||
|
||||
// Section 13 - Gradients and Patterns
|
||||
|
||||
${helpers.predefined_type("stop-opacity", "Opacity", "1.0", products="gecko")}
|
||||
|
||||
// Section 15 - Filter Effects
|
||||
|
||||
${helpers.predefined_type("flood-opacity", "Opacity", "1.0", products="gecko")}
|
||||
|
||||
// CSS Masking Module Level 1
|
||||
// https://www.w3.org/TR/css-masking-1/
|
||||
${helpers.single_keyword("mask-type", "luminance alpha", products="gecko")}
|
||||
|
|
|
@ -22,6 +22,8 @@ ${helpers.single_keyword("color-interpolation-filters",
|
|||
products="gecko",
|
||||
gecko_constant_prefix="NS_STYLE_COLOR_INTERPOLATION")}
|
||||
|
||||
${helpers.predefined_type("fill-opacity", "Opacity", "1.0", products="gecko")}
|
||||
|
||||
${helpers.single_keyword("fill-rule", "nonzero evenodd", products="gecko")}
|
||||
|
||||
${helpers.single_keyword("shape-rendering",
|
||||
|
@ -32,6 +34,11 @@ ${helpers.single_keyword("stroke-linecap", "butt round square", products="gecko"
|
|||
|
||||
${helpers.single_keyword("stroke-linejoin", "miter round bevel", products="gecko")}
|
||||
|
||||
${helpers.predefined_type("stroke-miterlimit", "Number", "4.0", "parse_at_least_one",
|
||||
products="gecko")}
|
||||
|
||||
${helpers.predefined_type("stroke-opacity", "Opacity", "1.0", products="gecko")}
|
||||
|
||||
// Section 14 - Clipping, Masking and Compositing
|
||||
${helpers.single_keyword("clip-rule", "nonzero evenodd",
|
||||
products="gecko",
|
||||
|
|
|
@ -10,3 +10,6 @@
|
|||
|
||||
${helpers.single_keyword("-moz-box-align", "stretch start center baseline end", products="gecko",
|
||||
gecko_ffi_name="mBoxAlign", gecko_constant_prefix="NS_STYLE_BOX_ALIGN")}
|
||||
|
||||
${helpers.predefined_type("-moz-box-flex", "Number", "0.0", "parse_non_negative", products="gecko",
|
||||
gecko_ffi_name="mBoxFlex")}
|
||||
|
|
|
@ -1475,6 +1475,73 @@ pub mod specified {
|
|||
write!(dest, "{}s", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[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)]
|
||||
pub struct Opacity(pub CSSFloat);
|
||||
|
||||
impl Opacity {
|
||||
pub fn parse(input: &mut Parser) -> Result<Opacity, ()> {
|
||||
parse_number(input).map(Opacity)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for Opacity {
|
||||
type ComputedValue = CSSFloat;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value<Cx: TContext>(&self, _: &Cx) -> CSSFloat {
|
||||
if self.0 < 0.0 {
|
||||
0.0
|
||||
} else if self.0 > 1.0 {
|
||||
1.0
|
||||
} else {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for Opacity {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
self.0.to_css(dest)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod computed {
|
||||
|
@ -2087,4 +2154,6 @@ pub mod computed {
|
|||
}
|
||||
}
|
||||
pub type Length = Au;
|
||||
pub type Number = CSSFloat;
|
||||
pub type Opacity = CSSFloat;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue