mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-04 15:19:16 +00:00
Reifying the result gets quite ad-hoc. Firstly because "parse a component value" produces a ComponentValue, not a full StyleValue like we need for math functions. And second, because not all math functions can be reified as a CSSNumericValue: Besides the fact that I haven't implemented CalculatedStyleValue reification at all yet, there are a lot of math functions with no corresponding CSSMathValue in the spec yet. If the calculation tree contains any of those, the best we can do is reify as a CSSStyleValue, and that isn't a valid return value from CSSNumericValue.parse(). So, I made us throw a SyntaxError in those cases. This seems to match Chrome's behaviour. Spec issue: https://github.com/w3c/css-houdini-drafts/issues/1090
63 lines
1.8 KiB
C++
63 lines
1.8 KiB
C++
/*
|
|
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/FlyString.h>
|
|
#include <LibWeb/Bindings/CSSNumericValuePrototype.h>
|
|
#include <LibWeb/CSS/CSSStyleValue.h>
|
|
#include <LibWeb/CSS/NumericType.h>
|
|
#include <LibWeb/WebIDL/Types.h>
|
|
|
|
namespace Web::CSS {
|
|
|
|
struct CSSNumericType {
|
|
WebIDL::Long length {};
|
|
WebIDL::Long angle {};
|
|
WebIDL::Long time {};
|
|
WebIDL::Long frequency {};
|
|
WebIDL::Long resolution {};
|
|
WebIDL::Long flex {};
|
|
WebIDL::Long percent {};
|
|
Optional<Bindings::CSSNumericBaseType> percent_hint {};
|
|
};
|
|
|
|
// https://drafts.css-houdini.org/css-typed-om-1/#cssnumericvalue
|
|
class CSSNumericValue : public CSSStyleValue {
|
|
WEB_PLATFORM_OBJECT(CSSNumericValue, CSSStyleValue);
|
|
GC_DECLARE_ALLOCATOR(CSSNumericValue);
|
|
|
|
public:
|
|
struct SerializationParams {
|
|
Optional<double> minimum {};
|
|
Optional<double> maximum {};
|
|
bool nested { false };
|
|
bool parenless { false };
|
|
};
|
|
virtual ~CSSNumericValue() override = default;
|
|
|
|
CSSNumericType type_for_bindings() const;
|
|
NumericType const& type() const { return m_type; }
|
|
|
|
virtual String to_string() const final override { return to_string({}); }
|
|
String to_string(SerializationParams const&) const;
|
|
|
|
static WebIDL::ExceptionOr<GC::Ref<CSSNumericValue>> parse(JS::VM&, String const& css_text);
|
|
|
|
protected:
|
|
explicit CSSNumericValue(JS::Realm&, NumericType);
|
|
|
|
virtual void initialize(JS::Realm&) override;
|
|
|
|
NumericType m_type;
|
|
};
|
|
|
|
// https://drafts.css-houdini.org/css-typed-om-1/#typedefdef-cssnumberish
|
|
using CSSNumberish = Variant<double, GC::Root<CSSNumericValue>>;
|
|
|
|
GC::Ref<CSSNumericValue> rectify_a_numberish_value(JS::Realm&, CSSNumberish const&, Optional<FlyString> unit = {});
|
|
|
|
}
|