SVGSVGPaintable.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. if (!context.has_svg_context())
  27. context.set_svg_context(SVGContext(absolute_rect()));
  28. context.painter().save();
  29. context.painter().add_clip_rect(context.enclosing_device_rect(absolute_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.painter().restore();
  37. context.clear_svg_context();
  38. }
  39. }