Skip to content

Commit 4576cc9

Browse files
author
bors-servo
authored
Auto merge of #17186 - servo:derive-all-the-things, r=<try>
Use more generics and remove more code from mako files
2 parents 2da8eb0 + a9cb635 commit 4576cc9

File tree

10 files changed

+168
-164
lines changed

10 files changed

+168
-164
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/helpers/animated_properties.mako.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ use values::CSSFloat;
3939
use values::{Auto, Either};
4040
use values::computed::{Angle, LengthOrPercentageOrAuto, LengthOrPercentageOrNone};
4141
use values::computed::{BorderCornerRadius, ClipRect};
42-
use values::computed::{CalcLengthOrPercentage, Context, LengthOrPercentage};
43-
use values::computed::{MaxLength, MozLength};
44-
use values::computed::ToComputedValue;
42+
use values::computed::{CalcLengthOrPercentage, Context, ComputedValueAsSpecified};
43+
use values::computed::{LengthOrPercentage, MaxLength, MozLength, ToComputedValue};
4544
use values::generics::{SVGPaint, SVGPaintKind};
4645
use values::generics::border::BorderCornerRadius as GenericBorderCornerRadius;
4746
use values::generics::position as generic_position;
@@ -73,6 +72,10 @@ pub enum TransitionProperty {
7372
Unsupported(Atom)
7473
}
7574

