/* * Copyright (c) 2023, MacDue * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include namespace Web::HTML { class CanvasPatternPaintStyle final : public Gfx::PaintStyle { public: enum class Repetition { Repeat, RepeatX, RepeatY, NoRepeat }; static ErrorOr> create(Gfx::Bitmap const& bitmap, Repetition repetition) { return adopt_nonnull_ref_or_enomem(new (nothrow) CanvasPatternPaintStyle(bitmap, repetition)); } virtual void paint(Gfx::IntRect physical_bounding_box, PaintFunction paint) const override; private: CanvasPatternPaintStyle(Gfx::Bitmap const& bitmap, Repetition repetition) : m_bitmap(bitmap) , m_repetition(repetition) { } NonnullRefPtr m_bitmap; Repetition m_repetition { Repetition::Repeat }; }; class CanvasPattern final : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(CanvasPattern, Bindings::PlatformObject); public: static WebIDL::ExceptionOr> create(JS::Realm&, CanvasImageSource const& image, StringView repetition); ~CanvasPattern(); NonnullRefPtr to_gfx_paint_style() { return m_pattern; } private: CanvasPattern(JS::Realm&, CanvasPatternPaintStyle&); virtual JS::ThrowCompletionOr initialize(JS::Realm&) override; NonnullRefPtr m_pattern; }; }