aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-07-05 07:33:13 -0700
committerGitHub <noreply@github.com>2017-07-05 07:33:13 -0700
commit296a215e5404eb0fd0c0a34cc1283cd0b84aaea9 (patch)
tree076fdfbca28efe25f4d5af3d20e1661ea1c0e388
parent5baea7b73223283b551cf378bb714491a2383c28 (diff)
parent4a2ede9b3a096ad25e0d40bf12d21cd5dd9e4b50 (diff)
downloadservo-296a215e5404eb0fd0c0a34cc1283cd0b84aaea9.tar.gz
servo-296a215e5404eb0fd0c0a34cc1283cd0b84aaea9.zip
Auto merge of #17603 - servo:derive-all-the-things, r=SimonSapin
Clean up vector_longhand a bit <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17603) <!-- Reviewable:end -->
-rw-r--r--components/style/properties/helpers.mako.rs322
-rw-r--r--components/style/properties/helpers/animated_properties.mako.rs18
-rw-r--r--components/style/properties/longhand/background.mako.rs14
-rw-r--r--components/style/properties/longhand/box.mako.rs3
-rw-r--r--components/style/properties/longhand/inherited_svg.mako.rs1
-rw-r--r--components/style/properties/longhand/svg.mako.rs17
6 files changed, 178 insertions, 197 deletions
diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs
index 0f2027fe401..f7fd7f608f1 100644
--- a/components/style/properties/helpers.mako.rs
+++ b/components/style/properties/helpers.mako.rs
@@ -69,208 +69,200 @@
// FIXME (Manishearth): Add computed_value_as_specified argument
// and handle the empty case correctly
<%doc>
- To be used in cases where we have a grammar like
- "<thing> [ , <thing> ]*". `gecko_only` should be set
- to True for cases where Servo takes a single value
- and Stylo supports vector values.
+ To be used in cases where we have a grammar like "<thing> [ , <thing> ]*".
Setting allow_empty to False allows for cases where the vector
is empty. The grammar for these is usually "none | <thing> [ , <thing> ]*".
We assume that the default/initial value is an empty vector for these.
`initial_value` need not be defined for these.
</%doc>
-<%def name="vector_longhand(name, gecko_only=False, allow_empty=False,
- delegate_animate=False, separator='Comma', **kwargs)">
- <%call expr="longhand(name, vector=True, **kwargs)">
- % if not gecko_only:
+<%def name="vector_longhand(name, animation_value_type=None, allow_empty=False, separator='Comma', **kwargs)">
+ <%call expr="longhand(name, animation_value_type=animation_value_type, vector=True, **kwargs)">
+ #[allow(unused_imports)]
+ use smallvec::SmallVec;
+ use std::fmt;
+ #[allow(unused_imports)]
+ use style_traits::HasViewportPercentage;
+ use style_traits::{Separator, ToCss};
+
+ pub mod single_value {
#[allow(unused_imports)]
- use smallvec::SmallVec;
- use std::fmt;
+ use cssparser::{Parser, BasicParseError};
#[allow(unused_imports)]
- use style_traits::HasViewportPercentage;
- use style_traits::{Separator, ToCss};
-
- pub mod single_value {
- #[allow(unused_imports)]
- use cssparser::{Parser, BasicParseError};
- #[allow(unused_imports)]
- use parser::{Parse, ParserContext};
- #[allow(unused_imports)]
- use properties::ShorthandId;
- #[allow(unused_imports)]
- use selectors::parser::SelectorParseError;
- #[allow(unused_imports)]
- use style_traits::{ParseError, StyleParseError};
- #[allow(unused_imports)]
- use values::computed::{Context, ToComputedValue};
- #[allow(unused_imports)]
- use values::{computed, specified};
- #[allow(unused_imports)]
- use values::{Auto, Either, None_, Normal};
- ${caller.body()}
- }
+ use parser::{Parse, ParserContext};
+ #[allow(unused_imports)]
+ use properties::ShorthandId;
+ #[allow(unused_imports)]
+ use selectors::parser::SelectorParseError;
+ #[allow(unused_imports)]
+ use style_traits::{ParseError, StyleParseError};
+ #[allow(unused_imports)]
+ use values::computed::{Context, ToComputedValue};
+ #[allow(unused_imports)]
+ use values::{computed, specified};
+ #[allow(unused_imports)]
+ use values::{Auto, Either, None_, Normal};
+ ${caller.body()}
+ }
- /// The definition of the computed value for ${name}.
- pub mod computed_value {
- pub use super::single_value::computed_value as single_value;
- pub use self::single_value::T as SingleComputedValue;
+ /// The definition of the computed value for ${name}.
+ pub mod computed_value {
+ pub use super::single_value::computed_value as single_value;
+ pub use self::single_value::T as SingleComputedValue;
+ % if allow_empty and allow_empty != "NotInitial":
+ use std::vec::IntoIter;
+ % else:
+ use smallvec::{IntoIter, SmallVec};
+ % endif
+ use values::computed::ComputedVecIter;
+
+ /// The computed value, effectively a list of single values.
+ #[derive(Debug, Clone, PartialEq)]
+ #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
+ pub struct T(
% if allow_empty and allow_empty != "NotInitial":
- use std::vec::IntoIter;
+ pub Vec<single_value::T>,
% else:
- use smallvec::{IntoIter, SmallVec};
+ pub SmallVec<[single_value::T; 1]>,
% endif
- use values::computed::ComputedVecIter;
-
- /// The computed value, effectively a list of single values.
- #[derive(Debug, Clone, PartialEq)]
- #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
- pub struct T(
- % if allow_empty and allow_empty != "NotInitial":
- pub Vec<single_value::T>,
- % else:
- pub SmallVec<[single_value::T; 1]>,
- % endif
- );
-
- % if delegate_animate:
- use properties::animated_properties::Animatable;
- impl Animatable for T {
- fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64)
- -> Result<Self, ()> {
- self.0.add_weighted(&other.0, self_portion, other_portion).map(T)
- }
+ );
+
+ % if animation_value_type == "ComputedValue":
+ use properties::animated_properties::Animatable;
+ impl Animatable for T {
+ fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64)
+ -> Result<Self, ()> {
+ self.0.add_weighted(&other.0, self_portion, other_portion).map(T)
+ }
- fn add(&self, other: &Self) -> Result<Self, ()> {
- self.0.add(&other.0).map(T)
- }
+ fn add(&self, other: &Self) -> Result<Self, ()> {
+ self.0.add(&other.0).map(T)
+ }
- #[inline]
- fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
- self.0.compute_distance(&other.0)
- }
+ #[inline]
+ fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
+ self.0.compute_distance(&other.0)
+ }
- #[inline]
- fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> {
- self.0.compute_squared_distance(&other.0)
- }
+ #[inline]
+ fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> {
+ self.0.compute_squared_distance(&other.0)
}
- % endif
+ }
+ % endif
- pub type Iter<'a, 'cx, 'cx_a> = ComputedVecIter<'a, 'cx, 'cx_a, super::single_value::SpecifiedValue>;
+ pub type Iter<'a, 'cx, 'cx_a> = ComputedVecIter<'a, 'cx, 'cx_a, super::single_value::SpecifiedValue>;
- impl IntoIterator for T {
- type Item = single_value::T;
- % if allow_empty and allow_empty != "NotInitial":
- type IntoIter = IntoIter<single_value::T>;
- % else:
- type IntoIter = IntoIter<[single_value::T; 1]>;
- % endif
- fn into_iter(self) -> Self::IntoIter {
- self.0.into_iter()
- }
+ impl IntoIterator for T {
+ type Item = single_value::T;
+ % if allow_empty and allow_empty != "NotInitial":
+ type IntoIter = IntoIter<single_value::T>;
+ % else:
+ type IntoIter = IntoIter<[single_value::T; 1]>;
+ % endif
+ fn into_iter(self) -> Self::IntoIter {
+ self.0.into_iter()
}
}
+ }
- impl ToCss for computed_value::T {
- fn to_css<W>(&self, dest: &mut W) -> fmt::Result
- where W: fmt::Write,
- {
- let mut iter = self.0.iter();
- if let Some(val) = iter.next() {
- val.to_css(dest)?;
- } else {
- % if allow_empty:
- dest.write_str("none")?;
- % else:
- warn!("Found empty value for property ${name}");
- % endif
- }
- for i in iter {
- dest.write_str(::style_traits::${separator}::separator())?;
- i.to_css(dest)?;
- }
- Ok(())
+ impl ToCss for computed_value::T {
+ fn to_css<W>(&self, dest: &mut W) -> fmt::Result
+ where W: fmt::Write,
+ {
+ let mut iter = self.0.iter();
+ if let Some(val) = iter.next() {
+ val.to_css(dest)?;
+ } else {
+ % if allow_empty:
+ dest.write_str("none")?;
+ % else:
+ warn!("Found empty value for property ${name}");
+ % endif
+ }
+ for i in iter {
+ dest.write_str(::style_traits::${separator}::separator())?;
+ i.to_css(dest)?;
}
+ Ok(())
}
+ }
- /// The specified value of ${name}.
- #[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
- #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
- pub struct SpecifiedValue(pub Vec<single_value::SpecifiedValue>);
+ /// The specified value of ${name}.
+ #[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
+ #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
+ pub struct SpecifiedValue(pub Vec<single_value::SpecifiedValue>);
- impl ToCss for SpecifiedValue {
- fn to_css<W>(&self, dest: &mut W) -> fmt::Result
- where W: fmt::Write,
- {
- let mut iter = self.0.iter();
- if let Some(val) = iter.next() {
- val.to_css(dest)?;
- } else {
- % if allow_empty:
- dest.write_str("none")?;
- % else:
- warn!("Found empty value for property ${name}");
- % endif
- }
- for i in iter {
- dest.write_str(::style_traits::${separator}::separator())?;
- i.to_css(dest)?;
- }
- Ok(())
+ impl ToCss for SpecifiedValue {
+ fn to_css<W>(&self, dest: &mut W) -> fmt::Result
+ where W: fmt::Write,
+ {
+ let mut iter = self.0.iter();
+ if let Some(val) = iter.next() {
+ val.to_css(dest)?;
+ } else {
+ % if allow_empty:
+ dest.write_str("none")?;
+ % else:
+ warn!("Found empty value for property ${name}");
+ % endif
}
+ for i in iter {
+ dest.write_str(::style_traits::${separator}::separator())?;
+ i.to_css(dest)?;
+ }
+ Ok(())
}
+ }
- pub fn get_initial_value() -> computed_value::T {
- % if allow_empty and allow_empty != "NotInitial":
- computed_value::T(vec![])
- % else:
- let mut v = SmallVec::new();
- v.push(single_value::get_initial_value());
- computed_value::T(v)
- % endif
- }
+ pub fn get_initial_value() -> computed_value::T {
+ % if allow_empty and allow_empty != "NotInitial":
+ computed_value::T(vec![])
+ % else:
+ let mut v = SmallVec::new();
+ v.push(single_value::get_initial_value());
+ computed_value::T(v)
+ % endif
+ }
- pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
- -> Result<SpecifiedValue, ParseError<'i>> {
- use style_traits::Separator;
+ pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
+ -> Result<SpecifiedValue, ParseError<'i>> {
+ use style_traits::Separator;
- % if allow_empty:
- if input.try(|input| input.expect_ident_matching("none")).is_ok() {
- return Ok(SpecifiedValue(Vec::new()))
- }
- % endif
+ % if allow_empty:
+ if input.try(|input| input.expect_ident_matching("none")).is_ok() {
+ return Ok(SpecifiedValue(Vec::new()))
+ }
+ % endif
- ::style_traits::${separator}::parse(input, |parser| {
- single_value::parse(context, parser)
- }).map(SpecifiedValue)
- }
+ ::style_traits::${separator}::parse(input, |parser| {
+ single_value::parse(context, parser)
+ }).map(SpecifiedValue)
+ }
- pub use self::single_value::SpecifiedValue as SingleSpecifiedValue;
+ pub use self::single_value::SpecifiedValue as SingleSpecifiedValue;
- impl SpecifiedValue {
- pub fn compute_iter<'a, 'cx, 'cx_a>(&'a self, context: &'cx Context<'cx_a>)
- -> computed_value::Iter<'a, 'cx, 'cx_a> {
- computed_value::Iter::new(context, &self.0)
- }
+ impl SpecifiedValue {
+ pub fn compute_iter<'a, 'cx, 'cx_a>(&'a self, context: &'cx Context<'cx_a>)
+ -> computed_value::Iter<'a, 'cx, 'cx_a> {
+ computed_value::Iter::new(context, &self.0)
}
+ }
- impl ToComputedValue for SpecifiedValue {
- type ComputedValue = computed_value::T;
+ impl ToComputedValue for SpecifiedValue {
+ type ComputedValue = computed_value::T;
- #[inline]
- fn to_computed_value(&self, context: &Context) -> computed_value::T {
- computed_value::T(self.compute_iter(context).collect())
- }
- #[inline]
- fn from_computed_value(computed: &computed_value::T) -> Self {
- SpecifiedValue(computed.0.iter()
- .map(ToComputedValue::from_computed_value)
- .collect())
- }
+ #[inline]
+ fn to_computed_value(&self, context: &Context) -> computed_value::T {
+ computed_value::T(self.compute_iter(context).collect())
}
- % else:
- ${caller.body()}
- % endif
+ #[inline]
+ fn from_computed_value(computed: &computed_value::T) -> Self {
+ SpecifiedValue(computed.0.iter()
+ .map(ToComputedValue::from_computed_value)
+ .collect())
+ }
+ }
</%call>
</%def>
<%def name="longhand(*args, **kwargs)">
diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs
index 03a51eb0a39..3f5d91ba467 100644
--- a/components/style/properties/helpers/animated_properties.mako.rs
+++ b/components/style/properties/helpers/animated_properties.mako.rs
@@ -16,7 +16,6 @@ use euclid::{Point2D, Size2D};
#[cfg(feature = "gecko")] use gecko_string_cache::Atom;
use properties::{CSSWideKeyword, PropertyDeclaration};
use properties::longhands;
-use properties::longhands::background_size::computed_value::T as BackgroundSizeList;
use properties::longhands::font_weight::computed_value::T as FontWeight;
use properties::longhands::font_stretch::computed_value::T as FontStretch;
use properties::longhands::transform::computed_value::ComputedMatrix;
@@ -1083,23 +1082,6 @@ impl Animatable for VerticalAlign {
}
}
-impl Animatable for BackgroundSizeList {
- #[inline]
- fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
- self.0.add_weighted(&other.0, self_portion, other_portion).map(BackgroundSizeList)
- }
-
- #[inline]
- fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
- self.0.compute_distance(&other.0)
- }
-
- #[inline]
- fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> {
- self.0.compute_squared_distance(&other.0)
- }
-}
-
/// https://drafts.csswg.org/css-transitions/#animtype-lpcalc
impl Animatable for CalcLengthOrPercentage {
#[inline]
diff --git a/components/style/properties/longhand/background.mako.rs b/components/style/properties/longhand/background.mako.rs
index 96d05bed6c4..9e4a7c82856 100644
--- a/components/style/properties/longhand/background.mako.rs
+++ b/components/style/properties/longhand/background.mako.rs
@@ -24,11 +24,15 @@ ${helpers.predefined_type("background-image", "ImageLayer",
ignored_when_colors_disabled="True")}
% for (axis, direction, initial) in [("x", "Horizontal", "left"), ("y", "Vertical", "top")]:
- ${helpers.predefined_type("background-position-" + axis, "position::" + direction + "Position",
- initial_value="computed::LengthOrPercentage::zero()",
- initial_specified_value="SpecifiedValue::initial_specified_value()",
- spec="https://drafts.csswg.org/css-backgrounds-4/#propdef-background-position-" + axis,
- animation_value_type="ComputedValue", vector=True, delegate_animate=True)}
+ ${helpers.predefined_type(
+ "background-position-" + axis,
+ "position::" + direction + "Position",
+ initial_value="computed::LengthOrPercentage::zero()",
+ initial_specified_value="SpecifiedValue::initial_specified_value()",
+ spec="https://drafts.csswg.org/css-backgrounds-4/#propdef-background-position-" + axis,
+ animation_value_type="ComputedValue",
+ vector=True,
+ )}
% endfor
<%helpers:vector_longhand name="background-repeat" animation_value_type="discrete"
diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs
index b970745461d..591c6f43f21 100644
--- a/components/style/properties/longhand/box.mako.rs
+++ b/components/style/properties/longhand/box.mako.rs
@@ -679,8 +679,7 @@ ${helpers.predefined_type(
products="gecko",
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-snap-destination)",
animation_value_type="ComputedValue",
- allow_empty="NotInitial",
- delegate_animate=True,
+ allow_empty="NotInitial"
)}
<%helpers:longhand name="transform" extra_prefixes="webkit"
diff --git a/components/style/properties/longhand/inherited_svg.mako.rs b/components/style/properties/longhand/inherited_svg.mako.rs
index 13ce7492b3c..0ead8db90ef 100644
--- a/components/style/properties/longhand/inherited_svg.mako.rs
+++ b/components/style/properties/longhand/inherited_svg.mako.rs
@@ -94,7 +94,6 @@ ${helpers.predefined_type(
None,
"parse_non_negative",
vector=True,
- delegate_animate=True,
products="gecko",
animation_value_type="ComputedValue",
separator="CommaWithSpace",
diff --git a/components/style/properties/longhand/svg.mako.rs b/components/style/properties/longhand/svg.mako.rs
index 887cf057bb2..eaeba146ec5 100644
--- a/components/style/properties/longhand/svg.mako.rs
+++ b/components/style/properties/longhand/svg.mako.rs
@@ -89,12 +89,17 @@ ${helpers.single_keyword("mask-mode",
</%helpers:vector_longhand>
% for (axis, direction) in [("x", "Horizontal"), ("y", "Vertical")]:
- ${helpers.predefined_type("mask-position-" + axis, "position::" + direction + "Position",
- products="gecko", extra_prefixes="webkit",
- initial_value="computed::LengthOrPercentage::zero()",
- initial_specified_value="specified::PositionComponent::Center",
- spec="https://drafts.fxtf.org/css-masking/#propdef-mask-position",
- animation_value_type="ComputedValue", vector=True, delegate_animate=True)}
+ ${helpers.predefined_type(
+ "mask-position-" + axis,
+ "position::" + direction + "Position",
+ products="gecko",
+ extra_prefixes="webkit",
+ initial_value="computed::LengthOrPercentage::zero()",
+ initial_specified_value="specified::PositionComponent::Center",
+ spec="https://drafts.fxtf.org/css-masking/#propdef-mask-position",
+ animation_value_type="ComputedValue",
+ vector=True,
+ )}
% endfor
${helpers.single_keyword("mask-clip",