CanvasBox.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2020-2022, 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. #include <LibWeb/Painting/Paintable.h>
  9. namespace Web::Layout {
  10. CanvasBox::CanvasBox(DOM::Document& document, HTML::HTMLCanvasElement& element, NonnullRefPtr<CSS::StyleProperties> style)
  11. : ReplacedBox(document, element, move(style))
  12. {
  13. }
  14. CanvasBox::~CanvasBox()
  15. {
  16. }
  17. void CanvasBox::prepare_for_replaced_layout()
  18. {
  19. set_intrinsic_width(dom_node().width());
  20. set_intrinsic_height(dom_node().height());
  21. }
  22. void CanvasBox::paint(PaintContext& context, Painting::PaintPhase phase)
  23. {
  24. if (!is_visible())
  25. return;
  26. ReplacedBox::paint(context, phase);
  27. if (phase == Painting::PaintPhase::Foreground) {
  28. // FIXME: This should be done at a different level. Also rect() does not include padding etc!
  29. if (!context.viewport_rect().intersects(enclosing_int_rect(m_paint_box->absolute_rect())))
  30. return;
  31. if (dom_node().bitmap())
  32. context.painter().draw_scaled_bitmap(rounded_int_rect(m_paint_box->absolute_rect()), *dom_node().bitmap(), dom_node().bitmap()->rect(), 1.0f, to_gfx_scaling_mode(computed_values().image_rendering()));
  33. }
  34. }
  35. }