dom/events/AnimationEvent.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial