Repository: LadybirdBrowser/ladybird
File: Libraries/LibWeb/SVG/SVGGraphicsElement.h (C/C++)

Code before:
    virtual Gfx::AffineTransform element_transform() const
    {
        return m_transform;
    }

protected:
    SVGGraphicsElement(DOM::Document&, DOM::QualifiedName);

    virtual void initialize(JS::Realm&) override;

    Optional<Painting::PaintStyle> svg_paint_computed_value_to_gfx_paint_style(SVGPaintContext const& paint_context, Optional<CSS::SVGPaint> const& paint_value) const;

    Gfx::AffineTransform m_transform = {};

    template<typename T>
    GC::Ptr<T> try_resolve_url_to(CSS::URL const& url) const
    {
        // FIXME: Complete and use the entire URL, not just the fragment.
        Optional<FlyString> fragment;
        if (auto fragment_offset = url.url().find_byte_offset('#'); fragment_offset.has_value()) {
            fragment = MUST(url.url().substring_from_byte_offset_with_shared_superstring(fragment_offset.value() + 1));
        }
        if (!fragment.has_value())
            return {};
        if (auto node = document().get_element_by_id(*fragment))
            return as_if<T>(*node);

        auto containing_shadow = containing_shadow_root();
        if (containing_shadow) {
            if (auto node = containing_shadow->get_element_by_id(*fragment))
                return as_if<T>(*node);
        }

        return {};
    }

private:
    virtual bool is_svg_graphics_element() const final { return true; }
    float resolve_relative_to_viewport_size(CSS::LengthPercentage const& length_percentage) const;
};

Gfx::AffineTransform transform_from_transform_list(ReadonlySpan<Transform> transform_list);

}

namespace Web::DOM {

template<>
inline bool Node::fast_is<SVG::SVGGraphicsElement>() const { return is_svg_graphics_element(); }

}

Review comment (suggestion):
This will now return an empty `GC::Ptr` if it's not of type `T`, which is probably not what you meant? Try this:

```cpp
if (auto node = as_if<T>(document().get_element_by_id(*fragment).ptr()))
    return *node;
```

Code after:
    virtual Gfx::AffineTransform element_transform() const
    {
        return m_transform;
    }

protected:
    SVGGraphicsElement(DOM::Document&, DOM::QualifiedName);

    virtual void initialize(JS::Realm&) override;

    Optional<Painting::PaintStyle> svg_paint_computed_value_to_gfx_paint_style(SVGPaintContext const& paint_context, Optional<CSS::SVGPaint> const& paint_value) const;

    Gfx::AffineTransform m_transform = {};

    template<typename T>
    GC::Ptr<T> try_resolve_url_to(CSS::URL const& url) const
    {
        // FIXME: Complete and use the entire URL, not just the fragment.
        Optional<FlyString> fragment;
        if (auto fragment_offset = url.url().find_byte_offset('#'); fragment_offset.has_value()) {
            fragment = MUST(url.url().substring_from_byte_offset_with_shared_superstring(fragment_offset.value() + 1));
        }
        if (!fragment.has_value())
            return {};
        if (auto node = as_if<T>(document().get_element_by_id(*fragment).ptr()))
            return *node;

        auto containing_shadow = containing_shadow_root();
        if (containing_shadow) {
            if (auto node = as_if<T>(containing_shadow->get_element_by_id(*fragment).ptr()))
                return *node;
        }

        return {};
    }

private:
    virtual bool is_svg_graphics_element() const final { return true; }
    float resolve_relative_to_viewport_size(CSS::LengthPercentage const& length_percentage) const;
};

Gfx::AffineTransform transform_from_transform_list(ReadonlySpan<Transform> transform_list);

}

namespace Web::DOM {

template<>
inline bool Node::fast_is<SVG::SVGGraphicsElement>() const { return is_svg_graphics_element(); }

}