ImageBitmap.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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, GC::Root<FileAPI::Blob>, GC::Root<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. GC_DECLARE_ALLOCATOR(ImageBitmap);
  25. public:
  26. static GC::Ref<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. Gfx::Bitmap* bitmap() const;
  42. private:
  43. explicit ImageBitmap(JS::Realm&);
  44. // FIXME: We don't implement this flag yet:
  45. // An ImageBitmap object's bitmap has an origin-clean flag, which indicates whether the bitmap is tainted by content
  46. // from a different origin. The flag is initially set to true and may be changed to false by the steps of
  47. // createImageBitmap().
  48. virtual void initialize(JS::Realm&) override;
  49. virtual void visit_edges(Cell::Visitor&) override;
  50. WebIDL::UnsignedLong m_width = 0;
  51. WebIDL::UnsignedLong m_height = 0;
  52. RefPtr<Gfx::Bitmap> m_bitmap { nullptr };
  53. };
  54. }