From 6e311902dea51f794e77aefe17d1d6e8023dca55 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 20 Sep 2023 15:30:36 +0100 Subject: [PATCH] LibWeb: Replace PlaceItemsStyleValue with ShorthandStyleValue --- .../Libraries/LibWeb/CSS/StyleValues/BUILD.gn | 1 - Userland/Libraries/LibWeb/CMakeLists.txt | 1 - .../Libraries/LibWeb/CSS/Parser/Parser.cpp | 9 ++-- .../Libraries/LibWeb/CSS/StyleComputer.cpp | 8 ---- Userland/Libraries/LibWeb/CSS/StyleValue.cpp | 1 - Userland/Libraries/LibWeb/CSS/StyleValue.h | 1 - .../CSS/StyleValues/PlaceItemsStyleValue.cpp | 20 --------- .../CSS/StyleValues/PlaceItemsStyleValue.h | 42 ------------------- .../CSS/StyleValues/ShorthandStyleValue.cpp | 7 ++++ Userland/Libraries/LibWeb/Forward.h | 1 - 10 files changed, 13 insertions(+), 78 deletions(-) delete mode 100644 Userland/Libraries/LibWeb/CSS/StyleValues/PlaceItemsStyleValue.cpp delete mode 100644 Userland/Libraries/LibWeb/CSS/StyleValues/PlaceItemsStyleValue.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 90aeac7e6a..3e9f97d87f 100644 --- a/Meta/gn/secondary/Userland/Libraries/LibWeb/CSS/StyleValues/BUILD.gn +++ b/Meta/gn/secondary/Userland/Libraries/LibWeb/CSS/StyleValues/BUILD.gn @@ -27,7 +27,6 @@ source_set("StyleValues") { "MathDepthStyleValue.cpp", "NumberStyleValue.cpp", "OverflowStyleValue.cpp", - "PlaceItemsStyleValue.cpp", "PositionStyleValue.cpp", "RadialGradientStyleValue.cpp", "RectStyleValue.cpp", diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 6665700c37..6322e74021 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -104,7 +104,6 @@ set(SOURCES CSS/StyleValues/MathDepthStyleValue.cpp CSS/StyleValues/NumberStyleValue.cpp CSS/StyleValues/OverflowStyleValue.cpp - CSS/StyleValues/PlaceItemsStyleValue.cpp CSS/StyleValues/PositionStyleValue.cpp CSS/StyleValues/RadialGradientStyleValue.cpp CSS/StyleValues/RectStyleValue.cpp diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index eb8d3eb242..5c393094c1 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -61,7 +61,6 @@ #include #include #include -#include #include #include #include @@ -4602,13 +4601,17 @@ RefPtr Parser::parse_place_items_value(Vector const& if (component_values.size() == 1) { if (!property_accepts_identifier(PropertyID::JustifyItems, maybe_align_items_value->to_identifier())) return nullptr; - return PlaceItemsStyleValue::create(*maybe_align_items_value, *maybe_align_items_value); + return ShorthandStyleValue::create(PropertyID::PlaceItems, + { PropertyID::AlignItems, PropertyID::JustifyItems }, + { *maybe_align_items_value, *maybe_align_items_value }); } auto maybe_justify_items_value = parse_css_value_for_property(PropertyID::JustifyItems, tokens); if (!maybe_justify_items_value) return nullptr; - return PlaceItemsStyleValue::create(*maybe_align_items_value, *maybe_justify_items_value); + return ShorthandStyleValue::create(PropertyID::PlaceItems, + { PropertyID::AlignItems, PropertyID::JustifyItems }, + { *maybe_align_items_value, *maybe_justify_items_value }); } RefPtr Parser::parse_place_self_value(Vector const& component_values) diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 4bc17b97ff..356bec7b59 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -46,7 +46,6 @@ #include #include #include -#include #include #include #include @@ -499,13 +498,6 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope } if (property_id == CSS::PropertyID::PlaceItems) { - if (value.is_place_items()) { - auto const& place_items = value.as_place_items(); - set_longhand_property(CSS::PropertyID::AlignItems, place_items.align_items()); - set_longhand_property(CSS::PropertyID::JustifyItems, place_items.justify_items()); - return; - } - set_longhand_property(CSS::PropertyID::AlignItems, value); set_longhand_property(CSS::PropertyID::JustifyItems, value); return; diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp index cb3c3f26e5..f3a4e65080 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp @@ -41,7 +41,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 eec77fa8c9..f951b8df87 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -113,7 +113,6 @@ using StyleValueVector = Vector>; __ENUMERATE_STYLE_VALUE_TYPE(Number, number) \ __ENUMERATE_STYLE_VALUE_TYPE(Overflow, overflow) \ __ENUMERATE_STYLE_VALUE_TYPE(Percentage, percentage) \ - __ENUMERATE_STYLE_VALUE_TYPE(PlaceItems, place_items) \ __ENUMERATE_STYLE_VALUE_TYPE(Position, position) \ __ENUMERATE_STYLE_VALUE_TYPE(RadialGradient, radial_gradient) \ __ENUMERATE_STYLE_VALUE_TYPE(Ratio, ratio) \ diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/PlaceItemsStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/PlaceItemsStyleValue.cpp deleted file mode 100644 index 012463198b..0000000000 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/PlaceItemsStyleValue.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2023, Aliaksandr Kalenik - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include "PlaceItemsStyleValue.h" - -namespace Web::CSS { - -String PlaceItemsStyleValue::to_string() const -{ - auto align_items = m_properties.align_items->to_string(); - auto justify_items = m_properties.justify_items->to_string(); - if (align_items == justify_items) - return MUST(String::formatted("{}", align_items)); - return MUST(String::formatted("{} {}", align_items, justify_items)); -} - -} diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/PlaceItemsStyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/PlaceItemsStyleValue.h deleted file mode 100644 index 3d233e5437..0000000000 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/PlaceItemsStyleValue.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2023, Aliaksandr Kalenik - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include - -namespace Web::CSS { - -class PlaceItemsStyleValue final : public StyleValueWithDefaultOperators { -public: - static ValueComparingNonnullRefPtr create(ValueComparingNonnullRefPtr align_items, ValueComparingNonnullRefPtr justify_items) - { - return adopt_ref(*new (nothrow) PlaceItemsStyleValue(move(align_items), move(justify_items))); - } - virtual ~PlaceItemsStyleValue() override = default; - - ValueComparingNonnullRefPtr align_items() const { return m_properties.align_items; } - ValueComparingNonnullRefPtr justify_items() const { return m_properties.justify_items; } - - virtual String to_string() const override; - - bool properties_equal(PlaceItemsStyleValue const& other) const { return m_properties == other.m_properties; } - -private: - PlaceItemsStyleValue(ValueComparingNonnullRefPtr align_items, ValueComparingNonnullRefPtr justify_items) - : StyleValueWithDefaultOperators(Type::PlaceItems) - , m_properties { .align_items = move(align_items), .justify_items = move(justify_items) } - { - } - - struct Properties { - ValueComparingNonnullRefPtr align_items; - ValueComparingNonnullRefPtr justify_items; - 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 ad509bf350..13db582c71 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/ShorthandStyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/ShorthandStyleValue.cpp @@ -154,6 +154,13 @@ String ShorthandStyleValue::to_string() const return align_content; return MUST(String::formatted("{} {}", align_content, justify_content)); } + case PropertyID::PlaceItems: { + auto align_items = longhand(PropertyID::AlignItems)->to_string(); + auto justify_items = longhand(PropertyID::JustifyItems)->to_string(); + if (align_items == justify_items) + return align_items; + return MUST(String::formatted("{} {}", align_items, justify_items)); + } case PropertyID::PlaceSelf: { auto align_self = longhand(PropertyID::AlignSelf)->to_string(); auto justify_self = longhand(PropertyID::JustifySelf)->to_string(); diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index e28347e110..24c1714007 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -139,7 +139,6 @@ class OverflowStyleValue; class Percentage; class PercentageOrCalculated; class PercentageStyleValue; -class PlaceItemsStyleValue; class PositionStyleValue; class PropertyOwningCSSStyleDeclaration; class RadialGradientStyleValue;