mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +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):
|
class Longhand(object):
|
||||||
def __init__(self, style_struct, name, derived_from=None, keyword=None,
|
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):
|
need_clone=False, gecko_ffi_name=None):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.keyword = keyword
|
self.keyword = keyword
|
||||||
|
self.predefined_type = predefined_type
|
||||||
self.ident = to_rust_ident(name)
|
self.ident = to_rust_ident(name)
|
||||||
self.camel_case = to_camel_case(self.ident)
|
self.camel_case = to_camel_case(self.ident)
|
||||||
self.style_struct = style_struct
|
self.style_struct = style_struct
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
<%def name="predefined_type(name, type, initial_value, parse_method='parse', **kwargs)">
|
<%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)]
|
#[allow(unused_imports)]
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
pub type SpecifiedValue = specified::${type};
|
pub type SpecifiedValue = specified::${type};
|
||||||
|
|
|
@ -7,46 +7,9 @@
|
||||||
// Box-shadow, etc.
|
// Box-shadow, etc.
|
||||||
<% data.new_style_struct("Effects", inherited=False) %>
|
<% data.new_style_struct("Effects", inherited=False) %>
|
||||||
|
|
||||||
<%helpers:longhand name="opacity">
|
${helpers.predefined_type("opacity",
|
||||||
use cssparser::ToCss;
|
"Opacity",
|
||||||
use std::fmt;
|
"1.0")}
|
||||||
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:longhand name="box-shadow">
|
<%helpers:longhand name="box-shadow">
|
||||||
use cssparser::{self, ToCss};
|
use cssparser::{self, ToCss};
|
||||||
|
|
|
@ -63,6 +63,11 @@
|
||||||
// Flex container properties
|
// Flex container properties
|
||||||
${helpers.single_keyword("flex-direction", "row row-reverse column column-reverse", experimental=True)}
|
${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
|
// https://drafts.csswg.org/css-flexbox/#propdef-order
|
||||||
<%helpers:longhand name="order">
|
<%helpers:longhand name="order">
|
||||||
use values::computed::ComputedValueAsSpecified;
|
use values::computed::ComputedValueAsSpecified;
|
||||||
|
|
|
@ -13,6 +13,14 @@ ${helpers.single_keyword("dominant-baseline",
|
||||||
|
|
||||||
${helpers.single_keyword("vector-effect", "none non-scaling-stroke", products="gecko")}
|
${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
|
// CSS Masking Module Level 1
|
||||||
// https://www.w3.org/TR/css-masking-1/
|
// https://www.w3.org/TR/css-masking-1/
|
||||||
${helpers.single_keyword("mask-type", "luminance alpha", products="gecko")}
|
${helpers.single_keyword("mask-type", "luminance alpha", products="gecko")}
|
||||||
|
|
|
@ -22,6 +22,8 @@ ${helpers.single_keyword("color-interpolation-filters",
|
||||||
products="gecko",
|
products="gecko",
|
||||||
gecko_constant_prefix="NS_STYLE_COLOR_INTERPOLATION")}
|
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("fill-rule", "nonzero evenodd", products="gecko")}
|
||||||
|
|
||||||
${helpers.single_keyword("shape-rendering",
|
${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.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
|
// Section 14 - Clipping, Masking and Compositing
|
||||||
${helpers.single_keyword("clip-rule", "nonzero evenodd",
|
${helpers.single_keyword("clip-rule", "nonzero evenodd",
|
||||||
products="gecko",
|
products="gecko",
|
||||||
|
|
|
@ -10,3 +10,6 @@
|
||||||
|
|
||||||
${helpers.single_keyword("-moz-box-align", "stretch start center baseline end", products="gecko",
|
${helpers.single_keyword("-moz-box-align", "stretch start center baseline end", products="gecko",
|
||||||
gecko_ffi_name="mBoxAlign", gecko_constant_prefix="NS_STYLE_BOX_ALIGN")}
|
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)
|
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 {
|
pub mod computed {
|
||||||
|
@ -2087,4 +2154,6 @@ pub mod computed {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub type Length = Au;
|
pub type Length = Au;
|
||||||
|
pub type Number = CSSFloat;
|
||||||
|
pub type Opacity = CSSFloat;
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,6 +128,12 @@ pub struct ${style_struct.gecko_struct_name} {
|
||||||
}
|
}
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
|
<%def name="impl_simple_setter(ident, gecko_ffi_name)">
|
||||||
|
fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
|
||||||
|
${set_gecko_property(gecko_ffi_name, "v")}
|
||||||
|
}
|
||||||
|
</%def>
|
||||||
|
|
||||||
<%def name="impl_simple_copy(ident, gecko_ffi_name)">
|
<%def name="impl_simple_copy(ident, gecko_ffi_name)">
|
||||||
fn copy_${ident}_from(&mut self, other: &Self) {
|
fn copy_${ident}_from(&mut self, other: &Self) {
|
||||||
self.gecko.${gecko_ffi_name} = other.gecko.${gecko_ffi_name};
|
self.gecko.${gecko_ffi_name} = other.gecko.${gecko_ffi_name};
|
||||||
|
@ -186,6 +192,11 @@ def set_gecko_property(ffi_name, expr):
|
||||||
% endif
|
% endif
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
|
<%def name="impl_simple(ident, gecko_ffi_name)">
|
||||||
|
<%call expr="impl_simple_setter(ident, gecko_ffi_name)"></%call>
|
||||||
|
<%call expr="impl_simple_copy(ident, gecko_ffi_name)"></%call>
|
||||||
|
</%def>
|
||||||
|
|
||||||
<%def name="impl_app_units(ident, gecko_ffi_name, need_clone)">
|
<%def name="impl_app_units(ident, gecko_ffi_name, need_clone)">
|
||||||
fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
|
fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
|
||||||
self.gecko.${gecko_ffi_name} = v.0;
|
self.gecko.${gecko_ffi_name} = v.0;
|
||||||
|
@ -284,8 +295,14 @@ 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 = ["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]
|
||||||
stub_longhands = [x for x in longhands if x not in keyword_longhands]
|
simple_longhands = [x for x in longhands
|
||||||
|
if x.predefined_type in simple_types and not x.name in force_stub]
|
||||||
|
|
||||||
|
autogenerated_longhands = keyword_longhands + simple_longhands
|
||||||
|
stub_longhands = [x for x in longhands if x not in autogenerated_longhands]
|
||||||
%>
|
%>
|
||||||
impl ${style_struct.trait_name} for ${style_struct.gecko_struct_name} {
|
impl ${style_struct.trait_name} for ${style_struct.gecko_struct_name} {
|
||||||
/*
|
/*
|
||||||
|
@ -299,6 +316,9 @@ impl ${style_struct.trait_name} for ${style_struct.gecko_struct_name} {
|
||||||
% for longhand in keyword_longhands:
|
% for longhand in keyword_longhands:
|
||||||
<%call expr="impl_keyword(longhand.ident, longhand.gecko_ffi_name, longhand.keyword, longhand.need_clone)"></%call>
|
<%call expr="impl_keyword(longhand.ident, longhand.gecko_ffi_name, longhand.keyword, longhand.need_clone)"></%call>
|
||||||
% endfor
|
% endfor
|
||||||
|
% for longhand in simple_longhands:
|
||||||
|
<%call expr="impl_simple(longhand.ident, longhand.gecko_ffi_name)"></%call>
|
||||||
|
% endfor
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Stubs.
|
* Stubs.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue