diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index 9407bd5a944..50a5d6c18af 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -48,6 +48,7 @@ static bool is_platform_object(Type const& type) "DOMRectReadOnly"sv, "EventTarget"sv, "FileList"sv, + "FontFace"sv, "FormData"sv, "HTMLCollection"sv, "ImageBitmap"sv, diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index e1f9417041e..9557a37da84 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -54,6 +54,7 @@ set(SOURCES CSS/CSSTransition.cpp CSS/Display.cpp CSS/EdgeRect.cpp + CSS/FontFace.cpp CSS/Flex.cpp CSS/Frequency.cpp CSS/GridTrackPlacement.cpp diff --git a/Userland/Libraries/LibWeb/CSS/FontFace.cpp b/Userland/Libraries/LibWeb/CSS/FontFace.cpp new file mode 100644 index 00000000000..1315652a5dc --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/FontFace.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024, Andrew Kaster + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include +#include +#include + +namespace Web::CSS { + +JS_DEFINE_ALLOCATOR(FontFace); + +JS::NonnullGCPtr FontFace::construct_impl(JS::Realm& realm, String family, FontFaceSource source, FontFaceDescriptors const& descriptors) +{ + return realm.heap().allocate(realm, realm, move(family), move(source), descriptors); +} + +FontFace::FontFace(JS::Realm& realm, String, FontFaceSource, FontFaceDescriptors const&) + : Bindings::PlatformObject(realm) +{ +} + +void FontFace::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + + WEB_SET_PROTOTYPE_FOR_INTERFACE(FontFace); +} + +// https://drafts.csswg.org/css-font-loading/#dom-fontface-load +JS::ThrowCompletionOr> FontFace::load() +{ + // FIXME: Do the steps + auto promise = WebIDL::create_rejected_promise(realm(), WebIDL::NotSupportedError::create(realm(), "FontFace::load is not yet implemented"_fly_string)); + return verify_cast(*promise->promise()); +} + +} diff --git a/Userland/Libraries/LibWeb/CSS/FontFace.h b/Userland/Libraries/LibWeb/CSS/FontFace.h new file mode 100644 index 00000000000..fff97d3c09c --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/FontFace.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024, Andrew Kaster + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::CSS { + +struct FontFaceDescriptors { + String style = "normal"_string; + String weight = "normal"_string; + String stretch = "normal"_string; + String unicode_range = "U+0-10FFFF"_string; + String feature_settings = "normal"_string; + String variation_settings = "normal"_string; + String display = "auto"_string; + String ascent_override = "normal"_string; + String descent_override = "normal"_string; + String line_gap_override = "normal"_string; +}; + +class FontFace final : public Bindings::PlatformObject { + WEB_PLATFORM_OBJECT(FontFace, Bindings::PlatformObject); + JS_DECLARE_ALLOCATOR(FontFace); + +public: + using FontFaceSource = Variant, JS::Handle>; + + [[nodiscard]] static JS::NonnullGCPtr construct_impl(JS::Realm&, String family, FontFaceSource source, FontFaceDescriptors const& descriptors); + virtual ~FontFace() override = default; + + JS::ThrowCompletionOr> load(); + +private: + FontFace(JS::Realm&, String family, FontFaceSource source, FontFaceDescriptors const& descriptors); + + virtual void initialize(JS::Realm&) override; +}; + +} diff --git a/Userland/Libraries/LibWeb/CSS/FontFace.idl b/Userland/Libraries/LibWeb/CSS/FontFace.idl new file mode 100644 index 00000000000..f219c78c378 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/FontFace.idl @@ -0,0 +1,39 @@ +typedef (ArrayBuffer or ArrayBufferView) BinaryData; + +dictionary FontFaceDescriptors { + CSSOMString style = "normal"; + CSSOMString weight = "normal"; + CSSOMString stretch = "normal"; + CSSOMString unicodeRange = "U+0-10FFFF"; + CSSOMString featureSettings = "normal"; + CSSOMString variationSettings = "normal"; + CSSOMString display = "auto"; + CSSOMString ascentOverride = "normal"; + CSSOMString descentOverride = "normal"; + CSSOMString lineGapOverride = "normal"; +}; + +enum FontFaceLoadStatus { "unloaded", "loading", "loaded", "error" }; + +// https://drafts.csswg.org/css-font-loading/#fontface-interface +[Exposed=(Window,Worker)] +interface FontFace { + // FIXME: constructor(CSSOMString family, (CSSOMString or BinaryData) source, optional FontFaceDescriptors descriptors = {}); + constructor(CSSOMString family, CSSOMString source, optional FontFaceDescriptors descriptors = {}); + // FIXME: attribute CSSOMString family; + // FIXME: attribute CSSOMString style; + // FIXME: attribute CSSOMString weight; + // FIXME: attribute CSSOMString stretch; + // FIXME: attribute CSSOMString unicodeRange; + // FIXME: attribute CSSOMString featureSettings; + // FIXME: attribute CSSOMString variationSettings; + // FIXME: attribute CSSOMString display; + // FIXME: attribute CSSOMString ascentOverride; + // FIXME: attribute CSSOMString descentOverride; + // FIXME: attribute CSSOMString lineGapOverride; + + // FIXME: readonly attribute FontFaceLoadStatus status; + + Promise load(); + // FIXME: readonly attribute Promise loaded; +}; diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index ecf0ce8067a..29480d029ec 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -124,6 +124,7 @@ class FilterValueListStyleValue; class Flex; class FlexOrCalculated; class FlexStyleValue; +class FontFace; class Frequency; class FrequencyOrCalculated; class FrequencyPercentage; diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index b2be76c6aff..34cc390d310 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -29,6 +29,7 @@ libweb_js_bindings(CSS/CSSStyleRule) libweb_js_bindings(CSS/CSSStyleSheet) libweb_js_bindings(CSS/CSSSupportsRule) libweb_js_bindings(CSS/CSSTransition) +libweb_js_bindings(CSS/FontFace) libweb_js_bindings(CSS/MediaList) libweb_js_bindings(CSS/MediaQueryList) libweb_js_bindings(CSS/MediaQueryListEvent)