Browse Source

LibWeb: Replace PlaceItemsStyleValue with ShorthandStyleValue

Sam Atkins 1 năm trước cách đây
mục cha
commit
6e311902de

+ 0 - 1
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",

+ 0 - 1
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

+ 6 - 3
Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp

@@ -61,7 +61,6 @@
 #include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
 #include <LibWeb/CSS/StyleValues/OverflowStyleValue.h>
 #include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
-#include <LibWeb/CSS/StyleValues/PlaceItemsStyleValue.h>
 #include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
 #include <LibWeb/CSS/StyleValues/RatioStyleValue.h>
 #include <LibWeb/CSS/StyleValues/RectStyleValue.h>
@@ -4602,13 +4601,17 @@ RefPtr<StyleValue> Parser::parse_place_items_value(Vector<ComponentValue> 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<StyleValue> Parser::parse_place_self_value(Vector<ComponentValue> const& component_values)

+ 0 - 8
Userland/Libraries/LibWeb/CSS/StyleComputer.cpp

@@ -46,7 +46,6 @@
 #include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
 #include <LibWeb/CSS/StyleValues/OverflowStyleValue.h>
 #include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
-#include <LibWeb/CSS/StyleValues/PlaceItemsStyleValue.h>
 #include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
 #include <LibWeb/CSS/StyleValues/RectStyleValue.h>
 #include <LibWeb/CSS/StyleValues/ShorthandStyleValue.h>
@@ -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;

+ 0 - 1
Userland/Libraries/LibWeb/CSS/StyleValue.cpp

@@ -41,7 +41,6 @@
 #include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
 #include <LibWeb/CSS/StyleValues/OverflowStyleValue.h>
 #include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
-#include <LibWeb/CSS/StyleValues/PlaceItemsStyleValue.h>
 #include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
 #include <LibWeb/CSS/StyleValues/RadialGradientStyleValue.h>
 #include <LibWeb/CSS/StyleValues/RatioStyleValue.h>

+ 0 - 1
Userland/Libraries/LibWeb/CSS/StyleValue.h

@@ -113,7 +113,6 @@ using StyleValueVector = Vector<ValueComparingNonnullRefPtr<StyleValue const>>;
     __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)                                                \

+ 0 - 20
Userland/Libraries/LibWeb/CSS/StyleValues/PlaceItemsStyleValue.cpp

@@ -1,20 +0,0 @@
-/*
- * Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
- *
- * 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));
-}
-
-}

+ 0 - 42
Userland/Libraries/LibWeb/CSS/StyleValues/PlaceItemsStyleValue.h

@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <LibWeb/CSS/StyleValue.h>
-
-namespace Web::CSS {
-
-class PlaceItemsStyleValue final : public StyleValueWithDefaultOperators<PlaceItemsStyleValue> {
-public:
-    static ValueComparingNonnullRefPtr<PlaceItemsStyleValue> create(ValueComparingNonnullRefPtr<StyleValue> align_items, ValueComparingNonnullRefPtr<StyleValue> justify_items)
-    {
-        return adopt_ref(*new (nothrow) PlaceItemsStyleValue(move(align_items), move(justify_items)));
-    }
-    virtual ~PlaceItemsStyleValue() override = default;
-
-    ValueComparingNonnullRefPtr<StyleValue> align_items() const { return m_properties.align_items; }
-    ValueComparingNonnullRefPtr<StyleValue> 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<StyleValue> align_items, ValueComparingNonnullRefPtr<StyleValue> justify_items)
-        : StyleValueWithDefaultOperators(Type::PlaceItems)
-        , m_properties { .align_items = move(align_items), .justify_items = move(justify_items) }
-    {
-    }
-
-    struct Properties {
-        ValueComparingNonnullRefPtr<StyleValue> align_items;
-        ValueComparingNonnullRefPtr<StyleValue> justify_items;
-        bool operator==(Properties const&) const = default;
-    } m_properties;
-};
-
-}

+ 7 - 0
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();

+ 0 - 1
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;