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    pub(crate) fn new(
36        local_name: LocalName,
37        prefix: Option<Prefix>,
38        document: &Document,
39        proto: Option<HandleObject>,
40        can_gc: CanGc,
41    ) -> DomRoot<HTMLDataListElement> {
42        Node::reflect_node_with_proto(
43            Box::new(HTMLDataListElement::new_inherited(
44                local_name, prefix, document,
45            )),
46            document,
47            proto,
48            can_gc,
49        )
50    }
51}
52
53impl HTMLDataListElementMethods<crate::DomTypeHolder> for HTMLDataListElement {
54    /// <https://html.spec.whatwg.org/multipage/#dom-datalist-options>
55    fn Options(&self, can_gc: CanGc) -> DomRoot<HTMLCollection> {
56        HTMLCollection::new_with_filter_fn(
57            &self.owner_window(),
58            self.upcast(),
59            |element, _| element.is::<HTMLOptionElement>(),
60            can_gc,
61        )
62    }
63}