2025-04-03 11:44:06 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2026-04-18 10:54:06 +02:00
|
|
|
#include <LibWeb/Bindings/CSSFontFaceDescriptors.h>
|
2025-06-17 14:07:50 +01:00
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
2025-04-03 11:44:06 +01:00
|
|
|
#include <LibWeb/CSS/CSSFontFaceDescriptors.h>
|
2026-01-05 09:50:55 +00:00
|
|
|
#include <LibWeb/CSS/CSSFontFaceRule.h>
|
2025-06-17 14:07:50 +01:00
|
|
|
#include <LibWeb/WebIDL/ExceptionOr.h>
|
2025-04-03 11:44:06 +01:00
|
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
|
|
|
|
|
GC_DEFINE_ALLOCATOR(CSSFontFaceDescriptors);
|
|
|
|
|
|
|
|
|
|
GC::Ref<CSSFontFaceDescriptors> CSSFontFaceDescriptors::create(JS::Realm& realm, Vector<Descriptor> descriptors)
|
|
|
|
|
{
|
|
|
|
|
return realm.create<CSSFontFaceDescriptors>(realm, move(descriptors));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSSFontFaceDescriptors::CSSFontFaceDescriptors(JS::Realm& realm, Vector<Descriptor> descriptors)
|
2025-05-07 17:44:44 +01:00
|
|
|
: CSSDescriptors(realm, AtRuleID::FontFace, move(descriptors))
|
2025-04-03 11:44:06 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSSFontFaceDescriptors::~CSSFontFaceDescriptors() = default;
|
|
|
|
|
|
|
|
|
|
void CSSFontFaceDescriptors::initialize(JS::Realm& realm)
|
|
|
|
|
{
|
|
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(CSSFontFaceDescriptors);
|
2025-04-20 16:22:57 +02:00
|
|
|
Base::initialize(realm);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
2026-06-08 20:22:06 +02:00
|
|
|
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_property(Utf16FlyString const& property, StringView value, StringView priority)
|
2026-01-05 09:50:55 +00:00
|
|
|
{
|
|
|
|
|
TRY(Base::set_property(property, value, priority));
|
|
|
|
|
|
2026-06-08 20:22:06 +02:00
|
|
|
if (!property.is_ascii())
|
|
|
|
|
return {};
|
|
|
|
|
|
|
|
|
|
if (auto* font_face_rule = as_if<CSSFontFaceRule>(parent_rule().ptr())) {
|
|
|
|
|
auto property_string = property.to_utf16_string();
|
|
|
|
|
font_face_rule->handle_descriptor_change(MUST(FlyString::from_utf8(property_string.ascii_view())));
|
|
|
|
|
}
|
2026-01-05 09:50:55 +00:00
|
|
|
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-03 11:44:06 +01:00
|
|
|
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_ascent_override(StringView value)
|
|
|
|
|
{
|
2026-06-08 20:22:06 +02:00
|
|
|
return set_property("ascent-override"_utf16_fly_string, value, ""sv);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String CSSFontFaceDescriptors::ascent_override() const
|
|
|
|
|
{
|
2026-06-08 20:15:56 +02:00
|
|
|
return get_property_value("ascent-override"_utf16_fly_string);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_descent_override(StringView value)
|
|
|
|
|
{
|
2026-06-08 20:22:06 +02:00
|
|
|
return set_property("descent-override"_utf16_fly_string, value, ""sv);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String CSSFontFaceDescriptors::descent_override() const
|
|
|
|
|
{
|
2026-06-08 20:15:56 +02:00
|
|
|
return get_property_value("descent-override"_utf16_fly_string);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_font_display(StringView value)
|
|
|
|
|
{
|
2026-06-08 20:22:06 +02:00
|
|
|
return set_property("font-display"_utf16_fly_string, value, ""sv);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String CSSFontFaceDescriptors::font_display() const
|
|
|
|
|
{
|
2026-06-08 20:15:56 +02:00
|
|
|
return get_property_value("font-display"_utf16_fly_string);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_font_family(StringView value)
|
|
|
|
|
{
|
2026-06-08 20:22:06 +02:00
|
|
|
return set_property("font-family"_utf16_fly_string, value, ""sv);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String CSSFontFaceDescriptors::font_family() const
|
|
|
|
|
{
|
2026-06-08 20:15:56 +02:00
|
|
|
return get_property_value("font-family"_utf16_fly_string);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_font_feature_settings(StringView value)
|
|
|
|
|
{
|
2026-06-08 20:22:06 +02:00
|
|
|
return set_property("font-feature-settings"_utf16_fly_string, value, ""sv);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String CSSFontFaceDescriptors::font_feature_settings() const
|
|
|
|
|
{
|
2026-06-08 20:15:56 +02:00
|
|
|
return get_property_value("font-feature-settings"_utf16_fly_string);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_font_language_override(StringView value)
|
|
|
|
|
{
|
2026-06-08 20:22:06 +02:00
|
|
|
return set_property("font-language-override"_utf16_fly_string, value, ""sv);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String CSSFontFaceDescriptors::font_language_override() const
|
|
|
|
|
{
|
2026-06-08 20:15:56 +02:00
|
|
|
return get_property_value("font-language-override"_utf16_fly_string);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_font_named_instance(StringView value)
|
|
|
|
|
{
|
2026-06-08 20:22:06 +02:00
|
|
|
return set_property("font-named-instance"_utf16_fly_string, value, ""sv);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String CSSFontFaceDescriptors::font_named_instance() const
|
|
|
|
|
{
|
2026-06-08 20:15:56 +02:00
|
|
|
return get_property_value("font-named-instance"_utf16_fly_string);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_font_style(StringView value)
|
|
|
|
|
{
|
2026-06-08 20:22:06 +02:00
|
|
|
return set_property("font-style"_utf16_fly_string, value, ""sv);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String CSSFontFaceDescriptors::font_style() const
|
|
|
|
|
{
|
2026-06-08 20:15:56 +02:00
|
|
|
return get_property_value("font-style"_utf16_fly_string);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_font_variation_settings(StringView value)
|
|
|
|
|
{
|
2026-06-08 20:22:06 +02:00
|
|
|
return set_property("font-variation-settings"_utf16_fly_string, value, ""sv);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String CSSFontFaceDescriptors::font_variation_settings() const
|
|
|
|
|
{
|
2026-06-08 20:15:56 +02:00
|
|
|
return get_property_value("font-variation-settings"_utf16_fly_string);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_font_weight(StringView value)
|
|
|
|
|
{
|
2026-06-08 20:22:06 +02:00
|
|
|
return set_property("font-weight"_utf16_fly_string, value, ""sv);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String CSSFontFaceDescriptors::font_weight() const
|
|
|
|
|
{
|
2026-06-08 20:15:56 +02:00
|
|
|
return get_property_value("font-weight"_utf16_fly_string);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_font_width(StringView value)
|
|
|
|
|
{
|
2026-06-08 20:22:06 +02:00
|
|
|
return set_property("font-width"_utf16_fly_string, value, ""sv);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String CSSFontFaceDescriptors::font_width() const
|
|
|
|
|
{
|
2026-06-08 20:15:56 +02:00
|
|
|
return get_property_value("font-width"_utf16_fly_string);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_line_gap_override(StringView value)
|
|
|
|
|
{
|
2026-06-08 20:22:06 +02:00
|
|
|
return set_property("line-gap-override"_utf16_fly_string, value, ""sv);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String CSSFontFaceDescriptors::line_gap_override() const
|
|
|
|
|
{
|
2026-06-08 20:15:56 +02:00
|
|
|
return get_property_value("line-gap-override"_utf16_fly_string);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_src(StringView value)
|
|
|
|
|
{
|
2026-06-08 20:22:06 +02:00
|
|
|
return set_property("src"_utf16_fly_string, value, ""sv);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String CSSFontFaceDescriptors::src() const
|
|
|
|
|
{
|
2026-06-08 20:15:56 +02:00
|
|
|
return get_property_value("src"_utf16_fly_string);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_unicode_range(StringView value)
|
|
|
|
|
{
|
2026-06-08 20:22:06 +02:00
|
|
|
return set_property("unicode-range"_utf16_fly_string, value, ""sv);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String CSSFontFaceDescriptors::unicode_range() const
|
|
|
|
|
{
|
2026-06-08 20:15:56 +02:00
|
|
|
return get_property_value("unicode-range"_utf16_fly_string);
|
2025-04-03 11:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|