mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
style: Refactor vector types.
This fixes clamping of mask-size and moves it out of mako while at it. Bug: 1462829 Reviewed-by: hiro,xidorn MozReview-Commit-ID: 9hiTe63odna
This commit is contained in:
parent
3016a7f552
commit
32c6d5b7c6
18 changed files with 259 additions and 372 deletions
|
@ -4,85 +4,27 @@
|
|||
|
||||
//! Computed types for CSS values related to backgrounds.
|
||||
|
||||
use properties::animated_properties::RepeatableListAnimatable;
|
||||
use properties::longhands::background_size::computed_value::T as BackgroundSizeList;
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::{CssWriter, ToCss};
|
||||
use values::animated::{ToAnimatedValue, ToAnimatedZero};
|
||||
use values::computed::{Context, ToComputedValue};
|
||||
use values::computed::length::LengthOrPercentageOrAuto;
|
||||
use values::computed::length::NonNegativeLengthOrPercentageOrAuto;
|
||||
use values::generics::background::BackgroundSize as GenericBackgroundSize;
|
||||
use values::specified::background::BackgroundRepeat as SpecifiedBackgroundRepeat;
|
||||
use values::specified::background::BackgroundRepeatKeyword;
|
||||
|
||||
/// A computed value for the `background-size` property.
|
||||
pub type BackgroundSize = GenericBackgroundSize<LengthOrPercentageOrAuto>;
|
||||
pub type BackgroundSize = GenericBackgroundSize<NonNegativeLengthOrPercentageOrAuto>;
|
||||
|
||||
impl BackgroundSize {
|
||||
/// Returns `auto auto`.
|
||||
pub fn auto() -> Self {
|
||||
GenericBackgroundSize::Explicit {
|
||||
width: LengthOrPercentageOrAuto::Auto,
|
||||
height: LengthOrPercentageOrAuto::Auto,
|
||||
width: NonNegativeLengthOrPercentageOrAuto::auto(),
|
||||
height: NonNegativeLengthOrPercentageOrAuto::auto(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RepeatableListAnimatable for BackgroundSize {}
|
||||
|
||||
impl ToAnimatedZero for BackgroundSize {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedValue for BackgroundSize {
|
||||
type AnimatedValue = Self;
|
||||
|
||||
#[inline]
|
||||
fn to_animated_value(self) -> Self {
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
|
||||
use values::computed::{Length, Percentage};
|
||||
let clamp_animated_value = |value: LengthOrPercentageOrAuto| -> LengthOrPercentageOrAuto {
|
||||
match value {
|
||||
LengthOrPercentageOrAuto::Length(len) => {
|
||||
LengthOrPercentageOrAuto::Length(Length::new(len.px().max(0.)))
|
||||
},
|
||||
LengthOrPercentageOrAuto::Percentage(percent) => {
|
||||
LengthOrPercentageOrAuto::Percentage(Percentage(percent.0.max(0.)))
|
||||
},
|
||||
_ => value,
|
||||
}
|
||||
};
|
||||
match animated {
|
||||
GenericBackgroundSize::Explicit { width, height } => GenericBackgroundSize::Explicit {
|
||||
width: clamp_animated_value(width),
|
||||
height: clamp_animated_value(height),
|
||||
},
|
||||
_ => animated,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedValue for BackgroundSizeList {
|
||||
type AnimatedValue = Self;
|
||||
|
||||
#[inline]
|
||||
fn to_animated_value(self) -> Self {
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
|
||||
BackgroundSizeList(ToAnimatedValue::from_animated_value(animated.0))
|
||||
}
|
||||
}
|
||||
|
||||
/// The computed value of the `background-repeat` property:
|
||||
///
|
||||
/// https://drafts.csswg.org/css-backgrounds/#the-background-repeat
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue