Skip to content
Permalink
Browse files

style: Take down the global animatable props list and use a kwarg ins…

…tead
  • Loading branch information
emilio committed Jun 28, 2016
1 parent 793de6d commit faed3df59404711fb7273fc3547f5f3ace5f96c4
Showing with 393 additions and 238 deletions.
  1. +10 −52 components/style/properties/data.py
  2. +26 −0 components/style/properties/helpers/animated_properties.mako.rs
  3. +19 −10 components/style/properties/longhand/background.mako.rs
  4. +14 −8 components/style/properties/longhand/border.mako.rs
  5. +63 −35 components/style/properties/longhand/box.mako.rs
  6. +1 −1 components/style/properties/longhand/color.mako.rs
  7. +6 −3 components/style/properties/longhand/column.mako.rs
  8. +3 −3 components/style/properties/longhand/counters.mako.rs
  9. +28 −15 components/style/properties/longhand/effects.mako.rs
  10. +19 −8 components/style/properties/longhand/font.mako.rs
  11. +15 −7 components/style/properties/longhand/inherited_box.mako.rs
  12. +30 −14 components/style/properties/longhand/inherited_svg.mako.rs
  13. +10 −4 components/style/properties/longhand/inherited_table.mako.rs
  14. +32 −17 components/style/properties/longhand/inherited_text.mako.rs
  15. +5 −4 components/style/properties/longhand/list.mako.rs
  16. +2 −1 components/style/properties/longhand/margin.mako.rs
  17. +8 −5 components/style/properties/longhand/outline.mako.rs
  18. +2 −1 components/style/properties/longhand/padding.mako.rs
  19. +13 −9 components/style/properties/longhand/pointing.mako.rs
  20. +43 −20 components/style/properties/longhand/position.mako.rs
  21. +18 −8 components/style/properties/longhand/svg.mako.rs
  22. +2 −1 components/style/properties/longhand/table.mako.rs
  23. +11 −5 components/style/properties/longhand/text.mako.rs
  24. +6 −3 components/style/properties/longhand/ui.mako.rs
  25. +7 −4 components/style/properties/longhand/xul.mako.rs
@@ -16,54 +16,6 @@ def to_camel_case(ident):
return re.sub("(^|_|-)([a-z])", lambda m: m.group(2).upper(), ident.strip("_").strip("-"))


# https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_animated_properties
def is_known_animatable_property(name):
return name in [
"-moz-outline-radius", "-moz-outline-radius-bottomleft",
"-moz-outline-radius-bottomright", "-moz-outline-radius-topleft",
"-moz-outline-radius-topright", "-webkit-text-fill-color",
"-webkit-text-stroke", "-webkit-text-stroke-color",
"-webkit-touch-callout", "all", "backdrop-filter", "background",
"background-color", "background-position", "background-size", "border",
"border-bottom", "border-bottom-color", "border-bottom-left-radius",
"border-bottom-right-radius", "border-bottom-width", "border-color",
"border-left", "border-left-color", "border-left-width", "border-radius",
"border-right", "border-right-color", "border-right-width", "border-top",
"border-top-color", "border-top-left-radius", "border-top-right-radius",
"border-top-width", "border-width", "bottom", "box-shadow", "clip",
"clip-path", "color", "column-count", "column-gap", "column-rule",
"column-rule-color", "column-rule-width", "column-width", "columns",
"filter", "flex", "flex-basis", "flex-grow", "flex-shrink", "font",
"font-size", "font-size-adjust", "font-stretch", "font-weight",
"grid-column-gap", "grid-gap", "grid-row-gap", "height", "left",
"letter-spacing", "line-height", "margin", "margin-bottom",
"margin-left", "margin-right", "margin-top", "mask", "mask-position",
"mask-size", "max-height", "max-width", "min-height", "min-width",
"motion-offset", "motion-rotation", "object-position", "opacity",
"order", "outline", "outline-color", "outline-offset", "outline-width",
"padding", "padding-bottom", "padding-left", "padding-right",
"padding-top", "perspective", "perspective-origin", "right",
"scroll-snap-coordinate", "scroll-snap-destination",
"shape-image-threshold", "shape-margin", "shape-outside",
"text-decoration", "text-decoration-color", "text-emphasis",
"text-emphasis-color", "text-indent", "text-shadow", "top", "transform",
"transform-origin", "vertical-align", "visibility", "width",
"word-spacing", "z-index"
]


# FIXME: Servo doesn't support some animatable properties yet,those are in the
# following list, and can be implemented removing it from the list and
# implementing the Interpolate trait in helpers/animated_properties.mako.rs
def is_not_supported_animatable_property(name):
return name in [
"flex-basis", "column-width", "column-height", "column-count",
"column-gap", "clip", "filter", "transform-origin",
"perspective-origin", "font-stretch", "letter-spacing", "word-spacing",
"text-decoration"
]


class Keyword(object):
def __init__(self, name, values, gecko_constant_prefix=None,
extra_gecko_values=None, extra_servo_values=None):
@@ -93,9 +45,9 @@ def gecko_constant(self, value):


class Longhand(object):
def __init__(self, style_struct, name, derived_from=None, keyword=None,
def __init__(self, style_struct, name, animatable=None, derived_from=None, keyword=None,
predefined_type=None, custom_cascade=False, experimental=False, internal=False,
need_clone=False, gecko_ffi_name=None, animatable=None):
need_clone=False, gecko_ffi_name=None):
self.name = name
self.keyword = keyword
self.predefined_type = predefined_type
@@ -108,10 +60,16 @@ def __init__(self, style_struct, name, derived_from=None, keyword=None,
self.need_clone = need_clone
self.gecko_ffi_name = gecko_ffi_name or "m" + self.camel_case
self.derived_from = (derived_from or "").split()
if animatable is not None:

# This is done like this since just a plain bool argument seemed like
# really random.
if animatable is None:
raise TypeError("animatable should be specified for " + name + ")")
if isinstance(animatable, bool):
self.animatable = animatable
else:
self.animatable = is_known_animatable_property(name) and not is_not_supported_animatable_property(name)
assert animatable == "True" or animatable == "False"
self.animatable = animatable == "True"


class Shorthand(object):
@@ -20,6 +20,7 @@ use properties::longhands::box_shadow::computed_value::BoxShadow;
use properties::longhands::transform::computed_value::ComputedMatrix;
use properties::longhands::transform::computed_value::ComputedOperation as TransformOperation;
use properties::longhands::transform::computed_value::T as TransformList;
use properties::longhands::transform_origin::computed_value::T as TransformOrigin;
use properties::longhands::vertical_align::computed_value::T as VerticalAlign;
use properties::longhands::visibility::computed_value::T as Visibility;
use properties::longhands::z_index::computed_value::T as ZIndex;
@@ -821,6 +822,31 @@ impl Interpolate for LengthOrNone {
}
}

impl Interpolate for TransformOrigin {
fn interpolate(&self, other: &Self, time: f64) -> Option<Self> {
let horizontal = match self.horizontal.interpolate(&other.horizontal, time) {
Some(h) => h,
None => return None,
};

let vertical = match self.vertical.interpolate(&other.vertical, time) {
Some(v) => v,
None => return None,
};

let depth = match self.depth.interpolate(&other.depth, time) {
Some(d) => d,
None => return None,
};

Some(TransformOrigin {
horizontal: horizontal,
vertical: vertical,
depth: depth,
})
}
}

/// https://drafts.csswg.org/css-transforms/#interpolation-of-transforms
impl Interpolate for TransformList {
#[inline]
@@ -5,11 +5,12 @@
<%namespace name="helpers" file="/helpers.mako.rs" />

<% data.new_style_struct("Background", inherited=False) %>
${helpers.predefined_type(
"background-color", "CSSColor",
"::cssparser::Color::RGBA(::cssparser::RGBA { red: 0., green: 0., blue: 0., alpha: 0. }) /* transparent */")}

<%helpers:longhand name="background-image">
${helpers.predefined_type("background-color", "CSSColor",
"::cssparser::Color::RGBA(::cssparser::RGBA { red: 0., green: 0., blue: 0., alpha: 0. }) /* transparent */",
animatable=True)}

<%helpers:longhand name="background-image" animatable="False">
use cssparser::ToCss;
use std::fmt;
use values::specified::Image;
@@ -71,7 +72,7 @@ ${helpers.predefined_type(
}
</%helpers:longhand>

<%helpers:longhand name="background-position">
<%helpers:longhand name="background-position" animatable="True">
use cssparser::ToCss;
use std::fmt;
use values::LocalToCss;
@@ -186,15 +187,23 @@ ${helpers.predefined_type(
}
</%helpers:longhand>

${helpers.single_keyword("background-repeat", "repeat repeat-x repeat-y no-repeat")}
${helpers.single_keyword("background-repeat",
"repeat repeat-x repeat-y no-repeat",
animatable=False)}

${helpers.single_keyword("background-attachment", "scroll fixed" + (" local" if product == "gecko" else ""))}
${helpers.single_keyword("background-attachment",
"scroll fixed" + (" local" if product == "gecko" else ""),
animatable=False)}

${helpers.single_keyword("background-clip", "border-box padding-box content-box")}
${helpers.single_keyword("background-clip",
"border-box padding-box content-box",
animatable=False)}

${helpers.single_keyword("background-origin", "padding-box border-box content-box")}
${helpers.single_keyword("background-origin",
"padding-box border-box content-box",
animatable=False)}

<%helpers:longhand name="background-size">
<%helpers:longhand name="background-size" animatable="True">
use cssparser::{ToCss, Token};
use std::ascii::AsciiExt;
use std::fmt;
@@ -10,15 +10,19 @@
"bool") for side in ["top", "right", "bottom", "left"]]) %>

% for side in ["top", "right", "bottom", "left"]:
${helpers.predefined_type("border-%s-color" % side, "CSSColor", "::cssparser::Color::CurrentColor")}
${helpers.predefined_type("border-%s-color" % side, "CSSColor",
"::cssparser::Color::CurrentColor",
animatable=True)}
% endfor

% for side in ["top", "right", "bottom", "left"]:
${helpers.predefined_type("border-%s-style" % side, "BorderStyle", "specified::BorderStyle::none", need_clone=True)}
${helpers.predefined_type("border-%s-style" % side, "BorderStyle",
"specified::BorderStyle::none",
need_clone=True, animatable=False)}
% endfor

% for side in ["top", "right", "bottom", "left"]:
<%helpers:longhand name="border-${side}-width">
<%helpers:longhand name="border-${side}-width" animatable="True">
use app_units::Au;
use cssparser::ToCss;
use std::fmt;
@@ -60,13 +64,15 @@
% for corner in ["top-left", "top-right", "bottom-right", "bottom-left"]:
${helpers.predefined_type("border-" + corner + "-radius", "BorderRadiusSize",
"computed::BorderRadiusSize::zero()",
"parse")}
"parse",
animatable=True)}
% endfor

${helpers.single_keyword("box-decoration-break", "slice clone", products="gecko")}
${helpers.single_keyword("box-decoration-break", "slice clone",
products="gecko", animatable=False)}

${helpers.single_keyword("-moz-float-edge",
"content-box margin-box",
${helpers.single_keyword("-moz-float-edge", "content-box margin-box",
gecko_ffi_name="mFloatEdge",
gecko_constant_prefix="NS_STYLE_FLOAT_EDGE",
products="gecko")}
products="gecko",
animatable=False)}

0 comments on commit faed3df

Please sign in to comment.
You can’t perform that action at this time.