Skip to content

Commit

Permalink
web/core: Parse "justify-self" property
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwuelker committed Nov 23, 2023
1 parent c545c16 commit cec761e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
6 changes: 6 additions & 0 deletions crates/web/core/identifiers.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"b",
"background-color",
"base",
"baseline",
"basefont",
"before",
"beige",
Expand Down Expand Up @@ -129,6 +130,7 @@
"figcaption",
"figure",
"firebrick",
"first",
"first-letter",
"first-line",
"fixed",
Expand Down Expand Up @@ -193,10 +195,12 @@
"inset",
"is",
"ivory",
"justify-self",
"keygen",
"khaki",
"large",
"larger",
"last",
"lavender",
"lavenderblush",
"lawngreen",
Expand Down Expand Up @@ -271,6 +275,7 @@
"noembed",
"noframes",
"none",
"normal",
"noscript",
"object",
"ol",
Expand Down Expand Up @@ -354,6 +359,7 @@
"static",
"steelblue",
"sticky",
"stretch",
"strike",
"strong",
"style",
Expand Down
7 changes: 7 additions & 0 deletions crates/web/core/properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@
"value": "AutoOr<PercentageOr<Length>>",
"initial": "AutoOr::Auto"
},
{
"name": "justify-self",
"specification": "https://drafts.csswg.org/css-align-3/#propdef-justify-self",
"inherited": false,
"value": "AutoOr<JustifySelf>",
"initial": "AutoOr::Auto"
},
{
"name": "left",
"specification": "https://drafts.csswg.org/css-position/#propdef-left",
Expand Down
47 changes: 47 additions & 0 deletions crates/web/core/src/css/values/alignment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use crate::{
css::{self, CSSParse},
static_interned,
};

/// <https://drafts.csswg.org/css-align-3/#propdef-justify-self>
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum JustifySelf {
/// <https://drafts.csswg.org/css-align-3/#valdef-justify-self-normal>
Normal,

/// <https://drafts.csswg.org/css-align-3/#valdef-justify-self-stretch>
Stretch,

/// <https://drafts.csswg.org/css-align-3/#valdef-justify-self-first-baseline>
FirstBaseline,

/// <https://drafts.csswg.org/css-align-3/#valdef-justify-self-last-baseline>
LastBaseline,
// FIXME: There are more values here
}

impl<'a> CSSParse<'a> for JustifySelf {
fn parse(parser: &mut css::Parser<'a>) -> Result<Self, css::ParseError> {
let justify_self = match parser.expect_identifier()? {
static_interned!("normal") => Self::Normal,
static_interned!("stretch") => Self::Stretch,
static_interned!("first") => {
parser.skip_whitespace();
let static_interned!("baseline") = parser.expect_identifier()? else {
return Err(css::ParseError);
};
Self::FirstBaseline
},
static_interned!("last") => {
parser.skip_whitespace();
let static_interned!("baseline") = parser.expect_identifier()? else {
return Err(css::ParseError);
};
Self::LastBaseline
},
_ => return Err(css::ParseError),
};

Ok(justify_self)
}
}
2 changes: 2 additions & 0 deletions crates/web/core/src/css/values/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod alignment;
mod auto;
mod background_color;
mod border;
Expand All @@ -11,6 +12,7 @@ mod number;
mod percentage;
mod position;

pub use alignment::JustifySelf;
pub use auto::AutoOr;
pub use background_color::BackgroundColor;
pub use border::{Border, LineStyle, LineWidth};
Expand Down

0 comments on commit cec761e

Please sign in to comment.