2022-03-10 14:02:25 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <LibWeb/Layout/ImageBox.h>
|
2022-03-24 16:06:43 +01:00
|
|
|
#include <LibWeb/Layout/SVGSVGBox.h>
|
2022-03-10 14:02:25 +01:00
|
|
|
#include <LibWeb/Painting/SVGPaintable.h>
|
|
|
|
|
|
|
|
|
|
namespace Web::Painting {
|
|
|
|
|
|
|
|
|
|
SVGPaintable::SVGPaintable(Layout::SVGBox const& layout_box)
|
2022-03-18 22:13:26 +01:00
|
|
|
: PaintableBox(layout_box)
|
2022-03-10 14:02:25 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Layout::SVGBox const& SVGPaintable::layout_box() const
|
|
|
|
|
{
|
2022-03-10 15:50:57 +01:00
|
|
|
return static_cast<Layout::SVGBox const&>(layout_node());
|
2022-03-10 14:02:25 +01:00
|
|
|
}
|
|
|
|
|
|
2022-11-12 00:07:43 +03:00
|
|
|
void SVGPaintable::before_children_paint(PaintContext& context, PaintPhase phase) const
|
2022-03-10 14:02:25 +01:00
|
|
|
{
|
2022-11-12 00:07:43 +03:00
|
|
|
PaintableBox::before_children_paint(context, phase);
|
2022-03-10 14:02:25 +01:00
|
|
|
if (phase != PaintPhase::Foreground)
|
|
|
|
|
return;
|
|
|
|
|
context.svg_context().save();
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-12 00:07:43 +03:00
|
|
|
void SVGPaintable::after_children_paint(PaintContext& context, PaintPhase phase) const
|
2022-03-10 14:02:25 +01:00
|
|
|
{
|
2022-11-12 00:07:43 +03:00
|
|
|
PaintableBox::after_children_paint(context, phase);
|
2022-03-10 14:02:25 +01:00
|
|
|
if (phase != PaintPhase::Foreground)
|
|
|
|
|
return;
|
|
|
|
|
context.svg_context().restore();
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-24 16:06:43 +01:00
|
|
|
Gfx::FloatRect SVGPaintable::compute_absolute_rect() const
|
|
|
|
|
{
|
|
|
|
|
if (auto* svg_svg_box = layout_box().first_ancestor_of_type<Layout::SVGSVGBox>()) {
|
|
|
|
|
Gfx::FloatRect rect { effective_offset(), content_size() };
|
|
|
|
|
for (Layout::Box const* ancestor = svg_svg_box; ancestor && ancestor->paintable(); ancestor = ancestor->paintable()->containing_block())
|
|
|
|
|
rect.translate_by(ancestor->paint_box()->effective_offset());
|
|
|
|
|
return rect;
|
|
|
|
|
}
|
|
|
|
|
return PaintableBox::compute_absolute_rect();
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-10 14:02:25 +01:00
|
|
|
}
|