Make CSS Typed OM to_string() implementations produce Utf16String instead of building UTF-8 strings and converting at the JS binding boundary. Use Utf16StringBuilder for numeric, math, and transform serialization paths that already feed CSS Typed OM stringification. Keep the older CSSOM StyleValue serializer on StringBuilder for now, and convert only where Typed OM source values or parser re-entry still need the existing UTF-8 representation.
46 lines
1.4 KiB
C++
46 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 <AK/Utf16StringBuilder.h>
|
|
#include <LibWeb/CSS/CSSStyleValue.h>
|
|
|
|
namespace Web::CSS {
|
|
|
|
// https://drafts.css-houdini.org/css-typed-om-1/#typedefdef-csskeywordish
|
|
using CSSKeywordish = Variant<String, GC::Ref<CSSKeywordValue>>;
|
|
|
|
// https://drafts.css-houdini.org/css-typed-om-1/#csskeywordvalue
|
|
class CSSKeywordValue final : public CSSStyleValue {
|
|
WEB_PLATFORM_OBJECT(CSSKeywordValue, CSSStyleValue);
|
|
GC_DECLARE_ALLOCATOR(CSSKeywordValue);
|
|
|
|
public:
|
|
[[nodiscard]] static GC::Ref<CSSKeywordValue> create(JS::Realm&, FlyString value);
|
|
static WebIDL::ExceptionOr<GC::Ref<CSSKeywordValue>> construct_impl(JS::Realm&, FlyString value);
|
|
|
|
virtual ~CSSKeywordValue() override = default;
|
|
|
|
FlyString const& value() const { return m_value; }
|
|
WebIDL::ExceptionOr<void> set_value(FlyString value);
|
|
|
|
void serialize(Utf16StringBuilder&) const;
|
|
virtual WebIDL::ExceptionOr<Utf16String> to_string() const override;
|
|
virtual WebIDL::ExceptionOr<NonnullRefPtr<StyleValue const>> create_an_internal_representation(PropertyNameAndID const&, PerformTypeCheck) const override;
|
|
|
|
private:
|
|
explicit CSSKeywordValue(JS::Realm&, FlyString value);
|
|
|
|
virtual void initialize(JS::Realm&) override;
|
|
|
|
FlyString m_value;
|
|
};
|
|
|
|
GC::Ref<CSSKeywordValue> rectify_a_keywordish_value(JS::Realm&, CSSKeywordish const&);
|
|
|
|
}
|