Skip to content

Commit a9cb635

Browse files
committed
Use generics for scroll-snap-points-*
1 parent bc1eef8 commit a9cb635

File tree

9 files changed

+131
-110
lines changed

9 files changed

+131
-110
lines changed

components/style/properties/gecko.mako.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,23 +2232,16 @@ fn static_assert() {
22322232
}
22332233
% endfor
22342234

2235-
pub fn set_scroll_snap_points_x(&mut self, v: longhands::scroll_snap_points_x::computed_value::T) {
2236-
match v.0 {
2237-
None => self.gecko.mScrollSnapPointsX.set_value(CoordDataValue::None),
2238-
Some(l) => l.to_gecko_style_coord(&mut self.gecko.mScrollSnapPointsX),
2239-
};
2240-
}
2241-
2242-
${impl_coord_copy('scroll_snap_points_x', 'mScrollSnapPointsX')}
2243-
2244-
pub fn set_scroll_snap_points_y(&mut self, v: longhands::scroll_snap_points_y::computed_value::T) {
2245-
match v.0 {
2246-
None => self.gecko.mScrollSnapPointsY.set_value(CoordDataValue::None),
2247-
Some(l) => l.to_gecko_style_coord(&mut self.gecko.mScrollSnapPointsY),
2248-
};
2249-
}
2235+
% for axis in ["x", "y"]:
2236+
pub fn set_scroll_snap_points_${axis}(&mut self, v: longhands::scroll_snap_points_${axis}::computed_value::T) {
2237+
match v.repeated() {
2238+
None => self.gecko.mScrollSnapPoints${axis.upper()}.set_value(CoordDataValue::None),
2239+
Some(l) => l.to_gecko_style_coord(&mut self.gecko.mScrollSnapPoints${axis.upper()}),
2240+
};
2241+
}
22502242

2251-
${impl_coord_copy('scroll_snap_points_y', 'mScrollSnapPointsY')}
2243+
${impl_coord_copy('scroll_snap_points_' + axis, 'mScrollSnapPoints' + axis.upper())}
2244+
% endfor
22522245

22532246
pub fn set_scroll_snap_coordinate<I>(&mut self, v: I)
22542247
where I: IntoIterator<Item = longhands::scroll_snap_coordinate::computed_value::single_value::T>,

components/style/properties/longhand/box.mako.rs

Lines changed: 10 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -650,99 +650,16 @@ ${helpers.predefined_type("animation-delay",
650650
spec="https://drafts.csswg.org/css-animations/#propdef-animation-delay",
651651
allowed_in_keyframe_block=False)}
652652

653-
<%helpers:longhand products="gecko" name="scroll-snap-points-y" animation_value_type="none"
654-
spec="Nonstandard (https://www.w3.org/TR/2015/WD-css-snappoints-1-20150326/#scroll-snap-points)">
655-
use std::fmt;
656-
use style_traits::ToCss;
657-
use values::specified::LengthOrPercentage;
658-
659-
pub mod computed_value {
660-
use values::computed::LengthOrPercentage;
661-
662-
#[derive(Debug, Clone, PartialEq)]
663-
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
664-
pub struct T(pub Option<LengthOrPercentage>);
665-
}
666-
667-
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
668-
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
669-
pub enum SpecifiedValue {
670-
None,
671-
Repeat(LengthOrPercentage),
672-
}
673-
674-
impl ToCss for computed_value::T {
675-
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
676-
match self.0 {
677-
None => dest.write_str("none"),
678-
Some(ref l) => {
679-
try!(dest.write_str("repeat("));
680-
try!(l.to_css(dest));
681-
dest.write_str(")")
682-
},
683-
}
684-
}
685-
}
686-
impl ToCss for SpecifiedValue {
687-
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
688-
match *self {
689-
SpecifiedValue::None => dest.write_str("none"),
690-
SpecifiedValue::Repeat(ref l) => {
691-
try!(dest.write_str("repeat("));
692-
try!(l.to_css(dest));
693-
dest.write_str(")")
694-
},
695-
}
696-
}
697-
}
698-
699-
#[inline]
700-
pub fn get_initial_value() -> computed_value::T {
701-
computed_value::T(None)
702-
}
703-
704-
impl ToComputedValue for SpecifiedValue {
705-
type ComputedValue = computed_value::T;
706-
707-
#[inline]
708-
fn to_computed_value(&self, context: &Context) -> computed_value::T {
709-
match *self {
710-
SpecifiedValue::None => computed_value::T(None),
711-
SpecifiedValue::Repeat(ref l) =>
712-
computed_value::T(Some(l.to_computed_value(context))),
713-
}
714-
}
715-
#[inline]
716-
fn from_computed_value(computed: &computed_value::T) -> Self {
717-
match *computed {
718-
computed_value::T(None) => SpecifiedValue::None,
719-
computed_value::T(Some(l)) =>
720-
SpecifiedValue::Repeat(ToComputedValue::from_computed_value(&l))
721-
}
722-
}
723-
}
724-
725-
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
726-
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
727-
Ok(SpecifiedValue::None)
728-
} else if input.try(|input| input.expect_function_matching("repeat")).is_ok() {
729-
input.parse_nested_block(|input| {
730-
LengthOrPercentage::parse_non_negative(context, input).map(SpecifiedValue::Repeat)
731-
})
732-
} else {
733-
Err(())
734-
}
735-
}
736-
</%helpers:longhand>
737-
738-
<%helpers:longhand products="gecko" name="scroll-snap-points-x" animation_value_type="none"
739-
spec="Nonstandard (https://www.w3.org/TR/2015/WD-css-snappoints-1-20150326/#scroll-snap-points)">
740-
pub use super::scroll_snap_points_y::SpecifiedValue;
741-
pub use super::scroll_snap_points_y::computed_value;
742-
pub use super::scroll_snap_points_y::get_initial_value;
743-
pub use super::scroll_snap_points_y::parse;
744-
</%helpers:longhand>
745-
653+
% for axis in ["x", "y"]:
654+
${helpers.predefined_type(
655+
"scroll-snap-points-" + axis,
656+
"ScrollSnapPoint",
657+
"computed::ScrollSnapPoint::none()",
658+
animation_value_type="none",
659+
products="gecko",
660+
spec="Nonstandard (https://www.w3.org/TR/2015/WD-css-snappoints-1-20150326/#scroll-snap-points)",
661+
)}
662+
% endfor
746663

747664
${helpers.predefined_type("scroll-snap-destination",
748665
"Position",
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
//! Computed types for legacy Gecko-only properties.
6+
7+
use values::computed::length::LengthOrPercentage;
8+
use values::generics::gecko::ScrollSnapPoint as GenericScrollSnapPoint;
9+
10+
/// A computed type for scroll snap points.
11+
pub type ScrollSnapPoint = GenericScrollSnapPoint<LengthOrPercentage>;

components/style/values/computed/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ pub use self::background::BackgroundSize;
2828
pub use self::border::{BorderImageSlice, BorderImageWidth, BorderImageSideWidth};
2929
pub use self::border::{BorderRadius, BorderCornerRadius};
3030
pub use self::image::{Gradient, GradientItem, ImageLayer, LineDirection, Image, ImageRect};
31+
#[cfg(feature = "gecko")]
32+
pub use self::gecko::ScrollSnapPoint;
3133
pub use self::rect::LengthOrNumberRect;
3234
pub use super::{Auto, Either, None_};
3335
#[cfg(feature = "gecko")]
@@ -46,6 +48,8 @@ pub mod background;
4648
pub mod basic_shape;
4749
pub mod border;
4850
pub mod image;
51+
#[cfg(feature = "gecko")]
52+
pub mod gecko;
4953
pub mod length;
5054
pub mod position;
5155
pub mod rect;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
//! Generic types for box properties.
6+
7+
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
8+
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue, ToCss)]
9+
pub enum VerticalAlign<LengthOrPercentage>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
//! Generic types for legacy Gecko-only properties that should probably be
6+
//! unshipped at some point in the future.
7+
8+
use std::fmt;
9+
use style_traits::ToCss;
10+
11+
/// A generic value for scroll snap points.
12+
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
13+
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue)]
14+
pub enum ScrollSnapPoint<LengthOrPercentage> {
15+
/// `none`
16+
None,
17+
/// `repeat(<length-or-percentage>)`
18+
Repeat(LengthOrPercentage)
19+
}
20+
21+
impl<L> ScrollSnapPoint<L> {
22+
/// Returns `none`.
23+
#[inline]
24+
pub fn none() -> Self {
25+
ScrollSnapPoint::None
26+
}
27+
28+
/// Returns the repeat argument, if any.
29+
#[inline]
30+
pub fn repeated(&self) -> Option<&L> {
31+
match *self {
32+
ScrollSnapPoint::None => None,
33+
ScrollSnapPoint::Repeat(ref length) => Some(length),
34+
}
35+
}
36+
}
37+
38+
impl<L> ToCss for ScrollSnapPoint<L>
39+
where
40+
L: ToCss,
41+
{
42+
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
43+
where
44+
W: fmt::Write,
45+
{
46+
match *self {
47+
ScrollSnapPoint::None => dest.write_str("none"),
48+
ScrollSnapPoint::Repeat(ref length) => {
49+
dest.write_str("repeat(")?;
50+
length.to_css(dest)?;
51+
dest.write_str(")")
52+
},
53+
}
54+
}
55+
}

