Skip to content

Commit

Permalink
style: Take down the global animatable props list and use a kwarg ins…
Browse files Browse the repository at this point in the history
…tead
  • Loading branch information
emilio committed Jun 28, 2016
1 parent 793de6d commit faed3df
Show file tree
Hide file tree
Showing 25 changed files with 393 additions and 238 deletions.
62 changes: 10 additions & 52 deletions components/style/properties/data.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down
26 changes: 26 additions & 0 deletions components/style/properties/helpers/animated_properties.mako.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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]
Expand Down
29 changes: 19 additions & 10 deletions components/style/properties/longhand/background.mako.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 14 additions & 8 deletions components/style/properties/longhand/border.mako.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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.