content/events/src/nsDOMTransitionEvent.cpp
author David Anderson <danderson@mozilla.com>
Mon, 21 May 2012 14:40:04 -0700
changeset 109823 80e4ab0d24bc64ceaa7693ab5def36faffde7a40
parent 108863 f93960a93ad97a56d308bd9ce25d97cbc175d524
parent 96742 f4157e8c410708d76703f19e4dfb61859bfe32d8
child 110199 08187a7ea8974548382f5d7775df8171a4ec6449
permissions -rw-r--r--
Merge from mozilla-central.

/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
/* 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/. */

#include "nsDOMTransitionEvent.h"
#include "nsGUIEvent.h"
#include "nsDOMClassInfoID.h"
#include "nsIClassInfo.h"
#include "nsIXPCScriptable.h"

nsDOMTransitionEvent::nsDOMTransitionEvent(nsPresContext *aPresContext,
                                           nsTransitionEvent *aEvent)
  : nsDOMEvent(aPresContext, aEvent ? aEvent
                                    : new nsTransitionEvent(false, 0,
                                                            EmptyString(),
                                                            0.0))
{
  if (aEvent) {
    mEventIsInternal = false;
  }
  else {
    mEventIsInternal = true;
    mEvent->time = PR_Now();
  }
}

nsDOMTransitionEvent::~nsDOMTransitionEvent()
{
  if (mEventIsInternal) {
    delete TransitionEvent();
    mEvent = nsnull;
  }
}

DOMCI_DATA(TransitionEvent, nsDOMTransitionEvent)

NS_INTERFACE_MAP_BEGIN(nsDOMTransitionEvent)
  NS_INTERFACE_MAP_ENTRY(nsIDOMTransitionEvent)
  NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(TransitionEvent)
NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)

NS_IMPL_ADDREF_INHERITED(nsDOMTransitionEvent, nsDOMEvent)
NS_IMPL_RELEASE_INHERITED(nsDOMTransitionEvent, nsDOMEvent)

NS_IMETHODIMP
nsDOMTransitionEvent::GetPropertyName(nsAString & aPropertyName)
{
  aPropertyName = TransitionEvent()->propertyName;
  return NS_OK;
}

NS_IMETHODIMP
nsDOMTransitionEvent::GetElapsedTime(float *aElapsedTime)
{
  *aElapsedTime = TransitionEvent()->elapsedTime;
  return NS_OK;
}

NS_IMETHODIMP
nsDOMTransitionEvent::InitTransitionEvent(const nsAString & typeArg,
                                          bool canBubbleArg,
                                          bool cancelableArg,
                                          const nsAString & propertyNameArg,
                                          float elapsedTimeArg)
{
  nsresult rv = nsDOMEvent::InitEvent(typeArg, canBubbleArg, cancelableArg);
  NS_ENSURE_SUCCESS(rv, rv);

  TransitionEvent()->propertyName = propertyNameArg;
  TransitionEvent()->elapsedTime = elapsedTimeArg;

  return NS_OK;
}

nsresult
NS_NewDOMTransitionEvent(nsIDOMEvent **aInstancePtrResult,
                         nsPresContext *aPresContext,
                         nsTransitionEvent *aEvent)
{
  nsDOMTransitionEvent *it = new nsDOMTransitionEvent(aPresContext, aEvent);
  return CallQueryInterface(it, aInstancePtrResult);
}