components/style/values/generics/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use values::specified::url::SpecifiedUrl;
1616
pub mod background;
1717
pub mod basic_shape;
1818
pub mod border;
19+
#[cfg(feature = "gecko")]
20+
pub mod gecko;
1921
pub mod grid;
2022
pub mod image;
2123
pub mod position;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
//! Specified types for legacy Gecko-only properties.
6+
7+
use cssparser::Parser;
8+
use parser::{Parse, ParserContext};
9+
use values::generics::gecko::ScrollSnapPoint as GenericScrollSnapPoint;
10+
use values::specified::length::LengthOrPercentage;
11+
12+
/// A specified type for scroll snap points.
13+
pub type ScrollSnapPoint = GenericScrollSnapPoint<LengthOrPercentage>;
14+
15+
impl Parse for ScrollSnapPoint {
16+
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
17+
if input.try(|i| i.expect_ident_matching("none")).is_ok() {
18+
return Ok(GenericScrollSnapPoint::None);
19+
}
20+
input.expect_function_matching("repeat")?;
21+
let length = input.parse_nested_block(|i|
22+
LengthOrPercentage::parse_non_negative(context, i)
23+
)?;
24+
Ok(GenericScrollSnapPoint::Repeat(length))
25+
}
26+
}

components/style/values/specified/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth};
3535
pub use self::border::{BorderImageSideWidth, BorderRadius, BorderSideWidth};
3636
pub use self::color::Color;
3737
pub use self::rect::LengthOrNumberRect;
38-
pub use super::generics::grid::GridLine;
38+
#[cfg(feature = "gecko")]
39+
pub use self::gecko::ScrollSnapPoint;
3940
pub use self::image::{ColorStop, EndingShape as GradientEndingShape, Gradient};
4041
pub use self::image::{GradientItem, GradientKind, Image, ImageRect, ImageLayer};
4142
pub use self::length::AbsoluteLength;
@@ -46,6 +47,7 @@ pub use self::length::{MaxLength, MozLength};
4647
pub use self::position::{Position, PositionComponent};
4748
pub use self::text::{LetterSpacing, LineHeight, WordSpacing};
4849
pub use self::transform::{TimingFunction, TransformOrigin};
50+
pub use super::generics::grid::GridLine;
4951

5052
#[cfg(feature = "gecko")]
5153
pub mod align;
@@ -54,6 +56,8 @@ pub mod basic_shape;
5456
pub mod border;
5557
pub mod calc;
5658
pub mod color;
59+
#[cfg(feature = "gecko")]
60+
pub mod gecko;
5761
pub mod grid;
5862
pub mod image;
5963
pub mod length;

0 commit comments

Comments
 (0)