From 52cd0b2f472f7c90b1ca8c65446da3c82bfb3359 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Thu, 23 Mar 2023 17:44:13 +0000 Subject: [PATCH] LibWeb: Split BackgroundRepeatStyleValue out of StyleValue.{h,cpp} --- Userland/Libraries/LibWeb/CMakeLists.txt | 1 + .../Libraries/LibWeb/CSS/Parser/Parser.cpp | 1 + .../CSS/ResolvedCSSStyleDeclaration.cpp | 3 +- Userland/Libraries/LibWeb/CSS/StyleValue.cpp | 6 +-- Userland/Libraries/LibWeb/CSS/StyleValue.h | 29 ------------- .../BackgroundRepeatStyleValue.cpp | 28 +++++++++++++ .../StyleValues/BackgroundRepeatStyleValue.h | 42 +++++++++++++++++++ Userland/Libraries/LibWeb/Layout/Node.cpp | 1 + 8 files changed, 76 insertions(+), 35 deletions(-) create mode 100644 Userland/Libraries/LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.cpp create mode 100644 Userland/Libraries/LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.h diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 9f95467170..f93f5b1dcd 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -65,6 +65,7 @@ set(SOURCES CSS/StyleSheetList.cpp CSS/StyleValue.cpp CSS/StyleValues/AngleStyleValue.cpp + CSS/StyleValues/BackgroundRepeatStyleValue.cpp CSS/StyleValues/BackgroundStyleValue.cpp CSS/Supports.cpp CSS/SyntaxHighlighter/SyntaxHighlighter.cpp diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index bd13f458b6..7e38881d0c 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp index 0e25f087c9..774452a6e8 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -1,7 +1,7 @@ /* * Copyright (c) 2021-2023, Andreas Kling * Copyright (c) 2021, Tobias Christiansen - * Copyright (c) 2022, Sam Atkins + * Copyright (c) 2022-2023, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp index 25f4ab33a2..dec5a4cdb2 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -292,11 +293,6 @@ StyleValueList const& StyleValue::as_value_list() const return static_cast(*this); } -ErrorOr BackgroundRepeatStyleValue::to_string() const -{ - return String::formatted("{} {}", CSS::to_string(m_properties.repeat_x), CSS::to_string(m_properties.repeat_y)); -} - ErrorOr BackgroundSizeStyleValue::to_string() const { return String::formatted("{} {}", TRY(m_properties.size_x.to_string()), TRY(m_properties.size_y.to_string())); diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index 7fe90724b2..40b58da713 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -502,35 +502,6 @@ struct StyleValueWithDefaultOperators : public StyleValue { } }; -class BackgroundRepeatStyleValue final : public StyleValueWithDefaultOperators { -public: - static ValueComparingNonnullRefPtr create(Repeat repeat_x, Repeat repeat_y) - { - return adopt_ref(*new BackgroundRepeatStyleValue(repeat_x, repeat_y)); - } - virtual ~BackgroundRepeatStyleValue() override = default; - - Repeat repeat_x() const { return m_properties.repeat_x; } - Repeat repeat_y() const { return m_properties.repeat_y; } - - virtual ErrorOr to_string() const override; - - bool properties_equal(BackgroundRepeatStyleValue const& other) const { return m_properties == other.m_properties; } - -private: - BackgroundRepeatStyleValue(Repeat repeat_x, Repeat repeat_y) - : StyleValueWithDefaultOperators(Type::BackgroundRepeat) - , m_properties { .repeat_x = repeat_x, .repeat_y = repeat_y } - { - } - - struct Properties { - Repeat repeat_x; - Repeat repeat_y; - bool operator==(Properties const&) const = default; - } m_properties; -}; - // NOTE: This is not used for identifier sizes, like `cover` and `contain`. class BackgroundSizeStyleValue final : public StyleValueWithDefaultOperators { public: diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.cpp new file mode 100644 index 0000000000..65aeec5f8a --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2021, Tobias Christiansen + * Copyright (c) 2021-2023, Sam Atkins + * Copyright (c) 2022-2023, MacDue + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "BackgroundRepeatStyleValue.h" +#include + +namespace Web::CSS { + +BackgroundRepeatStyleValue::BackgroundRepeatStyleValue(Repeat repeat_x, Repeat repeat_y) + : StyleValueWithDefaultOperators(Type::BackgroundRepeat) + , m_properties { .repeat_x = repeat_x, .repeat_y = repeat_y } +{ +} + +BackgroundRepeatStyleValue::~BackgroundRepeatStyleValue() = default; + +ErrorOr BackgroundRepeatStyleValue::to_string() const +{ + return String::formatted("{} {}", CSS::to_string(m_properties.repeat_x), CSS::to_string(m_properties.repeat_y)); +} + +} diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.h new file mode 100644 index 0000000000..aea654e6e9 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2021, Tobias Christiansen + * Copyright (c) 2021-2023, Sam Atkins + * Copyright (c) 2022-2023, MacDue + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +namespace Web::CSS { + +class BackgroundRepeatStyleValue final : public StyleValueWithDefaultOperators { +public: + static ValueComparingNonnullRefPtr create(Repeat repeat_x, Repeat repeat_y) + { + return adopt_ref(*new BackgroundRepeatStyleValue(repeat_x, repeat_y)); + } + virtual ~BackgroundRepeatStyleValue() override; + + Repeat repeat_x() const { return m_properties.repeat_x; } + Repeat repeat_y() const { return m_properties.repeat_y; } + + virtual ErrorOr to_string() const override; + + bool properties_equal(BackgroundRepeatStyleValue const& other) const { return m_properties == other.m_properties; } + +private: + BackgroundRepeatStyleValue(Repeat repeat_x, Repeat repeat_y); + + struct Properties { + Repeat repeat_x; + Repeat repeat_y; + bool operator==(Properties const&) const = default; + } m_properties; +}; + +} diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index c93ede71f3..16978b8243 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -5,6 +5,7 @@ */ #include +#include #include #include #include