/* * Copyright (c) 2020, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include namespace Web::HTML { class HTMLCanvasElement final : public HTMLElement { WEB_PLATFORM_OBJECT(HTMLCanvasElement, HTMLElement); public: using RenderingContext = Variant, JS::Handle, Empty>; virtual ~HTMLCanvasElement() override; Gfx::Bitmap const* bitmap() const { return m_bitmap; } Gfx::Bitmap* bitmap() { return m_bitmap; } bool create_bitmap(size_t minimum_width = 0, size_t minimum_height = 0); JS::ThrowCompletionOr get_context(String const& type, JS::Value options); unsigned width() const; unsigned height() const; void set_width(unsigned); void set_height(unsigned); String to_data_url(String const& type, Optional quality) const; void present(); private: HTMLCanvasElement(DOM::Document&, DOM::QualifiedName); virtual void visit_edges(Cell::Visitor&) override; virtual JS::GCPtr create_layout_node(NonnullRefPtr) override; enum class HasOrCreatedContext { No, Yes, }; HasOrCreatedContext create_2d_context(); JS::ThrowCompletionOr create_webgl_context(JS::Value options); void reset_context_to_default_state(); RefPtr m_bitmap; Variant, JS::NonnullGCPtr, Empty> m_context; }; }