Coverage Report

Created: 2025-03-04 07:22

/src/serenity/Userland/Libraries/LibWeb/SVG/SVGGraphicsElement.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
3
 * Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
4
 *
5
 * SPDX-License-Identifier: BSD-2-Clause
6
 */
7
8
#pragma once
9
10
#include <LibGfx/PaintStyle.h>
11
#include <LibGfx/Path.h>
12
#include <LibWeb/DOM/Node.h>
13
#include <LibWeb/SVG/AttributeParser.h>
14
#include <LibWeb/SVG/SVGAnimatedTransformList.h>
15
#include <LibWeb/SVG/SVGElement.h>
16
#include <LibWeb/SVG/SVGGradientElement.h>
17
#include <LibWeb/SVG/TagNames.h>
18
#include <LibWeb/SVG/ViewBox.h>
19
20
namespace Web::SVG {
21
22
struct SVGBoundingBoxOptions {
23
    bool fill { true };
24
    bool stroke { false };
25
    bool markers { false };
26
    bool clipped { false };
27
};
28
29
class SVGGraphicsElement : public SVGElement {
30
    WEB_PLATFORM_OBJECT(SVGGraphicsElement, SVGElement);
31
32
public:
33
    virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
34
35
    virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) override;
36
37
    Optional<Gfx::Color> fill_color() const;
38
    Optional<Gfx::Color> stroke_color() const;
39
    Optional<float> stroke_width() const;
40
    Optional<float> fill_opacity() const;
41
    Optional<CSS::StrokeLinecap> stroke_linecap() const;
42
    Optional<CSS::StrokeLinejoin> stroke_linejoin() const;
43
    Optional<CSS::NumberOrCalculated> stroke_miterlimit() const;
44
    Optional<float> stroke_opacity() const;
45
    Optional<FillRule> fill_rule() const;
46
    Optional<ClipRule> clip_rule() const;
47
48
    float visible_stroke_width() const
49
0
    {
50
0
        if (auto color = stroke_color(); color.has_value() && color->alpha() > 0)
51
0
            return stroke_width().value_or(0);
52
0
        return 0;
53
0
    }
54
55
    Gfx::AffineTransform get_transform() const;
56
57
    Optional<Painting::PaintStyle> fill_paint_style(SVGPaintContext const&) const;
58
    Optional<Painting::PaintStyle> stroke_paint_style(SVGPaintContext const&) const;
59
60
    JS::GCPtr<SVG::SVGMaskElement const> mask() const;
61
    JS::GCPtr<SVG::SVGClipPathElement const> clip_path() const;
62
63
    JS::NonnullGCPtr<Geometry::DOMRect> get_b_box(Optional<SVGBoundingBoxOptions>);
64
    JS::NonnullGCPtr<SVGAnimatedTransformList> transform() const;
65
66
    JS::GCPtr<Geometry::DOMMatrix> get_screen_ctm();
67
68
protected:
69
    SVGGraphicsElement(DOM::Document&, DOM::QualifiedName);
70
71
    virtual void initialize(JS::Realm&) override;
72
73
    virtual Gfx::AffineTransform element_transform() const
74
0
    {
75
0
        return m_transform;
76
0
    }
77
78
    Optional<Painting::PaintStyle> svg_paint_computed_value_to_gfx_paint_style(SVGPaintContext const& paint_context, Optional<CSS::SVGPaint> const& paint_value) const;
79
80
    Gfx::AffineTransform m_transform = {};
81
82
    template<typename T>
83
    JS::GCPtr<T> try_resolve_url_to(URL::URL const& url) const
84
0
    {
85
0
        if (!url.fragment().has_value())
86
0
            return {};
87
0
        auto node = document().get_element_by_id(*url.fragment());
88
0
        if (!node)
89
0
            return {};
90
0
        if (is<T>(*node))
91
0
            return static_cast<T&>(*node);
92
0
        return {};
93
0
    }
Unexecuted instantiation: JS::GCPtr<Web::SVG::SVGGradientElement const> Web::SVG::SVGGraphicsElement::try_resolve_url_to<Web::SVG::SVGGradientElement const>(URL::URL const&) const
Unexecuted instantiation: JS::GCPtr<Web::SVG::SVGMaskElement const> Web::SVG::SVGGraphicsElement::try_resolve_url_to<Web::SVG::SVGMaskElement const>(URL::URL const&) const
Unexecuted instantiation: JS::GCPtr<Web::SVG::SVGClipPathElement const> Web::SVG::SVGGraphicsElement::try_resolve_url_to<Web::SVG::SVGClipPathElement const>(URL::URL const&) const
Unexecuted instantiation: JS::GCPtr<Web::SVG::SVGGeometryElement const> Web::SVG::SVGGraphicsElement::try_resolve_url_to<Web::SVG::SVGGeometryElement const>(URL::URL const&) const
94
95
private:
96
0
    virtual bool is_svg_graphics_element() const final { return true; }
97
};
98
99
Gfx::AffineTransform transform_from_transform_list(ReadonlySpan<Transform> transform_list);
100
101
}
102
103
namespace Web::DOM {
104
105
template<>
106
0
inline bool Node::fast_is<SVG::SVGGraphicsElement>() const { return is_svg_graphics_element(); }
107
108
}