script/dom/html/
htmlheadingelement.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::root::DomRoot;
10use crate::dom::document::Document;
11use crate::dom::html::htmlelement::HTMLElement;
12use crate::dom::node::Node;
13use crate::script_runtime::CanGc;
14
15#[derive(JSTraceable, MallocSizeOf)]
16pub(crate) enum HeadingLevel {
17    Heading1,
18    Heading2,
19    Heading3,
20    Heading4,
21    Heading5,
22    Heading6,
23}
24
25#[dom_struct]
26pub(crate) struct HTMLHeadingElement {
27    htmlelement: HTMLElement,
28    level: HeadingLevel,
29}
30
31impl HTMLHeadingElement {
32    fn new_inherited(
33        local_name: LocalName,
34        prefix: Option<Prefix>,
35        document: &Document,
36        level: HeadingLevel,
37    ) -> HTMLHeadingElement {
38        HTMLHeadingElement {
39            htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
40            level,
41        }
42    }
43
44    #[cfg_attr(crown, allow(crown::unrooted_must_root))]
45    pub(crate) fn new(
46        local_name: LocalName,
47        prefix: Option<Prefix>,
48        document: &Document,
49        proto: Option<HandleObject>,
50        level: HeadingLevel,
51        can_gc: CanGc,
52    ) -> DomRoot<HTMLHeadingElement> {
53        Node::reflect_node_with_proto(
54            Box::new(HTMLHeadingElement::new_inherited(
55                local_name, prefix, document, level,
56            )),
57            document,
58            proto,
59            can_gc,
60        )
61    }
62}