2022-08-24 12:21:58 +02:00
|
|
|
/*
|
2023-08-25 23:29:13 +02:00
|
|
|
* Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
2022-08-24 12:21:58 +02:00
|
|
|
* Copyright (c) 2022, Martin Falisse <mfalisse@outlook.com>
|
2025-11-18 15:25:03 +00:00
|
|
|
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
2022-08-24 12:21:58 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "GridTrackPlacement.h"
|
2023-01-16 17:29:15 +01:00
|
|
|
#include <AK/StringBuilder.h>
|
2026-03-30 12:21:07 +13:00
|
|
|
#include <LibWeb/CSS/Serialize.h>
|
2025-11-18 15:25:03 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/IntegerStyleValue.h>
|
2022-08-24 12:21:58 +02:00
|
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
|
2026-01-08 15:11:02 +00:00
|
|
|
void GridTrackPlacement::serialize(StringBuilder& builder, SerializationMode mode) const
|
2022-08-24 12:21:58 +02:00
|
|
|
{
|
2023-08-25 23:29:13 +02:00
|
|
|
m_value.visit(
|
|
|
|
|
[&](Auto const&) {
|
|
|
|
|
builder.append("auto"sv);
|
|
|
|
|
},
|
2023-08-27 16:27:35 +02:00
|
|
|
[&](AreaOrLine const& area_or_line) {
|
2026-02-22 22:41:24 +13:00
|
|
|
if (area_or_line.line_number && area_or_line.name.has_value()) {
|
2026-01-08 15:11:02 +00:00
|
|
|
area_or_line.line_number->serialize(builder, mode);
|
|
|
|
|
builder.append(' ');
|
|
|
|
|
builder.append(serialize_an_identifier(*area_or_line.name));
|
2026-02-22 22:41:24 +13:00
|
|
|
} else if (area_or_line.line_number) {
|
2026-01-08 15:11:02 +00:00
|
|
|
area_or_line.line_number->serialize(builder, mode);
|
2025-03-18 15:00:44 +00:00
|
|
|
} else if (area_or_line.name.has_value()) {
|
2026-01-08 15:11:02 +00:00
|
|
|
builder.append(serialize_an_identifier(*area_or_line.name));
|
2023-08-27 16:27:35 +02:00
|
|
|
}
|
2023-08-25 23:29:13 +02:00
|
|
|
},
|
|
|
|
|
[&](Span const& span) {
|
2025-07-08 14:31:40 +12:00
|
|
|
builder.append("span"sv);
|
|
|
|
|
|
2026-02-22 22:41:24 +13:00
|
|
|
if (!span.name.has_value() || !span.value->is_integer() || span.value->as_integer().integer() != 1) {
|
2026-01-08 15:11:02 +00:00
|
|
|
builder.append(' ');
|
2026-02-22 22:41:24 +13:00
|
|
|
span.value->serialize(builder, mode);
|
2026-01-08 15:11:02 +00:00
|
|
|
}
|
2025-07-08 14:31:40 +12:00
|
|
|
|
2026-01-08 15:11:02 +00:00
|
|
|
if (span.name.has_value()) {
|
|
|
|
|
builder.append(' ');
|
|
|
|
|
builder.append(span.name.value());
|
|
|
|
|
}
|
2023-08-25 23:29:13 +02:00
|
|
|
});
|
2026-01-08 15:11:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String GridTrackPlacement::to_string(SerializationMode mode) const
|
|
|
|
|
{
|
|
|
|
|
StringBuilder builder;
|
|
|
|
|
serialize(builder, mode);
|
2023-08-22 12:35:16 +01:00
|
|
|
return MUST(builder.to_string());
|
2022-08-24 12:21:58 +02:00
|
|
|
}
|
|
|
|
|
|
2025-11-18 15:25:03 +00:00
|
|
|
GridTrackPlacement GridTrackPlacement::absolutized(ComputationContext const& context) const
|
|
|
|
|
{
|
|
|
|
|
return m_value.visit(
|
|
|
|
|
[this](Auto const&) {
|
|
|
|
|
return *this;
|
|
|
|
|
},
|
|
|
|
|
[&](AreaOrLine const& area_or_line) -> GridTrackPlacement {
|
|
|
|
|
return AreaOrLine {
|
2026-02-22 22:41:24 +13:00
|
|
|
.line_number = area_or_line.line_number ? ValueComparingRefPtr<StyleValue const> { area_or_line.line_number->absolutized(context) } : nullptr,
|
2025-11-18 15:25:03 +00:00
|
|
|
.name = area_or_line.name,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
[&](Span const& span) -> GridTrackPlacement {
|
|
|
|
|
return Span {
|
2026-02-22 22:41:24 +13:00
|
|
|
.value = span.value->absolutized(context),
|
2025-11-18 15:25:03 +00:00
|
|
|
.name = span.name,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-24 12:21:58 +02:00
|
|
|
}
|