2022-08-24 12:21:15 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022, Martin Falisse <mfalisse@outlook.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "GridTrackSize.h"
|
2023-01-06 19:02:26 +01:00
|
|
|
#include <AK/String.h>
|
2022-08-24 12:21:15 +02:00
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
2022-10-30 13:27:57 +01:00
|
|
|
GridSize::GridSize(Length length)
|
2022-08-24 12:21:15 +02:00
|
|
|
: m_type(Type::Length)
|
|
|
|
, m_length(length)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-10-30 13:27:57 +01:00
|
|
|
GridSize::GridSize(Percentage percentage)
|
2022-08-24 12:21:15 +02:00
|
|
|
: m_type(Type::Percentage)
|
2022-09-13 17:42:39 +02:00
|
|
|
, m_length { Length::make_px(0) }
|
2022-08-24 12:21:15 +02:00
|
|
|
, m_percentage(percentage)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-10-30 13:27:57 +01:00
|
|
|
GridSize::GridSize(float flexible_length)
|
2022-08-24 12:21:15 +02:00
|
|
|
: m_type(Type::FlexibleLength)
|
2022-09-13 17:42:39 +02:00
|
|
|
, m_length { Length::make_px(0) }
|
2022-08-24 12:21:15 +02:00
|
|
|
, m_flexible_length(flexible_length)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-01-16 17:33:30 +01:00
|
|
|
GridSize::GridSize(Type type)
|
|
|
|
: m_length { Length::make_auto() }
|
|
|
|
{
|
|
|
|
VERIFY(type == Type::MinContent || type == Type::MaxContent);
|
|
|
|
m_type = type;
|
|
|
|
}
|
|
|
|
|
2022-10-30 13:27:57 +01:00
|
|
|
GridSize::GridSize()
|
|
|
|
: m_length { Length::make_auto() }
|
|
|
|
{
|
|
|
|
}
|
2022-09-13 17:42:39 +02:00
|
|
|
|
2022-10-30 13:27:57 +01:00
|
|
|
GridSize::~GridSize() = default;
|
|
|
|
|
|
|
|
GridSize GridSize::make_auto()
|
2022-09-07 15:09:32 +02:00
|
|
|
{
|
2022-10-30 13:27:57 +01:00
|
|
|
return GridSize(CSS::Length::make_auto());
|
2022-09-07 15:09:32 +02:00
|
|
|
}
|
|
|
|
|
2023-01-06 19:02:26 +01:00
|
|
|
ErrorOr<String> GridSize::to_string() const
|
2022-08-24 12:21:15 +02:00
|
|
|
{
|
|
|
|
switch (m_type) {
|
|
|
|
case Type::Length:
|
2023-01-06 19:02:26 +01:00
|
|
|
return m_length.to_string();
|
2022-08-24 12:21:15 +02:00
|
|
|
case Type::Percentage:
|
2023-01-06 19:02:26 +01:00
|
|
|
return m_percentage.to_string();
|
2022-08-24 12:21:15 +02:00
|
|
|
case Type::FlexibleLength:
|
2023-01-06 19:02:26 +01:00
|
|
|
return String::formatted("{}fr", m_flexible_length);
|
2023-01-16 17:33:30 +01:00
|
|
|
case Type::MaxContent:
|
2023-02-25 16:40:37 +01:00
|
|
|
return "max-content"_string;
|
2023-01-16 17:33:30 +01:00
|
|
|
case Type::MinContent:
|
2023-02-25 16:40:37 +01:00
|
|
|
return "min-content"_string;
|
2022-08-24 12:21:15 +02:00
|
|
|
}
|
|
|
|
VERIFY_NOT_REACHED();
|
|
|
|
}
|
|
|
|
|
2022-10-30 13:27:57 +01:00
|
|
|
Length GridSize::length() const
|
2022-09-13 17:42:39 +02:00
|
|
|
{
|
|
|
|
return m_length;
|
|
|
|
}
|
|
|
|
|
2022-10-30 13:27:57 +01:00
|
|
|
GridMinMax::GridMinMax(GridSize min_grid_size, GridSize max_grid_size)
|
|
|
|
: m_min_grid_size(min_grid_size)
|
|
|
|
, m_max_grid_size(max_grid_size)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-01-06 19:02:26 +01:00
|
|
|
ErrorOr<String> GridMinMax::to_string() const
|
2022-10-30 13:27:57 +01:00
|
|
|
{
|
|
|
|
StringBuilder builder;
|
|
|
|
builder.append("minmax("sv);
|
2023-01-06 19:02:26 +01:00
|
|
|
builder.appendff("{}", TRY(m_min_grid_size.to_string()));
|
2022-10-30 13:27:57 +01:00
|
|
|
builder.append(", "sv);
|
2023-01-06 19:02:26 +01:00
|
|
|
builder.appendff("{}", TRY(m_max_grid_size.to_string()));
|
2022-10-30 13:27:57 +01:00
|
|
|
builder.append(")"sv);
|
2023-01-06 19:02:26 +01:00
|
|
|
return builder.to_string();
|
2022-10-30 13:27:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GridRepeat::GridRepeat(GridTrackSizeList grid_track_size_list, int repeat_count)
|
|
|
|
: m_type(Type::Default)
|
|
|
|
, m_grid_track_size_list(grid_track_size_list)
|
|
|
|
, m_repeat_count(repeat_count)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GridRepeat::GridRepeat(GridTrackSizeList grid_track_size_list, Type type)
|
|
|
|
: m_type(type)
|
|
|
|
, m_grid_track_size_list(grid_track_size_list)
|
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.
2022-10-09 19:34:27 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-10-30 13:27:57 +01:00
|
|
|
GridRepeat::GridRepeat()
|
2022-10-15 13:04:24 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-01-06 19:02:26 +01:00
|
|
|
ErrorOr<String> GridRepeat::to_string() const
|
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.
2022-10-09 19:34:27 +02:00
|
|
|
{
|
2022-10-30 13:27:57 +01:00
|
|
|
StringBuilder builder;
|
|
|
|
builder.append("repeat("sv);
|
|
|
|
switch (m_type) {
|
|
|
|
case Type::AutoFit:
|
|
|
|
builder.append("auto-fill"sv);
|
|
|
|
break;
|
|
|
|
case Type::AutoFill:
|
|
|
|
builder.append("auto-fit"sv);
|
|
|
|
break;
|
|
|
|
case Type::Default:
|
|
|
|
builder.appendff("{}", m_repeat_count);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
VERIFY_NOT_REACHED();
|
2022-10-15 13:04:24 +02:00
|
|
|
}
|
2022-10-30 13:27:57 +01:00
|
|
|
builder.append(", "sv);
|
2023-01-06 19:02:26 +01:00
|
|
|
builder.appendff("{}", TRY(m_grid_track_size_list.to_string()));
|
2022-10-30 13:27:57 +01:00
|
|
|
builder.append(")"sv);
|
2023-01-06 19:02:26 +01:00
|
|
|
return builder.to_string();
|
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.
2022-10-09 19:34:27 +02:00
|
|
|
}
|
|
|
|
|
2022-10-30 13:27:57 +01:00
|
|
|
ExplicitGridTrack::ExplicitGridTrack(CSS::GridMinMax grid_minmax)
|
|
|
|
: m_type(Type::MinMax)
|
|
|
|
, m_grid_minmax(grid_minmax)
|
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.
2022-10-09 19:34:27 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-10-30 13:27:57 +01:00
|
|
|
ExplicitGridTrack::ExplicitGridTrack(CSS::GridRepeat grid_repeat)
|
|
|
|
: m_type(Type::Repeat)
|
|
|
|
, m_grid_repeat(grid_repeat)
|
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.
2022-10-09 19:34:27 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-10-30 13:27:57 +01:00
|
|
|
ExplicitGridTrack::ExplicitGridTrack(CSS::GridSize grid_size)
|
|
|
|
: m_type(Type::Default)
|
|
|
|
, m_grid_size(grid_size)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-01-06 19:02:26 +01:00
|
|
|
ErrorOr<String> ExplicitGridTrack::to_string() const
|
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.
2022-10-09 19:34:27 +02:00
|
|
|
{
|
2022-10-30 13:27:57 +01:00
|
|
|
switch (m_type) {
|
|
|
|
case Type::MinMax:
|
2023-01-06 19:02:26 +01:00
|
|
|
return m_grid_minmax.to_string();
|
2022-10-30 13:27:57 +01:00
|
|
|
case Type::Repeat:
|
2023-01-06 19:02:26 +01:00
|
|
|
return m_grid_repeat.to_string();
|
2022-10-30 13:27:57 +01:00
|
|
|
case Type::Default:
|
2023-01-06 19:02:26 +01:00
|
|
|
return m_grid_size.to_string();
|
2022-10-30 13:27:57 +01:00
|
|
|
default:
|
|
|
|
VERIFY_NOT_REACHED();
|
|
|
|
}
|
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.
2022-10-09 19:34:27 +02:00
|
|
|
}
|
|
|
|
|
2023-01-16 17:29:15 +01:00
|
|
|
GridTrackSizeList::GridTrackSizeList(Vector<CSS::ExplicitGridTrack> track_list, Vector<Vector<String>> line_names)
|
2022-10-30 13:27:57 +01:00
|
|
|
: m_track_list(track_list)
|
2022-10-30 13:45:40 +01:00
|
|
|
, m_line_names(line_names)
|
2022-10-15 13:02:45 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-10-30 13:27:57 +01:00
|
|
|
GridTrackSizeList::GridTrackSizeList()
|
|
|
|
: m_track_list({})
|
2022-10-30 13:45:40 +01:00
|
|
|
, m_line_names({})
|
2022-10-30 13:27:57 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GridTrackSizeList GridTrackSizeList::make_auto()
|
|
|
|
{
|
|
|
|
return GridTrackSizeList();
|
|
|
|
}
|
|
|
|
|
2023-01-06 19:02:26 +01:00
|
|
|
ErrorOr<String> GridTrackSizeList::to_string() const
|
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.
2022-10-09 19:34:27 +02:00
|
|
|
{
|
|
|
|
StringBuilder builder;
|
2022-10-30 13:45:40 +01:00
|
|
|
auto print_line_names = [&](size_t index) -> void {
|
|
|
|
builder.append("["sv);
|
|
|
|
for (size_t y = 0; y < m_line_names[index].size(); ++y) {
|
|
|
|
builder.append(m_line_names[index][y]);
|
|
|
|
if (y != m_line_names[index].size() - 1)
|
|
|
|
builder.append(" "sv);
|
|
|
|
}
|
|
|
|
builder.append("]"sv);
|
|
|
|
};
|
|
|
|
|
2022-10-30 13:27:57 +01:00
|
|
|
for (size_t i = 0; i < m_track_list.size(); ++i) {
|
2022-10-30 13:45:40 +01:00
|
|
|
if (m_line_names[i].size() > 0) {
|
|
|
|
print_line_names(i);
|
|
|
|
builder.append(" "sv);
|
|
|
|
}
|
2023-01-06 19:02:26 +01:00
|
|
|
builder.append(TRY(m_track_list[i].to_string()));
|
2022-10-30 13:27:57 +01:00
|
|
|
if (i < m_track_list.size() - 1)
|
|
|
|
builder.append(" "sv);
|
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.
2022-10-09 19:34:27 +02:00
|
|
|
}
|
2022-10-30 13:45:40 +01:00
|
|
|
if (m_line_names[m_track_list.size()].size() > 0) {
|
|
|
|
builder.append(" "sv);
|
|
|
|
print_line_names(m_track_list.size());
|
|
|
|
}
|
2023-01-06 19:02:26 +01:00
|
|
|
return builder.to_string();
|
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.
2022-10-09 19:34:27 +02:00
|
|
|
}
|
|
|
|
|
2022-08-24 12:21:15 +02:00
|
|
|
}
|