1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:47:45 +00:00

LibWeb: Add parent classes for managing GridTrackSizes

Add classes ExplicitTrackSizing and MetaGridTrackSize which will allow
for managing properties like auto-fill and minmax.

In the following CSS example there are 3 classes that will be used:
grid-template-column: repeat(auto-fill, minmax(50px, 1fr) 75px);

ExplicitTrackSizing - will contain the entire value. e.g.
repeat(auto-fill, minmax(50px, 1fr) 75px)

With a flag if it's a repeat, as well as references to the
MetaGridTrackSizes which is the next step down.

MetaGridTrackSize:
Contain the individual grid track sizes. Here there are two:
minmax(50px, 1fr) as well as 75px.

This way can keep track if it's a minmax function or not, and the
references to both GridTrackSizes in the case it is, or in just the one
if it is not.

GridTrackSize:
Is the most basic element, in this case there are three in total; two of
which are held by the first MetaGridTrackSize, and the third is held by
the second MetaGridTrackSize.
Examples: 50px, 1fr and 75px.
This commit is contained in:
martinfalisse 2022-10-09 19:34:27 +02:00 committed by Andreas Kling
parent 414a22a386
commit f7af190de0
10 changed files with 144 additions and 54 deletions

View file

@ -6,6 +6,7 @@
#pragma once
#include <AK/Vector.h>
#include <LibWeb/CSS/Length.h>
#include <LibWeb/CSS/Percentage.h>
@ -64,4 +65,48 @@ private:
float m_flexible_length { 0 };
};
class MetaGridTrackSize {
public:
MetaGridTrackSize(CSS::GridTrackSize);
GridTrackSize grid_track_size() const& { return m_min_grid_track_size; }
GridTrackSize min_grid_track_size() const& { return m_min_grid_track_size; }
GridTrackSize max_grid_track_size() const& { return m_max_grid_track_size; }
String to_string() const;
bool operator==(MetaGridTrackSize const& other) const
{
return m_min_grid_track_size == other.min_grid_track_size()
&& m_max_grid_track_size == other.max_grid_track_size();
}
private:
GridTrackSize m_min_grid_track_size;
GridTrackSize m_max_grid_track_size;
};
class ExplicitTrackSizing {
public:
ExplicitTrackSizing();
ExplicitTrackSizing(Vector<CSS::MetaGridTrackSize>);
ExplicitTrackSizing(Vector<CSS::MetaGridTrackSize>, int repeat_count);
static ExplicitTrackSizing make_auto() { return ExplicitTrackSizing(); };
bool is_repeat() const { return m_is_repeat; }
int repeat_count() const { return m_repeat_count; }
Vector<CSS::MetaGridTrackSize> meta_grid_track_sizes() const& { return m_meta_grid_track_sizes; }
String to_string() const;
bool operator==(ExplicitTrackSizing const& other) const
{
return m_meta_grid_track_sizes == other.meta_grid_track_sizes();
}
private:
Vector<CSS::MetaGridTrackSize> m_meta_grid_track_sizes;
bool m_is_repeat { false };
int m_repeat_count { 0 };
};
}