Skip to content

Truly independent web browser

2.0 KB
Raw Blame
/*
 * Copyright (c) 2025, Jelle Raaijmakers <[email protected]>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/Vector.h>
#include <LibGfx/Forward.h>
#include <LibWeb/SVG/AttributeParsing.h>
#include <LibWeb/SVG/SVGAnimatedEnumeration.h>
#include <LibWeb/SVG/SVGElement.h>
#include <LibWeb/SVG/SVGURIReference.h>

namespace Web::SVG {

// https://drafts.fxtf.org/filter-effects/#elementdef-filter
class SVGFilterElement final
    : public SVGElement
    , public SVGURIReferenceMixin<SupportsXLinkHref::No> {
    WEB_WRAPPABLE(SVGFilterElement, SVGElement);
    GC_DECLARE_ALLOCATOR(SVGFilterElement);

public:
    virtual ~SVGFilterElement() override = default;

    virtual bool is_svg_filter_element() const final { return true; }

    // Hands every supported child primitive to the Rust primitive list behind `sink` as attribute
    // facts, with the frame an feImage draws for the list to retain.
    void push_primitives(void* sink, Gfx::IntSize dest_size);

    GC::Ref<SVGAnimatedEnumeration> filter_units();
    GC::Ref<SVGAnimatedEnumeration> primitive_units();

    // https://drafts.csswg.org/filter-effects-1#dom-svgfilterelement-x
    REFLECT_ANIMATED_LENGTH_ATTRIBUTE(x, Horizontal, SVGLengthValue::percentage(-10));

    // https://drafts.csswg.org/filter-effects-1#dom-svgfilterelement-y
    REFLECT_ANIMATED_LENGTH_ATTRIBUTE(y, Vertical, SVGLengthValue::percentage(-10));

    // https://drafts.csswg.org/filter-effects-1#dom-svgfilterelement-width
    REFLECT_ANIMATED_LENGTH_ATTRIBUTE(width, Horizontal, SVGLengthValue::percentage(120));

    // https://drafts.csswg.org/filter-effects-1#dom-svgfilterelement-height
    REFLECT_ANIMATED_LENGTH_ATTRIBUTE(height, Vertical, SVGLengthValue::percentage(120));

private:
    SVGFilterElement(DOM::Document&, DOM::QualifiedName);
    virtual void visit_edges(Cell::Visitor&) override;
};

}

namespace Web::DOM {

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

}