style/values/computed/
border.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5//! Computed types for CSS values related to borders.
6
7use crate::values::computed::length::{NonNegativeLength, NonNegativeLengthPercentage};
8use crate::values::computed::{NonNegativeNumber, NonNegativeNumberOrPercentage};
9use crate::values::generics::border::{
10    GenericBorderCornerRadius, GenericBorderImageSideWidth, GenericBorderImageSlice,
11    GenericBorderRadius, GenericBorderSpacing,
12};
13use crate::values::generics::rect::Rect;
14use crate::values::generics::size::Size2D;
15use crate::values::generics::NonNegative;
16use crate::Zero;
17use app_units::Au;
18
19pub use crate::values::specified::border::BorderImageRepeat;
20
21/// A computed value for -webkit-text-stroke-width.
22pub type LineWidth = Au;
23
24/// A computed value for border-width (and the like).
25pub type BorderSideWidth = Au;
26
27/// A computed value for the `border-image-width` property.
28pub type BorderImageWidth = Rect<BorderImageSideWidth>;
29
30/// A computed value for a single side of a `border-image-width` property.
31pub type BorderImageSideWidth =
32    GenericBorderImageSideWidth<NonNegativeLengthPercentage, NonNegativeNumber>;
33
34/// A computed value for the `border-image-slice` property.
35pub type BorderImageSlice = GenericBorderImageSlice<NonNegativeNumberOrPercentage>;
36
37/// A computed value for the `border-radius` property.
38pub type BorderRadius = GenericBorderRadius<NonNegativeLengthPercentage>;
39
40/// A computed value for the `border-*-radius` longhand properties.
41pub type BorderCornerRadius = GenericBorderCornerRadius<NonNegativeLengthPercentage>;
42
43/// A computed value for the `border-spacing` longhand property.
44pub type BorderSpacing = GenericBorderSpacing<NonNegativeLength>;
45
46impl BorderImageSideWidth {
47    /// Returns `1`.
48    #[inline]
49    pub fn one() -> Self {
50        GenericBorderImageSideWidth::Number(NonNegative(1.))
51    }
52}
53
54impl BorderImageSlice {
55    /// Returns the `100%` value.
56    #[inline]
57    pub fn hundred_percent() -> Self {
58        GenericBorderImageSlice {
59            offsets: Rect::all(NonNegativeNumberOrPercentage::hundred_percent()),
60            fill: false,
61        }
62    }
63}
64
65impl BorderSpacing {
66    /// Returns `0 0`.
67    pub fn zero() -> Self {
68        GenericBorderSpacing(Size2D::new(
69            NonNegativeLength::zero(),
70            NonNegativeLength::zero(),
71        ))
72    }
73
74    /// Returns the horizontal spacing.
75    pub fn horizontal(&self) -> Au {
76        Au::from(*self.0.width())
77    }
78
79    /// Returns the vertical spacing.
80    pub fn vertical(&self) -> Au {
81        Au::from(*self.0.height())
82    }
83}