VideoBox.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/HTML/HTMLVideoElement.h>
  7. #include <LibWeb/Layout/VideoBox.h>
  8. #include <LibWeb/Painting/VideoPaintable.h>
  9. namespace Web::Layout {
  10. VideoBox::VideoBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style)
  11. : ReplacedBox(document, element, move(style))
  12. {
  13. document.register_viewport_client(*this);
  14. }
  15. void VideoBox::finalize()
  16. {
  17. Base::finalize();
  18. // NOTE: We unregister from the document in finalize() to avoid trouble
  19. // in the scenario where our Document has already been swept by GC.
  20. document().unregister_viewport_client(*this);
  21. }
  22. HTML::HTMLVideoElement& VideoBox::dom_node()
  23. {
  24. return static_cast<HTML::HTMLVideoElement&>(ReplacedBox::dom_node());
  25. }
  26. HTML::HTMLVideoElement const& VideoBox::dom_node() const
  27. {
  28. return static_cast<HTML::HTMLVideoElement const&>(ReplacedBox::dom_node());
  29. }
  30. void VideoBox::prepare_for_replaced_layout()
  31. {
  32. CSSPixels width = dom_node().video_width();
  33. set_natural_width(width);
  34. CSSPixels height = dom_node().video_height();
  35. set_natural_height(height);
  36. if (width != 0 && height != 0)
  37. set_natural_aspect_ratio(width / height);
  38. else
  39. set_natural_aspect_ratio({});
  40. }
  41. void VideoBox::did_set_viewport_rect(CSSPixelRect const&)
  42. {
  43. // FIXME: Several steps in HTMLMediaElement indicate we may optionally handle whether the media object
  44. // is in view. Implement those steps.
  45. }
  46. JS::GCPtr<Painting::Paintable> VideoBox::create_paintable() const
  47. {
  48. return Painting::VideoPaintable::create(*this);
  49. }
  50. }