script/dom/html/
htmlheadelement.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::inheritance::Castable;
10use crate::dom::bindings::root::DomRoot;
11use crate::dom::document::Document;
12use crate::dom::html::htmlelement::HTMLElement;
13use crate::dom::node::{BindContext, Node};
14use crate::dom::userscripts::load_script;
15use crate::dom::virtualmethods::VirtualMethods;
16use crate::script_runtime::CanGc;
17
18#[dom_struct]
19pub(crate) struct HTMLHeadElement {
20    htmlelement: HTMLElement,
21}
22
23impl HTMLHeadElement {
24    fn new_inherited(
25        local_name: LocalName,
26        prefix: Option<Prefix>,
27        document: &Document,
28    ) -> HTMLHeadElement {
29        HTMLHeadElement {
30            htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
31        }
32    }
33
34    pub(crate) fn new(
35        local_name: LocalName,
36        prefix: Option<Prefix>,
37        document: &Document,
38        proto: Option<HandleObject>,
39        can_gc: CanGc,
40    ) -> DomRoot<HTMLHeadElement> {
41        let n = Node::reflect_node_with_proto(
42            Box::new(HTMLHeadElement::new_inherited(local_name, prefix, document)),
43            document,
44            proto,
45            can_gc,
46        );
47
48        n.upcast::<Node>().set_weird_parser_insertion_mode();
49        n
50    }
51}
52
53impl VirtualMethods for HTMLHeadElement {
54    fn super_type(&self) -> Option<&dyn VirtualMethods> {
55        Some(self.upcast::<HTMLElement>() as &dyn VirtualMethods)
56    }
57    fn bind_to_tree(&self, context: &BindContext, can_gc: CanGc) {
58        if let Some(s) = self.super_type() {
59            s.bind_to_tree(context, can_gc);
60        }
61        load_script(self);
62    }
63}