script/dom/html/
htmllielement.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, local_name};
7use js::rust::HandleObject;
8use style::attr::AttrValue;
9
10use crate::dom::bindings::codegen::Bindings::HTMLLIElementBinding::HTMLLIElementMethods;
11use crate::dom::bindings::inheritance::Castable;
12use crate::dom::bindings::root::DomRoot;
13use crate::dom::bindings::str::DOMString;
14use crate::dom::document::Document;
15use crate::dom::html::htmlelement::HTMLElement;
16use crate::dom::node::Node;
17use crate::dom::virtualmethods::VirtualMethods;
18use crate::script_runtime::CanGc;
19
20#[dom_struct]
21pub(crate) struct HTMLLIElement {
22    htmlelement: HTMLElement,
23}
24
25impl HTMLLIElement {
26    fn new_inherited(
27        local_name: LocalName,
28        prefix: Option<Prefix>,
29        document: &Document,
30    ) -> HTMLLIElement {
31        HTMLLIElement {
32            htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
33        }
34    }
35
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<HTMLLIElement> {
43        Node::reflect_node_with_proto(
44            Box::new(HTMLLIElement::new_inherited(local_name, prefix, document)),
45            document,
46            proto,
47            can_gc,
48        )
49    }
50}
51
52impl HTMLLIElementMethods<crate::DomTypeHolder> for HTMLLIElement {
53    // https://html.spec.whatwg.org/multipage/#dom-li-value
54    make_int_getter!(Value, "value");
55
56    // https://html.spec.whatwg.org/multipage/#dom-li-value
57    make_int_setter!(SetValue, "value");
58}
59
60impl VirtualMethods for HTMLLIElement {
61    fn super_type(&self) -> Option<&dyn VirtualMethods> {
62        Some(self.upcast::<HTMLElement>() as &dyn VirtualMethods)
63    }
64
65    fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
66        match name {
67            &local_name!("value") => AttrValue::from_i32(value.into(), 0),
68            _ => self
69                .super_type()
70                .unwrap()
71                .parse_plain_attribute(name, value),
72        }
73    }
74}