Skip to main content

hpx_browser/css_values/
property.rs

1use crate::css_values::types::{
2    color::Color, custom::VarReference, display::*, font::*, length::*,
3    transform::TransformFunction,
4};
5
6/// Identifies a CSS property by name.
7#[derive(Debug, Clone, PartialEq, Eq, Hash)]
8pub enum PropertyId {
9    Display,
10    Position,
11    Width,
12    Height,
13    MinWidth,
14    MinHeight,
15    MaxWidth,
16    MaxHeight,
17    MarginTop,
18    MarginRight,
19    MarginBottom,
20    MarginLeft,
21    PaddingTop,
22    PaddingRight,
23    PaddingBottom,
24    PaddingLeft,
25    BorderTopWidth,
26    BorderRightWidth,
27    BorderBottomWidth,
28    BorderLeftWidth,
29    BoxSizing,
30    OverflowX,
31    OverflowY,
32    Float,
33    Clear,
34    FlexDirection,
35    FlexWrap,
36    FlexGrow,
37    FlexShrink,
38    FlexBasis,
39    AlignItems,
40    AlignSelf,
41    AlignContent,
42    JustifyContent,
43    JustifyItems,
44    JustifySelf,
45    Gap,
46    RowGap,
47    ColumnGap,
48    FontSize,
49    FontFamily,
50    FontWeight,
51    FontStyle,
52    LineHeight,
53    TextAlign,
54    WhiteSpace,
55    Color,
56    BackgroundColor,
57    Visibility,
58    Opacity,
59    ZIndex,
60    ContentVisibility,
61    Transform,
62    Custom(String),
63}
64
65impl PropertyId {
66    pub fn from_name(name: &str) -> Self {
67        match name.to_ascii_lowercase().as_str() {
68            "display" => Self::Display,
69            "position" => Self::Position,
70            "width" => Self::Width,
71            "height" => Self::Height,
72            "min-width" => Self::MinWidth,
73            "min-height" => Self::MinHeight,
74            "max-width" => Self::MaxWidth,
75            "max-height" => Self::MaxHeight,
76            "margin-top" => Self::MarginTop,
77            "margin-right" => Self::MarginRight,
78            "margin-bottom" => Self::MarginBottom,
79            "margin-left" => Self::MarginLeft,
80            "padding-top" => Self::PaddingTop,
81            "padding-right" => Self::PaddingRight,
82            "padding-bottom" => Self::PaddingBottom,
83            "padding-left" => Self::PaddingLeft,
84            "border-top-width" => Self::BorderTopWidth,
85            "border-right-width" => Self::BorderRightWidth,
86            "border-bottom-width" => Self::BorderBottomWidth,
87            "border-left-width" => Self::BorderLeftWidth,
88            "box-sizing" => Self::BoxSizing,
89            "overflow-x" => Self::OverflowX,
90            "overflow-y" => Self::OverflowY,
91            "float" => Self::Float,
92            "clear" => Self::Clear,
93            "flex-direction" => Self::FlexDirection,
94            "flex-wrap" => Self::FlexWrap,
95            "flex-grow" => Self::FlexGrow,
96            "flex-shrink" => Self::FlexShrink,
97            "flex-basis" => Self::FlexBasis,
98            "align-items" => Self::AlignItems,
99            "align-self" => Self::AlignSelf,
100            "align-content" => Self::AlignContent,
101            "justify-content" => Self::JustifyContent,
102            "justify-items" => Self::JustifyItems,
103            "justify-self" => Self::JustifySelf,
104            "gap" => Self::Gap,
105            "row-gap" => Self::RowGap,
106            "column-gap" => Self::ColumnGap,
107            "font-size" => Self::FontSize,
108            "font-family" => Self::FontFamily,
109            "font-weight" => Self::FontWeight,
110            "font-style" => Self::FontStyle,
111            "line-height" => Self::LineHeight,
112            "text-align" => Self::TextAlign,
113            "white-space" => Self::WhiteSpace,
114            "color" => Self::Color,
115            "background-color" => Self::BackgroundColor,
116            "visibility" => Self::Visibility,
117            "opacity" => Self::Opacity,
118            "z-index" => Self::ZIndex,
119            "content-visibility" => Self::ContentVisibility,
120            "transform" => Self::Transform,
121            name if name.starts_with("--") => Self::Custom(name.to_string()),
122            _ => Self::Custom(name.to_string()),
123        }
124    }
125}
126
127/// A typed CSS property value.
128#[derive(Debug, Clone, PartialEq)]
129pub enum CssValue {
130    Initial,
131    Inherit,
132    Unset,
133    Revert,
134    RevertLayer,
135    Display(Display),
136    Position(Position),
137    BoxSizing(BoxSizing),
138    Overflow(Overflow),
139    Float(Float),
140    Clear(Clear),
141    Visibility(Visibility),
142    ContentVisibility(ContentVisibility),
143    Length(Length),
144    LengthPercentage(LengthPercentage),
145    LengthPercentageAuto(LengthPercentageAuto),
146    Number(f64),
147    Integer(i32),
148    Color(Color),
149    FlexDirection(FlexDirection),
150    FlexWrap(FlexWrap),
151    Alignment(AlignmentValue),
152    FontFamily(Vec<FontFamily>),
153    FontWeight(FontWeight),
154    FontStyle(FontStyle),
155    TextAlign(TextAlign),
156    WhiteSpace(WhiteSpace),
157    LineHeight(LineHeight),
158    Transform(Vec<TransformFunction>),
159    CustomValue(String),
160    Var(VarReference),
161}
162
163#[derive(Debug, Clone, PartialEq)]
164pub enum LineHeight {
165    Normal,
166    Number(f64),
167    Length(Length),
168    Percentage(f64),
169}
170
171#[derive(Debug, Clone, PartialEq)]
172pub struct PropertyDeclaration {
173    pub property: PropertyId,
174    pub value: CssValue,
175    pub important: bool,
176}