style: Move background-repeat and mask-repeat outside of mako.

This commit is contained in:
Emilio Cobos Álvarez 2017-10-24 14:30:12 +02:00
parent 326f914018
commit fd1e2c1f3f
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
8 changed files with 168 additions and 126 deletions

View file

@ -48,7 +48,7 @@ use std::default::Default;
use std::mem; use std::mem;
use std::sync::Arc; use std::sync::Arc;
use style::computed_values::{background_attachment, background_clip, background_origin}; use style::computed_values::{background_attachment, background_clip, background_origin};
use style::computed_values::{background_repeat, border_style, cursor}; use style::computed_values::{border_style, cursor};
use style::computed_values::{image_rendering, overflow_x, pointer_events, position, visibility}; use style::computed_values::{image_rendering, overflow_x, pointer_events, position, visibility};
use style::logical_geometry::{LogicalMargin, LogicalPoint, LogicalRect, LogicalSize, WritingMode}; use style::logical_geometry::{LogicalMargin, LogicalPoint, LogicalRect, LogicalSize, WritingMode};
use style::properties::ComputedValues; use style::properties::ComputedValues;
@ -66,6 +66,7 @@ use style::values::generics::image::{Circle, Ellipse, EndingShape as GenericEndi
use style::values::generics::image::{GradientItem as GenericGradientItem, GradientKind}; use style::values::generics::image::{GradientItem as GenericGradientItem, GradientKind};
use style::values::generics::image::{Image, ShapeExtent}; use style::values::generics::image::{Image, ShapeExtent};
use style::values::generics::image::PaintWorklet; use style::values::generics::image::PaintWorklet;
use style::values::specified::background::RepeatKeyword as BackgroundRepeatKeyword;
use style::values::specified::position::{X, Y}; use style::values::specified::position::{X, Y};
use style_traits::CSSPixel; use style_traits::CSSPixel;
use style_traits::ToCss; use style_traits::ToCss;
@ -1177,17 +1178,17 @@ impl FragmentDisplayListBuilding for Fragment {
// Adjust origin and size based on background-repeat // Adjust origin and size based on background-repeat
let background_repeat = get_cyclic(&background.background_repeat.0, index); let background_repeat = get_cyclic(&background.background_repeat.0, index);
match background_repeat.0 { match background_repeat.0 {
background_repeat::single_value::RepeatKeyword::NoRepeat => { BackgroundRepeatKeyword::NoRepeat => {
bounds.origin.x = anchor_origin_x; bounds.origin.x = anchor_origin_x;
bounds.size.width = image_size.width; bounds.size.width = image_size.width;
} }
background_repeat::single_value::RepeatKeyword::Repeat => { BackgroundRepeatKeyword::Repeat => {
ImageFragmentInfo::tile_image(&mut bounds.origin.x, ImageFragmentInfo::tile_image(&mut bounds.origin.x,
&mut bounds.size.width, &mut bounds.size.width,
anchor_origin_x, anchor_origin_x,
image_size.width); image_size.width);
} }
background_repeat::single_value::RepeatKeyword::Space => { BackgroundRepeatKeyword::Space => {
ImageFragmentInfo::tile_image_spaced(&mut bounds.origin.x, ImageFragmentInfo::tile_image_spaced(&mut bounds.origin.x,
&mut bounds.size.width, &mut bounds.size.width,
&mut tile_spacing.width, &mut tile_spacing.width,
@ -1195,7 +1196,7 @@ impl FragmentDisplayListBuilding for Fragment {
image_size.width); image_size.width);
} }
background_repeat::single_value::RepeatKeyword::Round => { BackgroundRepeatKeyword::Round => {
ImageFragmentInfo::tile_image_round(&mut bounds.origin.x, ImageFragmentInfo::tile_image_round(&mut bounds.origin.x,
&mut bounds.size.width, &mut bounds.size.width,
anchor_origin_x, anchor_origin_x,
@ -1203,17 +1204,17 @@ impl FragmentDisplayListBuilding for Fragment {
} }
}; };
match background_repeat.1 { match background_repeat.1 {
background_repeat::single_value::RepeatKeyword::NoRepeat => { BackgroundRepeatKeyword::NoRepeat => {
bounds.origin.y = anchor_origin_y; bounds.origin.y = anchor_origin_y;
bounds.size.height = image_size.height; bounds.size.height = image_size.height;
} }
background_repeat::single_value::RepeatKeyword::Repeat => { BackgroundRepeatKeyword::Repeat => {
ImageFragmentInfo::tile_image(&mut bounds.origin.y, ImageFragmentInfo::tile_image(&mut bounds.origin.y,
&mut bounds.size.height, &mut bounds.size.height,
anchor_origin_y, anchor_origin_y,
image_size.height); image_size.height);
} }
background_repeat::single_value::RepeatKeyword::Space => { BackgroundRepeatKeyword::Space => {
ImageFragmentInfo::tile_image_spaced(&mut bounds.origin.y, ImageFragmentInfo::tile_image_spaced(&mut bounds.origin.y,
&mut bounds.size.height, &mut bounds.size.height,
&mut tile_spacing.height, &mut tile_spacing.height,
@ -1221,7 +1222,7 @@ impl FragmentDisplayListBuilding for Fragment {
image_size.height); image_size.height);
} }
background_repeat::single_value::RepeatKeyword::Round => { BackgroundRepeatKeyword::Round => {
ImageFragmentInfo::tile_image_round(&mut bounds.origin.y, ImageFragmentInfo::tile_image_round(&mut bounds.origin.y,
&mut bounds.size.height, &mut bounds.size.height,
anchor_origin_y, anchor_origin_y,

View file

@ -3659,7 +3659,7 @@ fn static_assert() {
%> %>
<%self:simple_image_array_property name="repeat" shorthand="${shorthand}" field_name="mRepeat"> <%self:simple_image_array_property name="repeat" shorthand="${shorthand}" field_name="mRepeat">
use properties::longhands::${shorthand}_repeat::single_value::computed_value::RepeatKeyword; use values::specified::background::RepeatKeyword;
use gecko_bindings::structs::nsStyleImageLayers_Repeat; use gecko_bindings::structs::nsStyleImageLayers_Repeat;
use gecko_bindings::structs::StyleImageLayerRepeat; use gecko_bindings::structs::StyleImageLayerRepeat;
@ -3682,7 +3682,7 @@ fn static_assert() {
pub fn clone_${shorthand}_repeat(&self) -> longhands::${shorthand}_repeat::computed_value::T { pub fn clone_${shorthand}_repeat(&self) -> longhands::${shorthand}_repeat::computed_value::T {
use properties::longhands::${shorthand}_repeat::single_value::computed_value::T; use properties::longhands::${shorthand}_repeat::single_value::computed_value::T;
use properties::longhands::${shorthand}_repeat::single_value::computed_value::RepeatKeyword; use values::specified::background::RepeatKeyword;
use gecko_bindings::structs::StyleImageLayerRepeat; use gecko_bindings::structs::StyleImageLayerRepeat;
fn to_servo(repeat: StyleImageLayerRepeat) -> RepeatKeyword { fn to_servo(repeat: StyleImageLayerRepeat) -> RepeatKeyword {

View file

@ -40,101 +40,16 @@ ${helpers.predefined_type("background-image", "ImageLayer",
)} )}
% endfor % endfor
<%helpers:vector_longhand name="background-repeat" animation_value_type="discrete" ${helpers.predefined_type(
spec="https://drafts.csswg.org/css-backgrounds/#the-background-repeat" "background-repeat",
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER"> "BackgroundRepeat",
use std::fmt; "computed::BackgroundRepeat::repeat()",
use style_traits::ToCss; initial_specified_value="specified::BackgroundRepeat::repeat()",
animation_value_type="discrete",
define_css_keyword_enum!(RepeatKeyword: vector=True,
"repeat" => Repeat, spec="https://drafts.csswg.org/css-backgrounds/#the-background-repeat",
"space" => Space, flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
"round" => Round, )}
"no-repeat" => NoRepeat);
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)]
pub enum SpecifiedValue {
RepeatX,
RepeatY,
Other(RepeatKeyword, Option<RepeatKeyword>),
}
pub mod computed_value {
pub use super::RepeatKeyword;
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
pub struct T(pub RepeatKeyword, pub RepeatKeyword);
}
impl ToCss for computed_value::T {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match (self.0, self.1) {
(RepeatKeyword::Repeat, RepeatKeyword::NoRepeat) => dest.write_str("repeat-x"),
(RepeatKeyword::NoRepeat, RepeatKeyword::Repeat) => dest.write_str("repeat-y"),
(horizontal, vertical) => {
horizontal.to_css(dest)?;
if horizontal != vertical {
dest.write_str(" ")?;
vertical.to_css(dest)?;
}
Ok(())
},
}
}
}
#[inline]
pub fn get_initial_value() -> computed_value::T {
computed_value::T(RepeatKeyword::Repeat, RepeatKeyword::Repeat)
}
#[inline]
pub fn get_initial_specified_value() -> SpecifiedValue {
SpecifiedValue::Other(RepeatKeyword::Repeat, None)
}
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
#[inline]
fn to_computed_value(&self, _context: &Context) -> computed_value::T {
match *self {
SpecifiedValue::RepeatX =>
computed_value::T(RepeatKeyword::Repeat, RepeatKeyword::NoRepeat),
SpecifiedValue::RepeatY =>
computed_value::T(RepeatKeyword::NoRepeat, RepeatKeyword::Repeat),
SpecifiedValue::Other(horizontal, vertical) =>
computed_value::T(horizontal, vertical.unwrap_or(horizontal))
}
}
#[inline]
fn from_computed_value(computed: &computed_value::T) -> Self {
match (computed.0, computed.1) {
(RepeatKeyword::Repeat, RepeatKeyword::NoRepeat) => SpecifiedValue::RepeatX,
(RepeatKeyword::NoRepeat, RepeatKeyword::Repeat) => SpecifiedValue::RepeatY,
(horizontal, vertical) => SpecifiedValue::Other(horizontal, Some(vertical)),
}
}
}
pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<SpecifiedValue, ParseError<'i>> {
let ident = input.expect_ident_cloned()?;
(match_ignore_ascii_case! { &ident,
"repeat-x" => Ok(SpecifiedValue::RepeatX),
"repeat-y" => Ok(SpecifiedValue::RepeatY),
_ => Err(()),
}).or_else(|()| {
let horizontal: Result<_, ParseError> = RepeatKeyword::from_ident(&ident)
.map_err(|()| input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident.clone())));
let horizontal = horizontal?;
let vertical = input.try(RepeatKeyword::parse).ok();
Ok(SpecifiedValue::Other(horizontal, vertical))
})
}
</%helpers:vector_longhand>
${helpers.single_keyword("background-attachment", ${helpers.single_keyword("background-attachment",
"scroll fixed" + (" local" if product == "gecko" else ""), "scroll fixed" + (" local" if product == "gecko" else ""),

View file

@ -81,23 +81,17 @@ ${helpers.single_keyword("mask-mode",
animation_value_type="discrete", animation_value_type="discrete",
spec="https://drafts.fxtf.org/css-masking/#propdef-mask-mode")} spec="https://drafts.fxtf.org/css-masking/#propdef-mask-mode")}
<%helpers:vector_longhand name="mask-repeat" products="gecko" animation_value_type="discrete" extra_prefixes="webkit" ${helpers.predefined_type(
spec="https://drafts.fxtf.org/css-masking/#propdef-mask-repeat"> "mask-repeat",
pub use properties::longhands::background_repeat::single_value::parse; "BackgroundRepeat",
pub use properties::longhands::background_repeat::single_value::SpecifiedValue; "computed::BackgroundRepeat::repeat()",
pub use properties::longhands::background_repeat::single_value::computed_value; initial_specified_value="specified::BackgroundRepeat::repeat()",
pub use properties::longhands::background_repeat::single_value::RepeatKeyword; products="gecko",
extra_prefixes="webkit",
#[inline] animation_value_type="discrete",
pub fn get_initial_value() -> computed_value::T { spec="https://drafts.fxtf.org/css-masking/#propdef-mask-repeat",
computed_value::T(RepeatKeyword::Repeat, RepeatKeyword::Repeat) vector=True,
} )}
#[inline]
pub fn get_initial_specified_value() -> SpecifiedValue {
SpecifiedValue::Other(RepeatKeyword::Repeat, None)
}
</%helpers:vector_longhand>
% for (axis, direction) in [("x", "Horizontal"), ("y", "Vertical")]: % for (axis, direction) in [("x", "Horizontal"), ("y", "Vertical")]:
${helpers.predefined_type( ${helpers.predefined_type(

View file

@ -6,9 +6,13 @@
use properties::animated_properties::RepeatableListAnimatable; use properties::animated_properties::RepeatableListAnimatable;
use properties::longhands::background_size::computed_value::T as BackgroundSizeList; use properties::longhands::background_size::computed_value::T as BackgroundSizeList;
use std::fmt;
use style_traits::ToCss;
use values::animated::{ToAnimatedValue, ToAnimatedZero}; use values::animated::{ToAnimatedValue, ToAnimatedZero};
use values::computed::{Context, ToComputedValue};
use values::computed::length::LengthOrPercentageOrAuto; use values::computed::length::LengthOrPercentageOrAuto;
use values::generics::background::BackgroundSize as GenericBackgroundSize; use values::generics::background::BackgroundSize as GenericBackgroundSize;
use values::specified::background::{BackgroundRepeat as SpecifiedBackgroundRepeat, RepeatKeyword};
/// A computed value for the `background-size` property. /// A computed value for the `background-size` property.
pub type BackgroundSize = GenericBackgroundSize<LengthOrPercentageOrAuto>; pub type BackgroundSize = GenericBackgroundSize<LengthOrPercentageOrAuto>;
@ -77,3 +81,72 @@ impl ToAnimatedValue for BackgroundSizeList {
BackgroundSizeList(ToAnimatedValue::from_animated_value(animated.0)) BackgroundSizeList(ToAnimatedValue::from_animated_value(animated.0))
} }
} }
/// The computed value of the `background-repeat` property:
///
/// https://drafts.csswg.org/css-backgrounds/#the-background-repeat
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
pub struct BackgroundRepeat(pub RepeatKeyword, pub RepeatKeyword);
impl BackgroundRepeat {
/// Returns the `repeat repeat` value.
pub fn repeat() -> Self {
BackgroundRepeat(RepeatKeyword::Repeat, RepeatKeyword::Repeat)
}
}
impl ToCss for BackgroundRepeat {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
where
W: fmt::Write,
{
match (self.0, self.1) {
(RepeatKeyword::Repeat, RepeatKeyword::NoRepeat) => dest.write_str("repeat-x"),
(RepeatKeyword::NoRepeat, RepeatKeyword::Repeat) => dest.write_str("repeat-y"),
(horizontal, vertical) => {
horizontal.to_css(dest)?;
if horizontal != vertical {
dest.write_str(" ")?;
vertical.to_css(dest)?;
}
Ok(())
},
}
}
}
impl ToComputedValue for SpecifiedBackgroundRepeat {
type ComputedValue = BackgroundRepeat;
#[inline]
fn to_computed_value(&self, _: &Context) -> Self::ComputedValue {
match *self {
SpecifiedBackgroundRepeat::RepeatX => {
BackgroundRepeat(RepeatKeyword::Repeat, RepeatKeyword::NoRepeat)
}
SpecifiedBackgroundRepeat::RepeatY => {
BackgroundRepeat(RepeatKeyword::NoRepeat, RepeatKeyword::Repeat)
}
SpecifiedBackgroundRepeat::Keywords(horizontal, vertical) => {
BackgroundRepeat(horizontal, vertical.unwrap_or(horizontal))
}
}
}
#[inline]
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
// FIXME(emilio): Why can't this just be:
// SpecifiedBackgroundRepeat::Keywords(computed.0, computed.1)
match (computed.0, computed.1) {
(RepeatKeyword::Repeat, RepeatKeyword::NoRepeat) => {
SpecifiedBackgroundRepeat::RepeatX
}
(RepeatKeyword::NoRepeat, RepeatKeyword::Repeat) => {
SpecifiedBackgroundRepeat::RepeatY
}
(horizontal, vertical) => {
SpecifiedBackgroundRepeat::Keywords(horizontal, Some(vertical))
}
}
}
}

View file

@ -33,7 +33,7 @@ pub use properties::animated_properties::TransitionProperty;
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
pub use self::align::{AlignItems, AlignJustifyContent, AlignJustifySelf, JustifyItems}; pub use self::align::{AlignItems, AlignJustifyContent, AlignJustifySelf, JustifyItems};
pub use self::angle::Angle; pub use self::angle::Angle;
pub use self::background::BackgroundSize; pub use self::background::{BackgroundSize, BackgroundRepeat};
pub use self::border::{BorderImageSlice, BorderImageWidth, BorderImageSideWidth}; pub use self::border::{BorderImageSlice, BorderImageWidth, BorderImageSideWidth};
pub use self::border::{BorderRadius, BorderCornerRadius, BorderSpacing}; pub use self::border::{BorderRadius, BorderCornerRadius, BorderSpacing};
pub use self::box_::VerticalAlign; pub use self::box_::VerticalAlign;

View file

@ -15,7 +15,10 @@ use values::specified::length::LengthOrPercentageOrAuto;
pub type BackgroundSize = GenericBackgroundSize<LengthOrPercentageOrAuto>; pub type BackgroundSize = GenericBackgroundSize<LengthOrPercentageOrAuto>;
impl Parse for BackgroundSize { impl Parse for BackgroundSize {
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> { fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
if let Ok(width) = input.try(|i| LengthOrPercentageOrAuto::parse_non_negative(context, i)) { if let Ok(width) = input.try(|i| LengthOrPercentageOrAuto::parse_non_negative(context, i)) {
let height = input let height = input
.try(|i| LengthOrPercentageOrAuto::parse_non_negative(context, i)) .try(|i| LengthOrPercentageOrAuto::parse_non_negative(context, i))
@ -41,3 +44,59 @@ impl BackgroundSize {
} }
} }
} }
/// One of the keywords for `background-repeat`.
define_css_keyword_enum! { RepeatKeyword:
"repeat" => Repeat,
"space" => Space,
"round" => Round,
"no-repeat" => NoRepeat
}
/// The specified value for the `background-repeat` property.
///
/// https://drafts.csswg.org/css-backgrounds/#the-background-repeat
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)]
pub enum BackgroundRepeat {
/// `repeat-x`
RepeatX,
/// `repeat-y`
RepeatY,
/// `[repeat | space | round | no-repeat]{1,2}`
Keywords(RepeatKeyword, Option<RepeatKeyword>),
}
impl BackgroundRepeat {
/// Returns the `repeat` value.
#[inline]
pub fn repeat() -> Self {
BackgroundRepeat::Keywords(RepeatKeyword::Repeat, None)
}
}
impl Parse for BackgroundRepeat {
fn parse<'i, 't>(
_context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
let ident = input.expect_ident_cloned()?;
match_ignore_ascii_case! { &ident,
"repeat-x" => return Ok(BackgroundRepeat::RepeatX),
"repeat-y" => return Ok(BackgroundRepeat::RepeatY),
_ => {},
}
let horizontal = match RepeatKeyword::from_ident(&ident) {
Ok(h) => h,
Err(()) => {
return Err(input.new_custom_error(
SelectorParseErrorKind::UnexpectedIdent(ident.clone())
));
}
};
let vertical = input.try(RepeatKeyword::parse).ok();
Ok(BackgroundRepeat::Keywords(horizontal, vertical))
}
}

View file

@ -27,7 +27,7 @@ pub use properties::animated_properties::TransitionProperty;
pub use self::angle::Angle; pub use self::angle::Angle;
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
pub use self::align::{AlignItems, AlignJustifyContent, AlignJustifySelf, JustifyItems}; pub use self::align::{AlignItems, AlignJustifyContent, AlignJustifySelf, JustifyItems};
pub use self::background::BackgroundSize; pub use self::background::{BackgroundRepeat, BackgroundSize};
pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth}; pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth};
pub use self::border::{BorderImageSideWidth, BorderRadius, BorderSideWidth, BorderSpacing}; pub use self::border::{BorderImageSideWidth, BorderRadius, BorderSideWidth, BorderSpacing};
pub use self::box_::VerticalAlign; pub use self::box_::VerticalAlign;