mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Adds scroll-snap-type shorthand property, tests
This commit is contained in:
parent
75d35241db
commit
bdedcb9eb4
2 changed files with 83 additions and 0 deletions
|
@ -297,3 +297,37 @@ macro_rules! try_parse_one {
|
|||
}
|
||||
}
|
||||
</%helpers:shorthand>
|
||||
|
||||
<%helpers:shorthand name="scroll-snap-type" products="gecko"
|
||||
sub_properties="scroll-snap-type-x scroll-snap-type-y">
|
||||
use properties::longhands::scroll_snap_type_x;
|
||||
|
||||
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
|
||||
let result = try!(scroll_snap_type_x::parse(context, input));
|
||||
Ok(Longhands {
|
||||
scroll_snap_type_x: Some(result),
|
||||
scroll_snap_type_y: Some(result),
|
||||
})
|
||||
}
|
||||
|
||||
impl<'a> LonghandsToSerialize<'a> {
|
||||
// Serializes into the single keyword value if both scroll-snap-type and scroll-snap-type-y are same.
|
||||
// Otherwise into an empty string. This is done to match Gecko's behaviour.
|
||||
fn to_css_declared<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
let x_and_y_equal = match (self.scroll_snap_type_x, self.scroll_snap_type_y) {
|
||||
(&DeclaredValue::Value(ref x_value), &DeclaredValue::Value(ref y_value)) => {
|
||||
*x_value == *y_value
|
||||
},
|
||||
(&DeclaredValue::Initial, &DeclaredValue::Initial) => true,
|
||||
(&DeclaredValue::Inherit, &DeclaredValue::Inherit) => true,
|
||||
(x, y) => { *x == *y },
|
||||
};
|
||||
|
||||
if x_and_y_equal {
|
||||
self.scroll_snap_type_x.to_css(dest)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
</%helpers:shorthand>
|
||||
|
|
|
@ -1006,4 +1006,53 @@ mod shorthand_serialization {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod scroll_snap_type {
|
||||
pub use super::*;
|
||||
use style::properties::longhands::scroll_snap_type_x::computed_value::T as ScrollSnapTypeXValue;
|
||||
|
||||
#[test]
|
||||
fn should_serialize_to_empty_string_if_sub_types_not_equal() {
|
||||
let declarations = vec![
|
||||
(PropertyDeclaration::ScrollSnapTypeX(DeclaredValue::Value(ScrollSnapTypeXValue::mandatory)),
|
||||
Importance::Normal),
|
||||
(PropertyDeclaration::ScrollSnapTypeY(DeclaredValue::Value(ScrollSnapTypeXValue::none)),
|
||||
Importance::Normal)
|
||||
];
|
||||
|
||||
let block = PropertyDeclarationBlock {
|
||||
declarations: declarations,
|
||||
important_count: 0
|
||||
};
|
||||
|
||||
let mut s = String::new();
|
||||
|
||||
let x = block.single_value_to_css("scroll-snap-type", &mut s);
|
||||
|
||||
assert_eq!(x.is_ok(), true);
|
||||
assert_eq!(s, "scroll-snap-type: ;");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_serialize_to_single_value_if_sub_types_are_equal() {
|
||||
let declarations = vec![
|
||||
(PropertyDeclaration::ScrollSnapTypeX(DeclaredValue::Value(ScrollSnapTypeXValue::mandatory)),
|
||||
Importance::Normal),
|
||||
(PropertyDeclaration::ScrollSnapTypeY(DeclaredValue::Value(ScrollSnapTypeXValue::mandatory)),
|
||||
Importance::Normal)
|
||||
];
|
||||
|
||||
let block = PropertyDeclarationBlock {
|
||||
declarations: declarations,
|
||||
important_count: 0
|
||||
};
|
||||
|
||||
let mut s = String::new();
|
||||
|
||||
let x = block.single_value_to_css("scroll-snap-type", &mut s);
|
||||
|
||||
assert_eq!(x.is_ok(), true);
|
||||
assert_eq!(s, "scroll-snap-type: mandatory;");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue