diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2023-03-23 20:56:30 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-03-25 16:56:04 +0000 |
commit | 1c03bc7a6fed85ca0b57baa74c920bc4adf3a9c5 (patch) | |
tree | cabd60363366b742265c4f1d8f304d4e6adf4fa4 | |
parent | 9d5296889f2b77da2964575be34f070d1e48ea8c (diff) | |
download | serenity-1c03bc7a6fed85ca0b57baa74c920bc4adf3a9c5.zip |
LibWeb: Split BorderStyleValue out of StyleValue.{h,cpp}
8 files changed, 84 insertions, 42 deletions
diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 3ca2acf5ae..55d4847961 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -68,6 +68,7 @@ set(SOURCES CSS/StyleValues/BackgroundRepeatStyleValue.cpp CSS/StyleValues/BackgroundSizeStyleValue.cpp CSS/StyleValues/BackgroundStyleValue.cpp + CSS/StyleValues/BorderStyleValue.cpp CSS/Supports.cpp CSS/SyntaxHighlighter/SyntaxHighlighter.cpp CSS/Time.cpp diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index e0510d7744..a715a5e4d5 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -33,6 +33,7 @@ #include <LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.h> #include <LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h> #include <LibWeb/CSS/StyleValues/BackgroundStyleValue.h> +#include <LibWeb/CSS/StyleValues/BorderStyleValue.h> #include <LibWeb/DOM/Document.h> #include <LibWeb/Dump.h> #include <LibWeb/Infra/Strings.h> diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp index 774452a6e8..a2e7e535cb 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -14,6 +14,7 @@ #include <LibWeb/CSS/StyleComputer.h> #include <LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.h> #include <LibWeb/CSS/StyleValues/BackgroundStyleValue.h> +#include <LibWeb/CSS/StyleValues/BorderStyleValue.h> #include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Element.h> #include <LibWeb/Layout/Viewport.h> diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index dec8344565..383bd2d0f6 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -26,6 +26,7 @@ #include <LibWeb/CSS/StyleComputer.h> #include <LibWeb/CSS/StyleSheet.h> #include <LibWeb/CSS/StyleValues/BackgroundStyleValue.h> +#include <LibWeb/CSS/StyleValues/BorderStyleValue.h> #include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Element.h> #include <LibWeb/FontCache.h> diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp index a0373fc32a..93adda6910 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp @@ -15,6 +15,7 @@ #include <LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.h> #include <LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h> #include <LibWeb/CSS/StyleValues/BackgroundStyleValue.h> +#include <LibWeb/CSS/StyleValues/BorderStyleValue.h> #include <LibWeb/DOM/Document.h> #include <LibWeb/HTML/BrowsingContext.h> #include <LibWeb/Loader/LoadRequest.h> @@ -294,11 +295,6 @@ StyleValueList const& StyleValue::as_value_list() const return static_cast<StyleValueList const&>(*this); } -ErrorOr<String> BorderStyleValue::to_string() const -{ - return String::formatted("{} {} {}", TRY(m_properties.border_width->to_string()), TRY(m_properties.border_style->to_string()), TRY(m_properties.border_color->to_string())); -} - ErrorOr<String> BorderRadiusStyleValue::to_string() const { if (m_properties.horizontal_radius == m_properties.vertical_radius) diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index 68b9bdf327..babc355f95 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -502,43 +502,6 @@ struct StyleValueWithDefaultOperators : public StyleValue { } }; -class BorderStyleValue final : public StyleValueWithDefaultOperators<BorderStyleValue> { -public: - static ValueComparingNonnullRefPtr<BorderStyleValue> create( - ValueComparingNonnullRefPtr<StyleValue> border_width, - ValueComparingNonnullRefPtr<StyleValue> border_style, - ValueComparingNonnullRefPtr<StyleValue> border_color) - { - return adopt_ref(*new BorderStyleValue(move(border_width), move(border_style), move(border_color))); - } - virtual ~BorderStyleValue() override = default; - - ValueComparingNonnullRefPtr<StyleValue> border_width() const { return m_properties.border_width; } - ValueComparingNonnullRefPtr<StyleValue> border_style() const { return m_properties.border_style; } - ValueComparingNonnullRefPtr<StyleValue> border_color() const { return m_properties.border_color; } - - virtual ErrorOr<String> to_string() const override; - - bool properties_equal(BorderStyleValue const& other) const { return m_properties == other.m_properties; } - -private: - BorderStyleValue( - ValueComparingNonnullRefPtr<StyleValue> border_width, - ValueComparingNonnullRefPtr<StyleValue> border_style, - ValueComparingNonnullRefPtr<StyleValue> border_color) - : StyleValueWithDefaultOperators(Type::Border) - , m_properties { .border_width = move(border_width), .border_style = move(border_style), .border_color = move(border_color) } - { - } - - struct Properties { - ValueComparingNonnullRefPtr<StyleValue> border_width; - ValueComparingNonnullRefPtr<StyleValue> border_style; - ValueComparingNonnullRefPtr<StyleValue> border_color; - bool operator==(Properties const&) const = default; - } m_properties; -}; - class BorderRadiusStyleValue final : public StyleValueWithDefaultOperators<BorderRadiusStyleValue> { public: static ValueComparingNonnullRefPtr<BorderRadiusStyleValue> create(LengthPercentage const& horizontal_radius, LengthPercentage const& vertical_radius) diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/BorderStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/BorderStyleValue.cpp new file mode 100644 index 0000000000..7f75e95186 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/BorderStyleValue.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org> + * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org> + * Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "BorderStyleValue.h" + +namespace Web::CSS { + +BorderStyleValue::BorderStyleValue( + ValueComparingNonnullRefPtr<StyleValue> border_width, + ValueComparingNonnullRefPtr<StyleValue> border_style, + ValueComparingNonnullRefPtr<StyleValue> border_color) + : StyleValueWithDefaultOperators(Type::Border) + , m_properties { .border_width = move(border_width), .border_style = move(border_style), .border_color = move(border_color) } +{ +} + +BorderStyleValue::~BorderStyleValue() = default; + +ErrorOr<String> BorderStyleValue::to_string() const +{ + return String::formatted("{} {} {}", TRY(m_properties.border_width->to_string()), TRY(m_properties.border_style->to_string()), TRY(m_properties.border_color->to_string())); +} + +} diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/BorderStyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/BorderStyleValue.h new file mode 100644 index 0000000000..1a5e035996 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/BorderStyleValue.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org> + * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org> + * Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <LibWeb/CSS/StyleValue.h> + +namespace Web::CSS { + +class BorderStyleValue final : public StyleValueWithDefaultOperators<BorderStyleValue> { +public: + static ValueComparingNonnullRefPtr<BorderStyleValue> create( + ValueComparingNonnullRefPtr<StyleValue> border_width, + ValueComparingNonnullRefPtr<StyleValue> border_style, + ValueComparingNonnullRefPtr<StyleValue> border_color) + { + return adopt_ref(*new BorderStyleValue(move(border_width), move(border_style), move(border_color))); + } + virtual ~BorderStyleValue() override; + + ValueComparingNonnullRefPtr<StyleValue> border_width() const { return m_properties.border_width; } + ValueComparingNonnullRefPtr<StyleValue> border_style() const { return m_properties.border_style; } + ValueComparingNonnullRefPtr<StyleValue> border_color() const { return m_properties.border_color; } + + virtual ErrorOr<String> to_string() const override; + + bool properties_equal(BorderStyleValue const& other) const { return m_properties == other.m_properties; } + +private: + BorderStyleValue( + ValueComparingNonnullRefPtr<StyleValue> border_width, + ValueComparingNonnullRefPtr<StyleValue> border_style, + ValueComparingNonnullRefPtr<StyleValue> border_color); + + struct Properties { + ValueComparingNonnullRefPtr<StyleValue> border_width; + ValueComparingNonnullRefPtr<StyleValue> border_style; + ValueComparingNonnullRefPtr<StyleValue> border_color; + bool operator==(Properties const&) const = default; + } m_properties; +}; + +} |