LibWeb: Replace PlaceItemsStyleValue with ShorthandStyleValue

This commit is contained in:
Sam Atkins 2023-09-20 15:30:36 +01:00 committed by Sam Atkins
parent 8143d48161
commit 6e311902de
Notes: sideshowbarker 2024-07-18 04:38:32 +09:00
10 changed files with 13 additions and 78 deletions

View file

@ -27,7 +27,6 @@ source_set("StyleValues") {
"MathDepthStyleValue.cpp",
"NumberStyleValue.cpp",
"OverflowStyleValue.cpp",
"PlaceItemsStyleValue.cpp",
"PositionStyleValue.cpp",
"RadialGradientStyleValue.cpp",
"RectStyleValue.cpp",

View file

@ -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

View file

@ -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)

View file

@ -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;

View file

@ -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>

View file

@ -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) \

View file

@ -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));
}
}

View file

@ -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;
};
}

View file

@ -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();

View file

@ -139,7 +139,6 @@ class OverflowStyleValue;
class Percentage;
class PercentageOrCalculated;
class PercentageStyleValue;
class PlaceItemsStyleValue;
class PositionStyleValue;
class PropertyOwningCSSStyleDeclaration;
class RadialGradientStyleValue;