style: Add a generic way to deal with lists of values, ditch all uses of as_servo in style/animations.rs

This commit is contained in:
Emilio Cobos Álvarez 2016-06-30 16:50:09 -07:00
parent 07da4e4ea2
commit ba53c4ea8d
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
6 changed files with 120 additions and 53 deletions

View file

@ -47,7 +47,7 @@ class Keyword(object):
class Longhand(object):
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):
need_clone=False, need_index=False, gecko_ffi_name=None):
self.name = name
self.keyword = keyword
self.predefined_type = predefined_type
@ -58,6 +58,7 @@ class Longhand(object):
self.custom_cascade = custom_cascade
self.internal = internal
self.need_clone = need_clone
self.need_index = need_index
self.gecko_ffi_name = gecko_ffi_name or "m" + self.camel_case
self.derived_from = (derived_from or "").split()

View file

@ -225,6 +225,8 @@
}
}
pub use self::${to_camel_case(name)} as SingleComputedValue;
define_css_keyword_enum! { ${to_camel_case(name)}:
% for value in data.longhands_by_name[name].keyword.values_for(product):
"${value}" => ${to_rust_ident(value)},

View file

@ -7,8 +7,7 @@
<% data.new_style_struct("Box",
inherited=False,
gecko_name="Display",
additional_methods=[Method("transition_count", "usize")]) %>
gecko_name="Display") %>
// TODO(SimonSapin): don't parse `inline-table`, since we don't support it
<%helpers:longhand name="display"
@ -285,7 +284,9 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
</%helpers:longhand>
// TODO(pcwalton): Multiple transitions.
<%helpers:longhand name="transition-duration" animatable="False">
<%helpers:longhand name="transition-duration"
need_index="True"
animatable="False">
use values::computed::ComputedValueAsSpecified;
use values::specified::Time;
@ -343,7 +344,9 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
// TODO(pcwalton): Lots more timing functions.
// TODO(pcwalton): Multiple transitions.
<%helpers:longhand name="transition-timing-function" animatable="False">
<%helpers:longhand name="transition-timing-function"
need_index="True"
animatable="False">
use self::computed_value::{StartEnd, TransitionTimingFunction};
use euclid::point::Point2D;
@ -541,7 +544,9 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
}
</%helpers:longhand>
<%helpers:longhand name="transition-property" animatable="False">
<%helpers:longhand name="transition-property"
need_index="True"
animatable="False">
pub use self::computed_value::SingleComputedValue as SingleSpecifiedValue;
pub use self::computed_value::T as SpecifiedValue;
@ -592,7 +597,9 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
}
</%helpers:longhand>
<%helpers:longhand name="transition-delay" animatable="False">
<%helpers:longhand name="transition-delay"
need_index="True"
animatable="False">
pub use properties::longhands::transition_duration::{SingleSpecifiedValue, SpecifiedValue};
pub use properties::longhands::transition_duration::{computed_value};
pub use properties::longhands::transition_duration::{get_initial_single_value};
@ -600,6 +607,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
</%helpers:longhand>
<%helpers:longhand name="animation-name"
need_index="True"
animatable="False">
use values::computed::ComputedValueAsSpecified;
@ -608,6 +616,8 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
use std::fmt;
use string_cache::Atom;
pub use string_cache::Atom as SingleComputedValue;
#[derive(Debug, Clone, PartialEq, HeapSizeOf)]
pub struct T(pub Vec<Atom>);
@ -647,6 +657,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
</%helpers:longhand>
<%helpers:longhand name="animation-duration"
need_index="True"
animatable="False">
pub use super::transition_duration::computed_value;
pub use super::transition_duration::{parse, get_initial_value};
@ -654,19 +665,24 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
</%helpers:longhand>
<%helpers:longhand name="animation-timing-function"
need_index="True"
animatable="False">
pub use super::transition_timing_function::computed_value;
pub use super::transition_timing_function::{parse, get_initial_value};
pub use super::transition_timing_function::SpecifiedValue;
</%helpers:longhand>
<%helpers:longhand name="animation-iteration-count" animatable="False">
<%helpers:longhand name="animation-iteration-count"
need_index="True"
animatable="False">
use values::computed::ComputedValueAsSpecified;
pub mod computed_value {
use cssparser::ToCss;
use std::fmt;
pub use self::AnimationIterationCount as SingleComputedValue;
#[derive(Debug, Clone, PartialEq, HeapSizeOf)]
pub enum AnimationIterationCount {
Number(u32),
@ -731,18 +747,22 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
${helpers.keyword_list("animation-direction",
"normal reverse alternate alternate-reverse",
need_index=True,
animatable=False)}
${helpers.keyword_list("animation-play-state",
"running paused",
need_clone=True,
need_index=True,
animatable=False)}
${helpers.keyword_list("animation-fill-mode",
"none forwards backwards both",
need_index=True,
animatable=False)}
<%helpers:longhand name="animation-delay"
need_index="True"
animatable="False">
pub use super::transition_duration::computed_value;
pub use super::transition_duration::{parse, get_initial_value};

View file

@ -1082,12 +1082,61 @@ pub mod style_struct_traits {
#[allow(non_snake_case)]
fn clone_${longhand.ident}(&self) -> longhands::${longhand.ident}::computed_value::T;
% endif
% if longhand.need_index:
#[allow(non_snake_case)]
fn ${longhand.ident}_count(&self) -> usize;
#[allow(non_snake_case)]
fn ${longhand.ident}_at(&self, index: usize)
-> longhands::${longhand.ident}::computed_value::SingleComputedValue;
#[allow(non_snake_case)]
#[inline]
fn ${longhand.ident}_iter<'a>(&'a self)
-> ${longhand.camel_case}Iter<'a, Self> {
${longhand.camel_case}Iter {
style_struct: self,
current: 0,
max: self.${longhand.ident}_count(),
}
}
#[allow(non_snake_case)]
#[inline]
fn ${longhand.ident}_mod(&self, index: usize)
-> longhands::${longhand.ident}::computed_value::SingleComputedValue {
self.${longhand.ident}_at(index % self.${longhand.ident}_count())
}
% endif
% endfor
% for additional in style_struct.additional_methods:
#[allow(non_snake_case)]
${additional.declare()}
% endfor
}
% for longhand in style_struct.longhands:
% if longhand.need_index:
pub struct ${longhand.camel_case}Iter<'a, S: ${style_struct.trait_name} + 'static> {
style_struct: &'a S,
current: usize,
max: usize,
}
impl<'a, S: ${style_struct.trait_name} + 'static> Iterator for ${longhand.camel_case}Iter<'a, S> {
type Item = longhands::${longhand.ident}::computed_value::SingleComputedValue;
fn next(&mut self) -> Option<Self::Item> {
self.current += 1;
if self.current <= self.max {
Some(self.style_struct.${longhand.ident}_at(self.current - 1))
} else {
None
}
}
}
% endif
% endfor
% endfor
}
@ -1140,6 +1189,17 @@ pub mod style_structs {
self.${longhand.ident}.clone()
}
% endif
% if longhand.need_index:
fn ${longhand.ident}_count(&self) -> usize {
self.${longhand.ident}.0.len()
}
fn ${longhand.ident}_at(&self, index: usize)
-> longhands::${longhand.ident}::computed_value::SingleComputedValue {
self.${longhand.ident}.0[index].clone()
}
% endif
% endfor
% if style_struct.trait_name == "Border":
% for side in ["top", "right", "bottom", "left"]:
@ -1147,11 +1207,6 @@ pub mod style_structs {
self.border_${side}_width != ::app_units::Au(0)
}
% endfor
% elif style_struct.trait_name == "Box":
#[inline]
fn transition_count(&self) -> usize {
self.transition_property.0.len()
}
% elif style_struct.trait_name == "Font":
fn compute_font_hash(&mut self) {
// Corresponds to the fields in `gfx::font_template::FontTemplateDescriptor`.