Skip to content

Commit

Permalink
style: Move border-image-repeat outside of mako.
Browse files Browse the repository at this point in the history
  • Loading branch information
chansuke authored and emilio committed Feb 1, 2018
1 parent b4339ab commit 50b517d
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 59 deletions.
1 change: 1 addition & 0 deletions components/layout/display_list/builder.rs
Expand Up @@ -69,6 +69,7 @@ use style::values::computed::effects::SimpleShadow;
use style::values::computed::pointing::Cursor;
use style::values::generics::background::BackgroundSize;
use style::values::generics::image::{GradientKind, Image, PaintWorklet};
use style::values::specified::border::RepeatKeyword;
use style_traits::CSSPixel;
use style_traits::ToCss;
use style_traits::cursor::CursorKind;
Expand Down
4 changes: 2 additions & 2 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -1713,7 +1713,7 @@ fn static_assert() {
%>

pub fn set_border_image_repeat(&mut self, v: longhands::border_image_repeat::computed_value::T) {
use properties::longhands::border_image_repeat::computed_value::RepeatKeyword;
use values::specified::border::RepeatKeyword;
use gecko_bindings::structs::StyleBorderImageRepeat;

% for i, side in enumerate(["H", "V"]):
Expand All @@ -1735,7 +1735,7 @@ fn static_assert() {
}

pub fn clone_border_image_repeat(&self) -> longhands::border_image_repeat::computed_value::T {
use properties::longhands::border_image_repeat::computed_value::RepeatKeyword;
use values::specified::border::RepeatKeyword;
use gecko_bindings::structs::StyleBorderImageRepeat;

% for side in ["H", "V"]:
Expand Down
63 changes: 9 additions & 54 deletions components/style/properties/longhand/border.mako.rs
Expand Up @@ -101,60 +101,15 @@ ${helpers.predefined_type("border-image-outset", "LengthOrNumberRect",
flags="APPLIES_TO_FIRST_LETTER",
boxed=True)}

<%helpers:longhand name="border-image-repeat" animation_value_type="discrete"
flags="APPLIES_TO_FIRST_LETTER"
spec="https://drafts.csswg.org/css-backgrounds/#border-image-repeat">
pub mod computed_value {
pub use super::RepeatKeyword;

#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)]
pub struct T(pub RepeatKeyword, pub RepeatKeyword);
}

#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)]
pub struct SpecifiedValue(pub RepeatKeyword,
pub Option<RepeatKeyword>);

#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, ToCss)]
pub enum RepeatKeyword {
Stretch,
Repeat,
Round,
Space,
}

#[inline]
pub fn get_initial_value() -> computed_value::T {
computed_value::T(RepeatKeyword::Stretch, RepeatKeyword::Stretch)
}

#[inline]
pub fn get_initial_specified_value() -> SpecifiedValue {
SpecifiedValue(RepeatKeyword::Stretch, None)
}

impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;

#[inline]
fn to_computed_value(&self, _context: &Context) -> computed_value::T {
computed_value::T(self.0, self.1.unwrap_or(self.0))
}
#[inline]
fn from_computed_value(computed: &computed_value::T) -> Self {
SpecifiedValue(computed.0, Some(computed.1))
}
}

pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<SpecifiedValue, ParseError<'i>> {
let first = RepeatKeyword::parse(input)?;
let second = input.try(RepeatKeyword::parse).ok();

Ok(SpecifiedValue(first, second))
}
</%helpers:longhand>
${helpers.predefined_type(
"border-image-repeat",
"BorderImageRepeat",
"computed::BorderImageRepeat::stretch()",
initial_specified_value="specified::BorderImageRepeat::stretch()",
animation_value_type="discrete",
spec="https://drafts.csswg.org/css-backgrounds/#the-border-image-repeat",
flags="APPLIES_TO_FIRST_LETTER",
)}

${helpers.predefined_type("border-image-width", "BorderImageWidth",
initial_value="computed::BorderImageWidth::all(computed::BorderImageSideWidth::one())",
Expand Down
46 changes: 45 additions & 1 deletion components/style/values/computed/border.rs
Expand Up @@ -5,8 +5,10 @@
//! Computed types for CSS values related to borders.

use app_units::Au;
use std::fmt::{self, Write};
use style_traits::{ToCss, CssWriter};
use values::animated::ToAnimatedZero;
use values::computed::{Number, NumberOrPercentage};
use values::computed::{Context, Number, NumberOrPercentage, ToComputedValue};
use values::computed::length::{LengthOrPercentage, NonNegativeLength};
use values::generics::border::BorderCornerRadius as GenericBorderCornerRadius;
use values::generics::border::BorderImageSideWidth as GenericBorderImageSideWidth;
Expand All @@ -15,6 +17,7 @@ use values::generics::border::BorderRadius as GenericBorderRadius;
use values::generics::border::BorderSpacing as GenericBorderSpacing;
use values::generics::rect::Rect;
use values::generics::size::Size;
use values::specified::border::{BorderImageRepeat as SpecifiedBorderImageRepeat, RepeatKeyword};

/// A computed value for the `border-image-width` property.
pub type BorderImageWidth = Rect<BorderImageSideWidth>;
Expand Down Expand Up @@ -81,3 +84,44 @@ impl ToAnimatedZero for BorderCornerRadius {
Err(())
}
}

/// The computed value of the `border-image-repeat` property:
///
/// https://drafts.csswg.org/css-backgrounds/#the-border-image-repeat
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
pub struct BorderImageRepeat(pub RepeatKeyword, pub RepeatKeyword);

impl BorderImageRepeat {
/// Returns the `stretch` value.
pub fn stretch() -> Self {
BorderImageRepeat(RepeatKeyword::Stretch, RepeatKeyword::Stretch)
}
}

impl ToCss for BorderImageRepeat {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
self.0.to_css(dest)?;
if self.0 != self.1 {
dest.write_str(" ")?;
self.1.to_css(dest)?;
}
Ok(())
}
}

impl ToComputedValue for SpecifiedBorderImageRepeat {
type ComputedValue = BorderImageRepeat;

#[inline]
fn to_computed_value(&self, _: &Context) -> Self::ComputedValue {
BorderImageRepeat(self.0, self.1.unwrap_or(self.0))
}

#[inline]
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
SpecifiedBorderImageRepeat(computed.0, Some(computed.1))
}
}
2 changes: 1 addition & 1 deletion components/style/values/computed/mod.rs
Expand Up @@ -37,7 +37,7 @@ pub use self::align::{AlignItems, AlignContent, JustifyContent, SelfAlignment, J
pub use self::align::{AlignSelf, JustifySelf};
pub use self::angle::Angle;
pub use self::background::{BackgroundSize, BackgroundRepeat};
pub use self::border::{BorderImageSlice, BorderImageWidth, BorderImageSideWidth};
pub use self::border::{BorderImageRepeat, BorderImageSlice, BorderImageWidth, BorderImageSideWidth};
pub use self::border::{BorderRadius, BorderCornerRadius, BorderSpacing};
pub use self::font::{FontSize, FontSizeAdjust, FontSynthesis, FontWeight, FontVariantAlternates};
pub use self::font::{FontFamily, FontLanguageOverride, FontVariantSettings, FontVariantEastAsian};
Expand Down
36 changes: 36 additions & 0 deletions components/style/values/specified/border.rs
Expand Up @@ -171,3 +171,39 @@ impl Parse for BorderSpacing {
}).map(GenericBorderSpacing)
}
}

