mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-11 17:37:33 +02:00
Previously we were inconsistent by generating code for enum definitions but not generating code for dictionaries. With future changes to the IDL generator to expose helpers to convert to and from IDL values this produced circular depdendencies. To solve this problem, also generate the dictionary definitions in bindings headers.
63 lines
2.8 KiB
C++
63 lines
2.8 KiB
C++
/*
|
|
* Copyright (c) 2020-2022, Andreas Kling <andreas@ladybird.org>
|
|
* Copyright (c) 2024-2025, Kenneth Myhra <kennethmyhra@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibGfx/Forward.h>
|
|
#include <LibWeb/Bindings/ImageData.h>
|
|
#include <LibWeb/Bindings/PlatformObject.h>
|
|
#include <LibWeb/Bindings/Serializable.h>
|
|
#include <LibWeb/WebIDL/Types.h>
|
|
|
|
namespace Web::HTML {
|
|
|
|
class ImageData final
|
|
: public Bindings::PlatformObject
|
|
, public Bindings::Serializable {
|
|
WEB_PLATFORM_OBJECT(ImageData, Bindings::PlatformObject);
|
|
GC_DECLARE_ALLOCATOR(ImageData);
|
|
|
|
public:
|
|
[[nodiscard]] static GC::Ref<ImageData> create(JS::Realm&);
|
|
[[nodiscard]] static WebIDL::ExceptionOr<GC::Ref<ImageData>> create(JS::Realm&, u32 sw, u32 sh, Optional<Bindings::ImageDataSettings> const& settings = {});
|
|
[[nodiscard]] static WebIDL::ExceptionOr<GC::Ref<ImageData>> create(JS::Realm&, GC::Root<JS::Uint8ClampedArray> const& data, u32 sw, Optional<u32> sh = {}, Optional<Bindings::ImageDataSettings> const& settings = {});
|
|
|
|
[[nodiscard]] static WebIDL::ExceptionOr<GC::Ref<ImageData>> construct_impl(JS::Realm&, u32 sw, u32 sh, Optional<Bindings::ImageDataSettings> const& settings = {});
|
|
[[nodiscard]] static WebIDL::ExceptionOr<GC::Ref<ImageData>> construct_impl(JS::Realm&, GC::Root<JS::Uint8ClampedArray> const& data, u32 sw, Optional<u32> sh = {}, Optional<Bindings::ImageDataSettings> const& settings = {});
|
|
|
|
virtual ~ImageData() override;
|
|
|
|
WebIDL::UnsignedLong width() const;
|
|
WebIDL::UnsignedLong height() const;
|
|
|
|
Gfx::Bitmap& bitmap() { return *m_bitmap; }
|
|
Gfx::Bitmap const& bitmap() const { return *m_bitmap; }
|
|
|
|
JS::Uint8ClampedArray* data();
|
|
JS::Uint8ClampedArray const* data() const;
|
|
|
|
Bindings::PredefinedColorSpace color_space() const { return m_color_space; }
|
|
|
|
virtual WebIDL::ExceptionOr<void> serialization_steps(HTML::TransferDataEncoder&, bool for_storage, HTML::SerializationMemory&) override;
|
|
virtual WebIDL::ExceptionOr<void> deserialization_steps(HTML::TransferDataDecoder&, HTML::DeserializationMemory&) override;
|
|
|
|
private:
|
|
[[nodiscard]] static WebIDL::ExceptionOr<GC::Ref<ImageData>> initialize(JS::Realm&, u32 rows, u32 pixels_per_row, Optional<Bindings::ImageDataSettings> const&, GC::Ptr<JS::Uint8ClampedArray> = {}, Optional<Bindings::PredefinedColorSpace> = {});
|
|
|
|
explicit ImageData(JS::Realm&);
|
|
ImageData(JS::Realm&, NonnullRefPtr<Gfx::Bitmap>, GC::Ref<JS::Uint8ClampedArray>, Bindings::PredefinedColorSpace);
|
|
|
|
virtual void initialize(JS::Realm&) override;
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
RefPtr<Gfx::Bitmap> m_bitmap;
|
|
Bindings::PredefinedColorSpace m_color_space { Bindings::PredefinedColorSpace::Srgb };
|
|
GC::Ptr<JS::Uint8ClampedArray> m_data;
|
|
};
|
|
|
|
}
|