mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Make border-spacing serialization consistent, and move it to precomputed_type.
This commit is contained in:
parent
f9c06d7932
commit
2ac1327e4b
21 changed files with 200 additions and 219 deletions
|
@ -348,8 +348,8 @@ impl ToAnimatedValue for ComputedBorderCornerRadius {
|
|||
|
||||
#[inline]
|
||||
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
|
||||
ComputedBorderCornerRadius::new(animated.0.width.clamp_to_non_negative(),
|
||||
animated.0.height.clamp_to_non_negative())
|
||||
ComputedBorderCornerRadius::new((animated.0).0.width.clamp_to_non_negative(),
|
||||
(animated.0).0.height.clamp_to_non_negative())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,12 +4,15 @@
|
|||
|
||||
//! Computed types for CSS values related to borders.
|
||||
|
||||
use app_units::Au;
|
||||
use values::animated::ToAnimatedZero;
|
||||
use values::computed::{Number, NumberOrPercentage};
|
||||
use values::computed::length::LengthOrPercentage;
|
||||
use values::computed::length::{LengthOrPercentage, NonNegativeLength};
|
||||
use values::generics::border::BorderCornerRadius as GenericBorderCornerRadius;
|
||||
use values::generics::border::BorderImageSideWidth as GenericBorderImageSideWidth;
|
||||
use values::generics::border::BorderImageSlice as GenericBorderImageSlice;
|
||||
use values::generics::border::BorderRadius as GenericBorderRadius;
|
||||
use values::generics::border::BorderSpacing as GenericBorderSpacing;
|
||||
use values::generics::rect::Rect;
|
||||
use values::generics::size::Size;
|
||||
|
||||
|
@ -26,7 +29,10 @@ pub type BorderImageSlice = GenericBorderImageSlice<NumberOrPercentage>;
|
|||
pub type BorderRadius = GenericBorderRadius<LengthOrPercentage>;
|
||||
|
||||
/// A computed value for the `border-*-radius` longhand properties.
|
||||
pub type BorderCornerRadius = Size<LengthOrPercentage>;
|
||||
pub type BorderCornerRadius = GenericBorderCornerRadius<LengthOrPercentage>;
|
||||
|
||||
/// A computed value for the `border-spacing` longhand property.
|
||||
pub type BorderSpacing = GenericBorderSpacing<NonNegativeLength>;
|
||||
|
||||
impl BorderImageSideWidth {
|
||||
/// Returns `1`.
|
||||
|
@ -36,6 +42,38 @@ impl BorderImageSideWidth {
|
|||
}
|
||||
}
|
||||
|
||||
impl BorderSpacing {
|
||||
/// Returns `0 0`.
|
||||
pub fn zero() -> Self {
|
||||
GenericBorderSpacing(Size::new(NonNegativeLength::zero(), NonNegativeLength::zero()))
|
||||
}
|
||||
|
||||
/// Returns the horizontal spacing.
|
||||
pub fn horizontal(&self) -> Au {
|
||||
Au::from(*self.0.width())
|
||||
}
|
||||
|
||||
/// Returns the vertical spacing.
|
||||
pub fn vertical(&self) -> Au {
|
||||
Au::from(*self.0.height())
|
||||
}
|
||||
}
|
||||
|
||||
impl BorderCornerRadius {
|
||||
/// Returns `0 0`.
|
||||
pub fn zero() -> Self {
|
||||
GenericBorderCornerRadius(Size::new(LengthOrPercentage::zero(), LengthOrPercentage::zero()))
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for BorderSpacing {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
// FIXME(emilio): Why?
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for BorderCornerRadius {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
|
|
|
@ -35,7 +35,7 @@ pub use self::align::{AlignItems, AlignJustifyContent, AlignJustifySelf, Justify
|
|||
pub use self::angle::Angle;
|
||||
pub use self::background::BackgroundSize;
|
||||
pub use self::border::{BorderImageSlice, BorderImageWidth, BorderImageSideWidth};
|
||||
pub use self::border::{BorderRadius, BorderCornerRadius};
|
||||
pub use self::border::{BorderRadius, BorderCornerRadius, BorderSpacing};
|
||||
pub use self::box_::VerticalAlign;
|
||||
pub use self::color::{Color, ColorPropertyValue, RGBAColor};
|
||||
pub use self::effects::{BoxShadow, Filter, SimpleShadow};
|
||||
|
|
|
@ -33,6 +33,34 @@ pub struct BorderImageSlice<NumberOrPercentage> {
|
|||
pub fill: bool,
|
||||
}
|
||||
|
||||
/// A generic value for the `border-*-radius` longhand properties.
|
||||
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug)]
|
||||
#[derive(PartialEq, ToComputedValue, ToCss)]
|
||||
pub struct BorderCornerRadius<L>(pub Size<L>);
|
||||
|
||||
impl<L> BorderCornerRadius<L> {
|
||||
/// Trivially create a `BorderCornerRadius`.
|
||||
pub fn new(w: L, h: L) -> Self {
|
||||
BorderCornerRadius(Size::new(w, h))
|
||||
}
|
||||
}
|
||||
|
||||
/// A generic value for the `border-spacing` property.
|
||||
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug)]
|
||||
#[derive(PartialEq, ToAnimatedValue, ToComputedValue, ToCss)]
|
||||
pub struct BorderSpacing<L>(pub Size<L>);
|
||||
|
||||
impl<L> BorderSpacing<L> {
|
||||
/// Trivially create a `BorderCornerRadius`.
|
||||
pub fn new(w: L, h: L) -> Self {
|
||||
BorderSpacing(Size::new(w, h))
|
||||
}
|
||||
}
|
||||
|
||||
/// A generic value for `border-radius`, `outline-radius` and `inset()`.
|
||||
///
|
||||
/// https://drafts.csswg.org/css-backgrounds-3/#border-radius
|
||||
|
@ -42,13 +70,13 @@ pub struct BorderImageSlice<NumberOrPercentage> {
|
|||
#[derive(PartialEq, ToComputedValue)]
|
||||
pub struct BorderRadius<LengthOrPercentage> {
|
||||
/// The top left radius.
|
||||
pub top_left: Size<LengthOrPercentage>,
|
||||
pub top_left: BorderCornerRadius<LengthOrPercentage>,
|
||||
/// The top right radius.
|
||||
pub top_right: Size<LengthOrPercentage>,
|
||||
pub top_right: BorderCornerRadius<LengthOrPercentage>,
|
||||
/// The bottom right radius.
|
||||
pub bottom_right: Size<LengthOrPercentage>,
|
||||
pub bottom_right: BorderCornerRadius<LengthOrPercentage>,
|
||||
/// The bottom left radius.
|
||||
pub bottom_left: Size<LengthOrPercentage>,
|
||||
pub bottom_left: BorderCornerRadius<LengthOrPercentage>,
|
||||
}
|
||||
|
||||
impl<N> From<N> for BorderImageSlice<N>
|
||||
|
@ -80,7 +108,12 @@ impl<N> ToCss for BorderImageSlice<N>
|
|||
impl<L> BorderRadius<L> {
|
||||
/// Returns a new `BorderRadius<L>`.
|
||||
#[inline]
|
||||
pub fn new(tl: Size<L>, tr: Size<L>, br: Size<L>, bl: Size<L>) -> Self {
|
||||
pub fn new(
|
||||
tl: BorderCornerRadius<L>,
|
||||
tr: BorderCornerRadius<L>,
|
||||
br: BorderCornerRadius<L>,
|
||||
bl: BorderCornerRadius<L>
|
||||
) -> Self {
|
||||
BorderRadius {
|
||||
top_left: tl,
|
||||
top_right: tr,
|
||||
|
@ -112,10 +145,10 @@ impl<L> ToCss for BorderRadius<L>
|
|||
{
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
let BorderRadius {
|
||||
top_left: ref tl,
|
||||
top_right: ref tr,
|
||||
bottom_right: ref br,
|
||||
bottom_left: ref bl,
|
||||
top_left: BorderCornerRadius(ref tl),
|
||||
top_right: BorderCornerRadius(ref tr),
|
||||
bottom_right: BorderCornerRadius(ref br),
|
||||
bottom_left: BorderCornerRadius(ref bl),
|
||||
} = *self;
|
||||
|
||||
let widths = Rect::new(&tl.0.width, &tr.0.width, &br.0.width, &bl.0.width);
|
||||
|
|
|
@ -7,14 +7,16 @@
|
|||
use cssparser::Parser;
|
||||
use parser::{Parse, ParserContext};
|
||||
use style_traits::ParseError;
|
||||
use values::computed::{Context, NonNegativeLength, ToComputedValue};
|
||||
use values::generics::size::Size;
|
||||
use values::computed::{self, Context, ToComputedValue};
|
||||
use values::generics::border::BorderCornerRadius as GenericBorderCornerRadius;
|
||||
use values::generics::border::BorderImageSideWidth as GenericBorderImageSideWidth;
|
||||
use values::generics::border::BorderImageSlice as GenericBorderImageSlice;
|
||||
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::{AllowQuirks, Number, NumberOrPercentage};
|
||||
use values::specified::length::{Length, LengthOrPercentage};
|
||||
use values::specified::length::{Length, LengthOrPercentage, NonNegativeLength};
|
||||
|
||||
/// A specified value for a single side of the `border-width` property.
|
||||
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
||||
|
@ -44,7 +46,10 @@ pub type BorderImageSlice = GenericBorderImageSlice<NumberOrPercentage>;
|
|||
pub type BorderRadius = GenericBorderRadius<LengthOrPercentage>;
|
||||
|
||||
/// A specified value for the `border-*-radius` longhand properties.
|
||||
pub type BorderCornerRadius = Size<LengthOrPercentage>;
|
||||
pub type BorderCornerRadius = GenericBorderCornerRadius<LengthOrPercentage>;
|
||||
|
||||
/// A specified value for the `border-spacing` longhand properties.
|
||||
pub type BorderSpacing = GenericBorderSpacing<NonNegativeLength>;
|
||||
|
||||
impl BorderSideWidth {
|
||||
/// Parses, with quirks.
|
||||
|
@ -72,7 +77,7 @@ impl Parse for BorderSideWidth {
|
|||
}
|
||||
|
||||
impl ToComputedValue for BorderSideWidth {
|
||||
type ComputedValue = NonNegativeLength;
|
||||
type ComputedValue = computed::NonNegativeLength;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||
|
@ -149,11 +154,22 @@ impl Parse for BorderRadius {
|
|||
}
|
||||
|
||||
impl Parse for BorderCornerRadius {
|
||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||
let first = LengthOrPercentage::parse_non_negative(context, input)?;
|
||||
let second = input
|
||||
.try(|i| LengthOrPercentage::parse_non_negative(context, i))
|
||||
.unwrap_or_else(|_| first.clone());
|
||||
Ok(Self::new(first, second))
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
Size::parse_with(context, input, LengthOrPercentage::parse_non_negative)
|
||||
.map(GenericBorderCornerRadius)
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for BorderSpacing {
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
Size::parse_with(context, input, |context, input| {
|
||||
Length::parse_non_negative_quirky(context, input, AllowQuirks::Yes).map(From::from)
|
||||
}).map(GenericBorderSpacing)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ pub use self::angle::Angle;
|
|||
pub use self::align::{AlignItems, AlignJustifyContent, AlignJustifySelf, JustifyItems};
|
||||
pub use self::background::BackgroundSize;
|
||||
pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth};
|
||||
pub use self::border::{BorderImageSideWidth, BorderRadius, BorderSideWidth};
|
||||
pub use self::border::{BorderImageSideWidth, BorderRadius, BorderSideWidth, BorderSpacing};
|
||||
pub use self::box_::VerticalAlign;
|
||||
pub use self::color::{Color, ColorPropertyValue, RGBAColor};
|
||||
pub use self::effects::{BoxShadow, Filter, SimpleShadow};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue