script/dom/animations/
animation.rs1use dom_struct::dom_struct;
6use js::context::JSContext;
7use js::rust::HandleObject;
8use script_bindings::codegen::GenericBindings::DocumentBinding::DocumentMethods;
9use script_bindings::codegen::GenericBindings::WindowBinding::WindowMethods;
10use script_bindings::inheritance::Castable;
11use script_bindings::reflector::reflect_dom_object_with_proto_and_cx;
12use script_bindings::root::DomRoot;
13
14use crate::dom::animationeffect::AnimationEffect;
15use crate::dom::bindings::codegen::Bindings::AnimationBinding::AnimationMethods;
16use crate::dom::bindings::root::MutNullableDom;
17use crate::dom::eventtarget::EventTarget;
18use crate::dom::globalscope::GlobalScope;
19use crate::dom::types::AnimationTimeline;
20use crate::dom::window::Window;
21
22#[dom_struct]
24pub(crate) struct Animation {
25 event_target: EventTarget,
26
27 timeline: MutNullableDom<AnimationTimeline>,
29
30 associated_effect: MutNullableDom<AnimationEffect>,
32}
33
34impl Animation {
35 pub(crate) fn new_inherited() -> Self {
36 Self {
37 event_target: EventTarget::new_inherited(),
38 timeline: Default::default(),
39 associated_effect: Default::default(),
40 }
41 }
42
43 fn new_with_proto_and_cx(
44 cx: &mut JSContext,
45 global: &GlobalScope,
46 proto: Option<HandleObject>,
47 ) -> DomRoot<Self> {
48 reflect_dom_object_with_proto_and_cx(Box::new(Self::new_inherited()), global, proto, cx)
49 }
50
51 pub(crate) fn new(cx: &mut JSContext, global: &GlobalScope) -> DomRoot<Self> {
52 Self::new_with_proto_and_cx(cx, global, None)
53 }
54
55 fn set_the_timeline(&self, timeline: &AnimationTimeline) {
57 self.timeline.set(Some(timeline));
59 }
60
61 fn set_the_associated_effect(&self, effect: Option<&AnimationEffect>) {
63 self.associated_effect.set(effect);
65 }
66}
67
68impl AnimationMethods<crate::DomTypeHolder> for Animation {
69 fn Constructor(
71 cx: &mut JSContext,
72 window: &Window,
73 _object: Option<HandleObject>,
74 effect: Option<&AnimationEffect>,
75 ) -> DomRoot<Self> {
76 let animation = Animation::new(cx, window.upcast());
78
79 animation.set_the_timeline(window.Document().Timeline().upcast());
84
85 animation.set_the_associated_effect(effect);
88
89 animation
90 }
91}