mirror of
https://github.com/servo/servo.git
synced 2025-08-12 00:45:33 +01:00
style: Cleanup the animated value setup.
We have three different enums to represent slightly different things. Reuse them properly, and kill some code in the animated_properties module while at it. MozReview-Commit-ID: 5ZAly8f4lWy Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
This commit is contained in:
parent
0212c5d230
commit
3215e36b5b
12 changed files with 571 additions and 689 deletions
|
@ -4,13 +4,23 @@
|
|||
|
||||
use cssparser::SourceLocation;
|
||||
use servo_arc::Arc;
|
||||
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, Importance};
|
||||
use style::properties::animated_properties::AnimatableLonghand;
|
||||
use style::properties::{LonghandId, LonghandIdSet, PropertyDeclaration, PropertyDeclarationBlock, Importance};
|
||||
use style::shared_lock::SharedRwLock;
|
||||
use style::stylesheets::keyframes_rule::{Keyframe, KeyframesAnimation, KeyframePercentage, KeyframeSelector};
|
||||
use style::stylesheets::keyframes_rule::{KeyframesStep, KeyframesStepValue};
|
||||
use style::values::specified::{LengthOrPercentageOrAuto, NoCalcLength};
|
||||
|
||||
macro_rules! longhand_set {
|
||||
($($word:ident),+) => {{
|
||||
let mut set = LonghandIdSet::new();
|
||||
$(
|
||||
set.insert(LonghandId::$word);
|
||||
)+
|
||||
set
|
||||
}}
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_empty_keyframe() {
|
||||
let shared_lock = SharedRwLock::new();
|
||||
|
@ -20,7 +30,7 @@ fn test_empty_keyframe() {
|
|||
&shared_lock.read());
|
||||
let expected = KeyframesAnimation {
|
||||
steps: vec![],
|
||||
properties_changed: vec![],
|
||||
properties_changed: LonghandIdSet::new(),
|
||||
vendor_prefix: None,
|
||||
};
|
||||
|
||||
|
@ -43,7 +53,7 @@ fn test_no_property_in_keyframe() {
|
|||
&shared_lock.read());
|
||||
let expected = KeyframesAnimation {
|
||||
steps: vec![],
|
||||
properties_changed: vec![],
|
||||
properties_changed: LonghandIdSet::new(),
|
||||
vendor_prefix: None,
|
||||
};
|
||||
|
||||
|
@ -106,7 +116,7 @@ fn test_missing_property_in_initial_keyframe() {
|
|||
declared_timing_function: false,
|
||||
},
|
||||
],
|
||||
properties_changed: vec![AnimatableLonghand::Width, AnimatableLonghand::Height],
|
||||
properties_changed: longhand_set!(Width, Height),
|
||||
vendor_prefix: None,
|
||||
};
|
||||
|
||||
|
@ -169,7 +179,7 @@ fn test_missing_property_in_final_keyframe() {
|
|||
declared_timing_function: false,
|
||||
},
|
||||
],
|
||||
properties_changed: vec![AnimatableLonghand::Width, AnimatableLonghand::Height],
|
||||
properties_changed: longhand_set!(Width, Height),
|
||||
vendor_prefix: None,
|
||||
};
|
||||
|
||||
|
@ -234,7 +244,7 @@ fn test_missing_keyframe_in_both_of_initial_and_final_keyframe() {
|
|||
declared_timing_function: false,
|
||||
}
|
||||
],
|
||||
properties_changed: vec![AnimatableLonghand::Width, AnimatableLonghand::Height],
|
||||
properties_changed: longhand_set!(Width, Height),
|
||||
vendor_prefix: None,
|
||||
};
|
||||
|
||||
|
|
|
@ -119,6 +119,5 @@ mod selectors;
|
|||
mod supports;
|
||||
mod text_overflow;
|
||||
mod transition_duration;
|
||||
mod transition_property;
|
||||
mod transition_timing_function;
|
||||
mod value;
|
||||
|
|
|
@ -1,97 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use parsing::parse;
|
||||
use servo_atoms::Atom;
|
||||
use style::properties::animated_properties::TransitionProperty;
|
||||
use style::properties::longhands::transition_property;
|
||||
use style::properties::shorthands::transition;
|
||||
use style::values::CustomIdent;
|
||||
use style_traits::ToCss;
|
||||
|
||||
#[test]
|
||||
fn test_longhand_properties() {
|
||||
assert_roundtrip_with_context!(transition_property::parse, "margin-left");
|
||||
assert_roundtrip_with_context!(transition_property::parse, "background-color");
|
||||
assert_roundtrip_with_context!(transition_property::parse, "width");
|
||||
assert_roundtrip_with_context!(transition_property::parse, "transition-duration");
|
||||
assert_roundtrip_with_context!(transition_property::parse, "unsupported-property");
|
||||
assert_roundtrip_with_context!(transition_property::parse, "-other-unsupported-property");
|
||||
assert_roundtrip_with_context!(transition_property::parse, "--var");
|
||||
|
||||
assert_eq!(
|
||||
parse_longhand!(transition_property, "margin-left, transition-delay, width, --var"),
|
||||
transition_property::SpecifiedValue(vec![
|
||||
TransitionProperty::MarginLeft,
|
||||
TransitionProperty::Unsupported(CustomIdent(Atom::from("transition-delay"))),
|
||||
TransitionProperty::Width,
|
||||
TransitionProperty::Unsupported(CustomIdent(Atom::from("--var"))),
|
||||
])
|
||||
);
|
||||
|
||||
assert!(parse(transition_property::parse, ".width").is_err());
|
||||
assert!(parse(transition_property::parse, "1width").is_err());
|
||||
assert!(parse(transition_property::parse, "- ").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_shorthand_properties() {
|
||||
assert_roundtrip_with_context!(transition_property::parse, "margin");
|
||||
assert_roundtrip_with_context!(transition_property::parse, "background");
|
||||
assert_roundtrip_with_context!(transition_property::parse, "border-bottom");
|
||||
|
||||
assert_eq!(parse_longhand!(transition_property, "margin, background"),
|
||||
transition_property::SpecifiedValue(
|
||||
vec![TransitionProperty::Margin,
|
||||
TransitionProperty::Background]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_keywords() {
|
||||
assert_roundtrip_with_context!(transition_property::parse, "all");
|
||||
assert_roundtrip_with_context!(transition_property::parse, "none");
|
||||
|
||||
assert_eq!(parse_longhand!(transition_property, "all"),
|
||||
transition_property::SpecifiedValue(vec![TransitionProperty::All]));
|
||||
assert_eq!(parse_longhand!(transition_property, "width, all"),
|
||||
transition_property::SpecifiedValue(vec![TransitionProperty::Width,
|
||||
TransitionProperty::All]));
|
||||
|
||||
// Using CSS Wide Keyword or none in the list will get the syntax invalid.
|
||||
// Note: Only "none" alone is valid.
|
||||
assert!(parse(transition_property::parse, "none").is_ok());
|
||||
assert_eq!(parse_longhand!(transition_property, "none"),
|
||||
transition_property::SpecifiedValue(vec![]));
|
||||
assert!(parse(transition_property::parse, "inherit").is_err());
|
||||
assert!(parse(transition_property::parse, "initial").is_err());
|
||||
assert!(parse(transition_property::parse, "unset").is_err());
|
||||
assert!(parse(transition_property::parse, "width, none").is_err());
|
||||
assert!(parse(transition_property::parse, "width, initial").is_err());
|
||||
assert!(parse(transition_property::parse, "width, inherit").is_err());
|
||||
assert!(parse(transition_property::parse, "width, unset").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_transition_shorthand() {
|
||||
let result = parse(transition::parse_value, "2s margin-left, 4s background").unwrap();
|
||||
assert_eq!(result.transition_property,
|
||||
parse_longhand!(transition_property, "margin-left, background"));
|
||||
|
||||
let result = parse(transition::parse_value, "2s margin, 4s all").unwrap();
|
||||
assert_eq!(result.transition_property,
|
||||
parse_longhand!(transition_property, "margin, all"));
|
||||
|
||||
let result = parse(transition::parse_value, "2s width, 3s --var, 4s background").unwrap();
|
||||
assert_eq!(result.transition_property,
|
||||
parse_longhand!(transition_property, "width, --var, background"));
|
||||
|
||||
let result = parse(transition::parse_value, "none").unwrap();
|
||||
assert_eq!(result.transition_property,
|
||||
parse_longhand!(transition_property, "none"));
|
||||
|
||||
assert!(parse(transition::parse_value, "2s width, none").is_err());
|
||||
assert!(parse(transition::parse_value, "2s width, 2s initial").is_err());
|
||||
assert!(parse(transition::parse_value, "2s width, 3s unset").is_err());
|
||||
assert!(parse(transition::parse_value, "2s width, 4s inherit").is_err());
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue