ImageBitmap.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (c) 2024, Lucas Chollet <lucas.chollet@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/OwnPtr.h>
  8. #include <LibGfx/Bitmap.h>
  9. #include <LibWeb/Bindings/PlatformObject.h>
  10. #include <LibWeb/Bindings/Serializable.h>
  11. #include <LibWeb/Bindings/Transferable.h>
  12. #include <LibWeb/Forward.h>
  13. #include <LibWeb/HTML/Canvas/CanvasDrawImage.h>
  14. namespace Web::HTML {
  15. using ImageBitmapSource = Variant<CanvasImageSource, JS::Handle<FileAPI::Blob>, JS::Handle<ImageData>>;
  16. // https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#imagebitmapoptions
  17. struct ImageBitmapOptions {
  18. // FIXME: Implement these fields
  19. };
  20. class ImageBitmap final : public Bindings::PlatformObject
  21. , public Web::Bindings::Serializable
  22. , public Web::Bindings::Transferable {
  23. WEB_PLATFORM_OBJECT(ImageBitmap, Bindings::PlatformObject);
  24. JS_DECLARE_ALLOCATOR(ImageBitmap);
  25. public:
  26. static JS::NonnullGCPtr<ImageBitmap> create(JS::Realm&);
  27. virtual ~ImageBitmap() override = default;
  28. // ^Web::Bindings::Serializable
  29. virtual StringView interface_name() const override { return "ImageBitmap"sv; }
  30. virtual WebIDL::ExceptionOr<void> serialization_steps(HTML::SerializationRecord&, bool for_storage, HTML::SerializationMemory&) override;
  31. virtual WebIDL::ExceptionOr<void> deserialization_steps(ReadonlySpan<u32> const&, size_t& position, HTML::DeserializationMemory&) override;
  32. // ^Web::Bindings::Transferable
  33. virtual WebIDL::ExceptionOr<void> transfer_steps(HTML::TransferDataHolder&) override;
  34. virtual WebIDL::ExceptionOr<void> transfer_receiving_steps(HTML::TransferDataHolder&) override;
  35. virtual HTML::TransferType primary_interface() const override;
  36. WebIDL::UnsignedLong width() const;
  37. WebIDL::UnsignedLong height() const;
  38. void close();
  39. // Implementation specific:
  40. void set_bitmap(RefPtr<Gfx::Bitmap>);
  41. private:
  42. explicit ImageBitmap(JS::Realm&);
  43. // FIXME: We don't implement this flag yet:
  44. // An ImageBitmap object's bitmap has an origin-clean flag, which indicates whether the bitmap is tainted by content
  45. // from a different origin. The flag is initially set to true and may be changed to false by the steps of
  46. // createImageBitmap().
  47. virtual void initialize(JS::Realm&) override;
  48. virtual void visit_edges(Cell::Visitor&) override;
  49. WebIDL::UnsignedLong m_width = 0;
  50. WebIDL::UnsignedLong m_height = 0;
  51. RefPtr<Gfx::Bitmap> m_bitmap { nullptr };
  52. };
  53. }