diff options
author | Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com> | 2023-05-21 18:08:41 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-05-22 06:05:19 +0200 |
commit | 6e0601a63e3639712c86ab1394e0261d3bc491c7 (patch) | |
tree | 332a281c9e4446b57cd6ff283d8215a40fc4eb51 /Userland/Libraries/LibWeb | |
parent | b49e9d2eaba04148869ec41472d15c94973412d3 (diff) | |
download | serenity-6e0601a63e3639712c86ab1394e0261d3bc491c7.zip |
LibWeb/CSS: Implement parsing of grid-auto-columns and grid-auto-rows
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/ComputedValues.h | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 26 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/Parser.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Properties.json | 24 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleProperties.cpp | 12 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleProperties.h | 2 |
6 files changed, 71 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/ComputedValues.h b/Userland/Libraries/LibWeb/CSS/ComputedValues.h index dd50f5a282..17284b72a5 100644 --- a/Userland/Libraries/LibWeb/CSS/ComputedValues.h +++ b/Userland/Libraries/LibWeb/CSS/ComputedValues.h @@ -251,6 +251,8 @@ public: CSS::Size const& min_height() const { return m_noninherited.min_height; } CSS::Size const& max_height() const { return m_noninherited.max_height; } Variant<CSS::VerticalAlign, CSS::LengthPercentage> const& vertical_align() const { return m_noninherited.vertical_align; } + CSS::GridTrackSizeList const& grid_auto_columns() const { return m_noninherited.grid_auto_columns; } + CSS::GridTrackSizeList const& grid_auto_rows() const { return m_noninherited.grid_auto_rows; } CSS::GridTrackSizeList const& grid_template_columns() const { return m_noninherited.grid_template_columns; } CSS::GridTrackSizeList const& grid_template_rows() const { return m_noninherited.grid_template_rows; } CSS::GridTrackPlacement const& grid_column_end() const { return m_noninherited.grid_column_end; } @@ -385,6 +387,8 @@ protected: CSS::BoxSizing box_sizing { InitialValues::box_sizing() }; CSS::ContentData content; Variant<CSS::VerticalAlign, CSS::LengthPercentage> vertical_align { InitialValues::vertical_align() }; + CSS::GridTrackSizeList grid_auto_columns; + CSS::GridTrackSizeList grid_auto_rows; CSS::GridTrackSizeList grid_template_columns; CSS::GridTrackSizeList grid_template_rows; CSS::GridTrackPlacement grid_column_end { InitialValues::grid_column_end() }; @@ -471,6 +475,8 @@ public: void set_box_sizing(CSS::BoxSizing value) { m_noninherited.box_sizing = value; } void set_vertical_align(Variant<CSS::VerticalAlign, CSS::LengthPercentage> value) { m_noninherited.vertical_align = move(value); } void set_visibility(CSS::Visibility value) { m_inherited.visibility = value; } + void set_grid_auto_columns(CSS::GridTrackSizeList value) { m_noninherited.grid_auto_columns = move(value); } + void set_grid_auto_rows(CSS::GridTrackSizeList value) { m_noninherited.grid_auto_rows = move(value); } void set_grid_template_columns(CSS::GridTrackSizeList value) { m_noninherited.grid_template_columns = move(value); } void set_grid_template_rows(CSS::GridTrackSizeList value) { m_noninherited.grid_template_rows = move(value); } void set_grid_column_end(CSS::GridTrackPlacement value) { m_noninherited.grid_column_end = value; } diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index ad09ecc2eb..8e7becf3b7 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -6486,6 +6486,24 @@ ErrorOr<RefPtr<StyleValue>> Parser::parse_grid_track_size_list(Vector<ComponentV return GridTrackSizeListStyleValue::create(CSS::GridTrackSizeList(track_list, line_names_list)); } +ErrorOr<RefPtr<StyleValue>> Parser::parse_grid_auto_track_sizes(Vector<ComponentValue> const& component_values) +{ + // https://www.w3.org/TR/css-grid-2/#auto-tracks + // <track-size>+ + Vector<CSS::ExplicitGridTrack> track_list; + TokenStream tokens { component_values }; + while (tokens.has_next_token()) { + auto token = tokens.next_token(); + auto track_sizing_function = parse_track_sizing_function(token); + if (!track_sizing_function.has_value()) + return GridTrackSizeListStyleValue::make_auto(); + // FIXME: Handle multiple repeat values (should combine them here, or remove + // any other ones if the first one is auto-fill, etc.) + track_list.append(track_sizing_function.value()); + } + return GridTrackSizeListStyleValue::create(CSS::GridTrackSizeList(track_list, {})); +} + ErrorOr<RefPtr<StyleValue>> Parser::parse_grid_track_placement(Vector<ComponentValue> const& component_values) { // https://www.w3.org/TR/css-grid-2/#line-placement @@ -6962,6 +6980,14 @@ Parser::ParseErrorOr<NonnullRefPtr<StyleValue>> Parser::parse_css_value(Property if (auto parsed_value = FIXME_TRY(parse_grid_track_size_list(component_values))) return parsed_value.release_nonnull(); return ParseError::SyntaxError; + case PropertyID::GridAutoColumns: + if (auto parsed_value = FIXME_TRY(parse_grid_auto_track_sizes(component_values))) + return parsed_value.release_nonnull(); + return ParseError::SyntaxError; + case PropertyID::GridAutoRows: + if (auto parsed_value = FIXME_TRY(parse_grid_auto_track_sizes(component_values))) + return parsed_value.release_nonnull(); + return ParseError::SyntaxError; case PropertyID::ListStyle: if (auto parsed_value = FIXME_TRY(parse_list_style_value(component_values))) return parsed_value.release_nonnull(); diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h index b8a06ad8ca..4b1514ee72 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h @@ -323,6 +323,7 @@ private: ErrorOr<RefPtr<StyleValue>> parse_transform_value(Vector<ComponentValue> const&); ErrorOr<RefPtr<StyleValue>> parse_transform_origin_value(Vector<ComponentValue> const&); ErrorOr<RefPtr<StyleValue>> parse_grid_track_size_list(Vector<ComponentValue> const&, bool allow_separate_line_name_blocks = false); + ErrorOr<RefPtr<StyleValue>> parse_grid_auto_track_sizes(Vector<ComponentValue> const&); ErrorOr<RefPtr<StyleValue>> parse_grid_track_size_list_shorthand_value(Vector<ComponentValue> const&); ErrorOr<RefPtr<StyleValue>> parse_grid_track_placement(Vector<ComponentValue> const&); ErrorOr<RefPtr<StyleValue>> parse_grid_track_placement_shorthand_value(Vector<ComponentValue> const&); diff --git a/Userland/Libraries/LibWeb/CSS/Properties.json b/Userland/Libraries/LibWeb/CSS/Properties.json index 06d240c415..20e56e3e28 100644 --- a/Userland/Libraries/LibWeb/CSS/Properties.json +++ b/Userland/Libraries/LibWeb/CSS/Properties.json @@ -958,6 +958,30 @@ "string" ] }, + "grid-auto-columns": { + "inherited": false, + "initial": "auto", + "valid-identifiers": [ + "auto" + ], + "valid-types": [ + "length", + "percentage", + "string" + ] + }, + "grid-auto-rows": { + "inherited": false, + "initial": "auto", + "valid-identifiers": [ + "auto" + ], + "valid-types": [ + "length", + "percentage", + "string" + ] + }, "grid-template-columns": { "inherited": false, "initial": "auto", diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp index f1409954a1..0aa12da1d6 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -758,6 +758,18 @@ Optional<CSS::FontVariant> StyleProperties::font_variant() const return value_id_to_font_variant(value->to_identifier()); } +CSS::GridTrackSizeList StyleProperties::grid_auto_columns() const +{ + auto value = property(CSS::PropertyID::GridAutoColumns); + return value->as_grid_track_size_list().grid_track_size_list(); +} + +CSS::GridTrackSizeList StyleProperties::grid_auto_rows() const +{ + auto value = property(CSS::PropertyID::GridAutoRows); + return value->as_grid_track_size_list().grid_track_size_list(); +} + CSS::GridTrackSizeList StyleProperties::grid_template_columns() const { auto value = property(CSS::PropertyID::GridTemplateColumns); diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.h b/Userland/Libraries/LibWeb/CSS/StyleProperties.h index 48611441dd..8d9e31c789 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.h +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.h @@ -85,6 +85,8 @@ public: Optional<CSS::PointerEvents> pointer_events() const; Variant<CSS::VerticalAlign, CSS::LengthPercentage> vertical_align() const; Optional<CSS::FontVariant> font_variant() const; + CSS::GridTrackSizeList grid_auto_columns() const; + CSS::GridTrackSizeList grid_auto_rows() const; CSS::GridTrackSizeList grid_template_columns() const; CSS::GridTrackSizeList grid_template_rows() const; CSS::GridTrackPlacement grid_column_end() const; |