SVGPaintable.cpp 977 B

12345678910111213141516171819202122232425262728293031323334
  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. CSSPixelRect SVGPaintable::compute_absolute_rect() const
  19. {
  20. if (auto* svg_svg_box = layout_box().first_ancestor_of_type<Layout::SVGSVGBox>()) {
  21. CSSPixelRect rect { offset(), content_size() };
  22. for (Layout::Box const* ancestor = svg_svg_box; ancestor && ancestor->paintable(); ancestor = ancestor->paintable()->containing_block())
  23. rect.translate_by(ancestor->paintable_box()->offset());
  24. return rect;
  25. }
  26. return PaintableBox::compute_absolute_rect();
  27. }
  28. }