Coverage Report

Created: 2026-02-14 08:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibWeb/HTML/CanvasPattern.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2023, MacDue <macdue@dueutil.tech>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <LibGfx/PaintStyle.h>
10
#include <LibWeb/Bindings/PlatformObject.h>
11
#include <LibWeb/HTML/Canvas/CanvasDrawImage.h>
12
13
namespace Web::HTML {
14
15
class CanvasPatternPaintStyle final : public Gfx::PaintStyle {
16
public:
17
    enum class Repetition {
18
        Repeat,
19
        RepeatX,
20
        RepeatY,
21
        NoRepeat
22
    };
23
24
    static ErrorOr<NonnullRefPtr<CanvasPatternPaintStyle>> create(Gfx::Bitmap const& bitmap, Repetition repetition)
25
0
    {
26
0
        return adopt_nonnull_ref_or_enomem(new (nothrow) CanvasPatternPaintStyle(bitmap, repetition));
27
0
    }
28
29
    virtual void paint(Gfx::IntRect physical_bounding_box, PaintFunction paint) const override;
30
31
private:
32
    CanvasPatternPaintStyle(Gfx::Bitmap const& bitmap, Repetition repetition)
33
0
        : m_bitmap(bitmap)
34
0
        , m_repetition(repetition)
35
0
    {
36
0
    }
37
38
    NonnullRefPtr<Gfx::Bitmap const> m_bitmap;
39
    Repetition m_repetition { Repetition::Repeat };
40
};
41
42
class CanvasPattern final : public Bindings::PlatformObject {
43
    WEB_PLATFORM_OBJECT(CanvasPattern, Bindings::PlatformObject);
44
    JS_DECLARE_ALLOCATOR(CanvasPattern);
45
46
public:
47
    static WebIDL::ExceptionOr<JS::GCPtr<CanvasPattern>> create(JS::Realm&, CanvasImageSource const& image, StringView repetition);
48
49
    ~CanvasPattern();
50
51
0
    NonnullRefPtr<Gfx::PaintStyle> to_gfx_paint_style() { return m_pattern; }
52
53
private:
54
    CanvasPattern(JS::Realm&, CanvasPatternPaintStyle&);
55
56
    virtual void initialize(JS::Realm&) override;
57
58
    NonnullRefPtr<CanvasPatternPaintStyle> m_pattern;
59
};
60
61
}