script/dom/html/
htmlmenuelement.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::HTMLMenuElementBinding::HTMLMenuElementMethods;
10use crate::dom::bindings::root::DomRoot;
11use crate::dom::document::Document;
12use crate::dom::html::htmlelement::HTMLElement;
13use crate::dom::node::Node;
14use crate::script_runtime::CanGc;
15
16#[dom_struct]
17pub(crate) struct HTMLMenuElement {
18    htmlelement: HTMLElement,
19}
20
21impl HTMLMenuElement {
22    fn new_inherited(
23        local_name: LocalName,
24        prefix: Option<Prefix>,
25        document: &Document,
26    ) -> HTMLMenuElement {
27        HTMLMenuElement {
28            htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
29        }
30    }
31
32    #[cfg_attr(crown, allow(crown::unrooted_must_root))]
33    pub(crate) fn new(
34        local_name: LocalName,
35        prefix: Option<Prefix>,
36        document: &Document,
37        proto: Option<HandleObject>,
38        can_gc: CanGc,
39    ) -> DomRoot<HTMLMenuElement> {
40        Node::reflect_node_with_proto(
41            Box::new(HTMLMenuElement::new_inherited(local_name, prefix, document)),
42            document,
43            proto,
44            can_gc,
45        )
46    }
47}
48
49impl HTMLMenuElementMethods<crate::DomTypeHolder> for HTMLMenuElement {
50    // spec just mandates that compact reflects the content attribute,
51    // with no other semantics. Layout could use it to
52    // change line spacing, but nothing requires it to do so.
53
54    // https://html.spec.whatwg.org/multipage/#dom-menu-compact
55    make_bool_setter!(SetCompact, "compact");
56
57    // https://html.spec.whatwg.org/multipage/#dom-menu-compact
58    make_bool_getter!(Compact, "compact");
59}