Skip to main content

script/dom/svg/
svgpatternelement.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use dom_struct::dom_struct;
6use html5ever::{LocalName, Prefix};
7use js::rust::HandleObject;
8use stylo_dom::ElementState;
9
10use crate::dom::bindings::inheritance::Castable;
11use crate::dom::bindings::root::DomRoot;
12use crate::dom::document::Document;
13use crate::dom::node::Node;
14use crate::dom::node::virtualmethods::VirtualMethods;
15use crate::dom::svg::svgelement::SVGElement;
16
17#[dom_struct]
18pub(crate) struct SVGPatternElement {
19    svgelement: SVGElement,
20}
21
22impl SVGPatternElement {
23    fn new_inherited(
24        local_name: LocalName,
25        prefix: Option<Prefix>,
26        document: &Document,
27    ) -> SVGPatternElement {
28        SVGPatternElement {
29            svgelement: SVGElement::new_inherited_with_state(
30                ElementState::empty(),
31                local_name,
32                prefix,
33                document,
34            ),
35        }
36    }
37
38    pub(crate) fn new(
39        cx: &mut js::context::JSContext,
40        local_name: LocalName,
41        prefix: Option<Prefix>,
42        document: &Document,
43        proto: Option<HandleObject>,
44    ) -> DomRoot<SVGPatternElement> {
45        Node::reflect_node_with_proto(
46            cx,
47            Box::new(SVGPatternElement::new_inherited(
48                local_name, prefix, document,
49            )),
50            document,
51            proto,
52        )
53    }
54}
55
56impl VirtualMethods for SVGPatternElement {
57    fn super_type(&self) -> Option<&dyn VirtualMethods> {
58        Some(self.upcast::<SVGElement>() as &dyn VirtualMethods)
59    }
60}