diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 55d4847961..179a536eb9 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/BorderRadiusShorthandStyleValue.cpp CSS/StyleValues/BorderStyleValue.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 a715a5e4d5..418f5428f0 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -33,6 +33,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 a2e7e535cb..0113ab2e97 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 383bd2d0f6..a8ab94605a 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -26,6 +26,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 93adda6910..623138e425 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -302,11 +303,6 @@ ErrorOr BorderRadiusStyleValue::to_string() const return String::formatted("{} / {}", TRY(m_properties.horizontal_radius.to_string()), TRY(m_properties.vertical_radius.to_string())); } -ErrorOr BorderRadiusShorthandStyleValue::to_string() const -{ - return String::formatted("{} {} {} {} / {} {} {} {}", TRY(m_properties.top_left->horizontal_radius().to_string()), TRY(m_properties.top_right->horizontal_radius().to_string()), TRY(m_properties.bottom_right->horizontal_radius().to_string()), TRY(m_properties.bottom_left->horizontal_radius().to_string()), TRY(m_properties.top_left->vertical_radius().to_string()), TRY(m_properties.top_right->vertical_radius().to_string()), TRY(m_properties.bottom_right->vertical_radius().to_string()), TRY(m_properties.bottom_left->vertical_radius().to_string())); -} - void CalculatedStyleValue::CalculationResult::add(CalculationResult const& other, Layout::Node const* layout_node, PercentageBasis const& percentage_basis) { add_or_subtract_internal(SumOperation::Add, other, layout_node, percentage_basis); diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index babc355f95..030bd0a61d 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -535,47 +535,6 @@ private: } m_properties; }; -class BorderRadiusShorthandStyleValue final : public StyleValueWithDefaultOperators { -public: - static ValueComparingNonnullRefPtr create( - ValueComparingNonnullRefPtr top_left, - ValueComparingNonnullRefPtr top_right, - ValueComparingNonnullRefPtr bottom_right, - ValueComparingNonnullRefPtr bottom_left) - { - return adopt_ref(*new BorderRadiusShorthandStyleValue(move(top_left), move(top_right), move(bottom_right), move(bottom_left))); - } - virtual ~BorderRadiusShorthandStyleValue() override = default; - - auto top_left() const { return m_properties.top_left; } - auto top_right() const { return m_properties.top_right; } - auto bottom_right() const { return m_properties.bottom_right; } - auto bottom_left() const { return m_properties.bottom_left; } - - virtual ErrorOr to_string() const override; - - bool properties_equal(BorderRadiusShorthandStyleValue const& other) const { return m_properties == other.m_properties; } - -private: - BorderRadiusShorthandStyleValue( - ValueComparingNonnullRefPtr top_left, - ValueComparingNonnullRefPtr top_right, - ValueComparingNonnullRefPtr bottom_right, - ValueComparingNonnullRefPtr bottom_left) - : StyleValueWithDefaultOperators(Type::BorderRadiusShorthand) - , m_properties { .top_left = move(top_left), .top_right = move(top_right), .bottom_right = move(bottom_right), .bottom_left = move(bottom_left) } - { - } - - struct Properties { - ValueComparingNonnullRefPtr top_left; - ValueComparingNonnullRefPtr top_right; - ValueComparingNonnullRefPtr bottom_right; - ValueComparingNonnullRefPtr bottom_left; - bool operator==(Properties const&) const = default; - } m_properties; -}; - class CalculatedStyleValue : public StyleValue { public: enum class ResolvedType { diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.cpp new file mode 100644 index 0000000000..201f26a6b0 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.cpp @@ -0,0 +1,19 @@ +/* + * 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 "BorderRadiusShorthandStyleValue.h" + +namespace Web::CSS { + +ErrorOr BorderRadiusShorthandStyleValue::to_string() const +{ + return String::formatted("{} {} {} {} / {} {} {} {}", TRY(m_properties.top_left->horizontal_radius().to_string()), TRY(m_properties.top_right->horizontal_radius().to_string()), TRY(m_properties.bottom_right->horizontal_radius().to_string()), TRY(m_properties.bottom_left->horizontal_radius().to_string()), TRY(m_properties.top_left->vertical_radius().to_string()), TRY(m_properties.top_right->vertical_radius().to_string()), TRY(m_properties.bottom_right->vertical_radius().to_string()), TRY(m_properties.bottom_left->vertical_radius().to_string())); +} + +} diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.h new file mode 100644 index 0000000000..9f82881262 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.h @@ -0,0 +1,57 @@ +/* + * 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 + +namespace Web::CSS { + +class BorderRadiusShorthandStyleValue final : public StyleValueWithDefaultOperators { +public: + static ValueComparingNonnullRefPtr create( + ValueComparingNonnullRefPtr top_left, + ValueComparingNonnullRefPtr top_right, + ValueComparingNonnullRefPtr bottom_right, + ValueComparingNonnullRefPtr bottom_left) + { + return adopt_ref(*new BorderRadiusShorthandStyleValue(move(top_left), move(top_right), move(bottom_right), move(bottom_left))); + } + virtual ~BorderRadiusShorthandStyleValue() override = default; + + auto top_left() const { return m_properties.top_left; } + auto top_right() const { return m_properties.top_right; } + auto bottom_right() const { return m_properties.bottom_right; } + auto bottom_left() const { return m_properties.bottom_left; } + + virtual ErrorOr to_string() const override; + + bool properties_equal(BorderRadiusShorthandStyleValue const& other) const { return m_properties == other.m_properties; } + +private: + BorderRadiusShorthandStyleValue( + ValueComparingNonnullRefPtr top_left, + ValueComparingNonnullRefPtr top_right, + ValueComparingNonnullRefPtr bottom_right, + ValueComparingNonnullRefPtr bottom_left) + : StyleValueWithDefaultOperators(Type::BorderRadiusShorthand) + , m_properties { .top_left = move(top_left), .top_right = move(top_right), .bottom_right = move(bottom_right), .bottom_left = move(bottom_left) } + { + } + + struct Properties { + ValueComparingNonnullRefPtr top_left; + ValueComparingNonnullRefPtr top_right; + ValueComparingNonnullRefPtr bottom_right; + ValueComparingNonnullRefPtr bottom_left; + bool operator==(Properties const&) const = default; + } m_properties; +}; + +}