ladybird/Libraries/LibWeb/CSS/CSSPageDescriptors.cpp
Andreas Kling 22a26babc5 LibWeb: Take UTF-16 names in get_property_value
Change get_property_value() to take a Utf16FlyString so generated CSS
property accessors can pass their JS property names through without
constructing FlyString instances first.

Keep the existing internal descriptor and custom-property storage shape
for now, and convert at those boundaries while the remaining CSS
property APIs are migrated separately.
2026-06-09 11:48:02 +02:00

124 lines
3.1 KiB
C++

/*
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/CSSPageDescriptors.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/CSS/CSSPageDescriptors.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::CSS {
GC_DEFINE_ALLOCATOR(CSSPageDescriptors);
GC::Ref<CSSPageDescriptors> CSSPageDescriptors::create(JS::Realm& realm, Vector<Descriptor> descriptors)
{
return realm.create<CSSPageDescriptors>(realm, move(descriptors));
}
CSSPageDescriptors::CSSPageDescriptors(JS::Realm& realm, Vector<Descriptor> descriptors)
: CSSDescriptors(realm, AtRuleID::Page, move(descriptors))
{
}
CSSPageDescriptors::~CSSPageDescriptors() = default;
void CSSPageDescriptors::initialize(JS::Realm& realm)
{
WEB_SET_PROTOTYPE_FOR_INTERFACE(CSSPageDescriptors);
Base::initialize(realm);
}
WebIDL::ExceptionOr<void> CSSPageDescriptors::set_margin(StringView value)
{
return set_property("margin"_fly_string, value, ""sv);
}
String CSSPageDescriptors::margin() const
{
return get_property_value("margin"_utf16_fly_string);
}
WebIDL::ExceptionOr<void> CSSPageDescriptors::set_margin_top(StringView value)
{
return set_property("margin-top"_fly_string, value, ""sv);
}
String CSSPageDescriptors::margin_top() const
{
return get_property_value("margin-top"_utf16_fly_string);
}
WebIDL::ExceptionOr<void> CSSPageDescriptors::set_margin_right(StringView value)
{
return set_property("margin-right"_fly_string, value, ""sv);
}
String CSSPageDescriptors::margin_right() const
{
return get_property_value("margin-right"_utf16_fly_string);
}
WebIDL::ExceptionOr<void> CSSPageDescriptors::set_margin_bottom(StringView value)
{
return set_property("margin-bottom"_fly_string, value, ""sv);
}
String CSSPageDescriptors::margin_bottom() const
{
return get_property_value("margin-bottom"_utf16_fly_string);
}
WebIDL::ExceptionOr<void> CSSPageDescriptors::set_margin_left(StringView value)
{
return set_property("margin-left"_fly_string, value, ""sv);
}
String CSSPageDescriptors::margin_left() const
{
return get_property_value("margin-left"_utf16_fly_string);
}
WebIDL::ExceptionOr<void> CSSPageDescriptors::set_size(StringView value)
{
return set_property("size"_fly_string, value, ""sv);
}
String CSSPageDescriptors::size() const
{
return get_property_value("size"_utf16_fly_string);
}
WebIDL::ExceptionOr<void> CSSPageDescriptors::set_page_orientation(StringView value)
{
return set_property("page-orientation"_fly_string, value, ""sv);
}
String CSSPageDescriptors::page_orientation() const
{
return get_property_value("page-orientation"_utf16_fly_string);
}
WebIDL::ExceptionOr<void> CSSPageDescriptors::set_marks(StringView value)
{
return set_property("marks"_fly_string, value, ""sv);
}
String CSSPageDescriptors::marks() const
{
return get_property_value("marks"_utf16_fly_string);
}
WebIDL::ExceptionOr<void> CSSPageDescriptors::set_bleed(StringView value)
{
return set_property("bleed"_fly_string, value, ""sv);
}
String CSSPageDescriptors::bleed() const
{
return get_property_value("bleed"_utf16_fly_string);
}
}