Skip to main content

script/dom/html/textual/
htmlmarqueeelement.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, 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    // <https://html.spec.whatwg.org/multipage/#dom-marquee-width>
51    make_getter!(Width, "width");
52    // <https://html.spec.whatwg.org/multipage/#dom-marquee-width>
53    make_dimension_setter!(SetWidth, "width");
54
55    // <https://html.spec.whatwg.org/multipage/#dom-marquee-height>
56    make_getter!(Height, "height");
57    // <https://html.spec.whatwg.org/multipage/#dom-marquee-height>
58    make_dimension_setter!(SetHeight, "height");
59}
60
61impl VirtualMethods for HTMLMarqueeElement {
62    fn super_type(&self) -> Option<&dyn VirtualMethods> {
63        Some(self.upcast::<HTMLElement>() as &dyn VirtualMethods)
64    }
65
66    fn attribute_affects_presentational_hints(&self, attr: AttrRef<'_>) -> bool {
67        match attr.local_name() {
68            &local_name!("width") | &local_name!("height") => true,
69            _ => self
70                .super_type()
71                .unwrap()
72                .attribute_affects_presentational_hints(attr),
73        }
74    }
75
76    fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
77        match *name {
78            local_name!("width") => AttrValue::from_dimension(value.into()),
79            local_name!("height") => AttrValue::from_dimension(value.into()),
80            _ => self
81                .super_type()
82                .unwrap()
83                .parse_plain_attribute(name, value),
84        }
85    }
86}
87
88impl LayoutDom<'_, HTMLMarqueeElement> {
89    pub(crate) fn width(self) -> LengthOrPercentageOrAuto {
90        self.upcast::<Element>()
91            .dimension_attr_value(local_name!("width"))
92    }
93
94    pub(crate) fn height(self) -> LengthOrPercentageOrAuto {
95        self.upcast::<Element>()
96            .dimension_attr_value(local_name!("height"))
97    }
98}