mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:17:44 +00:00
LibWeb: Replace PlaceSelfStyleValue with ShorthandStyleValue
Turns out we were parsing `place-self` as a PlaceItemsStyleValue sometimes, whoops.
This commit is contained in:
parent
1b0939b418
commit
8143d48161
10 changed files with 13 additions and 78 deletions
|
@ -28,7 +28,6 @@ source_set("StyleValues") {
|
|||
"NumberStyleValue.cpp",
|
||||
"OverflowStyleValue.cpp",
|
||||
"PlaceItemsStyleValue.cpp",
|
||||
"PlaceSelfStyleValue.cpp",
|
||||
"PositionStyleValue.cpp",
|
||||
"RadialGradientStyleValue.cpp",
|
||||
"RectStyleValue.cpp",
|
||||
|
|
|
@ -105,7 +105,6 @@ set(SOURCES
|
|||
CSS/StyleValues/NumberStyleValue.cpp
|
||||
CSS/StyleValues/OverflowStyleValue.cpp
|
||||
CSS/StyleValues/PlaceItemsStyleValue.cpp
|
||||
CSS/StyleValues/PlaceSelfStyleValue.cpp
|
||||
CSS/StyleValues/PositionStyleValue.cpp
|
||||
CSS/StyleValues/RadialGradientStyleValue.cpp
|
||||
CSS/StyleValues/RectStyleValue.cpp
|
||||
|
|
|
@ -62,7 +62,6 @@
|
|||
#include <LibWeb/CSS/StyleValues/OverflowStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PlaceItemsStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PlaceSelfStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/RatioStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/RectStyleValue.h>
|
||||
|
@ -4622,13 +4621,17 @@ RefPtr<StyleValue> Parser::parse_place_self_value(Vector<ComponentValue> const&
|
|||
if (component_values.size() == 1) {
|
||||
if (!property_accepts_identifier(PropertyID::JustifySelf, maybe_align_self_value->to_identifier()))
|
||||
return nullptr;
|
||||
return PlaceSelfStyleValue::create(*maybe_align_self_value, *maybe_align_self_value);
|
||||
return ShorthandStyleValue::create(PropertyID::PlaceSelf,
|
||||
{ PropertyID::AlignSelf, PropertyID::JustifySelf },
|
||||
{ *maybe_align_self_value, *maybe_align_self_value });
|
||||
}
|
||||
|
||||
auto maybe_justify_self_value = parse_css_value_for_property(PropertyID::JustifySelf, tokens);
|
||||
if (!maybe_justify_self_value)
|
||||
return nullptr;
|
||||
return PlaceItemsStyleValue::create(*maybe_align_self_value, *maybe_justify_self_value);
|
||||
return ShorthandStyleValue::create(PropertyID::PlaceSelf,
|
||||
{ PropertyID::AlignSelf, PropertyID::JustifySelf },
|
||||
{ *maybe_align_self_value, *maybe_justify_self_value });
|
||||
}
|
||||
|
||||
RefPtr<StyleValue> Parser::parse_quotes_value(Vector<ComponentValue> const& component_values)
|
||||
|
|
|
@ -47,7 +47,6 @@
|
|||
#include <LibWeb/CSS/StyleValues/OverflowStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PlaceItemsStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PlaceSelfStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/RectStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/ShorthandStyleValue.h>
|
||||
|
@ -513,13 +512,6 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
|||
}
|
||||
|
||||
if (property_id == CSS::PropertyID::PlaceSelf) {
|
||||
if (value.is_place_self()) {
|
||||
auto const& place_self = value.as_place_self();
|
||||
set_longhand_property(CSS::PropertyID::AlignSelf, place_self.align_self());
|
||||
set_longhand_property(CSS::PropertyID::JustifySelf, place_self.justify_self());
|
||||
return;
|
||||
}
|
||||
|
||||
set_longhand_property(CSS::PropertyID::AlignSelf, value);
|
||||
set_longhand_property(CSS::PropertyID::JustifySelf, value);
|
||||
return;
|
||||
|
|
|
@ -42,7 +42,6 @@
|
|||
#include <LibWeb/CSS/StyleValues/OverflowStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PlaceItemsStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PlaceSelfStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/RadialGradientStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/RatioStyleValue.h>
|
||||
|
|
|
@ -114,7 +114,6 @@ using StyleValueVector = Vector<ValueComparingNonnullRefPtr<StyleValue const>>;
|
|||
__ENUMERATE_STYLE_VALUE_TYPE(Overflow, overflow) \
|
||||
__ENUMERATE_STYLE_VALUE_TYPE(Percentage, percentage) \
|
||||
__ENUMERATE_STYLE_VALUE_TYPE(PlaceItems, place_items) \
|
||||
__ENUMERATE_STYLE_VALUE_TYPE(PlaceSelf, place_self) \
|
||||
__ENUMERATE_STYLE_VALUE_TYPE(Position, position) \
|
||||
__ENUMERATE_STYLE_VALUE_TYPE(RadialGradient, radial_gradient) \
|
||||
__ENUMERATE_STYLE_VALUE_TYPE(Ratio, ratio) \
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "PlaceSelfStyleValue.h"
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
String PlaceSelfStyleValue::to_string() const
|
||||
{
|
||||
auto align_self = m_properties.align_self->to_string();
|
||||
auto justify_self = m_properties.justify_self->to_string();
|
||||
if (align_self == justify_self)
|
||||
return MUST(String::formatted("{}", align_self));
|
||||
return MUST(String::formatted("{} {}", align_self, justify_self));
|
||||
}
|
||||
|
||||
}
|
|
@ -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 PlaceSelfStyleValue final : public StyleValueWithDefaultOperators<PlaceSelfStyleValue> {
|
||||
public:
|
||||
static ValueComparingNonnullRefPtr<PlaceSelfStyleValue> create(ValueComparingNonnullRefPtr<StyleValue> align_self, ValueComparingNonnullRefPtr<StyleValue> justify_self)
|
||||
{
|
||||
return adopt_ref(*new (nothrow) PlaceSelfStyleValue(move(align_self), move(justify_self)));
|
||||
}
|
||||
virtual ~PlaceSelfStyleValue() override = default;
|
||||
|
||||
ValueComparingNonnullRefPtr<StyleValue> align_self() const { return m_properties.align_self; }
|
||||
ValueComparingNonnullRefPtr<StyleValue> justify_self() const { return m_properties.justify_self; }
|
||||
|
||||
virtual String to_string() const override;
|
||||
|
||||
bool properties_equal(PlaceSelfStyleValue const& other) const { return m_properties == other.m_properties; }
|
||||
|
||||
private:
|
||||
PlaceSelfStyleValue(ValueComparingNonnullRefPtr<StyleValue> align_self, ValueComparingNonnullRefPtr<StyleValue> justify_self)
|
||||
: StyleValueWithDefaultOperators(Type::PlaceSelf)
|
||||
, m_properties { .align_self = move(align_self), .justify_self = move(justify_self) }
|
||||
{
|
||||
}
|
||||
|
||||
struct Properties {
|
||||
ValueComparingNonnullRefPtr<StyleValue> align_self;
|
||||
ValueComparingNonnullRefPtr<StyleValue> justify_self;
|
||||
bool operator==(Properties const&) const = default;
|
||||
} m_properties;
|
||||
};
|
||||
|
||||
}
|
|
@ -154,6 +154,13 @@ String ShorthandStyleValue::to_string() const
|
|||
return align_content;
|
||||
return MUST(String::formatted("{} {}", align_content, justify_content));
|
||||
}
|
||||
case PropertyID::PlaceSelf: {
|
||||
auto align_self = longhand(PropertyID::AlignSelf)->to_string();
|
||||
auto justify_self = longhand(PropertyID::JustifySelf)->to_string();
|
||||
if (align_self == justify_self)
|
||||
return align_self;
|
||||
return MUST(String::formatted("{} {}", align_self, justify_self));
|
||||
}
|
||||
default:
|
||||
StringBuilder builder;
|
||||
auto first = true;
|
||||
|
|
|
@ -140,7 +140,6 @@ class Percentage;
|
|||
class PercentageOrCalculated;
|
||||
class PercentageStyleValue;
|
||||
class PlaceItemsStyleValue;
|
||||
class PlaceSelfStyleValue;
|
||||
class PositionStyleValue;
|
||||
class PropertyOwningCSSStyleDeclaration;
|
||||
class RadialGradientStyleValue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue