use dom_struct::dom_struct;
use js::context::JSContext;
use js::rust::HandleObject;
use script_bindings::codegen::GenericBindings::DocumentBinding::DocumentMethods;
use script_bindings::codegen::GenericBindings::WindowBinding::WindowMethods;
use script_bindings::inheritance::Castable;
use script_bindings::reflector::reflect_dom_object_with_proto_and_cx;
use script_bindings::root::DomRoot;
use crate::dom::animationeffect::AnimationEffect;
use crate::dom::bindings::codegen::Bindings::AnimationBinding::AnimationMethods;
use crate::dom::bindings::root::MutNullableDom;
use crate::dom::eventtarget::EventTarget;
use crate::dom::globalscope::GlobalScope;
use crate::dom::types::AnimationTimeline;
use crate::dom::window::Window;
#[dom_struct]
pub(crate) struct Animation {
event_target: EventTarget,
timeline: MutNullableDom<AnimationTimeline>,
associated_effect: MutNullableDom<AnimationEffect>,
}
impl Animation {
pub(crate) fn new_inherited() -> Self {
Self {
event_target: EventTarget::new_inherited(),
timeline: Default::default(),
associated_effect: Default::default(),
}
}
fn new_with_proto_and_cx(
cx: &mut JSContext,
global: &GlobalScope,
proto: Option<HandleObject>,
) -> DomRoot<Self> {
reflect_dom_object_with_proto_and_cx(Box::new(Self::new_inherited()), global, proto, cx)
}
pub(crate) fn new(cx: &mut JSContext, global: &GlobalScope) -> DomRoot<Self> {
Self::new_with_proto_and_cx(cx, global, None)
}
fn set_the_timeline(&self, timeline: &AnimationTimeline) {
self.timeline.set(Some(timeline));
}
fn set_the_associated_effect(&self, effect: Option<&AnimationEffect>) {
self.associated_effect.set(effect);
}
}
impl AnimationMethods<crate::DomTypeHolder> for Animation {
fn Constructor(
cx: &mut JSContext,
window: &Window,
_object: Option<HandleObject>,
effect: Option<&AnimationEffect>,
) -> DomRoot<Self> {
let document = window.Document();
let animation = Animation::new(cx, window.upcast());
animation.set_the_timeline(document.Timeline().upcast());
animation.set_the_associated_effect(effect);
animation
}
fn GetEffect(&self) -> Option<DomRoot<AnimationEffect>> {
self.associated_effect.get()
}
fn SetEffect(&self, effect: Option<&AnimationEffect>) {
self.set_the_associated_effect(effect);
}
}