script/dom/html/
htmldatalistelement.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::codegen::Bindings::HTMLDataListElementBinding::HTMLDataListElementMethods;
10use crate::dom::bindings::inheritance::Castable;
11use crate::dom::bindings::root::DomRoot;
12use crate::dom::document::Document;
13use crate::dom::html::htmlcollection::HTMLCollection;
14use crate::dom::html::htmlelement::HTMLElement;
15use crate::dom::html::htmloptionelement::HTMLOptionElement;
16use crate::dom::node::{Node, NodeTraits};
17use crate::script_runtime::CanGc;
18
19#[dom_struct]
20pub(crate) struct HTMLDataListElement {
21    htmlelement: HTMLElement,
22}
23
24impl HTMLDataListElement {
25    fn new_inherited(
26        local_name: LocalName,
27        prefix: Option<Prefix>,
28        document: &Document,
29    ) -> HTMLDataListElement {
30        HTMLDataListElement {
31            htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
32        }
33    }
34
35    #[cfg_attr(crown, allow(crown::unrooted_must_root))]
36    pub(crate) fn new(
37        local_name: LocalName,
38        prefix: Option<Prefix>,
39        document: &Document,
40        proto: Option<HandleObject>,
41        can_gc: CanGc,
42    ) -> DomRoot<HTMLDataListElement> {
43        Node::reflect_node_with_proto(
44            Box::new(HTMLDataListElement::new_inherited(
45                local_name, prefix, document,
46            )),
47            document,
48            proto,
49            can_gc,
50        )
51    }
52}
53
54impl HTMLDataListElementMethods<crate::DomTypeHolder> for HTMLDataListElement {
55    // https://html.spec.whatwg.org/multipage/#dom-datalist-options
56    fn Options(&self, can_gc: CanGc) -> DomRoot<HTMLCollection> {
57        HTMLCollection::new_with_filter_fn(
58            &self.owner_window(),
59            self.upcast(),
60            |element, _| element.is::<HTMLOptionElement>(),
61            can_gc,
62        )
63    }
64}