LibWeb: Add stub implementation of FontFaceSet and Document.fonts

This is now enough for duolingo to load and use its fallback fonts.
This commit is contained in:
Andrew Kaster 2024-05-07 14:49:31 -06:00 committed by Andreas Kling
commit e10721f1b5
Notes: sideshowbarker 2024-07-17 05:03:11 +09:00
13 changed files with 174 additions and 1 deletions

View file

@ -8,6 +8,7 @@
#include <LibWeb/Bindings/DedicatedWorkerExposedInterfaces.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/WorkerGlobalScopePrototype.h>
#include <LibWeb/CSS/FontFaceSet.h>
#include <LibWeb/HTML/EventHandler.h>
#include <LibWeb/HTML/EventNames.h>
#include <LibWeb/HTML/MessageEvent.h>
@ -53,6 +54,7 @@ void WorkerGlobalScope::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_navigator);
visitor.visit(m_internal_port);
visitor.visit(m_page);
visitor.visit(m_fonts);
}
void WorkerGlobalScope::finalize()
@ -127,4 +129,11 @@ WebIDL::ExceptionOr<void> WorkerGlobalScope::post_message(JS::Value message, Str
ENUMERATE_WORKER_GLOBAL_SCOPE_EVENT_HANDLERS(__ENUMERATE)
#undef __ENUMERATE
JS::NonnullGCPtr<CSS::FontFaceSet> WorkerGlobalScope::fonts()
{
if (!m_fonts)
m_fonts = CSS::FontFaceSet::create(realm());
return *m_fonts;
}
}

View file

@ -77,6 +77,8 @@ public:
WebIDL::ExceptionOr<void> post_message(JS::Value message, StructuredSerializeOptions const&);
JS::NonnullGCPtr<CSS::FontFaceSet> fonts();
// Non-IDL public methods
URL::URL const& url() const { return m_url.value(); }
@ -136,6 +138,9 @@ private:
// https://html.spec.whatwg.org/multipage/workers.html#concept-workerglobalscope-cross-origin-isolated-capability
bool m_cross_origin_isolated_capability { false };
// https://drafts.csswg.org/css-font-loading/#font-source
JS::GCPtr<CSS::FontFaceSet> m_fonts;
};
}

View file

@ -1,3 +1,4 @@
#import <CSS/FontFaceSet.idl>
#import <DOM/EventTarget.idl>
#import <DOM/EventHandler.idl>
#import <HTML/WindowOrWorkerGlobalScope.idl>
@ -28,3 +29,4 @@ interface WorkerGlobalScope : EventTarget {
};
WorkerGlobalScope includes WindowOrWorkerGlobalScope;
WorkerGlobalScope includes FontFaceSource;