CanvasBox.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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_intrinsic_width(dom_node().width());
  19. set_intrinsic_height(dom_node().height());
  20. }
  21. void CanvasBox::paint(PaintContext& context, PaintPhase phase)
  22. {
  23. if (!is_visible())
  24. return;
  25. ReplacedBox::paint(context, phase);
  26. if (phase == PaintPhase::Foreground) {
  27. // FIXME: This should be done at a different level. Also rect() does not include padding etc!
  28. if (!context.viewport_rect().intersects(enclosing_int_rect(absolute_rect())))
  29. return;
  30. if (dom_node().bitmap())
  31. context.painter().draw_scaled_bitmap(rounded_int_rect(absolute_rect()), *dom_node().bitmap(), dom_node().bitmap()->rect(), 1.0f, to_gfx_scaling_mode(computed_values().image_rendering()));
  32. }
  33. }
  34. }