2020-03-19 21:07:56 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-03-19 21:07:56 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/ByteBuffer.h>
|
|
|
|
#include <LibGfx/Forward.h>
|
2020-07-26 16:08:16 +03:00
|
|
|
#include <LibWeb/HTML/HTMLElement.h>
|
2022-06-04 06:22:42 +03:00
|
|
|
#include <LibWeb/WebGL/WebGLRenderingContext.h>
|
2020-03-19 21:07:56 +03:00
|
|
|
|
2020-07-28 19:20:36 +03:00
|
|
|
namespace Web::HTML {
|
2020-03-19 21:07:56 +03:00
|
|
|
|
2020-07-28 04:54:19 +03:00
|
|
|
class HTMLCanvasElement final : public HTMLElement {
|
2022-08-28 14:42:07 +03:00
|
|
|
WEB_PLATFORM_OBJECT(HTMLCanvasElement, HTMLElement);
|
|
|
|
|
2020-03-19 21:07:56 +03:00
|
|
|
public:
|
2022-09-02 16:53:02 +03:00
|
|
|
using RenderingContext = Variant<JS::Handle<CanvasRenderingContext2D>, JS::Handle<WebGL::WebGLRenderingContext>, Empty>;
|
2020-03-19 21:07:56 +03:00
|
|
|
|
|
|
|
virtual ~HTMLCanvasElement() override;
|
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
Gfx::Bitmap const* bitmap() const { return m_bitmap; }
|
2020-04-15 13:12:19 +03:00
|
|
|
Gfx::Bitmap* bitmap() { return m_bitmap; }
|
2022-06-04 06:22:42 +03:00
|
|
|
bool create_bitmap(size_t minimum_width = 0, size_t minimum_height = 0);
|
2020-03-19 21:07:56 +03:00
|
|
|
|
2022-06-04 06:22:42 +03:00
|
|
|
JS::ThrowCompletionOr<RenderingContext> get_context(String const& type, JS::Value options);
|
2020-03-19 21:07:56 +03:00
|
|
|
|
2020-06-21 16:37:13 +03:00
|
|
|
unsigned width() const;
|
|
|
|
unsigned height() const;
|
2020-04-15 13:12:19 +03:00
|
|
|
|
2021-11-13 02:54:21 +03:00
|
|
|
void set_width(unsigned);
|
|
|
|
void set_height(unsigned);
|
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
String to_data_url(String const& type, Optional<double> quality) const;
|
2021-04-20 00:47:29 +03:00
|
|
|
|
2022-06-04 06:22:42 +03:00
|
|
|
void present();
|
|
|
|
|
2020-03-19 21:07:56 +03:00
|
|
|
private:
|
2022-08-28 14:42:07 +03:00
|
|
|
HTMLCanvasElement(DOM::Document&, DOM::QualifiedName);
|
|
|
|
|
2022-09-02 16:53:02 +03:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
2022-02-05 15:17:01 +03:00
|
|
|
virtual RefPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override;
|
2020-03-19 21:07:56 +03:00
|
|
|
|
2022-06-04 06:22:42 +03:00
|
|
|
enum class HasOrCreatedContext {
|
|
|
|
No,
|
|
|
|
Yes,
|
|
|
|
};
|
|
|
|
|
|
|
|
HasOrCreatedContext create_2d_context();
|
|
|
|
JS::ThrowCompletionOr<HasOrCreatedContext> create_webgl_context(JS::Value options);
|
|
|
|
void reset_context_to_default_state();
|
|
|
|
|
2020-03-19 21:07:56 +03:00
|
|
|
RefPtr<Gfx::Bitmap> m_bitmap;
|
2022-09-02 16:53:02 +03:00
|
|
|
|
|
|
|
Variant<JS::NonnullGCPtr<HTML::CanvasRenderingContext2D>, JS::NonnullGCPtr<WebGL::WebGLRenderingContext>, Empty> m_context;
|
2020-03-19 21:07:56 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|