mirror of
https://github.com/servo/servo.git
synced 2025-09-03 19:48:21 +01:00
Auto merge of #14104 - iamrohit7:scroll-snap-type, r=Manishearth,waffles
Adds scroll-snap-type shorthand property <!-- Please describe your changes on the following line: --> Follow up to #14017 --- r=Manishearth <!-- 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] There are tests for these changes `scroll_snap_type::should_serialize_to_single_value_if_sub_types_are_equal`, `scroll_snap_type::should_serialize_to_empty_string_if_sub_types_not_equal` <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- 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/14104) <!-- Reviewable:end -->
This commit is contained in:
commit
3959817424
5 changed files with 103 additions and 16 deletions
|
@ -214,16 +214,13 @@ impl PropertyDeclarationBlock {
|
||||||
if !self.declarations.iter().all(|decl| decl.0.shorthands().contains(&shorthand)) {
|
if !self.declarations.iter().all(|decl| decl.0.shorthands().contains(&shorthand)) {
|
||||||
return Err(fmt::Error)
|
return Err(fmt::Error)
|
||||||
}
|
}
|
||||||
let success = try!(shorthand.serialize_shorthand_to_buffer(
|
let iter = self.declarations.iter().map(get_declaration as fn(_) -> _);
|
||||||
dest,
|
match shorthand.get_shorthand_appendable_value(iter) {
|
||||||
self.declarations.iter()
|
Some(AppendableValue::Css(css)) => dest.write_str(css),
|
||||||
.map(get_declaration as fn(_) -> _),
|
Some(AppendableValue::DeclarationsForShorthand(_, decls)) => {
|
||||||
&mut true)
|
shorthand.longhands_to_css(decls, dest)
|
||||||
);
|
}
|
||||||
if success {
|
_ => Ok(())
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err(fmt::Error)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -978,7 +978,8 @@ fn static_assert() {
|
||||||
|
|
||||||
<% skip_box_longhands= """display overflow-y vertical-align
|
<% skip_box_longhands= """display overflow-y vertical-align
|
||||||
-moz-binding page-break-before page-break-after
|
-moz-binding page-break-before page-break-after
|
||||||
scroll-snap-points-x scroll-snap-points-y transform""" %>
|
scroll-snap-points-x scroll-snap-points-y transform
|
||||||
|
scroll-snap-type-y""" %>
|
||||||
<%self:impl_trait style_struct_name="Box" skip_longhands="${skip_box_longhands}">
|
<%self:impl_trait style_struct_name="Box" skip_longhands="${skip_box_longhands}">
|
||||||
|
|
||||||
// We manually-implement the |display| property until we get general
|
// We manually-implement the |display| property until we get general
|
||||||
|
@ -1220,6 +1221,11 @@ fn static_assert() {
|
||||||
pub fn copy_transform_from(&mut self, other: &Self) {
|
pub fn copy_transform_from(&mut self, other: &Self) {
|
||||||
unsafe { self.gecko.mSpecifiedTransform.set(&other.gecko.mSpecifiedTransform); }
|
unsafe { self.gecko.mSpecifiedTransform.set(&other.gecko.mSpecifiedTransform); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<% scroll_snap_type_keyword = Keyword("scroll-snap-type", "none mandatory proximity") %>
|
||||||
|
|
||||||
|
${impl_keyword('scroll_snap_type_y', 'mScrollSnapTypeY', scroll_snap_type_keyword, need_clone=False)}
|
||||||
|
|
||||||
</%self:impl_trait>
|
</%self:impl_trait>
|
||||||
|
|
||||||
<%def name="simple_image_array_property(name, shorthand, field_name)">
|
<%def name="simple_image_array_property(name, shorthand, field_name)">
|
||||||
|
|
|
@ -1474,11 +1474,12 @@ ${helpers.single_keyword("scroll-snap-type-x",
|
||||||
animatable=False)}
|
animatable=False)}
|
||||||
|
|
||||||
// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-snap-type-y
|
// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-snap-type-y
|
||||||
${helpers.single_keyword("scroll-snap-type-y",
|
<%helpers:longhand products="gecko" name="scroll-snap-type-y" animatable="False">
|
||||||
"none mandatory proximity",
|
pub use super::scroll_snap_type_x::SpecifiedValue;
|
||||||
products="gecko",
|
pub use super::scroll_snap_type_x::computed_value;
|
||||||
gecko_constant_prefix="NS_STYLE_SCROLL_SNAP_TYPE",
|
pub use super::scroll_snap_type_x::get_initial_value;
|
||||||
animatable=False)}
|
pub use super::scroll_snap_type_x::parse;
|
||||||
|
</%helpers:longhand>
|
||||||
|
|
||||||
// Compositing and Blending Level 1
|
// Compositing and Blending Level 1
|
||||||
// http://www.w3.org/TR/compositing-1/
|
// http://www.w3.org/TR/compositing-1/
|
||||||
|
|
|
@ -297,3 +297,37 @@ macro_rules! try_parse_one {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</%helpers:shorthand>
|
</%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, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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, "mandatory");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue