script/dom/html/
htmlheadelement.rs1use dom_struct::dom_struct;
6use html5ever::{LocalName, Prefix};
7use js::context::JSContext;
8use js::rust::HandleObject;
9
10use crate::dom::bindings::inheritance::Castable;
11use crate::dom::bindings::root::DomRoot;
12use crate::dom::document::Document;
13use crate::dom::html::htmlelement::HTMLElement;
14use crate::dom::node::{BindContext, Node};
15use crate::dom::userscripts::load_script;
16use crate::dom::virtualmethods::VirtualMethods;
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 cx: &mut js::context::JSContext,
36 local_name: LocalName,
37 prefix: Option<Prefix>,
38 document: &Document,
39 proto: Option<HandleObject>,
40 ) -> DomRoot<HTMLHeadElement> {
41 let n = Node::reflect_node_with_proto(
42 cx,
43 Box::new(HTMLHeadElement::new_inherited(local_name, prefix, document)),
44 document,
45 proto,
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, cx: &mut JSContext, context: &BindContext) {
58 if let Some(s) = self.super_type() {
59 s.bind_to_tree(cx, context);
60 }
61 load_script(self);
62 }
63}