TransitionEvent.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  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/. */
  5. #include "mozilla/dom/TransitionEvent.h"
  6. #include "mozilla/ContentEvents.h"
  7. #include "prtime.h"
  8. namespace mozilla {
  9. namespace dom {
  10. TransitionEvent::TransitionEvent(EventTarget* aOwner,
  11. nsPresContext* aPresContext,
  12. InternalTransitionEvent* aEvent)
  13. : Event(aOwner, aPresContext,
  14. aEvent ? aEvent : new InternalTransitionEvent(false, eVoidEvent))
  15. {
  16. if (aEvent) {
  17. mEventIsInternal = false;
  18. }
  19. else {
  20. mEventIsInternal = true;
  21. mEvent->mTime = PR_Now();
  22. }
  23. }
  24. NS_INTERFACE_MAP_BEGIN(TransitionEvent)
  25. NS_INTERFACE_MAP_ENTRY(nsIDOMTransitionEvent)
  26. NS_INTERFACE_MAP_END_INHERITING(Event)
  27. NS_IMPL_ADDREF_INHERITED(TransitionEvent, Event)
  28. NS_IMPL_RELEASE_INHERITED(TransitionEvent, Event)
  29. // static
  30. already_AddRefed<TransitionEvent>
  31. TransitionEvent::Constructor(const GlobalObject& aGlobal,
  32. const nsAString& aType,
  33. const TransitionEventInit& aParam,
  34. ErrorResult& aRv)
  35. {
  36. nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
  37. RefPtr<TransitionEvent> e = new TransitionEvent(t, nullptr, nullptr);
  38. bool trusted = e->Init(t);
  39. e->InitEvent(aType, aParam.mBubbles, aParam.mCancelable);
  40. InternalTransitionEvent* internalEvent = e->mEvent->AsTransitionEvent();
  41. internalEvent->mPropertyName = aParam.mPropertyName;
  42. internalEvent->mElapsedTime = aParam.mElapsedTime;
  43. internalEvent->mPseudoElement = aParam.mPseudoElement;
  44. e->SetTrusted(trusted);
  45. e->SetComposed(aParam.mComposed);
  46. return e.forget();
  47. }
  48. NS_IMETHODIMP
  49. TransitionEvent::GetPropertyName(nsAString& aPropertyName)
  50. {
  51. aPropertyName = mEvent->AsTransitionEvent()->mPropertyName;
  52. return NS_OK;
  53. }
  54. NS_IMETHODIMP
  55. TransitionEvent::GetElapsedTime(float* aElapsedTime)
  56. {
  57. *aElapsedTime = ElapsedTime();
  58. return NS_OK;
  59. }
  60. float
  61. TransitionEvent::ElapsedTime()
  62. {
  63. return mEvent->AsTransitionEvent()->mElapsedTime;
  64. }
  65. NS_IMETHODIMP
  66. TransitionEvent::GetPseudoElement(nsAString& aPseudoElement)
  67. {
  68. aPseudoElement = mEvent->AsTransitionEvent()->mPseudoElement;
  69. return NS_OK;
  70. }
  71. } // namespace dom
  72. } // namespace mozilla
  73. using namespace mozilla;
  74. using namespace mozilla::dom;
  75. already_AddRefed<TransitionEvent>
  76. NS_NewDOMTransitionEvent(EventTarget* aOwner,
  77. nsPresContext* aPresContext,
  78. InternalTransitionEvent* aEvent)
  79. {
  80. RefPtr<TransitionEvent> it =
  81. new TransitionEvent(aOwner, aPresContext, aEvent);
  82. return it.forget();
  83. }