Coverage Report

Created: 2026-09-26 06:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibWeb/SVG/SVGImageElement.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2024, Tim Ledbetter <tim.ledbetter@ladybird.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <LibGfx/ImmutableBitmap.h>
10
#include <LibJS/Heap/GCPtr.h>
11
#include <LibWeb/Layout/ImageProvider.h>
12
#include <LibWeb/SVG/SVGAnimatedLength.h>
13
#include <LibWeb/SVG/SVGGraphicsElement.h>
14
15
namespace Web::SVG {
16
17
class SVGImageElement
18
    : public SVGGraphicsElement
19
    , public SVGURIReferenceMixin<SupportsXLinkHref::Yes>
20
    , public Layout::ImageProvider {
21
    WEB_PLATFORM_OBJECT(SVGImageElement, SVGGraphicsElement);
22
23
public:
24
    virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) override;
25
26
    JS::NonnullGCPtr<SVG::SVGAnimatedLength> x();
27
    JS::NonnullGCPtr<SVG::SVGAnimatedLength> y();
28
    JS::NonnullGCPtr<SVG::SVGAnimatedLength> width();
29
    JS::NonnullGCPtr<SVG::SVGAnimatedLength> height();
30
31
    Gfx::Rect<CSSPixels> bounding_box() const;
32
33
    // FIXME: This is a hack for images used as CanvasImageSource. Do something more elegant.
34
    RefPtr<Gfx::Bitmap> bitmap() const
35
0
    {
36
0
        auto bitmap = current_image_bitmap();
37
0
        if (!bitmap)
38
0
            return nullptr;
39
0
        return bitmap->bitmap();
40
0
    }
41
42
    // ^Layout::ImageProvider
43
    virtual bool is_image_available() const override;
44
    virtual Optional<CSSPixels> intrinsic_width() const override;
45
    virtual Optional<CSSPixels> intrinsic_height() const override;
46
    virtual Optional<CSSPixelFraction> intrinsic_aspect_ratio() const override;
47
    virtual RefPtr<Gfx::ImmutableBitmap> current_image_bitmap(Gfx::IntSize = {}) const override;
48
0
    virtual void set_visible_in_viewport(bool) override { }
49
0
    virtual JS::NonnullGCPtr<DOM::Element const> to_html_element() const override { return *this; }
50
51
protected:
52
    SVGImageElement(DOM::Document&, DOM::QualifiedName);
53
54
    virtual void initialize(JS::Realm&) override;
55
    virtual void visit_edges(Cell::Visitor&) override;
56
57
    void process_the_url(Optional<String> const& href);
58
    void fetch_the_document(URL::URL const& url);
59
60
private:
61
    virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override;
62
    void animate();
63
64
    JS::GCPtr<SVG::SVGAnimatedLength> m_x;
65
    JS::GCPtr<SVG::SVGAnimatedLength> m_y;
66
    JS::GCPtr<SVG::SVGAnimatedLength> m_width;
67
    JS::GCPtr<SVG::SVGAnimatedLength> m_height;
68
69
    RefPtr<Core::Timer> m_animation_timer;
70
    size_t m_current_frame_index { 0 };
71
    size_t m_loops_completed { 0 };
72
73
    URL::URL m_href;
74
75
    JS::GCPtr<HTML::SharedResourceRequest> m_resource_request;
76
    Optional<DOM::DocumentLoadEventDelayer> m_load_event_delayer;
77
};
78
79
}