1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 11:57:35 +00:00

LibWeb: Parse min and max-content

Parse min and max-content as well as use its values in the GridTrackSize
class.
This commit is contained in:
martinfalisse 2023-01-16 17:33:30 +01:00 committed by Andreas Kling
parent 9d99bd8258
commit 0448547553
3 changed files with 23 additions and 4 deletions

View file

@ -33,6 +33,13 @@ GridSize::GridSize(float flexible_length)
{
}
GridSize::GridSize(Type type)
: m_length { Length::make_auto() }
{
VERIFY(type == Type::MinContent || type == Type::MaxContent);
m_type = type;
}
GridSize::GridSize()
: m_length { Length::make_auto() }
{
@ -54,6 +61,10 @@ ErrorOr<String> GridSize::to_string() const
return m_percentage.to_string();
case Type::FlexibleLength:
return String::formatted("{}fr", m_flexible_length);
case Type::MaxContent:
return String::from_utf8("max-content"sv);
case Type::MinContent:
return String::from_utf8("min-content"sv);
}
VERIFY_NOT_REACHED();
}

View file

@ -18,12 +18,14 @@ public:
Length,
Percentage,
FlexibleLength,
// TODO: Max-Content
MaxContent,
MinContent,
};
GridSize(Length);
GridSize(Percentage);
GridSize(float);
GridSize(Type);
GridSize();
~GridSize();
@ -34,17 +36,19 @@ public:
bool is_length() const { return m_type == Type::Length; }
bool is_percentage() const { return m_type == Type::Percentage; }
bool is_flexible_length() const { return m_type == Type::FlexibleLength; }
bool is_max_content() const { return m_type == Type::MaxContent; }
bool is_min_content() const { return m_type == Type::MinContent; }
Length length() const;
Percentage percentage() const { return m_percentage; }
float flexible_length() const { return m_flexible_length; }
// https://drafts.csswg.org/css-grid/#layout-algorithm
// Intrinsic sizing function - min-content, max-content, auto, fit-content()
// https://www.w3.org/TR/css-grid-2/#layout-algorithm
// An intrinsic sizing function (min-content, max-content, auto, fit-content()).
// FIXME: Add missing properties once implemented.
bool is_intrinsic_track_sizing() const
{
return (m_type == Type::Length && m_length.is_auto());
return (m_type == Type::Length && m_length.is_auto()) || m_type == Type::MaxContent || m_type == Type::MinContent;
}
bool is_definite() const

View file

@ -5934,6 +5934,10 @@ Optional<CSS::GridSize> Parser::parse_grid_size(ComponentValue const& component_
}
if (token.is(Token::Type::Ident) && token.ident().equals_ignoring_case("auto"sv))
return GridSize::make_auto();
if (token.is(Token::Type::Ident) && token.ident().equals_ignoring_case("max-content"sv))
return GridSize(GridSize::Type::MaxContent);
if (token.is(Token::Type::Ident) && token.ident().equals_ignoring_case("min-content"sv))
return GridSize(GridSize::Type::MinContent);
auto dimension = parse_dimension(token);
if (!dimension.has_value())
return {};