mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +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
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue