mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 11:27: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:
parent
9d99bd8258
commit
0448547553
3 changed files with 23 additions and 4 deletions
|
@ -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()
|
GridSize::GridSize()
|
||||||
: m_length { Length::make_auto() }
|
: m_length { Length::make_auto() }
|
||||||
{
|
{
|
||||||
|
@ -54,6 +61,10 @@ ErrorOr<String> GridSize::to_string() const
|
||||||
return m_percentage.to_string();
|
return m_percentage.to_string();
|
||||||
case Type::FlexibleLength:
|
case Type::FlexibleLength:
|
||||||
return String::formatted("{}fr", m_flexible_length);
|
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();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,14 @@ public:
|
||||||
Length,
|
Length,
|
||||||
Percentage,
|
Percentage,
|
||||||
FlexibleLength,
|
FlexibleLength,
|
||||||
// TODO: Max-Content
|
MaxContent,
|
||||||
|
MinContent,
|
||||||
};
|
};
|
||||||
|
|
||||||
GridSize(Length);
|
GridSize(Length);
|
||||||
GridSize(Percentage);
|
GridSize(Percentage);
|
||||||
GridSize(float);
|
GridSize(float);
|
||||||
|
GridSize(Type);
|
||||||
GridSize();
|
GridSize();
|
||||||
~GridSize();
|
~GridSize();
|
||||||
|
|
||||||
|
@ -34,17 +36,19 @@ public:
|
||||||
bool is_length() const { return m_type == Type::Length; }
|
bool is_length() const { return m_type == Type::Length; }
|
||||||
bool is_percentage() const { return m_type == Type::Percentage; }
|
bool is_percentage() const { return m_type == Type::Percentage; }
|
||||||
bool is_flexible_length() const { return m_type == Type::FlexibleLength; }
|
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;
|
Length length() const;
|
||||||
Percentage percentage() const { return m_percentage; }
|
Percentage percentage() const { return m_percentage; }
|
||||||
float flexible_length() const { return m_flexible_length; }
|
float flexible_length() const { return m_flexible_length; }
|
||||||
|
|
||||||
// https://drafts.csswg.org/css-grid/#layout-algorithm
|
// https://www.w3.org/TR/css-grid-2/#layout-algorithm
|
||||||
// Intrinsic sizing function - min-content, max-content, auto, fit-content()
|
// An intrinsic sizing function (min-content, max-content, auto, fit-content()).
|
||||||
// FIXME: Add missing properties once implemented.
|
// FIXME: Add missing properties once implemented.
|
||||||
bool is_intrinsic_track_sizing() const
|
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
|
bool is_definite() const
|
||||||
|
|
|
@ -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))
|
if (token.is(Token::Type::Ident) && token.ident().equals_ignoring_case("auto"sv))
|
||||||
return GridSize::make_auto();
|
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);
|
auto dimension = parse_dimension(token);
|
||||||
if (!dimension.has_value())
|
if (!dimension.has_value())
|
||||||
return {};
|
return {};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue