script/dom/html/
htmlmapelement.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;
8
9use crate::dom::bindings::inheritance::Castable;
10use crate::dom::bindings::root::DomRoot;
11use crate::dom::document::Document;
12use crate::dom::html::htmlareaelement::HTMLAreaElement;
13use crate::dom::html::htmlelement::HTMLElement;
14use crate::dom::node::{Node, ShadowIncluding};
15use crate::script_runtime::CanGc;
16
17#[dom_struct]
18pub(crate) struct HTMLMapElement {
19    htmlelement: HTMLElement,
20}
21
22impl HTMLMapElement {
23    fn new_inherited(
24        local_name: LocalName,
25        prefix: Option<Prefix>,
26        document: &Document,
27    ) -> HTMLMapElement {
28        HTMLMapElement {
29            htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
30        }
31    }
32
33    #[cfg_attr(crown, allow(crown::unrooted_must_root))]
34    pub(crate) fn new(
35        local_name: LocalName,
36        prefix: Option<Prefix>,
37        document: &Document,
38        proto: Option<HandleObject>,
39        can_gc: CanGc,
40    ) -> DomRoot<HTMLMapElement> {
41        Node::reflect_node_with_proto(
42            Box::new(HTMLMapElement::new_inherited(local_name, prefix, document)),
43            document,
44            proto,
45            can_gc,
46        )
47    }
48
49    pub(crate) fn get_area_elements(&self) -> Vec<DomRoot<HTMLAreaElement>> {
50        self.upcast::<Node>()
51            .traverse_preorder(ShadowIncluding::No)
52            .filter_map(DomRoot::downcast::<HTMLAreaElement>)
53            .collect()
54    }
55}