ladybird/Libraries/LibWeb/CSS/StyleValues/RadialSizeStyleValue.h
Tim Ledbetter a27d269721 LibWeb: Pass StringBuilder around during StyleValue serialization
Previously, some StyleValues created a large number of intermediate
strings during serialization. Passing a StringBUilder into the
serialization function allows us to avoid a large number of these
unnecessary allocations.
2026-01-09 10:00:58 +01:00

46 lines
1.5 KiB
C++

/*
* Copyright (c) 2025, Callum Law <callumlaw1709@outlook.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/CSS/Enums.h>
#include <LibWeb/CSS/StyleValues/StyleValue.h>
namespace Web::CSS {
class RadialSizeStyleValue : public StyleValueWithDefaultOperators<RadialSizeStyleValue> {
public:
using Component = Variant<RadialExtent, NonnullRefPtr<StyleValue const>>;
static ValueComparingNonnullRefPtr<RadialSizeStyleValue const> create(Vector<Component> components)
{
VERIFY(components.size() == 1 || components.size() == 2);
return adopt_ref(*new (nothrow) RadialSizeStyleValue(move(components)));
}
virtual ~RadialSizeStyleValue() override = default;
virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(ComputationContext const&) const override;
virtual void serialize(StringBuilder&, SerializationMode) const override;
Vector<Component> components() const { return m_components; }
CSSPixels resolve_circle_size(CSSPixelPoint const& center, CSSPixelRect const& reference_box, Layout::Node const&) const;
CSSPixelSize resolve_ellipse_size(CSSPixelPoint const& center, CSSPixelRect const& reference_box, Layout::Node const&) const;
bool properties_equal(RadialSizeStyleValue const& other) const { return m_components == other.m_components; }
private:
explicit RadialSizeStyleValue(Vector<Component> components)
: StyleValueWithDefaultOperators(Type::RadialSize)
, m_components(move(components))
{
}
Vector<Component> m_components;
};
}