servo: Merge #13917 - Remove usage of 'keyword_list' (from Wafflespeanut:keywords); r=Manishearth

<!-- Please describe your changes on the following line: -->

We're using `keyword_list` to generate code for some of the animation properties. This could be achieved with `single_keyword` (passing `vector=True`).

---

<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach build-geckolib` does not report any errors

<!-- Either: -->
- [x] These changes do not require tests because it's a cleanup

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

r? @emilio

Source-Repo: https://github.com/servo/servo
Source-Revision: b3ad71353bf264770bf0b3a87b32d86928eb09d4
This commit is contained in:
Ravi Shankar 2016-11-17 14:34:33 -06:00
Родитель 484461d581
Коммит ec6d8e4f51
4 изменённых файлов: 149 добавлений и 208 удалений

Просмотреть файл

@ -12,9 +12,9 @@ use euclid::point::Point2D;
use keyframes::{KeyframesStep, KeyframesStepValue};
use properties::{self, CascadeFlags, ComputedValues, Importance};
use properties::animated_properties::{AnimatedProperty, TransitionProperty};
use properties::longhands::animation_direction::computed_value::AnimationDirection;
use properties::longhands::animation_direction::computed_value::single_value::T as AnimationDirection;
use properties::longhands::animation_iteration_count::computed_value::AnimationIterationCount;
use properties::longhands::animation_play_state::computed_value::AnimationPlayState;
use properties::longhands::animation_play_state::computed_value::single_value::T as AnimationPlayState;
use properties::longhands::transition_timing_function::computed_value::StartEnd;
use properties::longhands::transition_timing_function::computed_value::TransitionTimingFunction;
use std::sync::Arc;
@ -425,7 +425,7 @@ pub fn maybe_start_animations(context: &SharedStyleContext,
continue
}
if let Some(ref anim) = context.stylist.animations().get(&name) {
if let Some(ref anim) = context.stylist.animations().get(&name.0) {
debug!("maybe_start_animations: animation {} found", name);
// If this animation doesn't have any keyframe, we can just continue
@ -461,7 +461,7 @@ pub fn maybe_start_animations(context: &SharedStyleContext,
new_animations_sender
.send(Animation::Keyframes(node, name.clone(), KeyframesAnimationState {
.send(Animation::Keyframes(node, name.0.clone(), KeyframesAnimationState {
started_at: animation_start,
duration: duration as f64,
delay: delay as f64,
@ -540,7 +540,7 @@ pub fn update_style_for_animation(context: &SharedStyleContext,
let maybe_index = style.get_box()
.animation_name_iter()
.position(|animation_name| *name == animation_name);
.position(|animation_name| *name == animation_name.0);
let index = match maybe_index {
Some(index) => index,

Просмотреть файл

@ -53,7 +53,7 @@
</%doc>
<%def name="vector_longhand(name, gecko_only=False, allow_empty=False, **kwargs)">
<%call expr="longhand(name, **kwargs)">
% if product == "gecko" or not gecko_only:
% if not gecko_only:
use std::fmt;
use values::HasViewportPercentage;
use style_traits::ToCss;
@ -75,6 +75,7 @@
}
pub mod computed_value {
pub use super::single_value::computed_value as single_value;
pub use self::single_value::T as SingleComputedValue;
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct T(pub Vec<single_value::T>);
@ -123,6 +124,7 @@
Ok(())
}
}
pub fn get_initial_value() -> computed_value::T {
% if allow_empty:
computed_value::T(vec![])
@ -130,6 +132,7 @@
computed_value::T(vec![single_value::get_initial_value()])
% endif
}
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
% if allow_empty:
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
@ -145,6 +148,9 @@
}).map(SpecifiedValue)
% endif
}
pub use self::single_value::computed_value::T as SingleSpecifiedValue;
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
@ -364,79 +370,6 @@
% endif
</%def>
<%def name="keyword_list(name, values, **kwargs)">
<%
keyword_kwargs = {a: kwargs.pop(a, None) for a in [
'gecko_constant_prefix', 'gecko_enum_prefix',
'extra_gecko_values', 'extra_servo_values',
]}
%>
<%call expr="longhand(name, keyword=Keyword(name, values, **keyword_kwargs), **kwargs)">
use values::computed::ComputedValueAsSpecified;
pub use self::computed_value::T as SpecifiedValue;
use values::NoViewportPercentage;
impl NoViewportPercentage for SpecifiedValue {}
pub mod computed_value {
use std::fmt;
use style_traits::ToCss;
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct T(pub Vec<${to_camel_case(name)}>);
impl ToCss for T {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
debug_assert!(!self.0.is_empty(), "Always parses at least one");
for (index, item) in self.0.iter().enumerate() {
if index != 0 {
try!(dest.write_str(", "));
}
try!(item.to_css(dest));
}
Ok(())
}
}
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)},
% endfor
}
}
pub use self::computed_value::${to_camel_case(name)} as SingleSpecifiedValue;
#[inline]
pub fn parse_one(input: &mut Parser) -> Result<SingleSpecifiedValue, ()> {
SingleSpecifiedValue::parse(input)
}
#[inline]
pub fn get_initial_value() -> computed_value::T {
computed_value::T(vec![get_initial_single_value()])
}
#[inline]
pub fn get_initial_single_value() -> SingleSpecifiedValue {
SingleSpecifiedValue::${to_rust_ident(values.split()[0])}
}
#[inline]
pub fn parse(_context: &ParserContext, input: &mut Parser)
-> Result<SpecifiedValue, ()> {
Ok(SpecifiedValue(try!(
input.parse_comma_separated(computed_value::${to_camel_case(name)}::parse))))
}
impl ComputedValueAsSpecified for SpecifiedValue {}
</%call>
</%def>
<%def name="shorthand(name, sub_properties, experimental=False, **kwargs)">
<%
shorthand = data.declare_shorthand(name, sub_properties.split(), experimental=experimental,

Просмотреть файл

@ -350,8 +350,8 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
impl ComputedValueAsSpecified for SpecifiedValue {}
#[inline]
pub fn parse_one(input: &mut Parser) -> Result<SingleSpecifiedValue,()> {
Time::parse(input)
pub fn get_initial_single_value() -> Time {
Time(0.0)
}
#[inline]
@ -359,13 +359,8 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
computed_value::T(vec![get_initial_single_value()])
}
#[inline]
pub fn get_initial_single_value() -> Time {
Time(0.0)
}
pub fn parse(_: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
Ok(SpecifiedValue(try!(input.parse_comma_separated(parse_one))))
Ok(SpecifiedValue(try!(input.parse_comma_separated(Time::parse))))
}
</%helpers:longhand>
@ -421,8 +416,10 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
pub mod computed_value {
use euclid::point::Point2D;
use parser::Parse;
use std::fmt;
use style_traits::ToCss;
use values::specified;
use values::computed::ComputedValueAsSpecified;
pub use self::TransitionTimingFunction as SingleComputedValue;
@ -434,6 +431,58 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
Steps(u32, StartEnd),
}
impl Parse for TransitionTimingFunction {
fn parse(input: &mut ::cssparser::Parser) -> Result<Self, ()> {
if let Ok(function_name) = input.try(|input| input.expect_function()) {
return match_ignore_ascii_case! { function_name,
"cubic-bezier" => {
let (mut p1x, mut p1y, mut p2x, mut p2y) = (0.0, 0.0, 0.0, 0.0);
try!(input.parse_nested_block(|input| {
p1x = try!(specified::parse_number(input));
try!(input.expect_comma());
p1y = try!(specified::parse_number(input));
try!(input.expect_comma());
p2x = try!(specified::parse_number(input));
try!(input.expect_comma());
p2y = try!(specified::parse_number(input));
Ok(())
}));
let (p1, p2) = (Point2D::new(p1x, p1y), Point2D::new(p2x, p2y));
Ok(TransitionTimingFunction::CubicBezier(p1, p2))
},
"steps" => {
let (mut step_count, mut start_end) = (0, StartEnd::End);
try!(input.parse_nested_block(|input| {
step_count = try!(specified::parse_integer(input));
if input.try(|input| input.expect_comma()).is_ok() {
start_end = try!(match_ignore_ascii_case! {
try!(input.expect_ident()),
"start" => Ok(StartEnd::Start),
"end" => Ok(StartEnd::End),
_ => Err(())
});
}
Ok(())
}));
Ok(TransitionTimingFunction::Steps(step_count as u32, start_end))
},
_ => Err(())
}
}
match_ignore_ascii_case! {
try!(input.expect_ident()),
"ease" => Ok(super::ease()),
"linear" => Ok(super::linear()),
"ease-in" => Ok(super::ease_in()),
"ease-out" => Ok(super::ease_out()),
"ease-in-out" => Ok(super::ease_in_out()),
"step-start" => Ok(super::STEP_START),
"step-end" => Ok(super::STEP_END),
_ => Err(())
}
}
}
impl ToCss for TransitionTimingFunction {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
@ -500,68 +549,18 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
impl ComputedValueAsSpecified for SpecifiedValue {}
#[inline]
pub fn get_initial_value() -> computed_value::T {
computed_value::T(vec![get_initial_single_value()])
}
#[inline]
pub fn get_initial_single_value() -> TransitionTimingFunction {
ease()
}
pub fn parse_one(input: &mut Parser) -> Result<SingleSpecifiedValue,()> {
if let Ok(function_name) = input.try(|input| input.expect_function()) {
return match_ignore_ascii_case! { function_name,
"cubic-bezier" => {
let (mut p1x, mut p1y, mut p2x, mut p2y) = (0.0, 0.0, 0.0, 0.0);
try!(input.parse_nested_block(|input| {
p1x = try!(specified::parse_number(input));
try!(input.expect_comma());
p1y = try!(specified::parse_number(input));
try!(input.expect_comma());
p2x = try!(specified::parse_number(input));
try!(input.expect_comma());
p2y = try!(specified::parse_number(input));
Ok(())
}));
let (p1, p2) = (Point2D::new(p1x, p1y), Point2D::new(p2x, p2y));
Ok(TransitionTimingFunction::CubicBezier(p1, p2))
},
"steps" => {
let (mut step_count, mut start_end) = (0, computed_value::StartEnd::End);
try!(input.parse_nested_block(|input| {
step_count = try!(specified::parse_integer(input));
if input.try(|input| input.expect_comma()).is_ok() {
start_end = try!(match_ignore_ascii_case! {
try!(input.expect_ident()),
"start" => Ok(computed_value::StartEnd::Start),
"end" => Ok(computed_value::StartEnd::End),
_ => Err(())
});
}
Ok(())
}));
Ok(TransitionTimingFunction::Steps(step_count as u32, start_end))
},
_ => Err(())
}
}
match_ignore_ascii_case! {
try!(input.expect_ident()),
"ease" => Ok(ease()),
"linear" => Ok(linear()),
"ease-in" => Ok(ease_in()),
"ease-out" => Ok(ease_out()),
"ease-in-out" => Ok(ease_in_out()),
"step-start" => Ok(STEP_START),
"step-end" => Ok(STEP_END),
_ => Err(())
}
#[inline]
pub fn get_initial_value() -> computed_value::T {
computed_value::T(vec![get_initial_single_value()])
}
pub fn parse(_: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
Ok(SpecifiedValue(try!(input.parse_comma_separated(parse_one))))
Ok(SpecifiedValue(try!(input.parse_comma_separated(TransitionTimingFunction::parse))))
}
</%helpers:longhand>
@ -607,12 +606,6 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
computed_value::T(Vec::new())
}
#[inline]
pub fn parse_one(input: &mut Parser) -> Result<SingleSpecifiedValue, ()> {
SingleSpecifiedValue::parse(input)
}
pub fn parse(_: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
Ok(SpecifiedValue(try!(input.parse_comma_separated(SingleSpecifiedValue::parse))))
}
@ -627,9 +620,8 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
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};
pub use properties::longhands::transition_duration::{get_initial_value, parse, parse_one};
pub use properties::longhands::transition_duration::computed_value;
pub use properties::longhands::transition_duration::{get_initial_value, get_initial_single_value, parse};
</%helpers:longhand>
<%helpers:longhand name="animation-name"
@ -640,15 +632,38 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
use values::NoViewportPercentage;
pub mod computed_value {
use std::fmt;
use Atom;
use parser::Parse;
use std::fmt;
use std::ops::Deref;
use style_traits::ToCss;
pub use Atom as SingleComputedValue;
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct AnimationName(pub Atom);
impl fmt::Display for AnimationName {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
}
}
pub use self::AnimationName as SingleComputedValue;
impl Parse for AnimationName {
fn parse(input: &mut ::cssparser::Parser) -> Result<Self, ()> {
use cssparser::Token;
Ok(match input.next() {
Ok(Token::Ident(ref value)) if value != "none" => AnimationName(Atom::from(&**value)),
Ok(Token::QuotedString(value)) => AnimationName(Atom::from(&*value)),
_ => return Err(()),
})
}
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct T(pub Vec<Atom>);
pub struct T(pub Vec<AnimationName>);
impl ToCss for T {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
@ -670,18 +685,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
pub use self::computed_value::T as SpecifiedValue;
impl NoViewportPercentage for SpecifiedValue {}
pub use Atom as SingleSpecifiedValue;
#[inline]
pub fn parse_one(input: &mut Parser) -> Result<SingleSpecifiedValue, ()> {
use cssparser::Token;
Ok(match input.next() {
Ok(Token::Ident(ref value)) if value != "none" => Atom::from(&**value),
Ok(Token::QuotedString(value)) => Atom::from(&*value),
_ => return Err(()),
})
}
pub use self::computed_value::SingleComputedValue as SingleSpecifiedValue;
#[inline]
pub fn get_initial_value() -> computed_value::T {
@ -690,7 +694,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
pub fn parse(_: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
use std::borrow::Cow;
Ok(SpecifiedValue(try!(input.parse_comma_separated(parse_one))))
Ok(SpecifiedValue(try!(input.parse_comma_separated(SingleSpecifiedValue::parse))))
}
impl ComputedValueAsSpecified for SpecifiedValue {}
@ -701,8 +705,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
animatable="False",
allowed_in_keyframe_block="False">
pub use super::transition_duration::computed_value;
pub use super::transition_duration::{get_initial_value, get_initial_single_value};
pub use super::transition_duration::{parse, parse_one};
pub use super::transition_duration::{get_initial_value, get_initial_single_value, parse};
pub use super::transition_duration::SpecifiedValue;
pub use super::transition_duration::SingleSpecifiedValue;
</%helpers:longhand>
@ -712,8 +715,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
animatable="False",
allowed_in_keyframe_block="False">
pub use super::transition_timing_function::computed_value;
pub use super::transition_timing_function::{get_initial_value, get_initial_single_value};
pub use super::transition_timing_function::{parse, parse_one};
pub use super::transition_timing_function::{get_initial_value, get_initial_single_value, parse};
pub use super::transition_timing_function::SpecifiedValue;
pub use super::transition_timing_function::SingleSpecifiedValue;
</%helpers:longhand>
@ -726,6 +728,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
use values::NoViewportPercentage;
pub mod computed_value {
use parser::Parse;
use std::fmt;
use style_traits::ToCss;
@ -738,6 +741,21 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
Infinite,
}
impl Parse for AnimationIterationCount {
fn parse(input: &mut ::cssparser::Parser) -> Result<Self, ()> {
if input.try(|input| input.expect_ident_matching("infinite")).is_ok() {
return Ok(AnimationIterationCount::Infinite)
}
let number = try!(input.expect_integer());
if number < 0 {
return Err(());
}
Ok(AnimationIterationCount::Number(number as u32))
}
}
impl ToCss for AnimationIterationCount {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
@ -777,22 +795,9 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
AnimationIterationCount::Number(1)
}
pub fn parse_one(input: &mut Parser) -> Result<AnimationIterationCount, ()> {
if input.try(|input| input.expect_ident_matching("infinite")).is_ok() {
Ok(AnimationIterationCount::Infinite)
} else {
let number = try!(input.expect_integer());
if number < 0 {
return Err(());
}
Ok(AnimationIterationCount::Number(number as u32))
}
}
#[inline]
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
Ok(SpecifiedValue(try!(input.parse_comma_separated(parse_one))))
Ok(SpecifiedValue(try!(input.parse_comma_separated(AnimationIterationCount::parse))))
}
#[inline]
@ -803,34 +808,36 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
impl ComputedValueAsSpecified for SpecifiedValue {}
</%helpers:longhand>
${helpers.keyword_list("animation-direction",
"normal reverse alternate alternate-reverse",
need_index=True,
animatable=False,
allowed_in_keyframe_block=False)}
${helpers.single_keyword("animation-direction",
"normal reverse alternate alternate-reverse",
need_index=True,
animatable=False,
vector=True,
allowed_in_keyframe_block=False)}
// animation-play-state is the exception to the rule for allowed_in_keyframe_block:
// https://drafts.csswg.org/css-animations/#keyframes
${helpers.keyword_list("animation-play-state",
"running paused",
need_clone=True,
need_index=True,
animatable=False,
allowed_in_keyframe_block=True)}
${helpers.single_keyword("animation-play-state",
"running paused",
need_clone=True,
need_index=True,
animatable=False,
vector=True,
allowed_in_keyframe_block=True)}
${helpers.keyword_list("animation-fill-mode",
"none forwards backwards both",
need_index=True,
animatable=False,
allowed_in_keyframe_block=False)}
${helpers.single_keyword("animation-fill-mode",
"none forwards backwards both",
need_index=True,
animatable=False,
vector=True,
allowed_in_keyframe_block=False)}
<%helpers:longhand name="animation-delay"
need_index="True"
animatable="False",
allowed_in_keyframe_block="False">
pub use super::transition_duration::computed_value;
pub use super::transition_duration::{get_initial_value, get_initial_single_value};
pub use super::transition_duration::{parse, parse_one};
pub use super::transition_duration::{get_initial_value, get_initial_single_value, parse};
pub use super::transition_duration::SpecifiedValue;
pub use super::transition_duration::SingleSpecifiedValue;
</%helpers:longhand>

Просмотреть файл

@ -53,7 +53,7 @@
macro_rules! try_parse_one {
($input: expr, $var: ident, $prop_module: ident) => {
if $var.is_none() {
if let Ok(value) = $input.try($prop_module::parse_one) {
if let Ok(value) = $input.try($prop_module::computed_value::SingleComputedValue::parse) {
$var = Some(value);
continue;
}
@ -65,6 +65,7 @@ macro_rules! try_parse_one {
sub_properties="transition-property transition-duration
transition-timing-function
transition-delay">
use parser::Parse;
use properties::longhands::{transition_delay, transition_duration, transition_property};
use properties::longhands::{transition_timing_function};
@ -94,8 +95,7 @@ macro_rules! try_parse_one {
transition_duration:
duration.unwrap_or_else(transition_duration::get_initial_single_value),
transition_timing_function:
timing_function.unwrap_or_else(
transition_timing_function::get_initial_single_value),
timing_function.unwrap_or_else(transition_timing_function::get_initial_single_value),
transition_delay:
delay.unwrap_or_else(transition_delay::get_initial_single_value),
})
@ -154,6 +154,7 @@ macro_rules! try_parse_one {
animation-iteration-count animation-direction
animation-fill-mode animation-play-state"
allowed_in_keyframe_block="False">
use parser::Parse;
use properties::longhands::{animation_name, animation_duration, animation_timing_function};
use properties::longhands::{animation_delay, animation_iteration_count, animation_direction};
use properties::longhands::{animation_fill_mode, animation_play_state};
@ -210,11 +211,11 @@ macro_rules! try_parse_one {
animation_iteration_count:
iteration_count.unwrap_or_else(animation_iteration_count::get_initial_single_value),
animation_direction:
direction.unwrap_or_else(animation_direction::get_initial_single_value),
direction.unwrap_or_else(animation_direction::single_value::get_initial_value),
animation_fill_mode:
fill_mode.unwrap_or_else(animation_fill_mode::get_initial_single_value),
fill_mode.unwrap_or_else(animation_fill_mode::single_value::get_initial_value),
animation_play_state:
play_state.unwrap_or_else(animation_play_state::get_initial_single_value),
play_state.unwrap_or_else(animation_play_state::single_value::get_initial_value),
})
} else {
Err(())