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 outline-offset
28pub type BorderSideOffset = Au;
29
30/// A computed value for the `border-image-width` property.
31pub type BorderImageWidth = Rect<BorderImageSideWidth>;
32
33/// A computed value for a single side of a `border-image-width` property.
34pub type BorderImageSideWidth =
35    GenericBorderImageSideWidth<NonNegativeLengthPercentage, NonNegativeNumber>;
36
37/// A computed value for the `border-image-slice` property.
38pub type BorderImageSlice = GenericBorderImageSlice<NonNegativeNumberOrPercentage>;
39
40/// A computed value for the `border-radius` property.
41pub type BorderRadius = GenericBorderRadius<NonNegativeLengthPercentage>;
42
43/// A computed value for the `border-*-radius` longhand properties.
44pub type BorderCornerRadius = GenericBorderCornerRadius<NonNegativeLengthPercentage>;
45
46/// A computed value for the `border-spacing` longhand property.
47pub type BorderSpacing = GenericBorderSpacing<NonNegativeLength>;
48
49impl BorderImageSideWidth {
50    /// Returns `1`.
51    #[inline]
52    pub fn one() -> Self {
53        GenericBorderImageSideWidth::Number(NonNegative(1.))
54    }
55}
56
57impl BorderImageSlice {
58    /// Returns the `100%` value.
59    #[inline]
60    pub fn hundred_percent() -> Self {
61        GenericBorderImageSlice {
62            offsets: Rect::all(NonNegativeNumberOrPercentage::hundred_percent()),
63            fill: false,
64        }
65    }
66}
67
68impl BorderSpacing {
69    /// Returns `0 0`.
70    pub fn zero() -> Self {
71        GenericBorderSpacing(Size2D::new(
72            NonNegativeLength::zero(),
73            NonNegativeLength::zero(),
74        ))
75    }
76
77    /// Returns the horizontal spacing.
78    pub fn horizontal(&self) -> Au {
79        Au::from(*self.0.width())
80    }
81
82    /// Returns the vertical spacing.
83    pub fn vertical(&self) -> Au {
84        Au::from(*self.0.height())
85    }
86}