Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "mozilla/dom/AnimationEvent.h" |
michael@0 | 7 | #include "mozilla/ContentEvents.h" |
michael@0 | 8 | #include "prtime.h" |
michael@0 | 9 | |
michael@0 | 10 | namespace mozilla { |
michael@0 | 11 | namespace dom { |
michael@0 | 12 | |
michael@0 | 13 | AnimationEvent::AnimationEvent(EventTarget* aOwner, |
michael@0 | 14 | nsPresContext* aPresContext, |
michael@0 | 15 | InternalAnimationEvent* aEvent) |
michael@0 | 16 | : Event(aOwner, aPresContext, |
michael@0 | 17 | aEvent ? aEvent : new InternalAnimationEvent(false, 0)) |
michael@0 | 18 | { |
michael@0 | 19 | if (aEvent) { |
michael@0 | 20 | mEventIsInternal = false; |
michael@0 | 21 | } |
michael@0 | 22 | else { |
michael@0 | 23 | mEventIsInternal = true; |
michael@0 | 24 | mEvent->time = PR_Now(); |
michael@0 | 25 | } |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | NS_INTERFACE_MAP_BEGIN(AnimationEvent) |
michael@0 | 29 | NS_INTERFACE_MAP_ENTRY(nsIDOMAnimationEvent) |
michael@0 | 30 | NS_INTERFACE_MAP_END_INHERITING(Event) |
michael@0 | 31 | |
michael@0 | 32 | NS_IMPL_ADDREF_INHERITED(AnimationEvent, Event) |
michael@0 | 33 | NS_IMPL_RELEASE_INHERITED(AnimationEvent, Event) |
michael@0 | 34 | |
michael@0 | 35 | //static |
michael@0 | 36 | already_AddRefed<AnimationEvent> |
michael@0 | 37 | AnimationEvent::Constructor(const GlobalObject& aGlobal, |
michael@0 | 38 | const nsAString& aType, |
michael@0 | 39 | const AnimationEventInit& aParam, |
michael@0 | 40 | ErrorResult& aRv) |
michael@0 | 41 | { |
michael@0 | 42 | nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports()); |
michael@0 | 43 | nsRefPtr<AnimationEvent> e = new AnimationEvent(t, nullptr, nullptr); |
michael@0 | 44 | bool trusted = e->Init(t); |
michael@0 | 45 | |
michael@0 | 46 | aRv = e->InitEvent(aType, aParam.mBubbles, aParam.mCancelable); |
michael@0 | 47 | |
michael@0 | 48 | InternalAnimationEvent* internalEvent = e->mEvent->AsAnimationEvent(); |
michael@0 | 49 | internalEvent->animationName = aParam.mAnimationName; |
michael@0 | 50 | internalEvent->elapsedTime = aParam.mElapsedTime; |
michael@0 | 51 | internalEvent->pseudoElement = aParam.mPseudoElement; |
michael@0 | 52 | |
michael@0 | 53 | e->SetTrusted(trusted); |
michael@0 | 54 | return e.forget(); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | NS_IMETHODIMP |
michael@0 | 58 | AnimationEvent::GetAnimationName(nsAString& aAnimationName) |
michael@0 | 59 | { |
michael@0 | 60 | aAnimationName = mEvent->AsAnimationEvent()->animationName; |
michael@0 | 61 | return NS_OK; |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | NS_IMETHODIMP |
michael@0 | 65 | AnimationEvent::GetElapsedTime(float* aElapsedTime) |
michael@0 | 66 | { |
michael@0 | 67 | *aElapsedTime = ElapsedTime(); |
michael@0 | 68 | return NS_OK; |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | float |
michael@0 | 72 | AnimationEvent::ElapsedTime() |
michael@0 | 73 | { |
michael@0 | 74 | return mEvent->AsAnimationEvent()->elapsedTime; |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | NS_IMETHODIMP |
michael@0 | 78 | AnimationEvent::GetPseudoElement(nsAString& aPseudoElement) |
michael@0 | 79 | { |
michael@0 | 80 | aPseudoElement = mEvent->AsAnimationEvent()->pseudoElement; |
michael@0 | 81 | return NS_OK; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | } // namespace dom |
michael@0 | 85 | } // namespace mozilla |
michael@0 | 86 | |
michael@0 | 87 | using namespace mozilla; |
michael@0 | 88 | using namespace mozilla::dom; |
michael@0 | 89 | |
michael@0 | 90 | nsresult |
michael@0 | 91 | NS_NewDOMAnimationEvent(nsIDOMEvent** aInstancePtrResult, |
michael@0 | 92 | EventTarget* aOwner, |
michael@0 | 93 | nsPresContext* aPresContext, |
michael@0 | 94 | InternalAnimationEvent* aEvent) |
michael@0 | 95 | { |
michael@0 | 96 | AnimationEvent* it = new AnimationEvent(aOwner, aPresContext, aEvent); |
michael@0 | 97 | NS_ADDREF(it); |
michael@0 | 98 | *aInstancePtrResult = static_cast<Event*>(it); |
michael@0 | 99 | return NS_OK; |
michael@0 | 100 | } |