summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAliaksandr Kalenik <kalenik.aliaksandr@gmail.com>2023-05-10 23:46:33 +0300
committerAndreas Kling <kling@serenityos.org>2023-05-11 18:36:56 +0200
commitc2f6ba8f5f13a49b1946aff1beca8abdc77724db (patch)
tree3a29b7ea161700d2b9ffbf298deac141b461e242 /Userland
parent7fee05e18c75d59a71f4c0c6af8f286e7759e64d (diff)
downloadserenity-c2f6ba8f5f13a49b1946aff1beca8abdc77724db.zip
LibWeb: Parse calc() function in grid sizes
Adds missing part of grid size parsing function to handle calc().
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp3
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp18
2 files changed, 19 insertions, 2 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp b/Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp
index 20e75a1c9a..22fcdb13fb 100644
--- a/Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp
+++ b/Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp
@@ -48,6 +48,9 @@ Size GridSize::css_size() const
return CSS::Size::make_auto();
if (m_length_percentage.is_length())
return CSS::Size::make_length(m_length_percentage.length());
+ if (m_length_percentage.is_calculated()) {
+ return CSS::Size::make_calculated(m_length_percentage.calculated());
+ }
return CSS::Size::make_percentage(m_length_percentage.percentage());
}
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
index bf9c709040..f0b890935e 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
@@ -6238,9 +6238,18 @@ ErrorOr<RefPtr<StyleValue>> Parser::parse_as_css_value(PropertyID property_id)
Optional<CSS::GridSize> Parser::parse_grid_size(ComponentValue const& component_value)
{
- // FIXME: Parse calc here if necessary
- if (component_value.is_function())
+ if (component_value.is_function()) {
+ auto const& function = component_value.function();
+ if (function.name().equals_ignoring_ascii_case("calc"sv)) {
+ auto calculated_style_value = parse_calculated_value(function.values());
+ if (calculated_style_value.is_error()) {
+ // FIXME: Propagate error
+ return {};
+ }
+ return GridSize(LengthPercentage { *calculated_style_value.release_value() });
+ }
return {};
+ }
auto token = component_value.token();
if (token.is(Token::Type::Dimension) && token.dimension_unit().equals_ignoring_ascii_case("fr"sv)) {
float numeric_value = token.dimension_value();
@@ -6417,6 +6426,11 @@ Optional<CSS::ExplicitGridTrack> Parser::parse_track_sizing_function(ComponentVa
return CSS::ExplicitGridTrack(maybe_min_max_value.value());
else
return {};
+ } else if (function_token.name().equals_ignoring_ascii_case("calc"sv)) {
+ auto grid_size = parse_grid_size(token);
+ if (!grid_size.has_value())
+ return {};
+ return CSS::ExplicitGridTrack(grid_size.value());
}
return {};
} else if (token.is(Token::Type::Ident) && token.token().ident().equals_ignoring_ascii_case("auto"sv)) {