75+
no_viewport_percentage!(TransitionProperty);
76+
77+
impl ComputedValueAsSpecified for TransitionProperty {}
78+
7679
impl TransitionProperty {
7780
/// Iterates over each longhand property.
7881
pub fn each<F: FnMut(&TransitionProperty) -> ()>(mut cb: F) {

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

Lines changed: 39 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -424,36 +424,17 @@ ${helpers.predefined_type("transition-timing-function",
424424
extra_prefixes="moz webkit",
425425
spec="https://drafts.csswg.org/css-transitions/#propdef-transition-timing-function")}
426426

427-
<%helpers:vector_longhand name="transition-property"
428-
allow_empty="True"
429-
need_index="True"
430-
animation_value_type="none"
431-
extra_prefixes="moz webkit"
432-
spec="https://drafts.csswg.org/css-transitions/#propdef-transition-property">
433-
434-
use values::computed::ComputedValueAsSpecified;
435-
436-
pub use properties::animated_properties::TransitionProperty;
437-
pub use properties::animated_properties::TransitionProperty as SpecifiedValue;
438-
439-
pub mod computed_value {
440-
// NB: Can't generate the type here because it needs all the longhands
441-
// generated beforehand.
442-
pub use super::SpecifiedValue as T;
443-
}
444-
445-
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
446-
SpecifiedValue::parse(input)
447-
}
448-
449-
pub fn get_initial_specified_value() -> SpecifiedValue {
450-
TransitionProperty::All
451-
}
452-
453-
no_viewport_percentage!(SpecifiedValue);
454-
455-
impl ComputedValueAsSpecified for SpecifiedValue { }
456-
</%helpers:vector_longhand>
427+
${helpers.predefined_type("transition-property",
428+
"TransitionProperty",
429+
"computed::TransitionProperty::All",
430+
initial_specified_value="specified::TransitionProperty::All",
431+
vector=True,
432+
allow_empty=True,
433+
need_index=True,
434+
needs_context=False,
435+
animation_value_type="none",
436+
extra_prefixes="moz webkit",
437+
spec="https://drafts.csswg.org/css-transitions/#propdef-transition-property")}
457438

458439
${helpers.predefined_type("transition-delay",
459440
"Time",
@@ -463,7 +444,7 @@ ${helpers.predefined_type("transition-delay",
463444
need_index=True,
464445
animation_value_type="none",
465446
extra_prefixes="moz webkit",
466-
spec="https://drafts.csswg.org/css-transitions/#propdef-transition-duration")}
447+
spec="https://drafts.csswg.org/css-transitions/#propdef-transition-delay")}
467448

468449
<%helpers:vector_longhand name="animation-name"
469450
need_index="True"
@@ -547,18 +528,16 @@ ${helpers.predefined_type("animation-duration",
547528
extra_prefixes="moz webkit",
548529
spec="https://drafts.csswg.org/css-transitions/#propdef-transition-duration")}
549530

550-
<%helpers:vector_longhand name="animation-timing-function"
551-
need_index="True"
531+
${helpers.predefined_type("animation-timing-function",
532+
"TimingFunction",
533+
"computed::TimingFunction::ease()",
534+
initial_specified_value="specified::TimingFunction::ease()",
535+
vector=True,
536+
need_index=True,
552537
animation_value_type="none",
553-
extra_prefixes="moz webkit"
554-
spec="https://drafts.csswg.org/css-animations/#propdef-animation-timing-function",
555-
allowed_in_keyframe_block="True">
556-
pub use properties::longhands::transition_timing_function::single_value::computed_value;
557-
pub use properties::longhands::transition_timing_function::single_value::get_initial_value;
558-
pub use properties::longhands::transition_timing_function::single_value::get_initial_specified_value;
559-
pub use properties::longhands::transition_timing_function::single_value::parse;
560-
pub use properties::longhands::transition_timing_function::single_value::SpecifiedValue;
561-
</%helpers:vector_longhand>
538+
extra_prefixes="moz webkit",
539+
allowed_in_keyframe_block=True,
540+
spec="https://drafts.csswg.org/css-transitions/#propdef-animation-timing-function")}
562541

563542
<%helpers:vector_longhand name="animation-iteration-count"
564543
need_index="True"
@@ -660,111 +639,27 @@ ${helpers.single_keyword("animation-fill-mode",
660639
spec="https://drafts.csswg.org/css-animations/#propdef-animation-fill-mode",
661640
allowed_in_keyframe_block=False)}
662641

663-
<%helpers:vector_longhand name="animation-delay"
664-
need_index="True"
642+
${helpers.predefined_type("animation-delay",
643+
"Time",
644+
"computed::Time::zero()",
645+
initial_specified_value="specified::Time::zero()",
646+
vector=True,
647+
need_index=True,
665648
animation_value_type="none",
666649
extra_prefixes="moz webkit",
667650
spec="https://drafts.csswg.org/css-animations/#propdef-animation-delay",
668-
allowed_in_keyframe_block="False">
669-
pub use properties::longhands::transition_delay::single_value::computed_value;
670-
pub use properties::longhands::transition_delay::single_value::get_initial_specified_value;
671-
pub use properties::longhands::transition_delay::single_value::{get_initial_value, parse};
672-
pub use properties::longhands::transition_delay::single_value::SpecifiedValue;
673-
</%helpers:vector_longhand>
674-
675-
<%helpers:longhand products="gecko" name="scroll-snap-points-y" animation_value_type="none"
676-
spec="Nonstandard (https://www.w3.org/TR/2015/WD-css-snappoints-1-20150326/#scroll-snap-points)">
677-
use std::fmt;
678-
use style_traits::ToCss;
679-
use values::specified::LengthOrPercentage;
680-
681-
pub mod computed_value {
682-
use values::computed::LengthOrPercentage;
683-
684-
#[derive(Debug, Clone, PartialEq)]
685-
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
686-
pub struct T(pub Option<LengthOrPercentage>);
687-
}
688-
689-
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
690-
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
691-
pub enum SpecifiedValue {
692-
None,
693-
Repeat(LengthOrPercentage),
694-
}
695-
696-
impl ToCss for computed_value::T {
697-
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
698-
match self.0 {
699-
None => dest.write_str("none"),
700-
Some(ref l) => {
701-
try!(dest.write_str("repeat("));
702-
try!(l.to_css(dest));
703-
dest.write_str(")")
704-
},
705-
}
706-
}
707-
}
708-
impl ToCss for SpecifiedValue {
709-
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
710-
match *self {
711-
SpecifiedValue::None => dest.write_str("none"),
712-
SpecifiedValue::Repeat(ref l) => {
713-
try!(dest.write_str("repeat("));
714-
try!(l.to_css(dest));
715-
dest.write_str(")")
716-
},
717-
}
718-
}
719-
}
720-
721-
#[inline]
722-
pub fn get_initial_value() -> computed_value::T {
723-
computed_value::T(None)
724-
}
725-
726-
impl ToComputedValue for SpecifiedValue {
727-
type ComputedValue = computed_value::T;
728-
729-
#[inline]
730-
fn to_computed_value(&self, context: &Context) -> computed_value::T {
731-
match *self {
732-
SpecifiedValue::None => computed_value::T(None),
733-
SpecifiedValue::Repeat(ref l) =>
734-
computed_value::T(Some(l.to_computed_value(context))),
735-
}
736-
}
737-
#[inline]
738-
fn from_computed_value(computed: &computed_value::T) -> Self {
739-
match *computed {
740-
computed_value::T(None) => SpecifiedValue::None,
741-
computed_value::T(Some(l)) =>
742-
SpecifiedValue::Repeat(ToComputedValue::from_computed_value(&l))
743-
}
744-
}
745-
}
746-
747-
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
748-
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
749-
Ok(SpecifiedValue::None)
750-
} else if input.try(|input| input.expect_function_matching("repeat")).is_ok() {
751-
input.parse_nested_block(|input| {
752-
LengthOrPercentage::parse_non_negative(context, input).map(SpecifiedValue::Repeat)
753-
})
754-
} else {
755-
Err(())
756-
}
757-
}
758-
</%helpers:longhand>
759-
760-
<%helpers:longhand products="gecko" name="scroll-snap-points-x" animation_value_type="none"
761-
spec="Nonstandard (https://www.w3.org/TR/2015/WD-css-snappoints-1-20150326/#scroll-snap-points)">
762-
pub use super::scroll_snap_points_y::SpecifiedValue;
763-
pub use super::scroll_snap_points_y::computed_value;
764-
pub use super::scroll_snap_points_y::get_initial_value;
765-
pub use super::scroll_snap_points_y::parse;
766-
</%helpers:longhand>
767-
651+
allowed_in_keyframe_block=False)}
652+
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
768663

769664
${helpers.predefined_type("scroll-snap-destination",
770665
"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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ use super::specified;
2323

2424
pub use app_units::Au;
2525
pub use cssparser::Color as CSSColor;
26+
pub use properties::animated_properties::TransitionProperty;
2627
pub use self::background::BackgroundSize;
2728
pub use self::border::{BorderImageSlice, BorderImageWidth, BorderImageSideWidth};
2829
pub use self::border::{BorderRadius, BorderCornerRadius};
2930
pub use self::image::{Gradient, GradientItem, ImageLayer, LineDirection, Image, ImageRect};
31+
#[cfg(feature = "gecko")]
32+
pub use self::gecko::ScrollSnapPoint;
3033
pub use self::rect::LengthOrNumberRect;
3134
pub use super::{Auto, Either, None_};
3235
#[cfg(feature = "gecko")]
@@ -45,6 +48,8 @@ pub mod background;
4548
pub mod basic_shape;
4649
pub mod border;
4750
pub mod image;
51+
#[cfg(feature = "gecko")]
52+
pub mod gecko;
4853
pub mod length;
4954
pub mod position;
5055
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;

0 commit comments

Comments
 (0)