CanvasBox.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibGfx/Painter.h>
  7. #include <LibWeb/Layout/CanvasBox.h>
  8. namespace Web::Layout {
  9. CanvasBox::CanvasBox(DOM::Document& document, HTML::HTMLCanvasElement& element, NonnullRefPtr<CSS::StyleProperties> style)
  10. : ReplacedBox(document, element, move(style))
  11. {
  12. }
  13. CanvasBox::~CanvasBox()
  14. {
  15. }
  16. void CanvasBox::prepare_for_replaced_layout()
  17. {
  18. set_has_intrinsic_width(true);
  19. set_has_intrinsic_height(true);
  20. set_intrinsic_width(dom_node().width());
  21. set_intrinsic_height(dom_node().height());
  22. }
  23. void CanvasBox::paint(PaintContext& context, PaintPhase phase)
  24. {
  25. if (!is_visible())
  26. return;
  27. ReplacedBox::paint(context, phase);
  28. if (phase == PaintPhase::Foreground) {
  29. // FIXME: This should be done at a different level. Also rect() does not include padding etc!
  30. if (!context.viewport_rect().intersects(enclosing_int_rect(absolute_rect())))
  31. return;
  32. if (dom_node().bitmap())
  33. context.painter().draw_scaled_bitmap(enclosing_int_rect(absolute_rect()), *dom_node().bitmap(), dom_node().bitmap()->rect());
  34. }
  35. }
  36. }