mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 12:20:00 +01:00
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.
69 lines
2.2 KiB
C++
69 lines
2.2 KiB
C++
/*
|
|
* Copyright (c) 2020, Andreas Kling <andreas@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/ByteBuffer.h>
|
|
#include <LibGfx/Forward.h>
|
|
#include <LibGfx/PaintingSurface.h>
|
|
#include <LibWeb/HTML/HTMLElement.h>
|
|
#include <LibWeb/WebIDL/Types.h>
|
|
|
|
namespace Web::HTML {
|
|
|
|
class HTMLCanvasElement final : public HTMLElement {
|
|
WEB_PLATFORM_OBJECT(HTMLCanvasElement, HTMLElement);
|
|
GC_DECLARE_ALLOCATOR(HTMLCanvasElement);
|
|
|
|
public:
|
|
using RenderingContext = Variant<GC::Root<CanvasRenderingContext2D>, GC::Root<WebGL::WebGLRenderingContext>, GC::Root<WebGL::WebGL2RenderingContext>, Empty>;
|
|
|
|
virtual ~HTMLCanvasElement() override;
|
|
|
|
Gfx::IntSize bitmap_size_for_canvas(size_t minimum_width = 0, size_t minimum_height = 0) const;
|
|
|
|
JS::ThrowCompletionOr<RenderingContext> get_context(String const& type, JS::Value options);
|
|
enum class HasOrCreatedContext {
|
|
No,
|
|
Yes,
|
|
};
|
|
HasOrCreatedContext create_2d_context();
|
|
|
|
WebIDL::UnsignedLong width() const;
|
|
WebIDL::UnsignedLong height() const;
|
|
|
|
WebIDL::ExceptionOr<void> set_width(WebIDL::UnsignedLong);
|
|
WebIDL::ExceptionOr<void> set_height(WebIDL::UnsignedLong);
|
|
|
|
String to_data_url(StringView type, JS::Value quality);
|
|
WebIDL::ExceptionOr<void> to_blob(GC::Ref<WebIDL::CallbackType> callback, StringView type, JS::Value quality);
|
|
|
|
void present();
|
|
|
|
RefPtr<Gfx::PaintingSurface> surface() const;
|
|
void allocate_painting_surface_if_needed();
|
|
|
|
private:
|
|
HTMLCanvasElement(DOM::Document&, DOM::QualifiedName);
|
|
|
|
virtual void initialize(JS::Realm&) override;
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
virtual void apply_presentational_hints(GC::Ref<CSS::CascadedProperties>) const override;
|
|
|
|
virtual GC::Ptr<Layout::Node> create_layout_node(CSS::StyleProperties) override;
|
|
virtual void adjust_computed_style(CSS::StyleProperties&) override;
|
|
|
|
template<typename ContextType>
|
|
JS::ThrowCompletionOr<HasOrCreatedContext> create_webgl_context(JS::Value options);
|
|
void reset_context_to_default_state();
|
|
void notify_context_about_canvas_size_change();
|
|
|
|
Variant<GC::Ref<HTML::CanvasRenderingContext2D>, GC::Ref<WebGL::WebGLRenderingContext>, GC::Ref<WebGL::WebGL2RenderingContext>, Empty> m_context;
|
|
};
|
|
|
|
}
|