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};
17
18#[dom_struct]
19pub(crate) struct HTMLDataListElement {
20    htmlelement: HTMLElement,
21}
22
23impl HTMLDataListElement {
24    fn new_inherited(
25        local_name: LocalName,
26        prefix: Option<Prefix>,
27        document: &Document,
28    ) -> HTMLDataListElement {
29        HTMLDataListElement {
30            htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
31        }
32    }
33
34    pub(crate) fn new(
35        cx: &mut js::context::JSContext,
36        local_name: LocalName,
37        prefix: Option<Prefix>,
38        document: &Document,
39        proto: Option<HandleObject>,
40    ) -> DomRoot<HTMLDataListElement> {
41        Node::reflect_node_with_proto(
42            cx,
43            Box::new(HTMLDataListElement::new_inherited(
44                local_name, prefix, document,
45            )),
46            document,
47            proto,
48        )
49    }
50}
51
52impl HTMLDataListElementMethods<crate::DomTypeHolder> for HTMLDataListElement {
53    /// <https://html.spec.whatwg.org/multipage/#dom-datalist-options>
54    fn Options(&self, cx: &mut js::context::JSContext) -> DomRoot<HTMLCollection> {
55        HTMLCollection::new_with_filter_fn(cx, &self.owner_window(), self.upcast(), |element, _| {
56            element.is::<HTMLOptionElement>()
57        })
58    }
59}