Files
ladybird/Libraries/LibWeb/CSS/StyleValues/TupleStyleValue.h
Callum Law 893eac18dd LibWeb: Add TupleStyleValue
Many CSS grammars call for us to parse `Foo || Bar` but we don't have a
good way to represent this unless we have a custom style value. Usually
we store the values in a `StyleValueList` but since that can only store
non-null elements we have to manually recheck which elements we have at
which index whenever we use it.

This style value holds a Vector of `RefPtr<StyleValue const>` so that we
can represent null values and know what values are at what index without
manually rechecking.
2026-02-20 22:01:44 +00:00

41 lines
1.1 KiB
C++

/*
* Copyright (c) 2026, Callum Law <callumlaw1709@outlook.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/CSS/StyleValues/StyleValue.h>
namespace Web::CSS {
class TupleStyleValue final : public StyleValueWithDefaultOperators<TupleStyleValue> {
public:
static ValueComparingNonnullRefPtr<TupleStyleValue const> create(StyleValueTuple values)
{
return adopt_ref(*new (nothrow) TupleStyleValue(move(values)));
}
virtual ~TupleStyleValue() override = default;
StyleValueTuple const& tuple() const { return m_tuple; }
virtual void serialize(StringBuilder&, SerializationMode) const override;
virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(ComputationContext const&) const override;
// FIXME: Support tokenization and reification
bool properties_equal(TupleStyleValue const& other) const { return m_tuple == other.m_tuple; }
private:
explicit TupleStyleValue(StyleValueTuple values)
: StyleValueWithDefaultOperators(Type::Tuple)
, m_tuple(move(values))
{
}
StyleValueTuple m_tuple;
};
}