Line data Source code
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/. */
6 :
7 : #include "mozilla/dom/AnimationEvent.h"
8 : #include "mozilla/ContentEvents.h"
9 : #include "prtime.h"
10 :
11 : namespace mozilla {
12 : namespace dom {
13 :
14 0 : AnimationEvent::AnimationEvent(EventTarget* aOwner,
15 : nsPresContext* aPresContext,
16 0 : InternalAnimationEvent* aEvent)
17 : : Event(aOwner, aPresContext,
18 0 : aEvent ? aEvent : new InternalAnimationEvent(false, eVoidEvent))
19 : {
20 0 : if (aEvent) {
21 0 : mEventIsInternal = false;
22 : }
23 : else {
24 0 : mEventIsInternal = true;
25 0 : mEvent->mTime = PR_Now();
26 : }
27 0 : }
28 :
29 0 : NS_INTERFACE_MAP_BEGIN(AnimationEvent)
30 0 : NS_INTERFACE_MAP_ENTRY(nsIDOMAnimationEvent)
31 0 : NS_INTERFACE_MAP_END_INHERITING(Event)
32 :
33 0 : NS_IMPL_ADDREF_INHERITED(AnimationEvent, Event)
34 0 : NS_IMPL_RELEASE_INHERITED(AnimationEvent, Event)
35 :
36 : //static
37 : already_AddRefed<AnimationEvent>
38 0 : AnimationEvent::Constructor(const GlobalObject& aGlobal,
39 : const nsAString& aType,
40 : const AnimationEventInit& aParam,
41 : ErrorResult& aRv)
42 : {
43 0 : nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
44 0 : RefPtr<AnimationEvent> e = new AnimationEvent(t, nullptr, nullptr);
45 0 : bool trusted = e->Init(t);
46 :
47 0 : e->InitEvent(aType, aParam.mBubbles, aParam.mCancelable);
48 :
49 0 : InternalAnimationEvent* internalEvent = e->mEvent->AsAnimationEvent();
50 0 : internalEvent->mAnimationName = aParam.mAnimationName;
51 0 : internalEvent->mElapsedTime = aParam.mElapsedTime;
52 0 : internalEvent->mPseudoElement = aParam.mPseudoElement;
53 :
54 0 : e->SetTrusted(trusted);
55 0 : e->SetComposed(aParam.mComposed);
56 0 : return e.forget();
57 : }
58 :
59 : NS_IMETHODIMP
60 0 : AnimationEvent::GetAnimationName(nsAString& aAnimationName)
61 : {
62 0 : aAnimationName = mEvent->AsAnimationEvent()->mAnimationName;
63 0 : return NS_OK;
64 : }
65 :
66 : NS_IMETHODIMP
67 0 : AnimationEvent::GetElapsedTime(float* aElapsedTime)
68 : {
69 0 : *aElapsedTime = ElapsedTime();
70 0 : return NS_OK;
71 : }
72 :
73 : float
74 0 : AnimationEvent::ElapsedTime()
75 : {
76 0 : return mEvent->AsAnimationEvent()->mElapsedTime;
77 : }
78 :
79 : NS_IMETHODIMP
80 0 : AnimationEvent::GetPseudoElement(nsAString& aPseudoElement)
81 : {
82 0 : aPseudoElement = mEvent->AsAnimationEvent()->mPseudoElement;
83 0 : return NS_OK;
84 : }
85 :
86 : } // namespace dom
87 : } // namespace mozilla
88 :
89 : using namespace mozilla;
90 : using namespace mozilla::dom;
91 :
92 : already_AddRefed<AnimationEvent>
93 0 : NS_NewDOMAnimationEvent(EventTarget* aOwner,
94 : nsPresContext* aPresContext,
95 : InternalAnimationEvent* aEvent)
96 : {
97 : RefPtr<AnimationEvent> it =
98 0 : new AnimationEvent(aOwner, aPresContext, aEvent);
99 0 : return it.forget();
100 : }
|