2022-08-24 12:21:58 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022, Martin Falisse <mfalisse@outlook.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "GridTrackPlacement.h"
|
2022-12-04 18:02:33 +00:00
|
|
|
#include <AK/DeprecatedString.h>
|
2022-08-24 12:21:58 +02:00
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
2022-10-30 13:40:57 +01:00
|
|
|
GridTrackPlacement::GridTrackPlacement(int span_count_or_position, bool has_span)
|
2022-09-17 18:09:35 +02:00
|
|
|
: m_type(has_span ? Type::Span : Type::Position)
|
2022-10-30 13:40:57 +01:00
|
|
|
, m_span_count_or_position(span_count_or_position)
|
2022-08-24 12:21:58 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
GridTrackPlacement::GridTrackPlacement(DeprecatedString line_name, int span_count_or_position, bool has_span)
|
2022-10-30 13:46:50 +01:00
|
|
|
: m_type(has_span ? Type::Span : Type::Position)
|
|
|
|
, m_span_count_or_position(span_count_or_position)
|
|
|
|
, m_line_name(line_name)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
GridTrackPlacement::GridTrackPlacement(DeprecatedString line_name, bool has_span)
|
2022-10-30 13:46:50 +01:00
|
|
|
: m_type(has_span ? Type::Span : Type::Position)
|
|
|
|
, m_line_name(line_name)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-08-24 12:21:58 +02:00
|
|
|
GridTrackPlacement::GridTrackPlacement()
|
2022-09-17 18:09:35 +02:00
|
|
|
: m_type(Type::Auto)
|
2022-08-24 12:21:58 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-01-06 19:02:26 +01:00
|
|
|
ErrorOr<String> GridTrackPlacement::to_string() const
|
2022-08-24 12:21:58 +02:00
|
|
|
{
|
|
|
|
StringBuilder builder;
|
2022-10-30 13:40:57 +01:00
|
|
|
if (is_auto()) {
|
|
|
|
builder.append("auto"sv);
|
2023-01-06 19:02:26 +01:00
|
|
|
return builder.to_string();
|
2022-10-30 13:40:57 +01:00
|
|
|
}
|
|
|
|
if (is_span()) {
|
|
|
|
builder.append("span"sv);
|
|
|
|
builder.append(" "sv);
|
|
|
|
}
|
|
|
|
if (m_span_count_or_position != 0) {
|
2023-01-06 19:02:26 +01:00
|
|
|
builder.append(TRY(String::number(m_span_count_or_position)));
|
2022-10-30 13:40:57 +01:00
|
|
|
builder.append(" "sv);
|
|
|
|
}
|
2022-10-30 13:46:50 +01:00
|
|
|
if (has_line_name()) {
|
|
|
|
builder.append(m_line_name);
|
|
|
|
}
|
2023-01-06 19:02:26 +01:00
|
|
|
return builder.to_string();
|
2022-08-24 12:21:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|