TransitionEvent.cpp (2297B)
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/TransitionEvent.h" 8 9 #include "mozilla/ContentEvents.h" 10 #include "prtime.h" 11 12 namespace mozilla::dom { 13 14 TransitionEvent::TransitionEvent(EventTarget* aOwner, 15 nsPresContext* aPresContext, 16 InternalTransitionEvent* aEvent) 17 : Event(aOwner, aPresContext, 18 aEvent ? aEvent : new InternalTransitionEvent(false, eVoidEvent)) { 19 if (aEvent) { 20 mEventIsInternal = false; 21 } else { 22 mEventIsInternal = true; 23 } 24 } 25 26 // static 27 already_AddRefed<TransitionEvent> TransitionEvent::Constructor( 28 const GlobalObject& aGlobal, const nsAString& aType, 29 const TransitionEventInit& aParam) { 30 nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports()); 31 RefPtr<TransitionEvent> e = new TransitionEvent(t, nullptr, nullptr); 32 bool trusted = e->Init(t); 33 34 e->InitEvent(aType, aParam.mBubbles, aParam.mCancelable); 35 36 InternalTransitionEvent* internalEvent = e->mEvent->AsTransitionEvent(); 37 internalEvent->mPropertyName = aParam.mPropertyName; 38 internalEvent->mElapsedTime = aParam.mElapsedTime; 39 internalEvent->mPseudoElement = aParam.mPseudoElement; 40 41 e->SetTrusted(trusted); 42 e->SetComposed(aParam.mComposed); 43 return e.forget(); 44 } 45 46 void TransitionEvent::GetPropertyName(nsAString& aPropertyName) const { 47 aPropertyName = mEvent->AsTransitionEvent()->mPropertyName; 48 } 49 50 float TransitionEvent::ElapsedTime() { 51 return mEvent->AsTransitionEvent()->mElapsedTime; 52 } 53 54 void TransitionEvent::GetPseudoElement(nsAString& aPseudoElement) const { 55 aPseudoElement = mEvent->AsTransitionEvent()->mPseudoElement; 56 } 57 58 } // namespace mozilla::dom 59 60 using namespace mozilla; 61 using namespace mozilla::dom; 62 63 already_AddRefed<TransitionEvent> NS_NewDOMTransitionEvent( 64 EventTarget* aOwner, nsPresContext* aPresContext, 65 InternalTransitionEvent* aEvent) { 66 RefPtr<TransitionEvent> it = 67 new TransitionEvent(aOwner, aPresContext, aEvent); 68 return it.forget(); 69 }