SVGSVGPaintable.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Layout/ImageBox.h>
  7. #include <LibWeb/Painting/SVGSVGPaintable.h>
  8. namespace Web::Painting {
  9. JS::NonnullGCPtr<SVGSVGPaintable> SVGSVGPaintable::create(Layout::SVGSVGBox const& layout_box)
  10. {
  11. return layout_box.heap().allocate_without_realm<SVGSVGPaintable>(layout_box);
  12. }
  13. SVGSVGPaintable::SVGSVGPaintable(Layout::SVGSVGBox const& layout_box)
  14. : PaintableBox(layout_box)
  15. {
  16. }
  17. Layout::SVGSVGBox const& SVGSVGPaintable::layout_box() const
  18. {
  19. return static_cast<Layout::SVGSVGBox const&>(layout_node());
  20. }
  21. void SVGSVGPaintable::before_children_paint(PaintContext& context, PaintPhase phase) const
  22. {
  23. PaintableBox::before_children_paint(context, phase);
  24. if (phase != PaintPhase::Foreground)
  25. return;
  26. context.recording_painter().save();
  27. auto clip_rect = absolute_rect();
  28. clip_rect.translate_by(enclosing_scroll_frame_offset().value_or({}));
  29. context.recording_painter().add_clip_rect(context.enclosing_device_rect(clip_rect).to_type<int>());
  30. }
  31. void SVGSVGPaintable::after_children_paint(PaintContext& context, PaintPhase phase) const
  32. {
  33. PaintableBox::after_children_paint(context, phase);
  34. if (phase != PaintPhase::Foreground)
  35. return;
  36. context.recording_painter().restore();
  37. }
  38. }