script/dom/html/embedded_content/
htmlembedelement.rs1use dom_struct::dom_struct;
6use html5ever::{LocalName, Prefix, local_name};
7use js::rust::HandleObject;
8use style::attr::{AttrValue, LengthOrPercentageOrAuto};
9
10use crate::dom::Element;
11use crate::dom::bindings::codegen::Bindings::HTMLEmbedElementBinding::HTMLEmbedElementMethods;
12use crate::dom::bindings::root::{DomRoot, LayoutDom};
13use crate::dom::bindings::str::DOMString;
14use crate::dom::document::Document;
15use crate::dom::element::attributes::storage::AttrRef;
16use crate::dom::html::htmlelement::HTMLElement;
17use crate::dom::node::Node;
18use crate::dom::node::virtualmethods::VirtualMethods;
19use crate::script_bindings::inheritance::Castable;
20
21#[dom_struct]
22pub(crate) struct HTMLEmbedElement {
23 htmlelement: HTMLElement,
24}
25
26impl HTMLEmbedElement {
27 fn new_inherited(
28 local_name: LocalName,
29 prefix: Option<Prefix>,
30 document: &Document,
31 ) -> HTMLEmbedElement {
32 HTMLEmbedElement {
33 htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
34 }
35 }
36
37 pub(crate) fn new(
38 cx: &mut js::context::JSContext,
39 local_name: LocalName,
40 prefix: Option<Prefix>,
41 document: &Document,
42 proto: Option<HandleObject>,
43 ) -> DomRoot<HTMLEmbedElement> {
44 Node::reflect_node_with_proto(
45 cx,
46 Box::new(HTMLEmbedElement::new_inherited(
47 local_name, prefix, document,
48 )),
49 document,
50 proto,
51 )
52 }
53}
54
55impl HTMLEmbedElementMethods<crate::DomTypeHolder> for HTMLEmbedElement {
56 make_getter!(Width, "width");
58 make_dimension_setter!(SetWidth, "width");
60
61 make_getter!(Height, "height");
63 make_dimension_setter!(SetHeight, "height");
65
66 make_dimension_uint_getter!(Hspace, "hspace");
68 make_dimension_uint_setter!(SetHspace, "hspace");
70
71 make_dimension_uint_getter!(Vspace, "vspace");
73 make_dimension_uint_setter!(SetVspace, "vspace");
75}
76
77impl VirtualMethods for HTMLEmbedElement {
78 fn super_type(&self) -> Option<&dyn VirtualMethods> {
79 Some(self.upcast::<HTMLElement>() as &dyn VirtualMethods)
80 }
81
82 fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
83 match *name {
84 local_name!("width") |
85 local_name!("height") |
86 local_name!("hspace") |
87 local_name!("vspace") => AttrValue::from_dimension(value.into()),
88 _ => self
89 .super_type()
90 .unwrap()
91 .parse_plain_attribute(name, value),
92 }
93 }
94
95 fn attribute_affects_presentational_hints(&self, attr: AttrRef<'_>) -> bool {
96 match attr.local_name() {
97 &local_name!("width") |
98 &local_name!("height") |
99 &local_name!("hspace") |
100 &local_name!("vspace") => true,
101 _ => self
102 .super_type()
103 .unwrap()
104 .attribute_affects_presentational_hints(attr),
105 }
106 }
107}
108
109impl LayoutDom<'_, HTMLEmbedElement> {
110 pub(crate) fn width(self) -> LengthOrPercentageOrAuto {
111 self.upcast::<Element>()
112 .dimension_attr_value(local_name!("width"))
113 }
114
115 pub(crate) fn height(self) -> LengthOrPercentageOrAuto {
116 self.upcast::<Element>()
117 .dimension_attr_value(local_name!("height"))
118 }
119
120 pub(crate) fn margin_right_left(self) -> LengthOrPercentageOrAuto {
121 self.upcast::<Element>()
122 .dimension_attr_value(local_name!("hspace"))
123 }
124
125 pub(crate) fn margin_top_bottom(self) -> LengthOrPercentageOrAuto {
126 self.upcast::<Element>()
127 .dimension_attr_value(local_name!("vspace"))
128 }
129}