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 <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>
|
2024-11-29 16:04:35 +00:00
|
|
|
#include <LibWeb/WebIDL/Types.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);
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DECLARE_ALLOCATOR(HTMLCanvasElement);
|
2022-08-28 13:42:07 +02:00
|
|
|
|
2020-03-19 19:07:56 +01:00
|
|
|
public:
|
2024-12-05 20:56:18 -07:00
|
|
|
using RenderingContext = Variant<GC::Root<CanvasRenderingContext2D>, GC::Root<WebGL::WebGLRenderingContext>, GC::Root<WebGL::WebGL2RenderingContext>, Empty>;
|
2020-03-19 19:07:56 +01:00
|
|
|
|
|
|
|
virtual ~HTMLCanvasElement() override;
|
|
|
|
|
2024-11-29 20:17:25 +01:00
|
|
|
Gfx::IntSize bitmap_size_for_canvas(size_t minimum_width = 0, size_t minimum_height = 0) const;
|
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);
|
2024-11-29 20:17:25 +01:00
|
|
|
enum class HasOrCreatedContext {
|
|
|
|
No,
|
|
|
|
Yes,
|
|
|
|
};
|
2025-04-28 16:01:47 +02:00
|
|
|
JS::ThrowCompletionOr<HasOrCreatedContext> create_2d_context(JS::Value options);
|
2020-03-19 19:07:56 +01:00
|
|
|
|
2024-11-29 16:04:35 +00:00
|
|
|
WebIDL::UnsignedLong width() const;
|
|
|
|
WebIDL::UnsignedLong height() const;
|
2020-04-15 12:12:19 +02:00
|
|
|
|
2024-11-29 16:04:35 +00:00
|
|
|
WebIDL::ExceptionOr<void> set_width(WebIDL::UnsignedLong);
|
|
|
|
WebIDL::ExceptionOr<void> set_height(WebIDL::UnsignedLong);
|
2021-11-13 00:54:21 +01:00
|
|
|
|
2024-12-28 15:47:58 +11:00
|
|
|
virtual void attribute_changed(FlyString const& local_name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_) override;
|
|
|
|
|
2024-11-08 09:13:54 +01:00
|
|
|
String to_data_url(StringView type, JS::Value quality);
|
2024-11-15 04:01:23 +13:00
|
|
|
WebIDL::ExceptionOr<void> to_blob(GC::Ref<WebIDL::CallbackType> callback, StringView type, JS::Value quality);
|
2025-07-14 21:24:22 +02:00
|
|
|
RefPtr<Gfx::Bitmap> get_bitmap_from_surface();
|
2021-04-19 23:47:29 +02:00
|
|
|
|
2022-06-04 04:22:42 +01:00
|
|
|
void present();
|
|
|
|
|
2024-11-29 20:17:25 +01:00
|
|
|
RefPtr<Gfx::PaintingSurface> surface() const;
|
|
|
|
void allocate_painting_surface_if_needed();
|
|
|
|
|
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;
|
|
|
|
|
2024-12-23 17:51:10 +01:00
|
|
|
virtual bool is_presentational_hint(FlyString const&) const override;
|
LibWeb: Split StyleComputer work into two phases with separate outputs
Before this change, StyleComputer would essentially take a DOM element,
find all the CSS rules that apply to it, and resolve the computed value
for each CSS property for that element.
This worked great, but it meant we had to do all the work of selector
matching and cascading every time.
To enable new optimizations, this change introduces a break in the
middle of this process where we've produced a "CascadedProperties".
This object contains the result of the cascade, before we've begun
turning cascaded values into computed values.
The cascaded properties are now stored with each element, which will
later allow us to do partial updates without re-running the full
StyleComputer machine. This will be particularly valuable for
re-implementing CSS inheritance, which is extremely heavy today.
Note that CSS animations and CSS transitions operate entirely on the
computed values, even though the cascade order would have you believe
they happen earlier. I'm not confident we have the right architecture
for this, but that's a separate issue.
2024-12-12 10:06:29 +01:00
|
|
|
virtual void apply_presentational_hints(GC::Ref<CSS::CascadedProperties>) const override;
|
2023-08-31 19:22:17 +02:00
|
|
|
|
2024-12-20 16:35:12 +01:00
|
|
|
virtual GC::Ptr<Layout::Node> create_layout_node(GC::Ref<CSS::ComputedProperties>) override;
|
2024-12-20 11:32:17 +01:00
|
|
|
virtual void adjust_computed_style(CSS::ComputedProperties&) override;
|
2020-03-19 19:07:56 +01:00
|
|
|
|
2024-12-05 20:56:18 -07:00
|
|
|
template<typename ContextType>
|
2022-06-04 04:22:42 +01:00
|
|
|
JS::ThrowCompletionOr<HasOrCreatedContext> create_webgl_context(JS::Value options);
|
|
|
|
void reset_context_to_default_state();
|
2024-11-29 20:17:25 +01:00
|
|
|
void notify_context_about_canvas_size_change();
|
2022-09-02 15:53:02 +02:00
|
|
|
|
2024-12-05 20:56:18 -07:00
|
|
|
Variant<GC::Ref<HTML::CanvasRenderingContext2D>, GC::Ref<WebGL::WebGLRenderingContext>, GC::Ref<WebGL::WebGL2RenderingContext>, Empty> m_context;
|
2020-03-19 19:07:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|