From 34591549b143ab620d59eee01e83b8019062f709 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 19 Sep 2023 16:01:44 +0100 Subject: [PATCH] LibWeb: Replace BorderRadiusShorthandStyleValue with ShorthandStyleValue --- .../Libraries/LibWeb/CSS/StyleValues/BUILD.gn | 1 - Userland/Libraries/LibWeb/CMakeLists.txt | 1 - .../Libraries/LibWeb/CSS/Parser/Parser.cpp | 5 +- .../CSS/ResolvedCSSStyleDeclaration.cpp | 5 +- .../Libraries/LibWeb/CSS/StyleComputer.cpp | 10 ---- Userland/Libraries/LibWeb/CSS/StyleValue.cpp | 1 - Userland/Libraries/LibWeb/CSS/StyleValue.h | 1 - .../BorderRadiusShorthandStyleValue.cpp | 27 --------- .../BorderRadiusShorthandStyleValue.h | 58 ------------------- .../CSS/StyleValues/ShorthandStyleValue.cpp | 18 ++++++ Userland/Libraries/LibWeb/Forward.h | 1 - 11 files changed, 24 insertions(+), 104 deletions(-) delete mode 100644 Userland/Libraries/LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.cpp delete mode 100644 Userland/Libraries/LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.h diff --git a/Meta/gn/secondary/Userland/Libraries/LibWeb/CSS/StyleValues/BUILD.gn b/Meta/gn/secondary/Userland/Libraries/LibWeb/CSS/StyleValues/BUILD.gn index 9664619c54a..10f9f2577c6 100644 --- a/Meta/gn/secondary/Userland/Libraries/LibWeb/CSS/StyleValues/BUILD.gn +++ b/Meta/gn/secondary/Userland/Libraries/LibWeb/CSS/StyleValues/BUILD.gn @@ -5,7 +5,6 @@ source_set("StyleValues") { "AngleStyleValue.cpp", "BackgroundRepeatStyleValue.cpp", "BackgroundSizeStyleValue.cpp", - "BorderRadiusShorthandStyleValue.cpp", "BorderRadiusStyleValue.cpp", "BorderStyleValue.cpp", "CalculatedStyleValue.cpp", diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 0bf74152f72..5e5fa7082df 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -82,7 +82,6 @@ set(SOURCES CSS/StyleValues/AngleStyleValue.cpp CSS/StyleValues/BackgroundRepeatStyleValue.cpp CSS/StyleValues/BackgroundSizeStyleValue.cpp - CSS/StyleValues/BorderRadiusShorthandStyleValue.cpp CSS/StyleValues/BorderRadiusStyleValue.cpp CSS/StyleValues/BorderStyleValue.cpp CSS/StyleValues/CalculatedStyleValue.cpp diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index cd14dfc56f0..8663a6d5c49 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -37,7 +37,6 @@ #include #include #include -#include #include #include #include @@ -3358,7 +3357,9 @@ RefPtr Parser::parse_border_radius_shorthand_value(Vector Parser::parse_shadow_value(Vector const& component_values, AllowInsetKeyword allow_inset_keyword) diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp index 418f3f0cb1f..2843a4644f6 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -244,7 +243,9 @@ RefPtr ResolvedCSSStyleDeclaration::style_value_for_property(L bottom_right_radius = maybe_bottom_right_radius.value().value->as_border_radius(); } - return BorderRadiusShorthandStyleValue::create(top_left_radius.release_nonnull(), top_right_radius.release_nonnull(), bottom_right_radius.release_nonnull(), bottom_left_radius.release_nonnull()); + return ShorthandStyleValue::create(property_id, + { PropertyID::BorderTopLeftRadius, PropertyID::BorderTopRightRadius, PropertyID::BorderBottomRightRadius, PropertyID::BorderBottomLeftRadius }, + { top_left_radius.release_nonnull(), top_right_radius.release_nonnull(), bottom_right_radius.release_nonnull(), bottom_left_radius.release_nonnull() }); } case PropertyID::BorderRight: { auto border = layout_node.computed_values().border_right(); diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index a851e612b4c..2e3f877bec4 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -551,15 +550,6 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope } if (property_id == CSS::PropertyID::BorderRadius) { - if (value.is_border_radius_shorthand()) { - auto const& shorthand = value.as_border_radius_shorthand(); - set_longhand_property(CSS::PropertyID::BorderTopLeftRadius, shorthand.top_left()); - set_longhand_property(CSS::PropertyID::BorderTopRightRadius, shorthand.top_right()); - set_longhand_property(CSS::PropertyID::BorderBottomRightRadius, shorthand.bottom_right()); - set_longhand_property(CSS::PropertyID::BorderBottomLeftRadius, shorthand.bottom_left()); - return; - } - set_longhand_property(CSS::PropertyID::BorderTopLeftRadius, value); set_longhand_property(CSS::PropertyID::BorderTopRightRadius, value); set_longhand_property(CSS::PropertyID::BorderBottomRightRadius, value); diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp index 79284db7a19..a8599d35e79 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index f1aa4e2e007..447ae169fb6 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -88,7 +88,6 @@ using StyleValueVector = Vector>; __ENUMERATE_STYLE_VALUE_TYPE(BackgroundSize, background_size) \ __ENUMERATE_STYLE_VALUE_TYPE(Border, border) \ __ENUMERATE_STYLE_VALUE_TYPE(BorderRadius, border_radius) \ - __ENUMERATE_STYLE_VALUE_TYPE(BorderRadiusShorthand, border_radius_shorthand) \ __ENUMERATE_STYLE_VALUE_TYPE(Calculated, calculated) \ __ENUMERATE_STYLE_VALUE_TYPE(Color, color) \ __ENUMERATE_STYLE_VALUE_TYPE(ConicGradient, conic_gradient) \ diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.cpp deleted file mode 100644 index 61069c664ac..00000000000 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 { - -String BorderRadiusShorthandStyleValue::to_string() const -{ - return MUST(String::formatted("{} {} {} {} / {} {} {} {}", - m_properties.top_left->horizontal_radius().to_string(), - m_properties.top_right->horizontal_radius().to_string(), - m_properties.bottom_right->horizontal_radius().to_string(), - m_properties.bottom_left->horizontal_radius().to_string(), - m_properties.top_left->vertical_radius().to_string(), - m_properties.top_right->vertical_radius().to_string(), - m_properties.bottom_right->vertical_radius().to_string(), - 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 deleted file mode 100644 index d78f607991b..00000000000 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 BorderRadiusShorthandStyleValue final : public StyleValueWithDefaultOperators { -public: - static ValueComparingNonnullRefPtr create( - ValueComparingNonnullRefPtr top_left, - ValueComparingNonnullRefPtr top_right, - ValueComparingNonnullRefPtr bottom_right, - ValueComparingNonnullRefPtr bottom_left) - { - return adopt_ref(*new (nothrow) 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 String 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; -}; - -} diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/ShorthandStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/ShorthandStyleValue.cpp index 72ef4d4ca95..54333c075db 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/ShorthandStyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/ShorthandStyleValue.cpp @@ -1,11 +1,13 @@ /* * Copyright (c) 2023, Ali Mohammad Pur + * Copyright (c) 2023, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ #include "ShorthandStyleValue.h" #include +#include #include namespace Web::CSS { @@ -72,6 +74,22 @@ String ShorthandStyleValue::to_string() const return MUST(builder.to_string()); } + case PropertyID::BorderRadius: { + auto& top_left = longhand(PropertyID::BorderTopLeftRadius)->as_border_radius(); + auto& top_right = longhand(PropertyID::BorderTopRightRadius)->as_border_radius(); + auto& bottom_right = longhand(PropertyID::BorderBottomRightRadius)->as_border_radius(); + auto& bottom_left = longhand(PropertyID::BorderBottomLeftRadius)->as_border_radius(); + + return MUST(String::formatted("{} {} {} {} / {} {} {} {}", + top_left.horizontal_radius().to_string(), + top_right.horizontal_radius().to_string(), + bottom_right.horizontal_radius().to_string(), + bottom_left.horizontal_radius().to_string(), + top_left.vertical_radius().to_string(), + top_right.vertical_radius().to_string(), + bottom_right.vertical_radius().to_string(), + bottom_left.vertical_radius().to_string())); + } case PropertyID::Flex: return MUST(String::formatted("{} {} {}", longhand(PropertyID::FlexGrow)->to_string(), longhand(PropertyID::FlexShrink)->to_string(), longhand(PropertyID::FlexBasis)->to_string())); case PropertyID::FlexFlow: diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index bbe497863b9..a179db0d28d 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -74,7 +74,6 @@ class AnglePercentage; class AngleStyleValue; class BackgroundRepeatStyleValue; class BackgroundSizeStyleValue; -class BorderRadiusShorthandStyleValue; class BorderRadiusStyleValue; class BorderStyleValue; class CSSConditionRule;