1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:27:43 +00:00

LibWeb: Replace PlaceSelfStyleValue with ShorthandStyleValue

Turns out we were parsing `place-self` as a PlaceItemsStyleValue
sometimes, whoops.
This commit is contained in:
Sam Atkins 2023-09-20 15:20:05 +01:00 committed by Sam Atkins
parent 1b0939b418
commit 8143d48161
10 changed files with 13 additions and 78 deletions

View file

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

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

View file

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