FontFaceSet.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibJS/Heap/Heap.h>
  7. #include <LibJS/Runtime/Realm.h>
  8. #include <LibWeb/Bindings/FontFaceSetPrototype.h>
  9. #include <LibWeb/Bindings/Intrinsics.h>
  10. #include <LibWeb/CSS/FontFaceSet.h>
  11. #include <LibWeb/WebIDL/Promise.h>
  12. namespace Web::CSS {
  13. JS_DEFINE_ALLOCATOR(FontFaceSet);
  14. JS::NonnullGCPtr<FontFaceSet> FontFaceSet::construct_impl(JS::Realm& realm, Vector<JS::Handle<FontFace>> initial_faces)
  15. {
  16. auto promise = WebIDL::create_promise(realm);
  17. return realm.heap().allocate<FontFaceSet>(realm, realm, promise, move(initial_faces));
  18. }
  19. JS::NonnullGCPtr<FontFaceSet> FontFaceSet::create(JS::Realm& realm)
  20. {
  21. return construct_impl(realm, {});
  22. }
  23. FontFaceSet::FontFaceSet(JS::Realm& realm, JS::NonnullGCPtr<WebIDL::Promise> ready_promise, Vector<JS::Handle<FontFace>>)
  24. : Bindings::PlatformObject(realm)
  25. , m_ready_promise(ready_promise)
  26. {
  27. // FIXME: Only set this after all the initial faces have been loaded
  28. m_status = Bindings::FontFaceSetLoadStatus::Loaded;
  29. // FIXME: Only resolve the promise after all the initial faces have been loaded
  30. WebIDL::resolve_promise(realm, *m_ready_promise);
  31. }
  32. void FontFaceSet::initialize(JS::Realm& realm)
  33. {
  34. Base::initialize(realm);
  35. WEB_SET_PROTOTYPE_FOR_INTERFACE(FontFaceSet);
  36. }
  37. void FontFaceSet::visit_edges(Cell::Visitor& visitor)
  38. {
  39. Base::visit_edges(visitor);
  40. visitor.visit(m_ready_promise);
  41. }
  42. // https://drafts.csswg.org/css-font-loading/#dom-fontfaceset-add
  43. JS::NonnullGCPtr<FontFaceSet> FontFaceSet::add(JS::Handle<FontFace>)
  44. {
  45. // FIXME: Do the steps
  46. return *this;
  47. }
  48. // https://drafts.csswg.org/css-font-loading/#dom-fontfaceset-load
  49. JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Promise>> FontFaceSet::load(String const&, String const&)
  50. {
  51. // FIXME: Do the steps
  52. auto promise = WebIDL::create_rejected_promise(realm(), WebIDL::NotSupportedError::create(realm(), "FontFaceSet::load is not yet implemented"_fly_string));
  53. return verify_cast<JS::Promise>(*promise->promise());
  54. }
  55. // https://drafts.csswg.org/css-font-loading/#font-face-set-ready
  56. JS::NonnullGCPtr<JS::Promise> FontFaceSet::ready() const
  57. {
  58. return verify_cast<JS::Promise>(*m_ready_promise->promise());
  59. }
  60. }