Serenity Operating System
1/*
2 * Copyright (c) 2022, Martin Falisse <mfalisse@outlook.com>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#pragma once
8
9#include <AK/String.h>
10
11namespace Web::CSS {
12
13class GridTrackPlacement {
14public:
15 enum class Type {
16 Span,
17 Position,
18 Auto
19 };
20
21 GridTrackPlacement(String line_name, int span_count_or_position, bool has_span = false);
22 GridTrackPlacement(int span_count_or_position, bool has_span = false);
23 GridTrackPlacement(String line_name, bool has_span = false);
24 GridTrackPlacement();
25
26 static GridTrackPlacement make_auto() { return GridTrackPlacement(); };
27
28 bool is_span() const { return m_type == Type::Span; }
29 bool is_position() const { return m_type == Type::Position; }
30 bool is_auto() const { return m_type == Type::Auto; }
31 bool is_auto_positioned() const { return m_type == Type::Auto || (m_type == Type::Span && !has_line_name()); }
32
33 bool has_line_name() const { return !m_line_name.is_empty(); }
34
35 int raw_value() const { return m_span_count_or_position; }
36 Type type() const { return m_type; }
37 String line_name() const { return m_line_name; }
38
39 ErrorOr<String> to_string() const;
40 bool operator==(GridTrackPlacement const& other) const
41 {
42 return m_type == other.type() && m_span_count_or_position == other.raw_value();
43 }
44
45private:
46 Type m_type;
47 int m_span_count_or_position { 0 };
48 String m_line_name;
49};
50
51}