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