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;
13
14#[derive(JSTraceable, MallocSizeOf)]
15pub(crate) enum HeadingLevel {
16    Heading1,
17    Heading2,
18    Heading3,
19    Heading4,
20    Heading5,
21    Heading6,
22}
23
24#[dom_struct]
25pub(crate) struct HTMLHeadingElement {
26    htmlelement: HTMLElement,
27    level: HeadingLevel,
28}
29
30impl HTMLHeadingElement {
31    fn new_inherited(
32        local_name: LocalName,
33        prefix: Option<Prefix>,
34        document: &Document,
35        level: HeadingLevel,
36    ) -> HTMLHeadingElement {
37        HTMLHeadingElement {
38            htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
39            level,
40        }
41    }
42
43    pub(crate) fn new(
44        cx: &mut js::context::JSContext,
45        local_name: LocalName,
46        prefix: Option<Prefix>,
47        document: &Document,
48        proto: Option<HandleObject>,
49        level: HeadingLevel,
50    ) -> DomRoot<HTMLHeadingElement> {
51        Node::reflect_node_with_proto(
52            cx,
53            Box::new(HTMLHeadingElement::new_inherited(
54                local_name, prefix, document, level,
55            )),
56            document,
57            proto,
58        )
59    }
60}