diff options
author | martinfalisse <martinmotteditfalisse@gmail.com> | 2022-08-24 12:21:58 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-08-25 13:47:48 +0200 |
commit | ca286fc220c534989da6b8c0e04b31f43041a7e7 (patch) | |
tree | e3a8982fc92283d6462dfcbdc1c68a8547a4662e | |
parent | fc369709730ddff69a2d20c4dd36e28d4f4ee194 (diff) | |
download | serenity-ca286fc220c534989da6b8c0e04b31f43041a7e7.zip |
LibWeb: Add GridTrackPlacement for grid-[column/row]-[start/end]
Add GridTrackPlacement to use with grid-column-start and related CSS
properties.
-rw-r--r-- | Userland/Libraries/LibWeb/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/GridTrackPlacement.cpp | 36 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/GridTrackPlacement.h | 38 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Forward.h | 1 |
4 files changed, 76 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 1c22c1eccd..5b05fdc915 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -40,6 +40,7 @@ set(SOURCES CSS/Display.cpp CSS/FontFace.cpp CSS/Frequency.cpp + CSS/GridTrackPlacement.cpp CSS/GridTrackSize.cpp CSS/Length.cpp CSS/MediaList.cpp diff --git a/Userland/Libraries/LibWeb/CSS/GridTrackPlacement.cpp b/Userland/Libraries/LibWeb/CSS/GridTrackPlacement.cpp new file mode 100644 index 0000000000..1c13eec2dd --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/GridTrackPlacement.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022, Martin Falisse <mfalisse@outlook.com> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "GridTrackPlacement.h" +#include <AK/String.h> + +namespace Web::CSS { + +GridTrackPlacement::GridTrackPlacement(int position, bool has_span) + : m_position(position) + , m_has_span(has_span) +{ +} + +GridTrackPlacement::GridTrackPlacement(int position) + : m_position(position) +{ +} + +GridTrackPlacement::GridTrackPlacement() +{ +} + +String GridTrackPlacement::to_string() const +{ + StringBuilder builder; + if (m_has_span) + builder.append("span "sv); + builder.append(String::number(m_position)); + return builder.to_string(); +} + +} diff --git a/Userland/Libraries/LibWeb/CSS/GridTrackPlacement.h b/Userland/Libraries/LibWeb/CSS/GridTrackPlacement.h new file mode 100644 index 0000000000..20cc0b6fde --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/GridTrackPlacement.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2022, Martin Falisse <mfalisse@outlook.com> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <AK/String.h> + +namespace Web::CSS { + +class GridTrackPlacement { +public: + GridTrackPlacement(int, bool); + GridTrackPlacement(int); + GridTrackPlacement(); + + static GridTrackPlacement make_auto() { return GridTrackPlacement(); }; + + void set_position(int position) { m_position = position; } + int position() const { return m_position; } + + void set_has_span(bool has_span) { m_has_span = has_span; } + bool has_span() const { return m_has_span; } + + String to_string() const; + bool operator==(GridTrackPlacement const& other) const + { + return m_position == other.position() && m_has_span == other.has_span(); + } + +private: + int m_position { 0 }; + bool m_has_span { false }; +}; + +} diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index ff66233853..0904e65f94 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -57,6 +57,7 @@ class FontStyleValue; class Frequency; class FrequencyPercentage; class FrequencyStyleValue; +class GridTrackPlacement; class GridTrackSize; class IdentifierStyleValue; class ImageStyleValue; |