ladybird/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.h
Timothy Flynn 2692db8699 LibJS+Everywhere: Allow Cell::initialize overrides to throw OOM errors
Note that as of this commit, there aren't any such throwers, and the
call site in Heap::allocate will drop exceptions on the floor. This
commit only serves to change the declaration of the overrides, make sure
they return an empty value, and to propagate OOM errors frm their base
initialize invocations.
2023-01-29 00:02:45 +00:00

63 lines
1.8 KiB
C++

/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/ByteBuffer.h>
#include <LibGfx/Forward.h>
#include <LibWeb/HTML/HTMLElement.h>
#include <LibWeb/WebGL/WebGLRenderingContext.h>
namespace Web::HTML {
class HTMLCanvasElement final : public HTMLElement {
WEB_PLATFORM_OBJECT(HTMLCanvasElement, HTMLElement);
public:
using RenderingContext = Variant<JS::Handle<CanvasRenderingContext2D>, JS::Handle<WebGL::WebGLRenderingContext>, 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<RenderingContext> get_context(DeprecatedString const& type, JS::Value options);
unsigned width() const;
unsigned height() const;
void set_width(unsigned);
void set_height(unsigned);
DeprecatedString to_data_url(DeprecatedString const& type, Optional<double> quality) const;
void present();
private:
HTMLCanvasElement(DOM::Document&, DOM::QualifiedName);
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override;
enum class HasOrCreatedContext {
No,
Yes,
};
HasOrCreatedContext create_2d_context();
JS::ThrowCompletionOr<HasOrCreatedContext> create_webgl_context(JS::Value options);
void reset_context_to_default_state();
RefPtr<Gfx::Bitmap> m_bitmap;
Variant<JS::NonnullGCPtr<HTML::CanvasRenderingContext2D>, JS::NonnullGCPtr<WebGL::WebGLRenderingContext>, Empty> m_context;
};
}