2020-03-19 19:07:56 +01:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2020, Andreas Kling <andreas@ladybird.org>
|
2020-03-19 19:07:56 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-03-19 19:07:56 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/ByteBuffer.h>
|
|
|
|
|
#include <LibGfx/Forward.h>
|
2024-09-25 15:44:58 +02:00
|
|
|
#include <LibGfx/PaintingSurface.h>
|
2020-07-26 15:08:16 +02:00
|
|
|
#include <LibWeb/HTML/HTMLElement.h>
|
2022-06-04 04:22:42 +01:00
|
|
|
#include <LibWeb/WebGL/WebGLRenderingContext.h>
|
2020-03-19 19:07:56 +01:00
|
|
|
|
2020-07-28 18:20:36 +02:00
|
|
|
namespace Web::HTML {
|
2020-03-19 19:07:56 +01:00
|
|
|
|
2020-07-28 02:54:19 +01:00
|
|
|
class HTMLCanvasElement final : public HTMLElement {
|
2022-08-28 13:42:07 +02:00
|
|
|
WEB_PLATFORM_OBJECT(HTMLCanvasElement, HTMLElement);
|
2023-11-19 19:47:52 +01:00
|
|
|
JS_DECLARE_ALLOCATOR(HTMLCanvasElement);
|
2022-08-28 13:42:07 +02:00
|
|
|
|
2020-03-19 19:07:56 +01:00
|
|
|
public:
|
2022-09-02 15:53:02 +02:00
|
|
|
using RenderingContext = Variant<JS::Handle<CanvasRenderingContext2D>, JS::Handle<WebGL::WebGLRenderingContext>, Empty>;
|
2020-03-19 19:07:56 +01:00
|
|
|
|
|
|
|
|
virtual ~HTMLCanvasElement() override;
|
|
|
|
|
|
2024-09-25 15:44:58 +02:00
|
|
|
bool allocate_painting_surface(size_t minimum_width = 0, size_t minimum_height = 0);
|
|
|
|
|
RefPtr<Gfx::PaintingSurface> surface() { return m_surface; }
|
|
|
|
|
RefPtr<Gfx::PaintingSurface const> surface() const { return m_surface; }
|
2020-03-19 19:07:56 +01:00
|
|
|
|
2023-09-03 15:58:55 +12:00
|
|
|
JS::ThrowCompletionOr<RenderingContext> get_context(String const& type, JS::Value options);
|
2020-03-19 19:07:56 +01:00
|
|
|
|
2020-06-21 15:37:13 +02:00
|
|
|
unsigned width() const;
|
|
|
|
|
unsigned height() const;
|
2020-04-15 12:12:19 +02:00
|
|
|
|
2023-05-25 20:37:57 +01:00
|
|
|
WebIDL::ExceptionOr<void> set_width(unsigned);
|
|
|
|
|
WebIDL::ExceptionOr<void> set_height(unsigned);
|
2021-11-13 00:54:21 +01:00
|
|
|
|
2023-09-16 22:00:37 +02:00
|
|
|
String to_data_url(StringView type, Optional<double> quality);
|
2023-09-03 15:58:55 +12:00
|
|
|
WebIDL::ExceptionOr<void> to_blob(JS::NonnullGCPtr<WebIDL::CallbackType> callback, StringView type, Optional<double> quality);
|
2021-04-19 23:47:29 +02:00
|
|
|
|
2022-06-04 04:22:42 +01:00
|
|
|
void present();
|
|
|
|
|
|
2020-03-19 19:07:56 +01:00
|
|
|
private:
|
2022-08-28 13:42:07 +02:00
|
|
|
HTMLCanvasElement(DOM::Document&, DOM::QualifiedName);
|
|
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2022-09-02 15:53:02 +02:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
|
2023-08-31 19:22:17 +02:00
|
|
|
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
|
|
|
|
|
|
2024-10-26 17:42:27 +02:00
|
|
|
virtual JS::GCPtr<Layout::Node> create_layout_node(CSS::StyleProperties) override;
|
2024-11-08 20:14:37 +08:00
|
|
|
virtual void adjust_computed_style(CSS::StyleProperties&) override;
|
2020-03-19 19:07:56 +01:00
|
|
|
|
2022-06-04 04:22:42 +01: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();
|
|
|
|
|
|
2024-09-25 15:44:58 +02:00
|
|
|
RefPtr<Gfx::PaintingSurface> m_surface;
|
2022-09-02 15:53:02 +02:00
|
|
|
|
|
|
|
|
Variant<JS::NonnullGCPtr<HTML::CanvasRenderingContext2D>, JS::NonnullGCPtr<WebGL::WebGLRenderingContext>, Empty> m_context;
|
2020-03-19 19:07:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|