mirror of
https://github.com/servo/servo.git
synced 2025-08-09 07:25:35 +01:00
Bug 1374233 - Part 5: Use NonNegativeLength and NonNegativeAu for border-spacing.
We already have NonNegativeLength and NonNegativeAu, so we can re-use it to define the specified value and the computed value of border-spacing. And then implement ToAnimatedValue for it. MozReview-Commit-ID: CLckpKMYVXU
This commit is contained in:
parent
2ef38ce67a
commit
190cd5b952
8 changed files with 67 additions and 33 deletions
|
@ -4582,8 +4582,8 @@ fn static_assert() {
|
|||
skip_longhands="border-spacing">
|
||||
|
||||
pub fn set_border_spacing(&mut self, v: longhands::border_spacing::computed_value::T) {
|
||||
self.gecko.mBorderSpacingCol = v.horizontal.0;
|
||||
self.gecko.mBorderSpacingRow = v.vertical.0;
|
||||
self.gecko.mBorderSpacingCol = v.horizontal.value();
|
||||
self.gecko.mBorderSpacingRow = v.vertical.value();
|
||||
}
|
||||
|
||||
pub fn copy_border_spacing_from(&mut self, other: &Self) {
|
||||
|
@ -4597,8 +4597,8 @@ fn static_assert() {
|
|||
|
||||
pub fn clone_border_spacing(&self) -> longhands::border_spacing::computed_value::T {
|
||||
longhands::border_spacing::computed_value::T {
|
||||
horizontal: Au(self.gecko.mBorderSpacingCol),
|
||||
vertical: Au(self.gecko.mBorderSpacingRow)
|
||||
horizontal: Au(self.gecko.mBorderSpacingCol).into(),
|
||||
vertical: Au(self.gecko.mBorderSpacingRow).into()
|
||||
}
|
||||
}
|
||||
</%self:impl_trait>
|
||||
|
|
|
@ -16,6 +16,7 @@ use euclid::{Point2D, Size2D};
|
|||
#[cfg(feature = "gecko")] use gecko_string_cache::Atom;
|
||||
use properties::{CSSWideKeyword, PropertyDeclaration};
|
||||
use properties::longhands;
|
||||
use properties::longhands::border_spacing::computed_value::T as BorderSpacing;
|
||||
use properties::longhands::font_weight::computed_value::T as FontWeight;
|
||||
use properties::longhands::font_stretch::computed_value::T as FontStretch;
|
||||
use properties::longhands::transform::computed_value::ComputedMatrix;
|
||||
|
|
|
@ -20,21 +20,21 @@ ${helpers.single_keyword("caption-side", "top bottom",
|
|||
animation_value_type="discrete",
|
||||
spec="https://drafts.csswg.org/css-tables/#propdef-caption-side")}
|
||||
|
||||
<%helpers:longhand name="border-spacing" animation_value_type="ComputedValue" boxed="True"
|
||||
<%helpers:longhand name="border-spacing" animation_value_type="BorderSpacing" boxed="True"
|
||||
spec="https://drafts.csswg.org/css-tables/#propdef-border-spacing">
|
||||
use app_units::Au;
|
||||
use values::specified::{AllowQuirks, Length};
|
||||
use values::specified::length::NonNegativeLength;
|
||||
|
||||
pub mod computed_value {
|
||||
use app_units::Au;
|
||||
use properties::animated_properties::Animatable;
|
||||
use values::animated::ToAnimatedZero;
|
||||
use values::animated::{ToAnimatedValue, ToAnimatedZero};
|
||||
use values::computed::NonNegativeAu;
|
||||
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, ToCss)]
|
||||
pub struct T {
|
||||
pub horizontal: Au,
|
||||
pub vertical: Au,
|
||||
pub horizontal: NonNegativeAu,
|
||||
pub vertical: NonNegativeAu,
|
||||
}
|
||||
|
||||
/// https://drafts.csswg.org/css-transitions/#animtype-simple-list
|
||||
|
@ -66,20 +66,38 @@ ${helpers.single_keyword("caption-side", "top bottom",
|
|||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
|
||||
}
|
||||
|
||||
impl ToAnimatedValue for T {
|
||||
type AnimatedValue = Self;
|
||||
|
||||
#[inline]
|
||||
fn to_animated_value(self) -> Self {
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
|
||||
T {
|
||||
horizontal: ToAnimatedValue::from_animated_value(animated.horizontal),
|
||||
vertical: ToAnimatedValue::from_animated_value(animated.vertical)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq, ToCss)]
|
||||
pub struct SpecifiedValue {
|
||||
pub horizontal: Length,
|
||||
pub vertical: Option<Length>,
|
||||
pub horizontal: NonNegativeLength,
|
||||
pub vertical: Option<NonNegativeLength>,
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
use values::computed::NonNegativeAu;
|
||||
computed_value::T {
|
||||
horizontal: Au(0),
|
||||
vertical: Au(0),
|
||||
horizontal: NonNegativeAu::zero(),
|
||||
vertical: NonNegativeAu::zero(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,14 +139,14 @@ ${helpers.single_keyword("caption-side", "top bottom",
|
|||
(None, None) => Err(StyleParseError::UnspecifiedError.into()),
|
||||
(Some(length), None) => {
|
||||
Ok(SpecifiedValue {
|
||||
horizontal: length,
|
||||
horizontal: length.into(),
|
||||
vertical: None,
|
||||
})
|
||||
}
|
||||
(Some(horizontal), Some(vertical)) => {
|
||||
Ok(SpecifiedValue {
|
||||
horizontal: horizontal,
|
||||
vertical: Some(vertical),
|
||||
horizontal: horizontal.into(),
|
||||
vertical: Some(vertical.into()),
|
||||
})
|
||||
}
|
||||
(None, Some(_)) => unreachable!(),
|
||||
|
|
|
@ -708,6 +708,20 @@ impl<T: Parse> Either<Length, T> {
|
|||
/// A wrapper of Length, whose value must be >= 0.
|
||||
pub type NonNegativeLength = NonNegative<Length>;
|
||||
|
||||
impl From<NoCalcLength> for NonNegativeLength {
|
||||
#[inline]
|
||||
fn from(len: NoCalcLength) -> Self {
|
||||
NonNegative::<Length>(Length::NoCalc(len))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Length> for NonNegativeLength {
|
||||
#[inline]
|
||||
fn from(len: Length) -> Self {
|
||||
NonNegative::<Length>(len)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Parse> Parse for Either<NonNegativeLength, T> {
|
||||
#[inline]
|
||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue