mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-15 20:49:41 +00:00
Because we store calculations as a tree of CalculationNodes inside a CalculatedStyleValue, instead of a tree of StyleValues directly, this implements a create_calculation_node() method on CSSNumericValue. CSSMathValue::create_an_internal_representation() then calls create_calculation_node() on itself, and wraps it in a CalculatedStyleValue. Lots of WPT passes again! Some regressions, which are expected: `cursor` fails a test for the same reason it fails other that set it to some kind of numeric value: We don't distinguish between "can contain a number" and "can accept a number by itself". This will affect any similar properties, but overall this is a big improvement.
50 lines
1.7 KiB
C++
50 lines
1.7 KiB
C++
/*
|
|
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/FlyString.h>
|
|
#include <LibWeb/CSS/CSSNumericValue.h>
|
|
|
|
namespace Web::CSS {
|
|
|
|
// https://drafts.css-houdini.org/css-typed-om-1/#cssunitvalue
|
|
class CSSUnitValue final : public CSSNumericValue {
|
|
WEB_PLATFORM_OBJECT(CSSUnitValue, CSSNumericValue);
|
|
GC_DECLARE_ALLOCATOR(CSSUnitValue);
|
|
|
|
public:
|
|
[[nodiscard]] static GC::Ref<CSSUnitValue> create(JS::Realm&, double value, FlyString unit);
|
|
static GC::Ptr<CSSUnitValue> create_from_sum_value_item(JS::Realm&, SumValueItem const&);
|
|
static WebIDL::ExceptionOr<GC::Ref<CSSUnitValue>> construct_impl(JS::Realm&, double value, FlyString unit);
|
|
|
|
virtual ~CSSUnitValue() override = default;
|
|
|
|
double value() const { return m_value; }
|
|
void set_value(double value);
|
|
|
|
FlyString const& unit() const { return m_unit; }
|
|
|
|
String serialize_unit_value(Optional<double> minimum, Optional<double> maximum) const;
|
|
|
|
GC::Ptr<CSSUnitValue> converted_to_unit(FlyString const& unit) const;
|
|
|
|
virtual bool is_equal_numeric_value(GC::Ref<CSSNumericValue> other) const override;
|
|
virtual Optional<SumValue> create_a_sum_value() const override;
|
|
|
|
virtual WebIDL::ExceptionOr<NonnullRefPtr<StyleValue const>> create_an_internal_representation(PropertyNameAndID const&) const override;
|
|
virtual WebIDL::ExceptionOr<NonnullRefPtr<CalculationNode const>> create_calculation_node(CalculationContext const&) const override;
|
|
|
|
private:
|
|
explicit CSSUnitValue(JS::Realm&, double value, FlyString unit, NumericType type);
|
|
|
|
virtual void initialize(JS::Realm&) override;
|
|
|
|
double m_value;
|
|
FlyString m_unit;
|
|
};
|
|
|
|
}
|