SVGPaintable.cpp 1.4 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/Layout/SVGSVGBox.h>
  8. #include <LibWeb/Painting/SVGPaintable.h>
  9. namespace Web::Painting {
  10. SVGPaintable::SVGPaintable(Layout::SVGBox const& layout_box)
  11. : PaintableBox(layout_box)
  12. {
  13. }
  14. Layout::SVGBox const& SVGPaintable::layout_box() const
  15. {
  16. return static_cast<Layout::SVGBox const&>(layout_node());
  17. }
  18. void SVGPaintable::before_children_paint(PaintContext& context, PaintPhase phase) const
  19. {
  20. PaintableBox::before_children_paint(context, phase);
  21. if (phase != PaintPhase::Foreground)
  22. return;
  23. context.svg_context().save();
  24. }
  25. void SVGPaintable::after_children_paint(PaintContext& context, PaintPhase phase) const
  26. {
  27. PaintableBox::after_children_paint(context, phase);
  28. if (phase != PaintPhase::Foreground)
  29. return;
  30. context.svg_context().restore();
  31. }
  32. CSSPixelRect SVGPaintable::compute_absolute_rect() const
  33. {
  34. if (auto* svg_svg_box = layout_box().first_ancestor_of_type<Layout::SVGSVGBox>()) {
  35. CSSPixelRect rect { effective_offset(), content_size() };
  36. for (Layout::Box const* ancestor = svg_svg_box; ancestor && ancestor->paintable(); ancestor = ancestor->paintable()->containing_block())
  37. rect.translate_by(ancestor->paint_box()->effective_offset());
  38. return rect;
  39. }
  40. return PaintableBox::compute_absolute_rect();
  41. }
  42. }