ImageBitmap.cpp 2.9 KB

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