Coverage Report

Created: 2025-03-04 07:22

/src/serenity/Userland/Libraries/LibWeb/CSS/FontFaceSet.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
3
 * Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
4
 *
5
 * SPDX-License-Identifier: BSD-2-Clause
6
 */
7
8
#pragma once
9
10
#include <LibJS/Runtime/Set.h>
11
#include <LibJS/Runtime/SetIterator.h>
12
#include <LibWeb/Bindings/FontFaceSetPrototype.h>
13
#include <LibWeb/Bindings/PlatformObject.h>
14
#include <LibWeb/CSS/FontFace.h>
15
#include <LibWeb/DOM/EventTarget.h>
16
17
namespace Web::CSS {
18
19
class FontFaceSet final : public DOM::EventTarget {
20
    WEB_PLATFORM_OBJECT(FontFaceSet, DOM::EventTarget);
21
    JS_DECLARE_ALLOCATOR(FontFaceSet);
22
23
public:
24
    [[nodiscard]] static JS::NonnullGCPtr<FontFaceSet> construct_impl(JS::Realm&, Vector<JS::Handle<FontFace>> const& initial_faces);
25
    [[nodiscard]] static JS::NonnullGCPtr<FontFaceSet> create(JS::Realm&);
26
0
    virtual ~FontFaceSet() override = default;
27
28
0
    JS::NonnullGCPtr<JS::Set> set_entries() const { return m_set_entries; }
29
30
    WebIDL::ExceptionOr<JS::NonnullGCPtr<FontFaceSet>> add(JS::Handle<FontFace>);
31
    bool delete_(JS::Handle<FontFace>);
32
    void clear();
33
34
    void set_onloading(WebIDL::CallbackType*);
35
    WebIDL::CallbackType* onloading();
36
    void set_onloadingdone(WebIDL::CallbackType*);
37
    WebIDL::CallbackType* onloadingdone();
38
    void set_onloadingerror(WebIDL::CallbackType*);
39
    WebIDL::CallbackType* onloadingerror();
40
41
    JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Promise>> load(String const& font, String const& text);
42
43
    JS::NonnullGCPtr<JS::Promise> ready() const;
44
0
    Bindings::FontFaceSetLoadStatus status() const { return m_status; }
45
46
private:
47
    FontFaceSet(JS::Realm&, JS::NonnullGCPtr<WebIDL::Promise> ready_promise, JS::NonnullGCPtr<JS::Set> set_entries);
48
49
    virtual void initialize(JS::Realm&) override;
50
    virtual void visit_edges(Cell::Visitor&) override;
51
52
    JS::NonnullGCPtr<JS::Set> m_set_entries;
53
    JS::GCPtr<WebIDL::Promise> m_ready_promise; // [[ReadyPromise]]
54
55
    Vector<JS::NonnullGCPtr<FontFace>> m_loading_fonts {}; // [[LoadingFonts]]
56
    Vector<JS::NonnullGCPtr<FontFace>> m_loaded_fonts {};  // [[LoadedFonts]]
57
    Vector<JS::NonnullGCPtr<FontFace>> m_failed_fonts {};  // [[FailedFonts]]
58
59
    Bindings::FontFaceSetLoadStatus m_status { Bindings::FontFaceSetLoadStatus::Loading };
60
};
61
62
}