/// A single border-image-repeat keyword.
#[allow(missing_docs)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, ToCss)]
pub enum RepeatKeyword {
Stretch,
Repeat,
Round,
Space,
}

/// The specified value for the `border-image-repeat` property.
///
/// https://drafts.csswg.org/css-backgrounds/#the-border-image-repeat
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)]
pub struct BorderImageRepeat(pub RepeatKeyword, pub Option<RepeatKeyword>);

impl BorderImageRepeat {
/// Returns the `stretch` value.
#[inline]
pub fn stretch() -> Self {
BorderImageRepeat(RepeatKeyword::Stretch, None)
}
}

impl Parse for BorderImageRepeat {
fn parse<'i, 't>(
_context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
let horizontal = RepeatKeyword::parse(input)?;
let vertical = input.try(RepeatKeyword::parse).ok();
Ok(BorderImageRepeat(horizontal, vertical))
}
}
2 changes: 1 addition & 1 deletion components/style/values/specified/mod.rs
Expand Up @@ -31,7 +31,7 @@ pub use self::align::{AlignContent, JustifyContent, AlignItems, ContentDistribut
pub use self::align::{AlignSelf, JustifySelf};
pub use self::background::{BackgroundRepeat, BackgroundSize};
pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth};
pub use self::border::{BorderImageSideWidth, BorderRadius, BorderSideWidth, BorderSpacing};
pub use self::border::{BorderImageRepeat, BorderImageSideWidth, BorderRadius, BorderSideWidth, BorderSpacing};
pub use self::font::{FontSize, FontSizeAdjust, FontSynthesis, FontWeight, FontVariantAlternates};
pub use self::font::{FontFamily, FontLanguageOverride, FontVariantSettings, FontVariantEastAsian};
pub use self::font::{FontVariantLigatures, FontVariantNumeric, FontFeatureSettings};
Expand Down

0 comments on commit 50b517d

Please sign in to comment.