/src/mozilla-central/dom/events/CustomEvent.cpp
Line | Count | Source (jump to first uncovered line) |
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 "CustomEvent.h" |
8 | | #include "mozilla/dom/CustomEventBinding.h" |
9 | | |
10 | | #include "mozilla/dom/BindingUtils.h" |
11 | | #include "nsContentUtils.h" |
12 | | #include "nsIXPConnect.h" |
13 | | |
14 | | using namespace mozilla; |
15 | | using namespace mozilla::dom; |
16 | | |
17 | | CustomEvent::CustomEvent(mozilla::dom::EventTarget* aOwner, |
18 | | nsPresContext* aPresContext, |
19 | | mozilla::WidgetEvent* aEvent) |
20 | | : Event(aOwner, aPresContext, aEvent) |
21 | | , mDetail(JS::NullValue()) |
22 | 0 | { |
23 | 0 | mozilla::HoldJSObjects(this); |
24 | 0 | } |
25 | | |
26 | | CustomEvent::~CustomEvent() |
27 | 0 | { |
28 | 0 | mozilla::DropJSObjects(this); |
29 | 0 | } |
30 | | |
31 | | NS_IMPL_CYCLE_COLLECTION_CLASS(CustomEvent) |
32 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(CustomEvent, Event) |
33 | 0 | tmp->mDetail.setUndefined(); |
34 | 0 | mozilla::DropJSObjects(this); |
35 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK_END |
36 | | |
37 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(CustomEvent, Event) |
38 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END |
39 | | |
40 | 0 | NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(CustomEvent, Event) |
41 | 0 | NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mDetail) |
42 | 0 | NS_IMPL_CYCLE_COLLECTION_TRACE_END |
43 | | |
44 | | NS_IMPL_ADDREF_INHERITED(CustomEvent, Event) |
45 | | NS_IMPL_RELEASE_INHERITED(CustomEvent, Event) |
46 | | |
47 | 0 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CustomEvent) |
48 | 0 | NS_INTERFACE_MAP_END_INHERITING(Event) |
49 | | |
50 | | already_AddRefed<CustomEvent> |
51 | | CustomEvent::Constructor(const GlobalObject& aGlobal, |
52 | | const nsAString& aType, |
53 | | const CustomEventInit& aParam, |
54 | | ErrorResult& aRv) |
55 | 0 | { |
56 | 0 | nsCOMPtr<mozilla::dom::EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports()); |
57 | 0 | RefPtr<CustomEvent> e = new CustomEvent(t, nullptr, nullptr); |
58 | 0 | bool trusted = e->Init(t); |
59 | 0 | JS::Rooted<JS::Value> detail(aGlobal.Context(), aParam.mDetail); |
60 | 0 | e->InitCustomEvent(aGlobal.Context(), aType, aParam.mBubbles, aParam.mCancelable, detail); |
61 | 0 | e->SetTrusted(trusted); |
62 | 0 | e->SetComposed(aParam.mComposed); |
63 | 0 | return e.forget(); |
64 | 0 | } |
65 | | |
66 | | JSObject* |
67 | | CustomEvent::WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) |
68 | 0 | { |
69 | 0 | return mozilla::dom::CustomEvent_Binding::Wrap(aCx, this, aGivenProto); |
70 | 0 | } |
71 | | |
72 | | void |
73 | | CustomEvent::InitCustomEvent(JSContext* aCx, |
74 | | const nsAString& aType, |
75 | | bool aCanBubble, |
76 | | bool aCancelable, |
77 | | JS::Handle<JS::Value> aDetail) |
78 | 0 | { |
79 | 0 | NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched); |
80 | 0 |
|
81 | 0 | Event::InitEvent(aType, aCanBubble, aCancelable); |
82 | 0 | mDetail = aDetail; |
83 | 0 | } |
84 | | |
85 | | void |
86 | | CustomEvent::GetDetail(JSContext* aCx, |
87 | | JS::MutableHandle<JS::Value> aRetval) |
88 | 0 | { |
89 | 0 | aRetval.set(mDetail); |
90 | 0 | } |
91 | | |
92 | | already_AddRefed<CustomEvent> |
93 | | NS_NewDOMCustomEvent(EventTarget* aOwner, |
94 | | nsPresContext* aPresContext, |
95 | | mozilla::WidgetEvent* aEvent) |
96 | 0 | { |
97 | 0 | RefPtr<CustomEvent> it = |
98 | 0 | new CustomEvent(aOwner, aPresContext, aEvent); |
99 | 0 | return it.forget(); |
100 | 0 | } |