1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/AnimationEvent.h"
8 #include "mozilla/ContentEvents.h"
11 namespace mozilla::dom
{
13 AnimationEvent::AnimationEvent(EventTarget
* aOwner
, nsPresContext
* aPresContext
,
14 InternalAnimationEvent
* aEvent
)
15 : Event(aOwner
, aPresContext
,
16 aEvent
? aEvent
: new InternalAnimationEvent(false, eVoidEvent
)) {
18 mEventIsInternal
= false;
20 mEventIsInternal
= true;
25 already_AddRefed
<AnimationEvent
> AnimationEvent::Constructor(
26 const GlobalObject
& aGlobal
, const nsAString
& aType
,
27 const AnimationEventInit
& aParam
) {
28 nsCOMPtr
<EventTarget
> t
= do_QueryInterface(aGlobal
.GetAsSupports());
29 RefPtr
<AnimationEvent
> e
= new AnimationEvent(t
, nullptr, nullptr);
30 bool trusted
= e
->Init(t
);
32 e
->InitEvent(aType
, aParam
.mBubbles
, aParam
.mCancelable
);
34 InternalAnimationEvent
* internalEvent
= e
->mEvent
->AsAnimationEvent();
35 internalEvent
->mAnimationName
= aParam
.mAnimationName
;
36 internalEvent
->mElapsedTime
= aParam
.mElapsedTime
;
37 internalEvent
->mPseudoElement
= aParam
.mPseudoElement
;
39 e
->SetTrusted(trusted
);
40 e
->SetComposed(aParam
.mComposed
);
44 void AnimationEvent::GetAnimationName(nsAString
& aAnimationName
) {
45 aAnimationName
= mEvent
->AsAnimationEvent()->mAnimationName
;
48 float AnimationEvent::ElapsedTime() {
49 return mEvent
->AsAnimationEvent()->mElapsedTime
;
52 void AnimationEvent::GetPseudoElement(nsAString
& aPseudoElement
) {
53 aPseudoElement
= mEvent
->AsAnimationEvent()->mPseudoElement
;
56 } // namespace mozilla::dom
58 using namespace mozilla
;
59 using namespace mozilla::dom
;
61 already_AddRefed
<AnimationEvent
> NS_NewDOMAnimationEvent(
62 EventTarget
* aOwner
, nsPresContext
* aPresContext
,
63 InternalAnimationEvent
* aEvent
) {
64 RefPtr
<AnimationEvent
> it
= new AnimationEvent(aOwner
, aPresContext
, aEvent
);