Coverage Report

Created: 2026-07-25 07:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibWeb/HTML/ImageBitmap.cpp
Line
Count
Source
1
/*
2
 * Copyright (c) 2024, Lucas Chollet <lucas.chollet@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#include <LibGfx/Bitmap.h>
8
#include <LibWeb/Bindings/ImageBitmapPrototype.h>
9
#include <LibWeb/HTML/ImageBitmap.h>
10
11
namespace Web::HTML {
12
13
JS_DEFINE_ALLOCATOR(ImageBitmap);
14
15
JS::NonnullGCPtr<ImageBitmap> ImageBitmap::create(JS::Realm& realm)
16
0
{
17
0
    return realm.heap().allocate<ImageBitmap>(realm, realm);
18
0
}
19
20
ImageBitmap::ImageBitmap(JS::Realm& realm)
21
0
    : Bindings::PlatformObject(realm)
22
0
{
23
0
}
24
25
void ImageBitmap::initialize(JS::Realm& realm)
26
0
{
27
0
    Base::initialize(realm);
28
0
    WEB_SET_PROTOTYPE_FOR_INTERFACE(ImageBitmap);
29
0
}
30
31
void ImageBitmap::visit_edges(Cell::Visitor& visitor)
32
0
{
33
0
    Base::visit_edges(visitor);
34
0
}
35
36
WebIDL::ExceptionOr<void> ImageBitmap::serialization_steps(HTML::SerializationRecord&, bool, HTML::SerializationMemory&)
37
0
{
38
    // FIXME: Implement this
39
0
    dbgln("(STUBBED) ImageBitmap::serialization_steps(HTML::SerializationRecord&, bool, HTML::SerializationMemory&)");
40
0
    return {};
41
0
}
42
43
WebIDL::ExceptionOr<void> ImageBitmap::deserialization_steps(ReadonlySpan<u32> const&, size_t&, HTML::DeserializationMemory&)
44
0
{
45
    // FIXME: Implement this
46
0
    dbgln("(STUBBED) ImageBitmap::deserialization_steps(ReadonlySpan<u32> const&, size_t&, HTML::DeserializationMemory&)");
47
0
    return {};
48
0
}
49
50
WebIDL::ExceptionOr<void> ImageBitmap::transfer_steps(HTML::TransferDataHolder&)
51
0
{
52
    // FIXME: Implement this
53
0
    dbgln("(STUBBED) ImageBitmap::transfer_steps(HTML::TransferDataHolder&)");
54
0
    return {};
55
0
}
56
57
WebIDL::ExceptionOr<void> ImageBitmap::transfer_receiving_steps(HTML::TransferDataHolder&)
58
0
{
59
    // FIXME: Implement this
60
0
    dbgln("(STUBBED) ImageBitmap::transfer_receiving_steps(HTML::TransferDataHolder&)");
61
0
    return {};
62
0
}
63
64
HTML::TransferType ImageBitmap::primary_interface() const
65
0
{
66
    // FIXME: Implement this
67
0
    dbgln("(STUBBED) ImageBitmap::primary_interface()");
68
0
    return {};
69
0
}
70
71
// https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#dom-imagebitmap-width
72
WebIDL::UnsignedLong ImageBitmap::width() const
73
0
{
74
    // 1. If this's [[Detached]] internal slot's value is true, then return 0.
75
0
    if (is_detached())
76
0
        return 0;
77
    // 2. Return this's width, in CSS pixels.
78
0
    return m_width;
79
0
}
80
81
// https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#dom-imagebitmap-height
82
WebIDL::UnsignedLong ImageBitmap::height() const
83
0
{
84
    // 1. If this's [[Detached]] internal slot's value is true, then return 0.
85
0
    if (is_detached())
86
0
        return 0;
87
    // 2. Return this's height, in CSS pixels.
88
0
    return m_height;
89
0
}
90
91
// https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#dom-imagebitmap-close
92
void ImageBitmap::close()
93
0
{
94
    // 1. Set this's [[Detached]] internal slot value to true.
95
0
    set_detached(true);
96
97
    // 2. Unset this's bitmap data.
98
0
    m_bitmap = nullptr;
99
0
}
100
101
void ImageBitmap::set_bitmap(RefPtr<Gfx::Bitmap> bitmap)
102
0
{
103
0
    m_bitmap = move(bitmap);
104
0
    m_width = m_bitmap->width();
105
0
    m_height = m_bitmap->height();
106
0
}
107
108
Gfx::Bitmap* ImageBitmap::bitmap() const
109
0
{
110
0
    return m_bitmap.ptr();
111
0
}
112
113
}