mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-04-19 02:10:26 +00:00
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.
51 lines
1.2 KiB
C++
51 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) 2026, Callum Law <callumlaw1709@outlook.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include "TupleStyleValue.h"
|
|
|
|
namespace Web::CSS {
|
|
|
|
void TupleStyleValue::serialize(StringBuilder& builder, SerializationMode mode) const
|
|
{
|
|
auto first = true;
|
|
|
|
for (auto const& value : m_tuple) {
|
|
if (value) {
|
|
if (!first)
|
|
builder.append(' ');
|
|
value->serialize(builder, mode);
|
|
first = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
ValueComparingNonnullRefPtr<StyleValue const> TupleStyleValue::absolutized(ComputationContext const& context) const
|
|
{
|
|
StyleValueTuple absolutized_tuple;
|
|
absolutized_tuple.ensure_capacity(m_tuple.size());
|
|
|
|
bool any_value_changed = false;
|
|
|
|
for (auto const& value : m_tuple) {
|
|
if (value) {
|
|
auto absolutized_value = value->absolutized(context);
|
|
|
|
if (absolutized_value != value)
|
|
any_value_changed = true;
|
|
|
|
absolutized_tuple.append(move(absolutized_value));
|
|
} else {
|
|
absolutized_tuple.append(nullptr);
|
|
}
|
|
}
|
|
|
|
if (!any_value_changed)
|
|
return *this;
|
|
|
|
return TupleStyleValue::create(move(absolutized_tuple));
|
|
}
|
|
|
|
}
|