зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #14913 - Refactor box longhands (from canaltinova:box-longhands); r=Manishearth
<!-- Please describe your changes on the following line: --> Converted some longhands into `vector_longhand` to reduce some repeated codes. Also some of longhands with same `SpecifiedValue` and `computed_value::T` changed. Re-exported SpecifiedValue instead of computed_value::T. Normally a computed_value can't have a parse function. --- <!-- 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 test-tidy` does not report any errors <!-- Either: --> - [X] These changes do not require tests because they're not changing the behavior of the longhands. <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 0d5e021537a18d1e5668c099305cebf754e93007
This commit is contained in:
Родитель
fc73f1abd9
Коммит
81472c45ea
|
@ -14,10 +14,10 @@ use keyframes::{KeyframesStep, KeyframesStepValue};
|
|||
use properties::{self, CascadeFlags, ComputedValues, Importance};
|
||||
use properties::animated_properties::{AnimatedProperty, TransitionProperty};
|
||||
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_iteration_count::single_value::computed_value::T as AnimationIterationCount;
|
||||
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 properties::longhands::transition_timing_function::single_value::computed_value::StartEnd;
|
||||
use properties::longhands::transition_timing_function::single_value::computed_value::T as TransitionTimingFunction;
|
||||
use std::sync::Arc;
|
||||
use std::sync::mpsc::Sender;
|
||||
use timer::Timer;
|
||||
|
|
|
@ -157,7 +157,7 @@
|
|||
% endif
|
||||
}
|
||||
|
||||
pub use self::single_value::computed_value::T as SingleSpecifiedValue;
|
||||
pub use self::single_value::SpecifiedValue as SingleSpecifiedValue;
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
type ComputedValue = computed_value::T;
|
||||
|
|
|
@ -28,32 +28,32 @@
|
|||
-moz-grid-group -moz-grid-line -moz-stack -moz-inline-stack -moz-deck
|
||||
-moz-popup -moz-groupbox""".split()
|
||||
%>
|
||||
pub use self::computed_value::T as SpecifiedValue;
|
||||
use values::computed::ComputedValueAsSpecified;
|
||||
use style_traits::ToCss;
|
||||
use values::NoViewportPercentage;
|
||||
impl NoViewportPercentage for SpecifiedValue {}
|
||||
|
||||
pub mod computed_value {
|
||||
use style_traits::ToCss;
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Clone, Eq, PartialEq, Copy, Hash, RustcEncodable, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf, Deserialize, Serialize))]
|
||||
pub enum T {
|
||||
% for value in values:
|
||||
${to_rust_ident(value)},
|
||||
% endfor
|
||||
}
|
||||
pub use super::SpecifiedValue as T;
|
||||
}
|
||||
|
||||
impl ToCss for T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> ::std::fmt::Result
|
||||
where W: ::std::fmt::Write,
|
||||
{
|
||||
match *self {
|
||||
% for value in values:
|
||||
T::${to_rust_ident(value)} => dest.write_str("${value}"),
|
||||
% endfor
|
||||
}
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Clone, Eq, PartialEq, Copy, Hash, RustcEncodable, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf, Deserialize, Serialize))]
|
||||
pub enum SpecifiedValue {
|
||||
% for value in values:
|
||||
${to_rust_ident(value)},
|
||||
% endfor
|
||||
}
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> ::std::fmt::Result
|
||||
where W: ::std::fmt::Write,
|
||||
{
|
||||
match *self {
|
||||
% for value in values:
|
||||
SpecifiedValue::${to_rust_ident(value)} => dest.write_str("${value}"),
|
||||
% endfor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -397,8 +397,6 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
|||
use values::computed::ComputedValueAsSpecified;
|
||||
use values::NoViewportPercentage;
|
||||
|
||||
pub use self::computed_value::T as SpecifiedValue;
|
||||
|
||||
impl NoViewportPercentage for SpecifiedValue {}
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
|
@ -407,18 +405,19 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// The specified and computed value for overflow-y is a wrapper on top of
|
||||
/// `overflow-x`, so we re-use the logic, but prevent errors from mistakenly
|
||||
/// assign one to other.
|
||||
///
|
||||
/// TODO(Manishearth, emilio): We may want to just use the same value.
|
||||
pub mod computed_value {
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct T(pub super::super::overflow_x::computed_value::T);
|
||||
pub use super::SpecifiedValue as T;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct SpecifiedValue(pub super::overflow_x::SpecifiedValue);
|
||||
|
||||
impl ComputedValueAsSpecified for SpecifiedValue {}
|
||||
|
||||
#[inline]
|
||||
|
@ -434,112 +433,77 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
|||
}
|
||||
</%helpers:longhand>
|
||||
|
||||
<%helpers:longhand name="transition-duration"
|
||||
need_index="True"
|
||||
animatable="False"
|
||||
spec="https://drafts.csswg.org/css-transitions/#propdef-transition-duration">
|
||||
use values::computed::ComputedValueAsSpecified;
|
||||
<%helpers:vector_longhand name="transition-duration"
|
||||
need_index="True"
|
||||
animatable="False"
|
||||
spec="https://drafts.csswg.org/css-transitions/#propdef-transition-duration">
|
||||
use values::specified::Time;
|
||||
|
||||
pub use self::computed_value::T as SpecifiedValue;
|
||||
pub use values::specified::Time as SingleSpecifiedValue;
|
||||
pub use values::specified::Time as SpecifiedValue;
|
||||
use values::NoViewportPercentage;
|
||||
impl NoViewportPercentage for SpecifiedValue {}
|
||||
|
||||
pub mod computed_value {
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::computed::{Context, ToComputedValue};
|
||||
|
||||
pub use values::computed::Time as SingleComputedValue;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct T(pub Vec<SingleComputedValue>);
|
||||
|
||||
impl ToCss for T {
|
||||
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, value) in self.0.iter().enumerate() {
|
||||
if i != 0 {
|
||||
try!(dest.write_str(", "))
|
||||
}
|
||||
try!(value.to_css(dest))
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
pub use values::computed::Time as T;
|
||||
}
|
||||
|
||||
impl ComputedValueAsSpecified for SpecifiedValue {}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_single_value() -> Time {
|
||||
pub fn get_initial_value() -> Time {
|
||||
Time(0.0)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
computed_value::T(vec![get_initial_single_value()])
|
||||
}
|
||||
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
|
||||
Ok(SpecifiedValue(try!(input.parse_comma_separated(|i| Time::parse(context, i)))))
|
||||
Time::parse(context, input)
|
||||
}
|
||||
</%helpers:longhand>
|
||||
</%helpers:vector_longhand>
|
||||
|
||||
// TODO(pcwalton): Lots more timing functions.
|
||||
<%helpers:longhand name="transition-timing-function"
|
||||
need_index="True"
|
||||
animatable="False"
|
||||
spec="https://drafts.csswg.org/css-transitions/#propdef-transition-timing-function">
|
||||
<%helpers:vector_longhand name="transition-timing-function"
|
||||
need_index="True"
|
||||
animatable="False"
|
||||
spec="https://drafts.csswg.org/css-transitions/#propdef-transition-timing-function">
|
||||
use self::computed_value::StartEnd;
|
||||
use self::computed_value::TransitionTimingFunction as ComputedTransitionTimingFunction;
|
||||
|
||||
use euclid::point::{Point2D, TypedPoint2D};
|
||||
use std::fmt;
|
||||
use std::marker::PhantomData;
|
||||
use style_traits::ToCss;
|
||||
|
||||
pub use self::TransitionTimingFunction as SingleSpecifiedValue;
|
||||
|
||||
// FIXME: This could use static variables and const functions when they are available.
|
||||
#[inline(always)]
|
||||
fn ease() -> ComputedTransitionTimingFunction {
|
||||
ComputedTransitionTimingFunction::CubicBezier(TypedPoint2D::new(0.25, 0.1),
|
||||
fn ease() -> computed_value::T {
|
||||
computed_value::T::CubicBezier(TypedPoint2D::new(0.25, 0.1),
|
||||
TypedPoint2D::new(0.25, 1.0))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn linear() -> ComputedTransitionTimingFunction {
|
||||
ComputedTransitionTimingFunction::CubicBezier(TypedPoint2D::new(0.0, 0.0),
|
||||
fn linear() -> computed_value::T {
|
||||
computed_value::T::CubicBezier(TypedPoint2D::new(0.0, 0.0),
|
||||
TypedPoint2D::new(1.0, 1.0))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn ease_in() -> ComputedTransitionTimingFunction {
|
||||
ComputedTransitionTimingFunction::CubicBezier(TypedPoint2D::new(0.42, 0.0),
|
||||
fn ease_in() -> computed_value::T {
|
||||
computed_value::T::CubicBezier(TypedPoint2D::new(0.42, 0.0),
|
||||
TypedPoint2D::new(1.0, 1.0))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn ease_out() -> ComputedTransitionTimingFunction {
|
||||
ComputedTransitionTimingFunction::CubicBezier(TypedPoint2D::new(0.0, 0.0),
|
||||
fn ease_out() -> computed_value::T {
|
||||
computed_value::T::CubicBezier(TypedPoint2D::new(0.0, 0.0),
|
||||
TypedPoint2D::new(0.58, 1.0))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn ease_in_out() -> ComputedTransitionTimingFunction {
|
||||
ComputedTransitionTimingFunction::CubicBezier(TypedPoint2D::new(0.42, 0.0),
|
||||
fn ease_in_out() -> computed_value::T {
|
||||
computed_value::T::CubicBezier(TypedPoint2D::new(0.42, 0.0),
|
||||
TypedPoint2D::new(0.58, 1.0))
|
||||
}
|
||||
|
||||
static STEP_START: ComputedTransitionTimingFunction =
|
||||
ComputedTransitionTimingFunction::Steps(1, StartEnd::Start);
|
||||
static STEP_END: ComputedTransitionTimingFunction =
|
||||
ComputedTransitionTimingFunction::Steps(1, StartEnd::End);
|
||||
static STEP_START: computed_value::T =
|
||||
computed_value::T::Steps(1, StartEnd::Start);
|
||||
static STEP_END: computed_value::T =
|
||||
computed_value::T::Steps(1, StartEnd::End);
|
||||
|
||||
pub mod computed_value {
|
||||
use euclid::point::Point2D;
|
||||
|
@ -547,20 +511,19 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
|||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
|
||||
pub use self::TransitionTimingFunction as SingleComputedValue;
|
||||
pub use super::parse;
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum TransitionTimingFunction {
|
||||
pub enum T {
|
||||
CubicBezier(Point2D<f32>, Point2D<f32>),
|
||||
Steps(u32, StartEnd),
|
||||
}
|
||||
|
||||
impl ToCss for TransitionTimingFunction {
|
||||
impl ToCss for T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
TransitionTimingFunction::CubicBezier(p1, p2) => {
|
||||
T::CubicBezier(p1, p2) => {
|
||||
try!(dest.write_str("cubic-bezier("));
|
||||
try!(p1.x.to_css(dest));
|
||||
try!(dest.write_str(", "));
|
||||
|
@ -571,7 +534,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
|||
try!(p2.y.to_css(dest));
|
||||
dest.write_str(")")
|
||||
}
|
||||
TransitionTimingFunction::Steps(steps, start_end) => {
|
||||
T::Steps(steps, start_end) => {
|
||||
super::serialize_steps(dest, steps, start_end)
|
||||
}
|
||||
}
|
||||
|
@ -593,25 +556,6 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct T(pub Vec<TransitionTimingFunction>);
|
||||
|
||||
impl ToCss for T {
|
||||
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, value) in self.0.iter().enumerate() {
|
||||
if i != 0 {
|
||||
try!(dest.write_str(", "))
|
||||
}
|
||||
try!(value.to_css(dest))
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
define_css_keyword_enum!(FunctionKeyword:
|
||||
|
@ -625,17 +569,13 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
|||
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum TransitionTimingFunction {
|
||||
pub enum SpecifiedValue {
|
||||
CubicBezier(Point2D<f32>, Point2D<f32>),
|
||||
Steps(u32, StartEnd),
|
||||
Keyword(FunctionKeyword),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct SpecifiedValue(pub Vec<TransitionTimingFunction>);
|
||||
|
||||
impl Parse for TransitionTimingFunction {
|
||||
impl Parse for SpecifiedValue {
|
||||
fn parse(_context: &ParserContext, input: &mut ::cssparser::Parser) -> Result<Self, ()> {
|
||||
if let Ok(function_name) = input.try(|input| input.expect_function()) {
|
||||
return match_ignore_ascii_case! { function_name,
|
||||
|
@ -652,7 +592,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
|||
Ok(())
|
||||
}));
|
||||
let (p1, p2) = (Point2D::new(p1x, p1y), Point2D::new(p2x, p2y));
|
||||
Ok(TransitionTimingFunction::CubicBezier(p1, p2))
|
||||
Ok(SpecifiedValue::CubicBezier(p1, p2))
|
||||
},
|
||||
"steps" => {
|
||||
let (mut step_count, mut start_end) = (0, StartEnd::End);
|
||||
|
@ -668,12 +608,12 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
|||
}
|
||||
Ok(())
|
||||
}));
|
||||
Ok(TransitionTimingFunction::Steps(step_count as u32, start_end))
|
||||
Ok(SpecifiedValue::Steps(step_count as u32, start_end))
|
||||
},
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
Ok(TransitionTimingFunction::Keyword(try!(FunctionKeyword::parse(input))))
|
||||
Ok(SpecifiedValue::Keyword(try!(FunctionKeyword::parse(input))))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -688,10 +628,10 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
|||
}
|
||||
|
||||
// https://drafts.csswg.org/css-transitions/#serializing-a-timing-function
|
||||
impl ToCss for TransitionTimingFunction {
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
TransitionTimingFunction::CubicBezier(p1, p2) => {
|
||||
SpecifiedValue::CubicBezier(p1, p2) => {
|
||||
try!(dest.write_str("cubic-bezier("));
|
||||
try!(p1.x.to_css(dest));
|
||||
try!(dest.write_str(", "));
|
||||
|
@ -702,10 +642,10 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
|||
try!(p2.y.to_css(dest));
|
||||
dest.write_str(")")
|
||||
},
|
||||
TransitionTimingFunction::Steps(steps, start_end) => {
|
||||
SpecifiedValue::Steps(steps, start_end) => {
|
||||
serialize_steps(dest, steps, start_end)
|
||||
},
|
||||
TransitionTimingFunction::Keyword(keyword) => {
|
||||
SpecifiedValue::Keyword(keyword) => {
|
||||
match keyword {
|
||||
FunctionKeyword::StepStart => {
|
||||
serialize_steps(dest, 1, StartEnd::Start)
|
||||
|
@ -722,19 +662,19 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
|||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for TransitionTimingFunction {
|
||||
type ComputedValue = ComputedTransitionTimingFunction;
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
type ComputedValue = computed_value::T;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, _context: &Context) -> ComputedTransitionTimingFunction {
|
||||
fn to_computed_value(&self, _context: &Context) -> computed_value::T {
|
||||
match *self {
|
||||
TransitionTimingFunction::CubicBezier(p1, p2) => {
|
||||
ComputedTransitionTimingFunction::CubicBezier(p1, p2)
|
||||
SpecifiedValue::CubicBezier(p1, p2) => {
|
||||
computed_value::T::CubicBezier(p1, p2)
|
||||
},
|
||||
TransitionTimingFunction::Steps(count, start_end) => {
|
||||
ComputedTransitionTimingFunction::Steps(count, start_end)
|
||||
SpecifiedValue::Steps(count, start_end) => {
|
||||
computed_value::T::Steps(count, start_end)
|
||||
},
|
||||
TransitionTimingFunction::Keyword(keyword) => {
|
||||
SpecifiedValue::Keyword(keyword) => {
|
||||
match keyword {
|
||||
FunctionKeyword::Ease => ease(),
|
||||
FunctionKeyword::Linear => linear(),
|
||||
|
@ -748,44 +688,15 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
|||
}
|
||||
}
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &ComputedTransitionTimingFunction) -> Self {
|
||||
match *computed {
|
||||
computed_value::TransitionTimingFunction::CubicBezier(p1, p2) => {
|
||||
TransitionTimingFunction::CubicBezier(p1, p2)
|
||||
},
|
||||
computed_value::TransitionTimingFunction::Steps(count, start_end) => {
|
||||
TransitionTimingFunction::Steps(count, start_end)
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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, value) in self.0.iter().enumerate() {
|
||||
if i != 0 {
|
||||
try!(dest.write_str(", "))
|
||||
}
|
||||
try!(value.to_css(dest))
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
type ComputedValue = computed_value::T;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> computed_value::T {
|
||||
computed_value::T(self.0.iter().map(|f| f.to_computed_value(context)).collect())
|
||||
}
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &computed_value::T) -> Self {
|
||||
SpecifiedValue(computed.0.iter().map(|f| ToComputedValue::from_computed_value(f))
|
||||
.collect())
|
||||
match *computed {
|
||||
computed_value::T::CubicBezier(p1, p2) => {
|
||||
SpecifiedValue::CubicBezier(p1, p2)
|
||||
},
|
||||
computed_value::T::Steps(count, start_end) => {
|
||||
SpecifiedValue::Steps(count, start_end)
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -793,280 +704,192 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
|||
impl NoViewportPercentage for SpecifiedValue {}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_single_value() -> ComputedTransitionTimingFunction {
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
ease()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_specified_single_value() -> TransitionTimingFunction {
|
||||
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||
ToComputedValue::from_computed_value(&ease())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
computed_value::T(vec![get_initial_single_value()])
|
||||
}
|
||||
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
|
||||
Ok(SpecifiedValue(try!(input.parse_comma_separated(|i| {
|
||||
TransitionTimingFunction::parse(context, i)
|
||||
}))))
|
||||
SpecifiedValue::parse(context, input)
|
||||
}
|
||||
</%helpers:longhand>
|
||||
</%helpers:vector_longhand>
|
||||
|
||||
<%helpers:longhand name="transition-property"
|
||||
need_index="True"
|
||||
animatable="False"
|
||||
spec="https://drafts.csswg.org/css-transitions/#propdef-transition-property">
|
||||
<%helpers:vector_longhand name="transition-property"
|
||||
allow_empty="True"
|
||||
need_index="True"
|
||||
animatable="False"
|
||||
spec="https://drafts.csswg.org/css-transitions/#propdef-transition-property">
|
||||
|
||||
use values::computed::ComputedValueAsSpecified;
|
||||
|
||||
pub use self::computed_value::SingleComputedValue as SingleSpecifiedValue;
|
||||
pub use self::computed_value::T as SpecifiedValue;
|
||||
pub use properties::animated_properties::TransitionProperty;
|
||||
pub use properties::animated_properties::TransitionProperty as SpecifiedValue;
|
||||
|
||||
pub mod computed_value {
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
// 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))]
|
||||
pub struct T(pub Vec<SingleComputedValue>);
|
||||
|
||||
impl ToCss for T {
|
||||
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, value) in self.0.iter().enumerate() {
|
||||
if i != 0 {
|
||||
try!(dest.write_str(", "))
|
||||
}
|
||||
try!(value.to_css(dest))
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
computed_value::T(Vec::new())
|
||||
pub use super::SpecifiedValue as T;
|
||||
}
|
||||
|
||||
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
|
||||
Ok(SpecifiedValue(try!(input.parse_comma_separated(SingleSpecifiedValue::parse))))
|
||||
SpecifiedValue::parse(input)
|
||||
}
|
||||
|
||||
use values::NoViewportPercentage;
|
||||
impl NoViewportPercentage for SpecifiedValue {}
|
||||
|
||||
impl ComputedValueAsSpecified for SpecifiedValue { }
|
||||
</%helpers:longhand>
|
||||
</%helpers:vector_longhand>
|
||||
|
||||
<%helpers:longhand name="transition-delay"
|
||||
need_index="True"
|
||||
animatable="False"
|
||||
spec="https://drafts.csswg.org/css-transitions/#propdef-transition-delay">
|
||||
pub use properties::longhands::transition_duration::{SingleSpecifiedValue, SpecifiedValue};
|
||||
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:vector_longhand name="transition-delay"
|
||||
need_index="True"
|
||||
animatable="False"
|
||||
spec="https://drafts.csswg.org/css-transitions/#propdef-transition-delay">
|
||||
pub use properties::longhands::transition_duration::single_value::SpecifiedValue;
|
||||
pub use properties::longhands::transition_duration::single_value::computed_value;
|
||||
pub use properties::longhands::transition_duration::single_value::{get_initial_value, parse};
|
||||
</%helpers:vector_longhand>
|
||||
|
||||
<%helpers:longhand name="animation-name"
|
||||
need_index="True"
|
||||
animatable="False",
|
||||
allowed_in_keyframe_block="False"
|
||||
spec="https://drafts.csswg.org/css-animations/#propdef-animation-name">
|
||||
<%helpers:vector_longhand name="animation-name"
|
||||
allow_empty="True"
|
||||
need_index="True"
|
||||
animatable="False",
|
||||
allowed_in_keyframe_block="False"
|
||||
spec="https://drafts.csswg.org/css-animations/#propdef-animation-name">
|
||||
use Atom;
|
||||
use std::fmt;
|
||||
use std::ops::Deref;
|
||||
use style_traits::ToCss;
|
||||
use values::computed::ComputedValueAsSpecified;
|
||||
use values::NoViewportPercentage;
|
||||
|
||||
pub mod computed_value {
|
||||
use Atom;
|
||||
use parser::{Parse, ParserContext};
|
||||
use std::fmt;
|
||||
use std::ops::Deref;
|
||||
use style_traits::ToCss;
|
||||
pub use super::SpecifiedValue as T;
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct AnimationName(pub Atom);
|
||||
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct SpecifiedValue(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(_context: &ParserContext, 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<AnimationName>);
|
||||
|
||||
impl ToCss for T {
|
||||
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(", "));
|
||||
}
|
||||
// NB: to_string() needed due to geckolib backend.
|
||||
try!(dest.write_str(&*name.to_string()));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
impl fmt::Display for SpecifiedValue {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
pub use self::computed_value::T as SpecifiedValue;
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
dest.write_str(&*self.0.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for SpecifiedValue {
|
||||
fn parse(_context: &ParserContext, input: &mut ::cssparser::Parser) -> Result<Self, ()> {
|
||||
use cssparser::Token;
|
||||
Ok(match input.next() {
|
||||
Ok(Token::Ident(ref value)) if value != "none" => SpecifiedValue(Atom::from(&**value)),
|
||||
Ok(Token::QuotedString(value)) => SpecifiedValue(Atom::from(&*value)),
|
||||
_ => return Err(()),
|
||||
})
|
||||
}
|
||||
}
|
||||
impl NoViewportPercentage for SpecifiedValue {}
|
||||
pub use self::computed_value::SingleComputedValue as SingleSpecifiedValue;
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
computed_value::T(vec![])
|
||||
}
|
||||
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
|
||||
use std::borrow::Cow;
|
||||
Ok(SpecifiedValue(try!(input.parse_comma_separated(|i| SingleSpecifiedValue::parse(context, i)))))
|
||||
SpecifiedValue::parse(context, input)
|
||||
}
|
||||
|
||||
impl ComputedValueAsSpecified for SpecifiedValue {}
|
||||
</%helpers:longhand>
|
||||
</%helpers:vector_longhand>
|
||||
|
||||
<%helpers:longhand name="animation-duration"
|
||||
need_index="True"
|
||||
animatable="False",
|
||||
spec="https://drafts.csswg.org/css-animations/#propdef-animation-duration",
|
||||
allowed_in_keyframe_block="False">
|
||||
pub use super::transition_duration::computed_value;
|
||||
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>
|
||||
<%helpers:vector_longhand name="animation-duration"
|
||||
need_index="True"
|
||||
animatable="False",
|
||||
spec="https://drafts.csswg.org/css-animations/#propdef-animation-duration",
|
||||
allowed_in_keyframe_block="False">
|
||||
pub use properties::longhands::transition_duration::single_value::computed_value;
|
||||
pub use properties::longhands::transition_duration::single_value::{get_initial_value, parse};
|
||||
pub use properties::longhands::transition_duration::single_value::SpecifiedValue;
|
||||
</%helpers:vector_longhand>
|
||||
|
||||
<%helpers:longhand name="animation-timing-function"
|
||||
need_index="True"
|
||||
animatable="False",
|
||||
spec="https://drafts.csswg.org/css-animations/#propdef-animation-timing-function",
|
||||
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::{get_initial_specified_single_value, parse};
|
||||
pub use super::transition_timing_function::SpecifiedValue;
|
||||
pub use super::transition_timing_function::SingleSpecifiedValue;
|
||||
</%helpers:longhand>
|
||||
<%helpers:vector_longhand name="animation-timing-function"
|
||||
need_index="True"
|
||||
animatable="False",
|
||||
spec="https://drafts.csswg.org/css-animations/#propdef-animation-timing-function",
|
||||
allowed_in_keyframe_block="False">
|
||||
pub use properties::longhands::transition_timing_function::single_value::computed_value;
|
||||
pub use properties::longhands::transition_timing_function::single_value::get_initial_value;
|
||||
pub use properties::longhands::transition_timing_function::single_value::get_initial_specified_value;
|
||||
pub use properties::longhands::transition_timing_function::single_value::parse;
|
||||
pub use properties::longhands::transition_timing_function::single_value::SpecifiedValue;
|
||||
</%helpers:vector_longhand>
|
||||
|
||||
<%helpers:longhand name="animation-iteration-count"
|
||||
need_index="True"
|
||||
animatable="False",
|
||||
spec="https://drafts.csswg.org/css-animations/#propdef-animation-iteration-count",
|
||||
allowed_in_keyframe_block="False">
|
||||
<%helpers:vector_longhand name="animation-iteration-count"
|
||||
need_index="True"
|
||||
animatable="False",
|
||||
spec="https://drafts.csswg.org/css-animations/#propdef-animation-iteration-count",
|
||||
allowed_in_keyframe_block="False">
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::computed::ComputedValueAsSpecified;
|
||||
use values::NoViewportPercentage;
|
||||
|
||||
pub mod computed_value {
|
||||
use parser::{Parse, ParserContext};
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
pub use super::SpecifiedValue as T;
|
||||
}
|
||||
|
||||
pub use self::AnimationIterationCount as SingleComputedValue;
|
||||
// https://drafts.csswg.org/css-animations/#animation-iteration-count
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum SpecifiedValue {
|
||||
Number(f32),
|
||||
Infinite,
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/css-animations/#animation-iteration-count
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum AnimationIterationCount {
|
||||
Number(f32),
|
||||
Infinite,
|
||||
}
|
||||
|
||||
impl Parse for AnimationIterationCount {
|
||||
fn parse(_context: &ParserContext, 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_number());
|
||||
if number < 0.0 {
|
||||
return Err(());
|
||||
}
|
||||
|
||||
Ok(AnimationIterationCount::Number(number))
|
||||
impl Parse for SpecifiedValue {
|
||||
fn parse(_context: &ParserContext, input: &mut ::cssparser::Parser) -> Result<Self, ()> {
|
||||
if input.try(|input| input.expect_ident_matching("infinite")).is_ok() {
|
||||
return Ok(SpecifiedValue::Infinite)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for AnimationIterationCount {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
AnimationIterationCount::Number(n) => write!(dest, "{}", n),
|
||||
AnimationIterationCount::Infinite => dest.write_str("infinite"),
|
||||
}
|
||||
let number = try!(input.expect_number());
|
||||
if number < 0.0 {
|
||||
return Err(());
|
||||
}
|
||||
|
||||
Ok(SpecifiedValue::Number(number))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct T(pub Vec<AnimationIterationCount>);
|
||||
|
||||
impl ToCss for T {
|
||||
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, value) in self.0.iter().enumerate() {
|
||||
if i != 0 {
|
||||
try!(dest.write_str(", "))
|
||||
}
|
||||
try!(value.to_css(dest))
|
||||
}
|
||||
Ok(())
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
SpecifiedValue::Number(n) => write!(dest, "{}", n),
|
||||
SpecifiedValue::Infinite => dest.write_str("infinite"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub use self::computed_value::AnimationIterationCount;
|
||||
pub use self::computed_value::AnimationIterationCount as SingleSpecifiedValue;
|
||||
pub use self::computed_value::T as SpecifiedValue;
|
||||
impl NoViewportPercentage for SpecifiedValue {}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_single_value() -> AnimationIterationCount {
|
||||
AnimationIterationCount::Number(1.0)
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
computed_value::T::Number(1.0)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
Ok(SpecifiedValue(try!(input.parse_comma_separated(|i| {
|
||||
AnimationIterationCount::parse(context, i)
|
||||
}))))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
computed_value::T(vec![get_initial_single_value()])
|
||||
SpecifiedValue::parse(context, input)
|
||||
}
|
||||
|
||||
impl ComputedValueAsSpecified for SpecifiedValue {}
|
||||
</%helpers:longhand>
|
||||
</%helpers:vector_longhand>
|
||||
|
||||
${helpers.single_keyword("animation-direction",
|
||||
"normal reverse alternate alternate-reverse",
|
||||
|
@ -1095,16 +918,15 @@ ${helpers.single_keyword("animation-fill-mode",
|
|||
spec="https://drafts.csswg.org/css-animations/#propdef-animation-fill-mode",
|
||||
allowed_in_keyframe_block=False)}
|
||||
|
||||
<%helpers:longhand name="animation-delay"
|
||||
need_index="True"
|
||||
animatable="False",
|
||||
spec="https://drafts.csswg.org/css-animations/#propdef-animation-delay",
|
||||
allowed_in_keyframe_block="False">
|
||||
pub use super::transition_duration::computed_value;
|
||||
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>
|
||||
<%helpers:vector_longhand name="animation-delay"
|
||||
need_index="True"
|
||||
animatable="False",
|
||||
spec="https://drafts.csswg.org/css-animations/#propdef-animation-delay",
|
||||
allowed_in_keyframe_block="False">
|
||||
pub use properties::longhands::transition_duration::single_value::computed_value;
|
||||
pub use properties::longhands::transition_duration::single_value::{get_initial_value, parse};
|
||||
pub use properties::longhands::transition_duration::single_value::SpecifiedValue;
|
||||
</%helpers:vector_longhand>
|
||||
|
||||
<%helpers:longhand products="gecko" name="scroll-snap-points-y" animatable="False"
|
||||
spec="Nonstandard (https://www.w3.org/TR/2015/WD-css-snappoints-1-20150326/#scroll-snap-points)">
|
||||
|
|
|
@ -127,11 +127,12 @@ macro_rules! try_parse_one {
|
|||
Ok(SingleTransition {
|
||||
transition_property: property,
|
||||
transition_duration:
|
||||
duration.unwrap_or_else(transition_duration::get_initial_single_value),
|
||||
duration.unwrap_or_else(transition_duration::single_value::get_initial_value),
|
||||
transition_timing_function:
|
||||
timing_function.unwrap_or_else(transition_timing_function::get_initial_specified_single_value),
|
||||
timing_function.unwrap_or_else(transition_timing_function::single_value
|
||||
::get_initial_specified_value),
|
||||
transition_delay:
|
||||
delay.unwrap_or_else(transition_delay::get_initial_single_value),
|
||||
delay.unwrap_or_else(transition_delay::single_value::get_initial_value),
|
||||
})
|
||||
} else {
|
||||
Err(())
|
||||
|
@ -238,13 +239,14 @@ macro_rules! try_parse_one {
|
|||
Ok(SingleAnimation {
|
||||
animation_name: name,
|
||||
animation_duration:
|
||||
duration.unwrap_or_else(animation_duration::get_initial_single_value),
|
||||
duration.unwrap_or_else(animation_duration::single_value::get_initial_value),
|
||||
animation_timing_function:
|
||||
timing_function.unwrap_or_else(animation_timing_function::get_initial_specified_single_value),
|
||||
timing_function.unwrap_or_else(animation_timing_function::single_value
|
||||
::get_initial_specified_value),
|
||||
animation_delay:
|
||||
delay.unwrap_or_else(animation_delay::get_initial_single_value),
|
||||
delay.unwrap_or_else(animation_delay::single_value::get_initial_value),
|
||||
animation_iteration_count:
|
||||
iteration_count.unwrap_or_else(animation_iteration_count::get_initial_single_value),
|
||||
iteration_count.unwrap_or_else(animation_iteration_count::single_value::get_initial_value),
|
||||
animation_direction:
|
||||
direction.unwrap_or_else(animation_direction::single_value::get_initial_value),
|
||||
animation_fill_mode:
|
||||
|
|
|
@ -6,7 +6,7 @@ use cssparser::Parser;
|
|||
use media_queries::CSSErrorReporterTest;
|
||||
use parsing::parse;
|
||||
use style::parser::{Parse, ParserContext};
|
||||
use style::properties::longhands::animation_iteration_count::computed_value::AnimationIterationCount;
|
||||
use style::properties::longhands::animation_iteration_count::single_value::computed_value::T as AnimationIterationCount;
|
||||
use style::stylesheets::Origin;
|
||||
use style_traits::ToCss;
|
||||
|
||||
|
|
|
@ -536,10 +536,10 @@ mod shorthand_serialization {
|
|||
fn transition_should_serialize_all_available_properties() {
|
||||
use euclid::point::Point2D;
|
||||
use style::properties::animated_properties::TransitionProperty;
|
||||
use style::properties::longhands::transition_delay::SpecifiedValue as DelayContainer;
|
||||
use style::properties::longhands::transition_duration::SpecifiedValue as DurationContainer;
|
||||
use style::properties::longhands::transition_property::SpecifiedValue as PropertyContainer;
|
||||
use style::properties::longhands::transition_timing_function::SpecifiedValue as TimingContainer;
|
||||
use style::properties::longhands::transition_timing_function::TransitionTimingFunction;
|
||||
use style::properties::longhands::transition_timing_function;
|
||||
use style::values::specified::Time as TimeContainer;
|
||||
|
||||
let property_name = DeclaredValue::Value(
|
||||
|
@ -551,12 +551,13 @@ mod shorthand_serialization {
|
|||
);
|
||||
|
||||
let delay = DeclaredValue::Value(
|
||||
DurationContainer(vec![TimeContainer(4f32)])
|
||||
DelayContainer(vec![TimeContainer(4f32)])
|
||||
);
|
||||
|
||||
let timing_function = DeclaredValue::Value(
|
||||
TimingContainer(vec![
|
||||
TransitionTimingFunction::CubicBezier(Point2D::new(0f32, 5f32), Point2D::new(5f32, 10f32))
|
||||
transition_timing_function::SpecifiedValue(vec![
|
||||
transition_timing_function::single_value::SpecifiedValue::CubicBezier(
|
||||
Point2D::new(0f32, 5f32), Point2D::new(5f32, 10f32))
|
||||
])
|
||||
);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче