mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
style: Refactor all the animated properties to use the style system properly
This commit is contained in:
parent
818bc6d4a2
commit
6a362ae8e8
11 changed files with 929 additions and 1124 deletions
|
@ -525,170 +525,17 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", need_clone=
|
|||
}
|
||||
</%helpers:longhand>
|
||||
|
||||
// TODO(pcwalton): Lots more properties.
|
||||
<%helpers:longhand name="transition-property">
|
||||
use self::computed_value::TransitionProperty;
|
||||
|
||||
pub use self::computed_value::SingleComputedValue as SingleSpecifiedValue;
|
||||
pub use self::computed_value::T as SpecifiedValue;
|
||||
|
||||
pub mod computed_value {
|
||||
use cssparser::ToCss;
|
||||
use std::fmt;
|
||||
|
||||
pub use self::TransitionProperty as SingleComputedValue;
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum TransitionProperty {
|
||||
All,
|
||||
BackgroundColor,
|
||||
BackgroundPosition,
|
||||
BorderBottomColor,
|
||||
BorderBottomWidth,
|
||||
BorderLeftColor,
|
||||
BorderLeftWidth,
|
||||
BorderRightColor,
|
||||
BorderRightWidth,
|
||||
BorderSpacing,
|
||||
BorderTopColor,
|
||||
BorderTopWidth,
|
||||
Bottom,
|
||||
Color,
|
||||
Clip,
|
||||
FontSize,
|
||||
FontWeight,
|
||||
Height,
|
||||
Left,
|
||||
LetterSpacing,
|
||||
LineHeight,
|
||||
MarginBottom,
|
||||
MarginLeft,
|
||||
MarginRight,
|
||||
MarginTop,
|
||||
MaxHeight,
|
||||
MaxWidth,
|
||||
MinHeight,
|
||||
MinWidth,
|
||||
Opacity,
|
||||
OutlineColor,
|
||||
OutlineWidth,
|
||||
PaddingBottom,
|
||||
PaddingLeft,
|
||||
PaddingRight,
|
||||
PaddingTop,
|
||||
Right,
|
||||
TextIndent,
|
||||
TextShadow,
|
||||
Top,
|
||||
Transform,
|
||||
VerticalAlign,
|
||||
Visibility,
|
||||
Width,
|
||||
WordSpacing,
|
||||
ZIndex,
|
||||
}
|
||||
|
||||
pub static ALL_TRANSITION_PROPERTIES: [TransitionProperty; 45] = [
|
||||
TransitionProperty::BackgroundColor,
|
||||
TransitionProperty::BackgroundPosition,
|
||||
TransitionProperty::BorderBottomColor,
|
||||
TransitionProperty::BorderBottomWidth,
|
||||
TransitionProperty::BorderLeftColor,
|
||||
TransitionProperty::BorderLeftWidth,
|
||||
TransitionProperty::BorderRightColor,
|
||||
TransitionProperty::BorderRightWidth,
|
||||
TransitionProperty::BorderSpacing,
|
||||
TransitionProperty::BorderTopColor,
|
||||
TransitionProperty::BorderTopWidth,
|
||||
TransitionProperty::Bottom,
|
||||
TransitionProperty::Color,
|
||||
TransitionProperty::Clip,
|
||||
TransitionProperty::FontSize,
|
||||
TransitionProperty::FontWeight,
|
||||
TransitionProperty::Height,
|
||||
TransitionProperty::Left,
|
||||
TransitionProperty::LetterSpacing,
|
||||
TransitionProperty::LineHeight,
|
||||
TransitionProperty::MarginBottom,
|
||||
TransitionProperty::MarginLeft,
|
||||
TransitionProperty::MarginRight,
|
||||
TransitionProperty::MarginTop,
|
||||
TransitionProperty::MaxHeight,
|
||||
TransitionProperty::MaxWidth,
|
||||
TransitionProperty::MinHeight,
|
||||
TransitionProperty::MinWidth,
|
||||
TransitionProperty::Opacity,
|
||||
TransitionProperty::OutlineColor,
|
||||
TransitionProperty::OutlineWidth,
|
||||
TransitionProperty::PaddingBottom,
|
||||
TransitionProperty::PaddingLeft,
|
||||
TransitionProperty::PaddingRight,
|
||||
TransitionProperty::PaddingTop,
|
||||
TransitionProperty::Right,
|
||||
TransitionProperty::TextIndent,
|
||||
TransitionProperty::TextShadow,
|
||||
TransitionProperty::Top,
|
||||
TransitionProperty::Transform,
|
||||
TransitionProperty::VerticalAlign,
|
||||
TransitionProperty::Visibility,
|
||||
TransitionProperty::Width,
|
||||
TransitionProperty::WordSpacing,
|
||||
TransitionProperty::ZIndex,
|
||||
];
|
||||
|
||||
impl ToCss for TransitionProperty {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
TransitionProperty::All => dest.write_str("all"),
|
||||
TransitionProperty::BackgroundColor => dest.write_str("background-color"),
|
||||
TransitionProperty::BackgroundPosition => dest.write_str("background-position"),
|
||||
TransitionProperty::BorderBottomColor => dest.write_str("border-bottom-color"),
|
||||
TransitionProperty::BorderBottomWidth => dest.write_str("border-bottom-width"),
|
||||
TransitionProperty::BorderLeftColor => dest.write_str("border-left-color"),
|
||||
TransitionProperty::BorderLeftWidth => dest.write_str("border-left-width"),
|
||||
TransitionProperty::BorderRightColor => dest.write_str("border-right-color"),
|
||||
TransitionProperty::BorderRightWidth => dest.write_str("border-right-width"),
|
||||
TransitionProperty::BorderSpacing => dest.write_str("border-spacing"),
|
||||
TransitionProperty::BorderTopColor => dest.write_str("border-top-color"),
|
||||
TransitionProperty::BorderTopWidth => dest.write_str("border-top-width"),
|
||||
TransitionProperty::Bottom => dest.write_str("bottom"),
|
||||
TransitionProperty::Color => dest.write_str("color"),
|
||||
TransitionProperty::Clip => dest.write_str("clip"),
|
||||
TransitionProperty::FontSize => dest.write_str("font-size"),
|
||||
TransitionProperty::FontWeight => dest.write_str("font-weight"),
|
||||
TransitionProperty::Height => dest.write_str("height"),
|
||||
TransitionProperty::Left => dest.write_str("left"),
|
||||
TransitionProperty::LetterSpacing => dest.write_str("letter-spacing"),
|
||||
TransitionProperty::LineHeight => dest.write_str("line-height"),
|
||||
TransitionProperty::MarginBottom => dest.write_str("margin-bottom"),
|
||||
TransitionProperty::MarginLeft => dest.write_str("margin-left"),
|
||||
TransitionProperty::MarginRight => dest.write_str("margin-right"),
|
||||
TransitionProperty::MarginTop => dest.write_str("margin-top"),
|
||||
TransitionProperty::MaxHeight => dest.write_str("max-height"),
|
||||
TransitionProperty::MaxWidth => dest.write_str("max-width"),
|
||||
TransitionProperty::MinHeight => dest.write_str("min-height"),
|
||||
TransitionProperty::MinWidth => dest.write_str("min-width"),
|
||||
TransitionProperty::Opacity => dest.write_str("opacity"),
|
||||
TransitionProperty::OutlineColor => dest.write_str("outline-color"),
|
||||
TransitionProperty::OutlineWidth => dest.write_str("outline-width"),
|
||||
TransitionProperty::PaddingBottom => dest.write_str("padding-bottom"),
|
||||
TransitionProperty::PaddingLeft => dest.write_str("padding-left"),
|
||||
TransitionProperty::PaddingRight => dest.write_str("padding-right"),
|
||||
TransitionProperty::PaddingTop => dest.write_str("padding-top"),
|
||||
TransitionProperty::Right => dest.write_str("right"),
|
||||
TransitionProperty::TextIndent => dest.write_str("text-indent"),
|
||||
TransitionProperty::TextShadow => dest.write_str("text-shadow"),
|
||||
TransitionProperty::Top => dest.write_str("top"),
|
||||
TransitionProperty::Transform => dest.write_str("transform"),
|
||||
TransitionProperty::VerticalAlign => dest.write_str("vertical-align"),
|
||||
TransitionProperty::Visibility => dest.write_str("visibility"),
|
||||
TransitionProperty::Width => dest.write_str("width"),
|
||||
TransitionProperty::WordSpacing => dest.write_str("word-spacing"),
|
||||
TransitionProperty::ZIndex => dest.write_str("z-index"),
|
||||
}
|
||||
}
|
||||
}
|
||||
// NB: Can't generate the type here because it needs all the longhands
|
||||
// generated beforehand.
|
||||
pub use properties::animated_properties::TransitionProperty;
|
||||
pub use properties::animated_properties::TransitionProperty as SingleComputedValue;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
|
@ -715,61 +562,8 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", need_clone=
|
|||
computed_value::T(Vec::new())
|
||||
}
|
||||
|
||||
pub fn parse_one(input: &mut Parser) -> Result<SingleSpecifiedValue,()> {
|
||||
match_ignore_ascii_case! {
|
||||
try!(input.expect_ident()),
|
||||
"all" => Ok(TransitionProperty::All),
|
||||
"background-color" => Ok(TransitionProperty::BackgroundColor),
|
||||
"background-position" => Ok(TransitionProperty::BackgroundPosition),
|
||||
"border-bottom-color" => Ok(TransitionProperty::BorderBottomColor),
|
||||
"border-bottom-width" => Ok(TransitionProperty::BorderBottomWidth),
|
||||
"border-left-color" => Ok(TransitionProperty::BorderLeftColor),
|
||||
"border-left-width" => Ok(TransitionProperty::BorderLeftWidth),
|
||||
"border-right-color" => Ok(TransitionProperty::BorderRightColor),
|
||||
"border-right-width" => Ok(TransitionProperty::BorderRightWidth),
|
||||
"border-spacing" => Ok(TransitionProperty::BorderSpacing),
|
||||
"border-top-color" => Ok(TransitionProperty::BorderTopColor),
|
||||
"border-top-width" => Ok(TransitionProperty::BorderTopWidth),
|
||||
"bottom" => Ok(TransitionProperty::Bottom),
|
||||
"color" => Ok(TransitionProperty::Color),
|
||||
"clip" => Ok(TransitionProperty::Clip),
|
||||
"font-size" => Ok(TransitionProperty::FontSize),
|
||||
"font-weight" => Ok(TransitionProperty::FontWeight),
|
||||
"height" => Ok(TransitionProperty::Height),
|
||||
"left" => Ok(TransitionProperty::Left),
|
||||
"letter-spacing" => Ok(TransitionProperty::LetterSpacing),
|
||||
"line-height" => Ok(TransitionProperty::LineHeight),
|
||||
"margin-bottom" => Ok(TransitionProperty::MarginBottom),
|
||||
"margin-left" => Ok(TransitionProperty::MarginLeft),
|
||||
"margin-right" => Ok(TransitionProperty::MarginRight),
|
||||
"margin-top" => Ok(TransitionProperty::MarginTop),
|
||||
"max-height" => Ok(TransitionProperty::MaxHeight),
|
||||
"max-width" => Ok(TransitionProperty::MaxWidth),
|
||||
"min-height" => Ok(TransitionProperty::MinHeight),
|
||||
"min-width" => Ok(TransitionProperty::MinWidth),
|
||||
"opacity" => Ok(TransitionProperty::Opacity),
|
||||
"outline-color" => Ok(TransitionProperty::OutlineColor),
|
||||
"outline-width" => Ok(TransitionProperty::OutlineWidth),
|
||||
"padding-bottom" => Ok(TransitionProperty::PaddingBottom),
|
||||
"padding-left" => Ok(TransitionProperty::PaddingLeft),
|
||||
"padding-right" => Ok(TransitionProperty::PaddingRight),
|
||||
"padding-top" => Ok(TransitionProperty::PaddingTop),
|
||||
"right" => Ok(TransitionProperty::Right),
|
||||
"text-indent" => Ok(TransitionProperty::TextIndent),
|
||||
"text-shadow" => Ok(TransitionProperty::TextShadow),
|
||||
"top" => Ok(TransitionProperty::Top),
|
||||
"transform" => Ok(TransitionProperty::Transform),
|
||||
"vertical-align" => Ok(TransitionProperty::VerticalAlign),
|
||||
"visibility" => Ok(TransitionProperty::Visibility),
|
||||
"width" => Ok(TransitionProperty::Width),
|
||||
"word-spacing" => Ok(TransitionProperty::WordSpacing),
|
||||
"z-index" => Ok(TransitionProperty::ZIndex),
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
|
||||
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(SingleSpecifiedValue::parse))))
|
||||
}
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
|
@ -790,9 +584,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", need_clone=
|
|||
</%helpers:longhand>
|
||||
|
||||
<%helpers:longhand name="animation-name" experimental="True">
|
||||
use cssparser::ToCss;
|
||||
use std::borrow::Cow;
|
||||
use std::fmt;
|
||||
use values::computed::ComputedValueAsSpecified;
|
||||
|
||||
pub mod computed_value {
|
||||
use cssparser::ToCss;
|
||||
|
@ -818,26 +610,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", need_clone=
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: Use Cows? Probably more codegen work would be needed, and this
|
||||
// could not be that worth it (animations arent *that* used).
|
||||
#[derive(Debug, Clone, PartialEq, HeapSizeOf)]
|
||||
pub struct SpecifiedValue(Vec<String>);
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
if self.0.is_empty() {
|
||||
return dest.write_str("none")
|
||||
}
|
||||
|
||||
for (i, name) in self.0.iter().enumerate() {
|
||||
if i != 0 {
|
||||
try!(dest.write_str(", "));
|
||||
}
|
||||
try!(dest.write_str(&name));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
pub use self::computed_value::T as SpecifiedValue;
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
|
@ -845,27 +618,13 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", need_clone=
|
|||
}
|
||||
|
||||
pub fn parse(_: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
|
||||
use std::borrow::Cow;
|
||||
Ok(SpecifiedValue(try!(input.parse_comma_separated(|input| {
|
||||
input.expect_ident().map(Cow::into_owned)
|
||||
}))))
|
||||
}
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
type ComputedValue = computed_value::T;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T {
|
||||
let mut ret = vec![];
|
||||
if let Some(animations) = context.animations() {
|
||||
for name in self.0.iter() {
|
||||
if animations.contains_key(&**name) {
|
||||
ret.push(name.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
computed_value::T(ret)
|
||||
}
|
||||
}
|
||||
impl ComputedValueAsSpecified for SpecifiedValue {}
|
||||
</%helpers:longhand>
|
||||
|
||||
<%helpers:longhand name="animation-duration" experimental="True">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue