mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-24 18:02:20 +00:00
LibWeb: Use variant to represent CSS::ExplicitGridTrack
No behavior change.
This commit is contained in:
parent
a321eca9d7
commit
8d83dce1d7
Notes:
github-actions[bot]
2025-06-13 17:58:49 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: 8d83dce1d7
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5080
Reviewed-by: https://github.com/trflynn89
3 changed files with 19 additions and 94 deletions
|
@ -179,44 +179,16 @@ String GridRepeat::to_string() const
|
|||
return MUST(builder.to_string());
|
||||
}
|
||||
|
||||
ExplicitGridTrack::ExplicitGridTrack(CSS::GridFitContent grid_fit_content)
|
||||
: m_type(Type::FitContent)
|
||||
, m_grid_fit_content(grid_fit_content)
|
||||
{
|
||||
}
|
||||
|
||||
ExplicitGridTrack::ExplicitGridTrack(CSS::GridMinMax grid_minmax)
|
||||
: m_type(Type::MinMax)
|
||||
, m_grid_minmax(grid_minmax)
|
||||
{
|
||||
}
|
||||
|
||||
ExplicitGridTrack::ExplicitGridTrack(CSS::GridRepeat grid_repeat)
|
||||
: m_type(Type::Repeat)
|
||||
, m_grid_repeat(grid_repeat)
|
||||
{
|
||||
}
|
||||
|
||||
ExplicitGridTrack::ExplicitGridTrack(CSS::GridSize grid_size)
|
||||
: m_type(Type::Default)
|
||||
, m_grid_size(grid_size)
|
||||
ExplicitGridTrack::ExplicitGridTrack(Variant<GridFitContent, GridRepeat, GridMinMax, GridSize>&& value)
|
||||
: m_value(move(value))
|
||||
{
|
||||
}
|
||||
|
||||
String ExplicitGridTrack::to_string() const
|
||||
{
|
||||
switch (m_type) {
|
||||
case Type::FitContent:
|
||||
return m_grid_fit_content.to_string();
|
||||
case Type::MinMax:
|
||||
return m_grid_minmax.to_string();
|
||||
case Type::Repeat:
|
||||
return m_grid_repeat.to_string();
|
||||
case Type::Default:
|
||||
return m_grid_size.to_string();
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
return m_value.visit([](auto const& track) {
|
||||
return track.to_string();
|
||||
});
|
||||
}
|
||||
|
||||
String GridLineNames::to_string() const
|
||||
|
|
|
@ -167,67 +167,25 @@ private:
|
|||
|
||||
class ExplicitGridTrack {
|
||||
public:
|
||||
enum class Type {
|
||||
FitContent,
|
||||
MinMax,
|
||||
Repeat,
|
||||
Default,
|
||||
};
|
||||
ExplicitGridTrack(CSS::GridFitContent);
|
||||
ExplicitGridTrack(CSS::GridRepeat);
|
||||
ExplicitGridTrack(CSS::GridMinMax);
|
||||
ExplicitGridTrack(CSS::GridSize);
|
||||
ExplicitGridTrack(Variant<GridFitContent, GridRepeat, GridMinMax, GridSize>&& value);
|
||||
|
||||
bool is_fit_content() const { return m_type == Type::FitContent; }
|
||||
GridFitContent fit_content() const
|
||||
{
|
||||
VERIFY(is_fit_content());
|
||||
return m_grid_fit_content;
|
||||
}
|
||||
bool is_fit_content() const { return m_value.has<GridFitContent>(); }
|
||||
GridFitContent const& fit_content() const { return m_value.get<GridFitContent>(); }
|
||||
|
||||
bool is_repeat() const { return m_type == Type::Repeat; }
|
||||
GridRepeat repeat() const
|
||||
{
|
||||
VERIFY(is_repeat());
|
||||
return m_grid_repeat;
|
||||
}
|
||||
bool is_repeat() const { return m_value.has<GridRepeat>(); }
|
||||
GridRepeat const& repeat() const { return m_value.get<GridRepeat>(); }
|
||||
|
||||
bool is_minmax() const { return m_type == Type::MinMax; }
|
||||
GridMinMax minmax() const
|
||||
{
|
||||
VERIFY(is_minmax());
|
||||
return m_grid_minmax;
|
||||
}
|
||||
bool is_minmax() const { return m_value.has<GridMinMax>(); }
|
||||
GridMinMax const& minmax() const { return m_value.get<GridMinMax>(); }
|
||||
|
||||
bool is_default() const { return m_type == Type::Default; }
|
||||
GridSize grid_size() const
|
||||
{
|
||||
VERIFY(is_default());
|
||||
return m_grid_size;
|
||||
}
|
||||
|
||||
Type type() const { return m_type; }
|
||||
bool is_default() const { return m_value.has<GridSize>(); }
|
||||
GridSize const& grid_size() const { return m_value.get<GridSize>(); }
|
||||
|
||||
String to_string() const;
|
||||
bool operator==(ExplicitGridTrack const& other) const
|
||||
{
|
||||
if (is_fit_content() && other.is_fit_content())
|
||||
return m_grid_fit_content == other.fit_content();
|
||||
if (is_repeat() && other.is_repeat())
|
||||
return m_grid_repeat == other.repeat();
|
||||
if (is_minmax() && other.is_minmax())
|
||||
return m_grid_minmax == other.minmax();
|
||||
if (is_default() && other.is_default())
|
||||
return m_grid_size == other.grid_size();
|
||||
return false;
|
||||
}
|
||||
bool operator==(ExplicitGridTrack const& other) const = default;
|
||||
|
||||
private:
|
||||
Type m_type;
|
||||
GridFitContent m_grid_fit_content;
|
||||
GridRepeat m_grid_repeat;
|
||||
GridMinMax m_grid_minmax;
|
||||
GridSize m_grid_size;
|
||||
Variant<GridFitContent, GridRepeat, GridMinMax, GridSize> m_value;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -577,18 +577,13 @@ void GridFormattingContext::initialize_grid_tracks_from_definition(GridDimension
|
|||
repeat_count = track_definition.repeat().repeat_count();
|
||||
}
|
||||
for (auto _ = 0; _ < repeat_count; _++) {
|
||||
switch (track_definition.type()) {
|
||||
case CSS::ExplicitGridTrack::Type::Default:
|
||||
case CSS::ExplicitGridTrack::Type::FitContent:
|
||||
case CSS::ExplicitGridTrack::Type::MinMax:
|
||||
if (track_definition.is_default() || track_definition.is_fit_content() || track_definition.is_minmax()) {
|
||||
tracks.append(GridTrack::create_from_definition(track_definition));
|
||||
break;
|
||||
case CSS::ExplicitGridTrack::Type::Repeat:
|
||||
} else if (track_definition.is_repeat()) {
|
||||
for (auto& explicit_grid_track : track_definition.repeat().grid_track_size_list().track_list()) {
|
||||
tracks.append(GridTrack::create_from_definition(explicit_grid_track));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
} else {
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue