1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/events/AnimationEvent.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,100 @@ 1.4 +/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "mozilla/dom/AnimationEvent.h" 1.10 +#include "mozilla/ContentEvents.h" 1.11 +#include "prtime.h" 1.12 + 1.13 +namespace mozilla { 1.14 +namespace dom { 1.15 + 1.16 +AnimationEvent::AnimationEvent(EventTarget* aOwner, 1.17 + nsPresContext* aPresContext, 1.18 + InternalAnimationEvent* aEvent) 1.19 + : Event(aOwner, aPresContext, 1.20 + aEvent ? aEvent : new InternalAnimationEvent(false, 0)) 1.21 +{ 1.22 + if (aEvent) { 1.23 + mEventIsInternal = false; 1.24 + } 1.25 + else { 1.26 + mEventIsInternal = true; 1.27 + mEvent->time = PR_Now(); 1.28 + } 1.29 +} 1.30 + 1.31 +NS_INTERFACE_MAP_BEGIN(AnimationEvent) 1.32 + NS_INTERFACE_MAP_ENTRY(nsIDOMAnimationEvent) 1.33 +NS_INTERFACE_MAP_END_INHERITING(Event) 1.34 + 1.35 +NS_IMPL_ADDREF_INHERITED(AnimationEvent, Event) 1.36 +NS_IMPL_RELEASE_INHERITED(AnimationEvent, Event) 1.37 + 1.38 +//static 1.39 +already_AddRefed<AnimationEvent> 1.40 +AnimationEvent::Constructor(const GlobalObject& aGlobal, 1.41 + const nsAString& aType, 1.42 + const AnimationEventInit& aParam, 1.43 + ErrorResult& aRv) 1.44 +{ 1.45 + nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports()); 1.46 + nsRefPtr<AnimationEvent> e = new AnimationEvent(t, nullptr, nullptr); 1.47 + bool trusted = e->Init(t); 1.48 + 1.49 + aRv = e->InitEvent(aType, aParam.mBubbles, aParam.mCancelable); 1.50 + 1.51 + InternalAnimationEvent* internalEvent = e->mEvent->AsAnimationEvent(); 1.52 + internalEvent->animationName = aParam.mAnimationName; 1.53 + internalEvent->elapsedTime = aParam.mElapsedTime; 1.54 + internalEvent->pseudoElement = aParam.mPseudoElement; 1.55 + 1.56 + e->SetTrusted(trusted); 1.57 + return e.forget(); 1.58 +} 1.59 + 1.60 +NS_IMETHODIMP 1.61 +AnimationEvent::GetAnimationName(nsAString& aAnimationName) 1.62 +{ 1.63 + aAnimationName = mEvent->AsAnimationEvent()->animationName; 1.64 + return NS_OK; 1.65 +} 1.66 + 1.67 +NS_IMETHODIMP 1.68 +AnimationEvent::GetElapsedTime(float* aElapsedTime) 1.69 +{ 1.70 + *aElapsedTime = ElapsedTime(); 1.71 + return NS_OK; 1.72 +} 1.73 + 1.74 +float 1.75 +AnimationEvent::ElapsedTime() 1.76 +{ 1.77 + return mEvent->AsAnimationEvent()->elapsedTime; 1.78 +} 1.79 + 1.80 +NS_IMETHODIMP 1.81 +AnimationEvent::GetPseudoElement(nsAString& aPseudoElement) 1.82 +{ 1.83 + aPseudoElement = mEvent->AsAnimationEvent()->pseudoElement; 1.84 + return NS_OK; 1.85 +} 1.86 + 1.87 +} // namespace dom 1.88 +} // namespace mozilla 1.89 + 1.90 +using namespace mozilla; 1.91 +using namespace mozilla::dom; 1.92 + 1.93 +nsresult 1.94 +NS_NewDOMAnimationEvent(nsIDOMEvent** aInstancePtrResult, 1.95 + EventTarget* aOwner, 1.96 + nsPresContext* aPresContext, 1.97 + InternalAnimationEvent* aEvent) 1.98 +{ 1.99 + AnimationEvent* it = new AnimationEvent(aOwner, aPresContext, aEvent); 1.100 + NS_ADDREF(it); 1.101 + *aInstancePtrResult = static_cast<Event*>(it); 1.102 + return NS_OK; 1.103 +}