ImageBitmap.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (c) 2024, Lucas Chollet <lucas.chollet@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibGfx/Bitmap.h>
  7. #include <LibWeb/Bindings/ImageBitmapPrototype.h>
  8. #include <LibWeb/HTML/ImageBitmap.h>
  9. namespace Web::HTML {
  10. GC_DEFINE_ALLOCATOR(ImageBitmap);
  11. GC::Ref<ImageBitmap> ImageBitmap::create(JS::Realm& realm)
  12. {
  13. return realm.create<ImageBitmap>(realm);
  14. }
  15. ImageBitmap::ImageBitmap(JS::Realm& realm)
  16. : Bindings::PlatformObject(realm)
  17. {
  18. }
  19. void ImageBitmap::initialize(JS::Realm& realm)
  20. {
  21. Base::initialize(realm);
  22. WEB_SET_PROTOTYPE_FOR_INTERFACE(ImageBitmap);
  23. }
  24. void ImageBitmap::visit_edges(Cell::Visitor& visitor)
  25. {
  26. Base::visit_edges(visitor);
  27. }
  28. WebIDL::ExceptionOr<void> ImageBitmap::serialization_steps(HTML::SerializationRecord&, bool, HTML::SerializationMemory&)
  29. {
  30. // FIXME: Implement this
  31. dbgln("(STUBBED) ImageBitmap::serialization_steps(HTML::SerializationRecord&, bool, HTML::SerializationMemory&)");
  32. return {};
  33. }
  34. WebIDL::ExceptionOr<void> ImageBitmap::deserialization_steps(ReadonlySpan<u32> const&, size_t&, HTML::DeserializationMemory&)
  35. {
  36. // FIXME: Implement this
  37. dbgln("(STUBBED) ImageBitmap::deserialization_steps(ReadonlySpan<u32> const&, size_t&, HTML::DeserializationMemory&)");
  38. return {};
  39. }
  40. WebIDL::ExceptionOr<void> ImageBitmap::transfer_steps(HTML::TransferDataHolder&)
  41. {
  42. // FIXME: Implement this
  43. dbgln("(STUBBED) ImageBitmap::transfer_steps(HTML::TransferDataHolder&)");
  44. return {};
  45. }
  46. WebIDL::ExceptionOr<void> ImageBitmap::transfer_receiving_steps(HTML::TransferDataHolder&)
  47. {
  48. // FIXME: Implement this
  49. dbgln("(STUBBED) ImageBitmap::transfer_receiving_steps(HTML::TransferDataHolder&)");
  50. return {};
  51. }
  52. HTML::TransferType ImageBitmap::primary_interface() const
  53. {
  54. // FIXME: Implement this
  55. dbgln("(STUBBED) ImageBitmap::primary_interface()");
  56. return {};
  57. }
  58. // https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#dom-imagebitmap-width
  59. WebIDL::UnsignedLong ImageBitmap::width() const
  60. {
  61. // 1. If this's [[Detached]] internal slot's value is true, then return 0.
  62. if (is_detached())
  63. return 0;
  64. // 2. Return this's width, in CSS pixels.
  65. return m_width;
  66. }
  67. // https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#dom-imagebitmap-height
  68. WebIDL::UnsignedLong ImageBitmap::height() const
  69. {
  70. // 1. If this's [[Detached]] internal slot's value is true, then return 0.
  71. if (is_detached())
  72. return 0;
  73. // 2. Return this's height, in CSS pixels.
  74. return m_height;
  75. }
  76. // https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#dom-imagebitmap-close
  77. void ImageBitmap::close()
  78. {
  79. // 1. Set this's [[Detached]] internal slot value to true.
  80. set_detached(true);
  81. // 2. Unset this's bitmap data.
  82. m_bitmap = nullptr;
  83. }
  84. void ImageBitmap::set_bitmap(RefPtr<Gfx::Bitmap> bitmap)
  85. {
  86. m_bitmap = move(bitmap);
  87. m_width = m_bitmap->width();
  88. m_height = m_bitmap->height();
  89. }
  90. Gfx::Bitmap* ImageBitmap::bitmap() const
  91. {
  92. return m_bitmap.ptr();
  93. }
  94. }