LibWeb: Properly serialize position/edge style values

This commit is contained in:
Gingeh 2024-11-29 22:44:14 +11:00 committed by Sam Atkins
commit 84150f972f
Notes: github-actions[bot] 2024-12-13 11:36:34 +00:00
21 changed files with 461 additions and 288 deletions

View file

@ -14,31 +14,45 @@ namespace Web::CSS {
class EdgeStyleValue final : public StyleValueWithDefaultOperators<EdgeStyleValue> {
public:
static ValueComparingNonnullRefPtr<EdgeStyleValue> create(PositionEdge edge, LengthPercentage const& offset)
static ValueComparingNonnullRefPtr<EdgeStyleValue> create(Optional<PositionEdge> edge, Optional<LengthPercentage> const& offset)
{
VERIFY(edge != PositionEdge::Center);
return adopt_ref(*new (nothrow) EdgeStyleValue(edge, offset));
}
virtual ~EdgeStyleValue() override = default;
// NOTE: `center` is converted to `left 50%` or `top 50%` in parsing, so is never returned here.
PositionEdge edge() const { return m_properties.edge; }
LengthPercentage const& offset() const { return m_properties.offset; }
Optional<PositionEdge> edge() const
{
if (m_properties.edge == PositionEdge::Center)
return {};
return m_properties.edge;
}
LengthPercentage offset() const
{
if (m_properties.edge == PositionEdge::Center)
return Percentage(50);
if (!m_properties.offset.has_value())
return Percentage(0);
return m_properties.offset.value();
}
virtual String to_string(SerializationMode) const override;
bool properties_equal(EdgeStyleValue const& other) const { return m_properties == other.m_properties; }
private:
EdgeStyleValue(PositionEdge edge, LengthPercentage const& offset)
EdgeStyleValue(Optional<PositionEdge> edge, Optional<LengthPercentage> const& offset)
: StyleValueWithDefaultOperators(Type::Edge)
, m_properties { .edge = edge, .offset = offset }
{
}
struct Properties {
PositionEdge edge;
LengthPercentage offset;
Optional<PositionEdge> edge;
Optional<LengthPercentage> offset;
bool operator==(Properties const&) const = default;
} m_properties;
};