/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use dom_struct::dom_struct; use html5ever::{LocalName, Prefix}; use js::rust::HandleObject; use crate::dom::bindings::codegen::Bindings::HTMLMapElementBinding::HTMLMapElementMethods; use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::root::{DomRoot, MutNullableDom}; use crate::dom::bindings::str::DOMString; use crate::dom::document::Document; use crate::dom::html::htmlareaelement::HTMLAreaElement; use crate::dom::html::htmlcollection::HTMLCollection; use crate::dom::html::htmlelement::HTMLElement; use crate::dom::node::{Node, NodeTraits, ShadowIncluding}; use crate::script_runtime::CanGc; #[dom_struct] pub(crate) struct HTMLMapElement { htmlelement: HTMLElement, /// areas: MutNullableDom, } impl HTMLMapElement { fn new_inherited( local_name: LocalName, prefix: Option, document: &Document, ) -> HTMLMapElement { HTMLMapElement { htmlelement: HTMLElement::new_inherited(local_name, prefix, document), areas: Default::default(), } } pub(crate) fn new( local_name: LocalName, prefix: Option, document: &Document, proto: Option, can_gc: CanGc, ) -> DomRoot { Node::reflect_node_with_proto( Box::new(HTMLMapElement::new_inherited(local_name, prefix, document)), document, proto, can_gc, ) } pub(crate) fn get_area_elements(&self) -> Vec> { self.upcast::() .traverse_preorder(ShadowIncluding::No) .filter_map(DomRoot::downcast::) .collect() } } impl HTMLMapElementMethods for HTMLMapElement { // make_getter!(Name, "name"); // make_atomic_setter!(SetName, "name"); /// fn Areas(&self, can_gc: CanGc) -> DomRoot { // The areas attribute must return an HTMLCollection rooted at the map element, whose filter // matches only area elements. self.areas.or_init(|| { HTMLCollection::new_with_filter_fn( &self.owner_window(), self.upcast(), |element, _| element.is::(), can_gc, ) }) } }