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

LibWeb: Add CSS CompositeStyleValue

This represents the value of properties assigned via their shorthands,
and is expanded when computing actual property values.
This commit is contained in:
Ali Mohammad Pur 2023-05-26 23:16:43 +03:30 committed by Andreas Kling
parent 49bb04a6ba
commit 279924242d
9 changed files with 209 additions and 13 deletions

View file

@ -0,0 +1,38 @@
/*
* Copyright (c) 2023, Ali Mohammad Pur <mpfard@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "CompositeStyleValue.h"
#include <LibWeb/CSS/StyleValues/StyleValueList.h>
namespace Web::CSS {
CompositeStyleValue::CompositeStyleValue(Vector<PropertyID> sub_properties, Vector<ValueComparingNonnullRefPtr<StyleValue const>> values)
: StyleValueWithDefaultOperators(Type::Composite)
, m_properties { move(sub_properties), move(values) }
{
if (m_properties.sub_properties.size() != m_properties.values.size()) {
dbgln("CompositeStyleValue: sub_properties and values must be the same size! {} != {}", m_properties.sub_properties.size(), m_properties.values.size());
VERIFY_NOT_REACHED();
}
}
CompositeStyleValue::~CompositeStyleValue() = default;
ErrorOr<String> CompositeStyleValue::to_string() const
{
StringBuilder builder;
auto first = true;
for (auto& value : m_properties.values) {
if (first)
first = false;
else
builder.append(' ');
builder.append(TRY(value->to_string()));
}
return builder.to_string();
}
}

View file

@ -0,0 +1,38 @@
/*
* Copyright (c) 2023, Ali Mohammad Pur <mpfard@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/CSS/StyleValue.h>
namespace Web::CSS {
class CompositeStyleValue final : public StyleValueWithDefaultOperators<CompositeStyleValue> {
public:
static ErrorOr<ValueComparingNonnullRefPtr<CompositeStyleValue>> create(Vector<PropertyID> sub_properties, Vector<ValueComparingNonnullRefPtr<StyleValue const>> values)
{
return adopt_nonnull_ref_or_enomem(new CompositeStyleValue(move(sub_properties), move(values)));
}
virtual ~CompositeStyleValue() override;
Vector<PropertyID> const& sub_properties() const { return m_properties.sub_properties; }
Vector<ValueComparingNonnullRefPtr<StyleValue const>> const& values() const { return m_properties.values; }
virtual ErrorOr<String> to_string() const override;
bool properties_equal(CompositeStyleValue const& other) const { return m_properties == other.m_properties; }
private:
CompositeStyleValue(Vector<PropertyID> sub_properties, Vector<ValueComparingNonnullRefPtr<StyleValue const>> values);
struct Properties {
Vector<PropertyID> sub_properties;
Vector<ValueComparingNonnullRefPtr<StyleValue const>> values;
bool operator==(Properties const&) const = default;
} m_properties;
};
}