Skip to content

Commit 127bfd6

Browse files
committed
LibWeb: Use Flex type in GridSize
1 parent dfd3d9a commit 127bfd6

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ GridSize::GridSize(LengthPercentage length_percentage)
1414
: m_type(Type::LengthPercentage)
1515
, m_length_percentage(length_percentage) {};
1616

17-
GridSize::GridSize(double flex_factor)
17+
GridSize::GridSize(Flex flex_factor)
1818
: m_type(Type::FlexibleLength)
1919
, m_length_percentage { Length::make_px(0) }
2020
, m_flex_factor(flex_factor)
@@ -87,7 +87,7 @@ String GridSize::to_string() const
8787
case Type::LengthPercentage:
8888
return m_length_percentage.to_string();
8989
case Type::FlexibleLength:
90-
return MUST(String::formatted("{}fr", m_flex_factor));
90+
return m_flex_factor.to_string();
9191
case Type::MaxContent:
9292
return "max-content"_string;
9393
case Type::MinContent:

Userland/Libraries/LibWeb/CSS/GridTrackSize.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class GridSize {
2222
};
2323

2424
GridSize(LengthPercentage);
25-
GridSize(double);
25+
GridSize(Flex);
2626
GridSize(Type);
2727
GridSize();
2828
~GridSize();
@@ -38,7 +38,7 @@ class GridSize {
3838
bool is_min_content() const { return m_type == Type::MinContent; }
3939

4040
LengthPercentage length_percentage() const { return m_length_percentage; }
41-
double flex_factor() const { return m_flex_factor; }
41+
double flex_factor() const { return m_flex_factor.to_fr(); }
4242

4343
// https://www.w3.org/TR/css-grid-2/#layout-algorithm
4444
// An intrinsic sizing function (min-content, max-content, auto, fit-content()).
@@ -57,13 +57,13 @@ class GridSize {
5757
{
5858
return m_type == other.type()
5959
&& m_length_percentage == other.length_percentage()
60-
&& m_flex_factor == other.flex_factor();
60+
&& m_flex_factor == other.m_flex_factor;
6161
}
6262

6363
private:
6464
Type m_type;
6565
LengthPercentage m_length_percentage;
66-
double m_flex_factor { 0 };
66+
Flex m_flex_factor { 0, Flex::Type::Fr };
6767
};
6868

6969
class GridMinMax {

Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5118,17 +5118,15 @@ RefPtr<StyleValue> Parser::parse_as_css_value(PropertyID property_id)
51185118
Optional<CSS::GridSize> Parser::parse_grid_size(ComponentValue const& component_value)
51195119
{
51205120
if (component_value.is_function()) {
5121-
if (auto maybe_calculated = parse_calculated_value(component_value))
5122-
return GridSize(LengthPercentage(maybe_calculated.release_nonnull()));
5121+
if (auto maybe_calculated = parse_calculated_value(component_value)) {
5122+
if (maybe_calculated->resolves_to_length_percentage())
5123+
return GridSize(LengthPercentage(maybe_calculated.release_nonnull()));
5124+
// FIXME: Support calculated <flex>
5125+
}
51235126

51245127
return {};
51255128
}
51265129
auto token = component_value.token();
5127-
if (token.is(Token::Type::Dimension) && token.dimension_unit().equals_ignoring_ascii_case("fr"sv)) {
5128-
auto numeric_value = token.dimension_value();
5129-
if (numeric_value)
5130-
return GridSize(numeric_value);
5131-
}
51325130
if (token.is(Token::Type::Ident) && token.ident().equals_ignoring_ascii_case("auto"sv))
51335131
return GridSize::make_auto();
51345132
if (token.is(Token::Type::Ident) && token.ident().equals_ignoring_ascii_case("max-content"sv))
@@ -5142,6 +5140,8 @@ Optional<CSS::GridSize> Parser::parse_grid_size(ComponentValue const& component_
51425140
return GridSize(dimension->length());
51435141
else if (dimension->is_percentage())
51445142
return GridSize(dimension->percentage());
5143+
else if (dimension->is_flex())
5144+
return GridSize(dimension->flex());
51455145
return {};
51465146
}
51475147

0 commit comments

Comments
 (0)