ladybird/Libraries/LibWeb/CSS/StyleValues/RatioStyleValue.h
Sam Atkins c57975c9fd LibWeb: Move and rename CSSStyleValue to StyleValues/StyleValue.{h,cpp}
This reverts 0e3487b9ab.

Back when I made that change, I thought we could make our StyleValue
classes match the typed-om definitions directly. However, they have
different requirements. Typed-om types need to be mutable and GCed,
whereas StyleValues are immutable and ideally wouldn't require a JS VM.

While I was already making such a cataclysmic change, I've moved it into
the StyleValues directory, because it *not* being there has bothered me
for a long time. 😅
2025-08-08 15:19:03 +01:00

49 lines
1.4 KiB
C++

/*
* Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/CSS/Ratio.h>
#include <LibWeb/CSS/StyleValues/StyleValue.h>
namespace Web::CSS {
class RatioStyleValue final : public StyleValueWithDefaultOperators<RatioStyleValue> {
public:
static ValueComparingNonnullRefPtr<RatioStyleValue const> create(Ratio ratio)
{
return adopt_ref(*new (nothrow) RatioStyleValue(move(ratio)));
}
virtual ~RatioStyleValue() override = default;
Ratio const& ratio() const { return m_ratio; }
Ratio& ratio() { return m_ratio; }
virtual String to_string(SerializationMode) const override { return m_ratio.to_string(); }
Vector<Parser::ComponentValue> tokenize() const override
{
return {
Parser::Token::create_number(Number { Number::Type::Number, m_ratio.numerator() }),
Parser::Token::create_whitespace(" "_string),
Parser::Token::create_delim('/'),
Parser::Token::create_whitespace(" "_string),
Parser::Token::create_number(Number { Number::Type::Number, m_ratio.denominator() }),
};
}
bool properties_equal(RatioStyleValue const& other) const { return m_ratio == other.m_ratio; }
private:
RatioStyleValue(Ratio&& ratio)
: StyleValueWithDefaultOperators(Type::Ratio)
, m_ratio(ratio)
{
}
Ratio m_ratio;
};
}