2011-04-11 23:18:44 -07:00
|
|
|
/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-04-11 23:18:44 -07:00
|
|
|
|
|
|
|
#include "nsDOMAnimationEvent.h"
|
2013-07-03 08:56:26 -07:00
|
|
|
#include "prtime.h"
|
2013-09-25 04:21:20 -07:00
|
|
|
#include "mozilla/ContentEvents.h"
|
2011-04-11 23:18:44 -07:00
|
|
|
|
2013-09-26 23:20:54 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2013-03-09 03:34:29 -08:00
|
|
|
nsDOMAnimationEvent::nsDOMAnimationEvent(mozilla::dom::EventTarget* aOwner,
|
|
|
|
nsPresContext *aPresContext,
|
2013-09-26 23:20:54 -07:00
|
|
|
InternalAnimationEvent* aEvent)
|
2013-03-09 03:34:29 -08:00
|
|
|
: nsDOMEvent(aOwner, aPresContext,
|
2013-09-26 23:20:54 -07:00
|
|
|
aEvent ? aEvent :
|
|
|
|
new InternalAnimationEvent(false, 0, EmptyString(),
|
|
|
|
0.0, EmptyString()))
|
2011-04-11 23:18:44 -07:00
|
|
|
{
|
|
|
|
if (aEvent) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mEventIsInternal = false;
|
2011-04-11 23:18:44 -07:00
|
|
|
}
|
|
|
|
else {
|
2011-10-17 07:59:28 -07:00
|
|
|
mEventIsInternal = true;
|
2011-04-11 23:18:44 -07:00
|
|
|
mEvent->time = PR_Now();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsDOMAnimationEvent)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMAnimationEvent)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsDOMAnimationEvent, nsDOMEvent)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsDOMAnimationEvent, nsDOMEvent)
|
|
|
|
|
2013-05-05 06:22:29 -07:00
|
|
|
//static
|
|
|
|
already_AddRefed<nsDOMAnimationEvent>
|
|
|
|
nsDOMAnimationEvent::Constructor(const mozilla::dom::GlobalObject& aGlobal,
|
|
|
|
const nsAString& aType,
|
|
|
|
const mozilla::dom::AnimationEventInit& aParam,
|
|
|
|
mozilla::ErrorResult& aRv)
|
|
|
|
{
|
2013-08-22 22:17:08 -07:00
|
|
|
nsCOMPtr<mozilla::dom::EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
|
2013-05-05 06:22:29 -07:00
|
|
|
nsRefPtr<nsDOMAnimationEvent> e = new nsDOMAnimationEvent(t, nullptr, nullptr);
|
|
|
|
bool trusted = e->Init(t);
|
2013-05-08 13:45:35 -07:00
|
|
|
|
|
|
|
aRv = e->InitEvent(aType, aParam.mBubbles, aParam.mCancelable);
|
|
|
|
|
2013-10-17 23:10:22 -07:00
|
|
|
InternalAnimationEvent* internalEvent = e->mEvent->AsAnimationEvent();
|
|
|
|
internalEvent->animationName = aParam.mAnimationName;
|
|
|
|
internalEvent->elapsedTime = aParam.mElapsedTime;
|
|
|
|
internalEvent->pseudoElement = aParam.mPseudoElement;
|
2013-05-08 13:45:35 -07:00
|
|
|
|
2013-05-05 06:22:29 -07:00
|
|
|
e->SetTrusted(trusted);
|
|
|
|
return e.forget();
|
|
|
|
}
|
|
|
|
|
2011-04-11 23:18:44 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMAnimationEvent::GetAnimationName(nsAString & aAnimationName)
|
|
|
|
{
|
2013-10-17 23:10:22 -07:00
|
|
|
aAnimationName = mEvent->AsAnimationEvent()->animationName;
|
2011-04-11 23:18:44 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMAnimationEvent::GetElapsedTime(float *aElapsedTime)
|
|
|
|
{
|
2013-03-14 14:16:03 -07:00
|
|
|
*aElapsedTime = ElapsedTime();
|
2011-04-11 23:18:44 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-10-17 23:10:22 -07:00
|
|
|
float
|
|
|
|
nsDOMAnimationEvent::ElapsedTime()
|
|
|
|
{
|
|
|
|
return mEvent->AsAnimationEvent()->elapsedTime;
|
|
|
|
}
|
|
|
|
|
2013-05-05 06:22:29 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMAnimationEvent::GetPseudoElement(nsAString& aPseudoElement)
|
|
|
|
{
|
2013-10-17 23:10:22 -07:00
|
|
|
aPseudoElement = mEvent->AsAnimationEvent()->pseudoElement;
|
2013-05-05 06:22:29 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-11 23:18:44 -07:00
|
|
|
nsresult
|
|
|
|
NS_NewDOMAnimationEvent(nsIDOMEvent **aInstancePtrResult,
|
2013-03-09 03:34:29 -08:00
|
|
|
mozilla::dom::EventTarget* aOwner,
|
2011-04-11 23:18:44 -07:00
|
|
|
nsPresContext *aPresContext,
|
2013-09-26 23:20:54 -07:00
|
|
|
InternalAnimationEvent *aEvent)
|
2011-04-11 23:18:44 -07:00
|
|
|
{
|
2013-03-09 03:34:29 -08:00
|
|
|
nsDOMAnimationEvent* it =
|
|
|
|
new nsDOMAnimationEvent(aOwner, aPresContext, aEvent);
|
2011-04-11 23:18:44 -07:00
|
|
|
return CallQueryInterface(it, aInstancePtrResult);
|
|
|
|
}
|