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