Files
ladybird/Libraries/LibWeb/CSS/StyleValues/OpacityValueStyleValue.h
Callum Law 8a7332b7b9 LibWeb: Add OpacityValueStyleValue
This allows us to avoid the ugly hack in
`property_accepted_type_ranges()`.

This also updates the `ValueType` to be `opacity-value` rather than
`opacity` to match the spec.
2026-04-22 14:24:12 +01:00

46 lines
1.4 KiB
C++

/*
* Copyright (c) 2026, Callum Law <callumlaw1709@outlook.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
#include <LibWeb/CSS/StyleValues/StyleValue.h>
namespace Web::CSS {
class OpacityValueStyleValue final : public StyleValueWithDefaultOperators<OpacityValueStyleValue> {
public:
static ValueComparingNonnullRefPtr<OpacityValueStyleValue const> create(NonnullRefPtr<StyleValue const>&& value)
{
return adopt_ref(*new (nothrow) OpacityValueStyleValue(move(value)));
}
virtual ~OpacityValueStyleValue() override = default;
virtual void serialize(StringBuilder&, SerializationMode) const override;
virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(ComputationContext const&) const override;
double resolved() const { return m_value->as_number().number(); }
virtual GC::Ref<CSSStyleValue> reify(JS::Realm& realm, FlyString const& associated_property) const override;
bool properties_equal(OpacityValueStyleValue const& other) const { return m_value == other.m_value; }
virtual bool is_computationally_independent() const override { return m_value->is_computationally_independent(); }
private:
OpacityValueStyleValue(NonnullRefPtr<StyleValue const>&& value)
: StyleValueWithDefaultOperators(Type::OpacityValue)
, m_value(move(value))
{
}
ValueComparingNonnullRefPtr<StyleValue const> m_value;
};
}