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