mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
style: Move background-repeat and mask-repeat outside of mako.
This commit is contained in:
parent
326f914018
commit
fd1e2c1f3f
8 changed files with 168 additions and 126 deletions
|
@ -3659,7 +3659,7 @@ fn static_assert() {
|
|||
%>
|
||||
|
||||
<%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::StyleImageLayerRepeat;
|
||||
|
||||
|
@ -3682,7 +3682,7 @@ fn static_assert() {
|
|||
|
||||
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::RepeatKeyword;
|
||||
use values::specified::background::RepeatKeyword;
|
||||
use gecko_bindings::structs::StyleImageLayerRepeat;
|
||||
|
||||
fn to_servo(repeat: StyleImageLayerRepeat) -> RepeatKeyword {
|
||||
|
|
|
@ -40,101 +40,16 @@ ${helpers.predefined_type("background-image", "ImageLayer",
|
|||
)}
|
||||
% endfor
|
||||
|
||||
<%helpers:vector_longhand name="background-repeat" animation_value_type="discrete"
|
||||
spec="https://drafts.csswg.org/css-backgrounds/#the-background-repeat"
|
||||
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER">
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
|
||||
define_css_keyword_enum!(RepeatKeyword:
|
||||
"repeat" => Repeat,
|
||||
"space" => Space,
|
||||
"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.predefined_type(
|
||||
"background-repeat",
|
||||
"BackgroundRepeat",
|
||||
"computed::BackgroundRepeat::repeat()",
|
||||
initial_specified_value="specified::BackgroundRepeat::repeat()",
|
||||
animation_value_type="discrete",
|
||||
vector=True,
|
||||
spec="https://drafts.csswg.org/css-backgrounds/#the-background-repeat",
|
||||
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
|
||||
)}
|
||||
|
||||
${helpers.single_keyword("background-attachment",
|
||||
"scroll fixed" + (" local" if product == "gecko" else ""),
|
||||
|
|
|
@ -81,23 +81,17 @@ ${helpers.single_keyword("mask-mode",
|
|||
animation_value_type="discrete",
|
||||
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"
|
||||
spec="https://drafts.fxtf.org/css-masking/#propdef-mask-repeat">
|
||||
pub use properties::longhands::background_repeat::single_value::parse;
|
||||
pub use properties::longhands::background_repeat::single_value::SpecifiedValue;
|
||||
pub use properties::longhands::background_repeat::single_value::computed_value;
|
||||
pub use properties::longhands::background_repeat::single_value::RepeatKeyword;
|
||||
|
||||
#[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)
|
||||
}
|
||||
</%helpers:vector_longhand>
|
||||
${helpers.predefined_type(
|
||||
"mask-repeat",
|
||||
"BackgroundRepeat",
|
||||
"computed::BackgroundRepeat::repeat()",
|
||||
initial_specified_value="specified::BackgroundRepeat::repeat()",
|
||||
products="gecko",
|
||||
extra_prefixes="webkit",
|
||||
animation_value_type="discrete",
|
||||
spec="https://drafts.fxtf.org/css-masking/#propdef-mask-repeat",
|
||||
vector=True,
|
||||
)}
|
||||
|
||||
% for (axis, direction) in [("x", "Horizontal"), ("y", "Vertical")]:
|
||||
${helpers.predefined_type(
|
||||
|
|
|
@ -6,9 +6,13 @@
|
|||
|
||||
use properties::animated_properties::RepeatableListAnimatable;
|
||||
use properties::longhands::background_size::computed_value::T as BackgroundSizeList;
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::animated::{ToAnimatedValue, ToAnimatedZero};
|
||||
use values::computed::{Context, ToComputedValue};
|
||||
use values::computed::length::LengthOrPercentageOrAuto;
|
||||
use values::generics::background::BackgroundSize as GenericBackgroundSize;
|
||||
use values::specified::background::{BackgroundRepeat as SpecifiedBackgroundRepeat, RepeatKeyword};
|
||||
|
||||
/// A computed value for the `background-size` property.
|
||||
pub type BackgroundSize = GenericBackgroundSize<LengthOrPercentageOrAuto>;
|
||||
|
@ -77,3 +81,72 @@ impl ToAnimatedValue for BackgroundSizeList {
|
|||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ pub use properties::animated_properties::TransitionProperty;
|
|||
#[cfg(feature = "gecko")]
|
||||
pub use self::align::{AlignItems, AlignJustifyContent, AlignJustifySelf, JustifyItems};
|
||||
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::{BorderRadius, BorderCornerRadius, BorderSpacing};
|
||||
pub use self::box_::VerticalAlign;
|
||||
|
|
|
@ -15,7 +15,10 @@ use values::specified::length::LengthOrPercentageOrAuto;
|
|||
pub type BackgroundSize = GenericBackgroundSize<LengthOrPercentageOrAuto>;
|
||||
|
||||
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)) {
|
||||
let height = input
|
||||
.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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ pub use properties::animated_properties::TransitionProperty;
|
|||
pub use self::angle::Angle;
|
||||
#[cfg(feature = "gecko")]
|
||||
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::{BorderImageSideWidth, BorderRadius, BorderSideWidth, BorderSpacing};
|
||||
pub use self::box_::VerticalAlign;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue