mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #16792 - birtles:make-animatable-trait, r=hiro
Combine ComputeDuration and Interpolate into a single trait Pull request for [Gecko bug 1363573](https://bugzilla.mozilla.org/show_bug.cgi?id=1363573) The pull request has been reviewed by @hiikezoe --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] There are tests for these changes in Gecko <!-- 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/16792) <!-- Reviewable:end -->
This commit is contained in:
commit
0040160b38
11 changed files with 559 additions and 761 deletions
|
@ -111,15 +111,12 @@
|
||||||
pub struct T(pub SmallVec<[single_value::T; 1]>);
|
pub struct T(pub SmallVec<[single_value::T; 1]>);
|
||||||
|
|
||||||
% if delegate_animate:
|
% if delegate_animate:
|
||||||
use properties::animated_properties::Interpolate;
|
use properties::animated_properties::Animatable;
|
||||||
impl Interpolate for T {
|
impl Animatable for T {
|
||||||
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
|
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
|
||||||
self.0.interpolate(&other.0, progress).map(T)
|
self.0.interpolate(&other.0, progress).map(T)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
use properties::animated_properties::ComputeDistance;
|
|
||||||
impl ComputeDistance for T {
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||||
self.0.compute_distance(&other.0)
|
self.0.compute_distance(&other.0)
|
||||||
|
@ -974,10 +971,10 @@
|
||||||
%>
|
%>
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
/// Macro for defining Interpolate trait for tuple struct which has Option<T>,
|
/// Macro for defining Animatable trait for tuple struct which has Option<T>,
|
||||||
/// e.g. struct T(pub Option<Au>).
|
/// e.g. struct T(pub Option<Au>).
|
||||||
<%def name="impl_interpolate_for_option_tuple(value_for_none)">
|
<%def name="impl_animatable_for_option_tuple(value_for_none)">
|
||||||
impl Interpolate for T {
|
impl Animatable for T {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
|
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
|
||||||
match (self, other) {
|
match (self, other) {
|
||||||
|
@ -995,13 +992,7 @@
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
</%def>
|
|
||||||
|
|
||||||
/// Macro for defining ComputeDistance trait for tuple struct which has Option<T>,
|
|
||||||
/// e.g. struct T(pub Option<Au>).
|
|
||||||
<%def name="impl_compute_distance_for_option_tuple(value_for_none)">
|
|
||||||
impl ComputeDistance for T {
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||||
match (self, other) {
|
match (self, other) {
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -195,7 +195,7 @@ ${helpers.single_keyword("background-origin",
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
use values::computed::LengthOrPercentageOrAuto;
|
use values::computed::LengthOrPercentageOrAuto;
|
||||||
use properties::animated_properties::{ComputeDistance, Interpolate, RepeatableListInterpolate};
|
use properties::animated_properties::{Animatable, RepeatableListAnimatable};
|
||||||
|
|
||||||
#[derive(PartialEq, Clone, Debug)]
|
#[derive(PartialEq, Clone, Debug)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
@ -212,9 +212,9 @@ ${helpers.single_keyword("background-origin",
|
||||||
Contain,
|
Contain,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RepeatableListInterpolate for T {}
|
impl RepeatableListAnimatable for T {}
|
||||||
|
|
||||||
impl Interpolate for T {
|
impl Animatable for T {
|
||||||
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
|
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
|
||||||
use properties::longhands::background_size::single_value::computed_value::ExplicitSize;
|
use properties::longhands::background_size::single_value::computed_value::ExplicitSize;
|
||||||
match (self, other) {
|
match (self, other) {
|
||||||
|
@ -227,9 +227,7 @@ ${helpers.single_keyword("background-origin",
|
||||||
_ => Err(()),
|
_ => Err(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl ComputeDistance for T {
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||||
self.compute_squared_distance(other).map(|sd| sd.sqrt())
|
self.compute_squared_distance(other).map(|sd| sd.sqrt())
|
||||||
|
|
|
@ -2181,7 +2181,7 @@ ${helpers.single_keyword("transform-style",
|
||||||
use values::specified::{NoCalcLength, LengthOrPercentage, Percentage};
|
use values::specified::{NoCalcLength, LengthOrPercentage, Percentage};
|
||||||
|
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
use properties::animated_properties::{ComputeDistance, Interpolate};
|
use properties::animated_properties::Animatable;
|
||||||
use values::computed::{Length, LengthOrPercentage};
|
use values::computed::{Length, LengthOrPercentage};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
|
@ -2192,7 +2192,7 @@ ${helpers.single_keyword("transform-style",
|
||||||
pub depth: Length,
|
pub depth: Length,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Interpolate for T {
|
impl Animatable for T {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
|
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
|
||||||
Ok(T {
|
Ok(T {
|
||||||
|
@ -2201,9 +2201,7 @@ ${helpers.single_keyword("transform-style",
|
||||||
depth: try!(self.depth.interpolate(&other.depth, time)),
|
depth: try!(self.depth.interpolate(&other.depth, time)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl ComputeDistance for T {
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||||
self.compute_squared_distance(other).map(|sd| sd.sqrt())
|
self.compute_squared_distance(other).map(|sd| sd.sqrt())
|
||||||
|
|
|
@ -1022,7 +1022,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
use properties::animated_properties::{ComputeDistance, Interpolate};
|
use properties::animated_properties::Animatable;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
use values::CSSFloat;
|
use values::CSSFloat;
|
||||||
|
@ -1054,7 +1054,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Interpolate for T {
|
impl Animatable for T {
|
||||||
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
|
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
|
||||||
match (*self, *other) {
|
match (*self, *other) {
|
||||||
(T::Number(ref number), T::Number(ref other)) =>
|
(T::Number(ref number), T::Number(ref other)) =>
|
||||||
|
@ -1062,9 +1062,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
_ => Err(()),
|
_ => Err(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl ComputeDistance for T {
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||||
match (*self, *other) {
|
match (*self, *other) {
|
||||||
|
|
|
@ -30,7 +30,7 @@ ${helpers.single_keyword("caption-side", "top bottom",
|
||||||
|
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use properties::animated_properties::{ComputeDistance, Interpolate};
|
use properties::animated_properties::Animatable;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
@ -40,7 +40,7 @@ ${helpers.single_keyword("caption-side", "top bottom",
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://drafts.csswg.org/css-transitions/#animtype-simple-list
|
/// https://drafts.csswg.org/css-transitions/#animtype-simple-list
|
||||||
impl Interpolate for T {
|
impl Animatable for T {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
|
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
|
||||||
Ok(T {
|
Ok(T {
|
||||||
|
@ -48,9 +48,7 @@ ${helpers.single_keyword("caption-side", "top bottom",
|
||||||
vertical: try!(self.vertical.interpolate(&other.vertical, time)),
|
vertical: try!(self.vertical.interpolate(&other.vertical, time)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl ComputeDistance for T {
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||||
self.compute_squared_distance(other).map(|sd| sd.sqrt())
|
self.compute_squared_distance(other).map(|sd| sd.sqrt())
|
||||||
|
|
|
@ -441,14 +441,13 @@ ${helpers.single_keyword("text-align-last",
|
||||||
|
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use properties::animated_properties::{ComputeDistance, Interpolate};
|
use properties::animated_properties::Animatable;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
pub struct T(pub Option<Au>);
|
pub struct T(pub Option<Au>);
|
||||||
|
|
||||||
${helpers.impl_interpolate_for_option_tuple('Au(0)')}
|
${helpers.impl_animatable_for_option_tuple('Au(0)')}
|
||||||
${helpers.impl_compute_distance_for_option_tuple('Au(0)')}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for computed_value::T {
|
impl ToCss for computed_value::T {
|
||||||
|
@ -527,14 +526,13 @@ ${helpers.single_keyword("text-align-last",
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
use properties::animated_properties::{ComputeDistance, Interpolate};
|
use properties::animated_properties::Animatable;
|
||||||
use values::computed::LengthOrPercentage;
|
use values::computed::LengthOrPercentage;
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
pub struct T(pub Option<LengthOrPercentage>);
|
pub struct T(pub Option<LengthOrPercentage>);
|
||||||
|
|
||||||
${helpers.impl_interpolate_for_option_tuple('LengthOrPercentage::zero()')}
|
${helpers.impl_animatable_for_option_tuple('LengthOrPercentage::zero()')}
|
||||||
${helpers.impl_compute_distance_for_option_tuple('LengthOrPercentage::zero()')}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for computed_value::T {
|
impl ToCss for computed_value::T {
|
||||||
|
|
|
@ -99,24 +99,17 @@ ${helpers.single_keyword("mask-mode",
|
||||||
pub use properties::longhands::background_position_x::single_value::parse;
|
pub use properties::longhands::background_position_x::single_value::parse;
|
||||||
pub use properties::longhands::background_position_x::single_value::SpecifiedValue;
|
pub use properties::longhands::background_position_x::single_value::SpecifiedValue;
|
||||||
pub use properties::longhands::background_position_x::single_value::computed_value;
|
pub use properties::longhands::background_position_x::single_value::computed_value;
|
||||||
use properties::animated_properties::{ComputeDistance, Interpolate, RepeatableListInterpolate};
|
use properties::animated_properties::{Animatable, RepeatableListAnimatable};
|
||||||
use properties::longhands::mask_position_x::computed_value::T as MaskPositionX;
|
use properties::longhands::mask_position_x::computed_value::T as MaskPositionX;
|
||||||
|
|
||||||
impl Interpolate for MaskPositionX {
|
impl Animatable for MaskPositionX {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
|
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
|
||||||
Ok(MaskPositionX(try!(self.0.interpolate(&other.0, progress))))
|
Ok(MaskPositionX(try!(self.0.interpolate(&other.0, progress))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RepeatableListInterpolate for MaskPositionX {}
|
impl RepeatableListAnimatable for MaskPositionX {}
|
||||||
|
|
||||||
impl ComputeDistance for MaskPositionX {
|
|
||||||
#[inline]
|
|
||||||
fn compute_distance(&self, _other: &Self) -> Result<f64, ()> {
|
|
||||||
Err(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</%helpers:vector_longhand>
|
</%helpers:vector_longhand>
|
||||||
|
|
||||||
<%helpers:vector_longhand name="mask-position-y" products="gecko"
|
<%helpers:vector_longhand name="mask-position-y" products="gecko"
|
||||||
|
@ -128,24 +121,17 @@ ${helpers.single_keyword("mask-mode",
|
||||||
pub use properties::longhands::background_position_y::single_value::parse;
|
pub use properties::longhands::background_position_y::single_value::parse;
|
||||||
pub use properties::longhands::background_position_y::single_value::SpecifiedValue;
|
pub use properties::longhands::background_position_y::single_value::SpecifiedValue;
|
||||||
pub use properties::longhands::background_position_y::single_value::computed_value;
|
pub use properties::longhands::background_position_y::single_value::computed_value;
|
||||||
use properties::animated_properties::{ComputeDistance, Interpolate, RepeatableListInterpolate};
|
use properties::animated_properties::{Animatable, RepeatableListAnimatable};
|
||||||
use properties::longhands::mask_position_y::computed_value::T as MaskPositionY;
|
use properties::longhands::mask_position_y::computed_value::T as MaskPositionY;
|
||||||
|
|
||||||
impl Interpolate for MaskPositionY {
|
impl Animatable for MaskPositionY {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
|
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
|
||||||
Ok(MaskPositionY(try!(self.0.interpolate(&other.0, progress))))
|
Ok(MaskPositionY(try!(self.0.interpolate(&other.0, progress))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RepeatableListInterpolate for MaskPositionY {}
|
impl RepeatableListAnimatable for MaskPositionY {}
|
||||||
|
|
||||||
impl ComputeDistance for MaskPositionY {
|
|
||||||
#[inline]
|
|
||||||
fn compute_distance(&self, _other: &Self) -> Result<f64, ()> {
|
|
||||||
Err(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</%helpers:vector_longhand>
|
</%helpers:vector_longhand>
|
||||||
|
|
||||||
${helpers.single_keyword("mask-clip",
|
${helpers.single_keyword("mask-clip",
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
use Atom;
|
use Atom;
|
||||||
pub use cssparser::{RGBA, Token, Parser, serialize_identifier, serialize_string};
|
pub use cssparser::{RGBA, Token, Parser, serialize_identifier, serialize_string};
|
||||||
use parser::{Parse, ParserContext};
|
use parser::{Parse, ParserContext};
|
||||||
use properties::animated_properties::{ComputeDistance, Interpolate};
|
use properties::animated_properties::Animatable;
|
||||||
use std::ascii::AsciiExt;
|
use std::ascii::AsciiExt;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::fmt::{self, Debug};
|
use std::fmt::{self, Debug};
|
||||||
|
@ -127,20 +127,13 @@ macro_rules! define_keyword_type {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Interpolate for $name {
|
impl Animatable for $name {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn interpolate(&self, _other: &Self, _progress: f64) -> Result<Self, ()> {
|
fn interpolate(&self, _other: &Self, _progress: f64) -> Result<Self, ()> {
|
||||||
Ok($name)
|
Ok($name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ComputeDistance for $name {
|
|
||||||
#[inline]
|
|
||||||
fn compute_distance(&self, _other: &Self) -> Result<f64, ()> {
|
|
||||||
Err(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for $name {
|
impl fmt::Debug for $name {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, $css)
|
write!(f, $css)
|
||||||
|
|
|
@ -75,7 +75,7 @@ use style::parser::{LengthParsingMode, ParserContext};
|
||||||
use style::properties::{CascadeFlags, ComputedValues, Importance, ParsedDeclaration, StyleBuilder};
|
use style::properties::{CascadeFlags, ComputedValues, Importance, ParsedDeclaration, StyleBuilder};
|
||||||
use style::properties::{PropertyDeclarationBlock, PropertyId};
|
use style::properties::{PropertyDeclarationBlock, PropertyId};
|
||||||
use style::properties::SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP;
|
use style::properties::SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP;
|
||||||
use style::properties::animated_properties::{AnimationValue, ComputeDistance, Interpolate, TransitionProperty};
|
use style::properties::animated_properties::{Animatable, AnimationValue, TransitionProperty};
|
||||||
use style::properties::parse_one_declaration;
|
use style::properties::parse_one_declaration;
|
||||||
use style::restyle_hints::{self, RestyleHint};
|
use style::restyle_hints::{self, RestyleHint};
|
||||||
use style::rule_tree::{StrongRuleNode, StyleSource};
|
use style::rule_tree::{StrongRuleNode, StyleSource};
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use cssparser::{Color, RGBA};
|
use cssparser::{Color, RGBA};
|
||||||
use style::properties::animated_properties::Interpolate;
|
use style::properties::animated_properties::Animatable;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rgba_color_interepolation_preserves_transparent() {
|
fn test_rgba_color_interepolation_preserves_transparent() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue