mirror of
https://github.com/servo/servo.git
synced 2025-08-07 22:45:34 +01:00
Introduce values::animated::Animate
This replaces the Animatable trait and merges its three former methods into a single one.
This commit is contained in:
parent
0cceeb9d5c
commit
aea0cd7ec7
23 changed files with 876 additions and 937 deletions
|
@ -4,16 +4,17 @@
|
|||
|
||||
use app_units::Au;
|
||||
use cssparser::RGBA;
|
||||
use style::properties::animated_properties::Animatable;
|
||||
use style::properties::longhands::transform::computed_value::ComputedOperation as TransformOperation;
|
||||
use style::properties::longhands::transform::computed_value::T as TransformList;
|
||||
use style::values::animated::ToAnimatedValue;
|
||||
use style::values::animated::{Animate, Procedure, ToAnimatedValue};
|
||||
use style::values::computed::Percentage;
|
||||
|
||||
fn interpolate_rgba(from: RGBA, to: RGBA, progress: f64) -> RGBA {
|
||||
let from = from.to_animated_value();
|
||||
let to = to.to_animated_value();
|
||||
RGBA::from_animated_value(from.interpolate(&to, progress).unwrap())
|
||||
RGBA::from_animated_value(
|
||||
from.animate(&to, Procedure::Interpolate { progress }).unwrap(),
|
||||
)
|
||||
}
|
||||
|
||||
// Color
|
||||
|
@ -74,11 +75,14 @@ fn test_transform_interpolation_on_translate() {
|
|||
TransformOperation::Translate(LengthOrPercentage::Length(Au(100)),
|
||||
LengthOrPercentage::Length(Au(0)),
|
||||
Au(75))]));
|
||||
assert_eq!(from.interpolate(&to, 0.5).unwrap(),
|
||||
TransformList(Some(vec![
|
||||
TransformOperation::Translate(LengthOrPercentage::Length(Au(50)),
|
||||
LengthOrPercentage::Length(Au(50)),
|
||||
Au(50))])));
|
||||
assert_eq!(
|
||||
from.animate(&to, Procedure::Interpolate { progress: 0.5 }).unwrap(),
|
||||
TransformList(Some(vec![TransformOperation::Translate(
|
||||
LengthOrPercentage::Length(Au(50)),
|
||||
LengthOrPercentage::Length(Au(50)),
|
||||
Au(50),
|
||||
)]))
|
||||
);
|
||||
|
||||
let from = TransformList(Some(vec![TransformOperation::Translate(
|
||||
LengthOrPercentage::Percentage(Percentage(0.5)),
|
||||
|
@ -90,7 +94,7 @@ fn test_transform_interpolation_on_translate() {
|
|||
LengthOrPercentage::Length(Au(50)),
|
||||
Au(75))]));
|
||||
assert_eq!(
|
||||
from.interpolate(&to, 0.5).unwrap(),
|
||||
from.animate(&to, Procedure::Interpolate { progress: 0.5 }).unwrap(),
|
||||
TransformList(Some(vec![TransformOperation::Translate(
|
||||
// calc(50px + 25%)
|
||||
LengthOrPercentage::Calc(CalcLengthOrPercentage::new(Au(50), Some(Percentage(0.25)))),
|
||||
|
@ -105,8 +109,10 @@ fn test_transform_interpolation_on_translate() {
|
|||
fn test_transform_interpolation_on_scale() {
|
||||
let from = TransformList(Some(vec![TransformOperation::Scale(1.0, 2.0, 1.0)]));
|
||||
let to = TransformList(Some(vec![TransformOperation::Scale(2.0, 4.0, 2.0)]));
|
||||
assert_eq!(from.interpolate(&to, 0.5).unwrap(),
|
||||
TransformList(Some(vec![TransformOperation::Scale(1.5, 3.0, 1.5)])));
|
||||
assert_eq!(
|
||||
from.animate(&to, Procedure::Interpolate { progress: 0.5 }).unwrap(),
|
||||
TransformList(Some(vec![TransformOperation::Scale(1.5, 3.0, 1.5)]))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -117,9 +123,12 @@ fn test_transform_interpolation_on_rotate() {
|
|||
Angle::from_radians(0.0))]));
|
||||
let to = TransformList(Some(vec![TransformOperation::Rotate(0.0, 0.0, 1.0,
|
||||
Angle::from_radians(100.0))]));
|
||||
assert_eq!(from.interpolate(&to, 0.5).unwrap(),
|
||||
TransformList(Some(vec![TransformOperation::Rotate(0.0, 0.0, 1.0,
|
||||
Angle::from_radians(50.0))])));
|
||||
assert_eq!(
|
||||
from.animate(&to, Procedure::Interpolate { progress: 0.5 }).unwrap(),
|
||||
TransformList(Some(vec![
|
||||
TransformOperation::Rotate(0.0, 0.0, 1.0, Angle::from_radians(50.0)),
|
||||
]))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -130,9 +139,13 @@ fn test_transform_interpolation_on_skew() {
|
|||
Angle::from_radians(100.0))]));
|
||||
let to = TransformList(Some(vec![TransformOperation::Skew(Angle::from_radians(100.0),
|
||||
Angle::from_radians(0.0))]));
|
||||
assert_eq!(from.interpolate(&to, 0.5).unwrap(),
|
||||
TransformList(Some(vec![TransformOperation::Skew(Angle::from_radians(50.0),
|
||||
Angle::from_radians(50.0))])));
|
||||
assert_eq!(
|
||||
from.animate(&to, Procedure::Interpolate { progress: 0.5 }).unwrap(),
|
||||
TransformList(Some(vec![TransformOperation::Skew(
|
||||
Angle::from_radians(50.0),
|
||||
Angle::from_radians(50.0),
|
||||
)]))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -146,7 +159,7 @@ fn test_transform_interpolation_on_mismatched_lists() {
|
|||
LengthOrPercentage::Length(Au(0)),
|
||||
Au(0))]));
|
||||
assert_eq!(
|
||||
from.interpolate(&to, 0.5).unwrap(),
|
||||
from.animate(&to, Procedure::Interpolate { progress: 0.5 }).unwrap(),
|
||||
TransformList(Some(vec![TransformOperation::InterpolateMatrix {
|
||||
from_list: from.clone(),
|
||||
to_list: to.clone(),
|
||||
|
|
|
@ -5,16 +5,14 @@
|
|||
use cssparser::SourceLocation;
|
||||
use euclid::ScaleFactor;
|
||||
use euclid::TypedSize2D;
|
||||
use html5ever::LocalName;
|
||||
use selectors::parser::{AncestorHashes, Selector};
|
||||
use selectors::parser::LocalName as LocalNameSelector;
|
||||
use servo_arc::Arc;
|
||||
use servo_atoms::Atom;
|
||||
use style::context::QuirksMode;
|
||||
use style::media_queries::{Device, MediaType};
|
||||
use style::properties::{PropertyDeclarationBlock, PropertyDeclaration};
|
||||
use style::properties::{longhands, Importance};
|
||||
use style::selector_map::{self, SelectorMap};
|
||||
use style::selector_map::SelectorMap;
|
||||
use style::selector_parser::{SelectorImpl, SelectorParser};
|
||||
use style::shared_lock::SharedRwLock;
|
||||
use style::stylesheets::StyleRule;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue