ladybird/Libraries/LibWeb/CSS/CSSUnitValue.h
Sam Atkins a139ad1c44
Some checks are pending
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
LibWeb/CSS: Implement CSSNumericValue.to()
Tries to convert the CSSNumericValue to a CSSUnitValue with the given
unit.

This gets us the remaining 11 WPT subtests for this method.
2025-09-12 13:45:41 +02:00

47 lines
1.4 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;
private:
explicit CSSUnitValue(JS::Realm&, double value, FlyString unit, NumericType type);
virtual void initialize(JS::Realm&) override;
double m_value;
FlyString m_unit;
};
}