style: Move border-image-repeat outside of mako.

This commit is contained in:
chansuke 2017-11-13 19:46:09 +09:00 committed by Emilio Cobos Álvarez
parent b4339ab5c8
commit 50b517d0db
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
7 changed files with 95 additions and 59 deletions

View file

@ -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;
@ -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>;
@ -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))
}
}

View file

@ -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};

View file

@ -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))
}
}

View file

@ -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};