script/dom/
documenttype.rs1use dom_struct::dom_struct;
6use js::context::JSContext;
7
8use crate::dom::bindings::codegen::Bindings::DocumentTypeBinding::DocumentTypeMethods;
9use crate::dom::bindings::codegen::UnionTypes::NodeOrString;
10use crate::dom::bindings::error::ErrorResult;
11use crate::dom::bindings::inheritance::Castable;
12use crate::dom::bindings::root::DomRoot;
13use crate::dom::bindings::str::DOMString;
14use crate::dom::document::Document;
15use crate::dom::node::Node;
16use crate::script_runtime::CanGc;
17
18#[dom_struct]
21pub(crate) struct DocumentType {
22 node: Node,
23 name: DOMString,
24 public_id: DOMString,
25 system_id: DOMString,
26}
27
28impl DocumentType {
29 fn new_inherited(
30 name: DOMString,
31 public_id: Option<DOMString>,
32 system_id: Option<DOMString>,
33 document: &Document,
34 ) -> DocumentType {
35 DocumentType {
36 node: Node::new_inherited(document),
37 name,
38 public_id: public_id.unwrap_or_default(),
39 system_id: system_id.unwrap_or_default(),
40 }
41 }
42 pub(crate) fn new(
43 name: DOMString,
44 public_id: Option<DOMString>,
45 system_id: Option<DOMString>,
46 document: &Document,
47 can_gc: CanGc,
48 ) -> DomRoot<DocumentType> {
49 Node::reflect_node(
50 Box::new(DocumentType::new_inherited(
51 name, public_id, system_id, document,
52 )),
53 document,
54 can_gc,
55 )
56 }
57
58 #[inline]
59 pub(crate) fn name(&self) -> &DOMString {
60 &self.name
61 }
62
63 #[inline]
64 pub(crate) fn public_id(&self) -> &DOMString {
65 &self.public_id
66 }
67
68 #[inline]
69 pub(crate) fn system_id(&self) -> &DOMString {
70 &self.system_id
71 }
72}
73
74impl DocumentTypeMethods<crate::DomTypeHolder> for DocumentType {
75 fn Name(&self) -> DOMString {
77 self.name.clone()
78 }
79
80 fn PublicId(&self) -> DOMString {
82 self.public_id.clone()
83 }
84
85 fn SystemId(&self) -> DOMString {
87 self.system_id.clone()
88 }
89
90 fn Before(&self, cx: &mut JSContext, nodes: Vec<NodeOrString>) -> ErrorResult {
92 self.upcast::<Node>().before(cx, nodes)
93 }
94
95 fn After(&self, cx: &mut JSContext, nodes: Vec<NodeOrString>) -> ErrorResult {
97 self.upcast::<Node>().after(cx, nodes)
98 }
99
100 fn ReplaceWith(&self, cx: &mut JSContext, nodes: Vec<NodeOrString>) -> ErrorResult {
102 self.upcast::<Node>().replace_with(cx, nodes)
103 }
104
105 fn Remove(&self, cx: &mut JSContext) {
107 self.upcast::<Node>().remove_self(cx);
108 }
109}