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/. */
7 #include "mozilla/dom/InvokeEvent.h"
8 #include "mozilla/dom/EventTarget.h"
9 #include "mozilla/dom/InvokeEventBinding.h"
10 #include "nsContentUtils.h"
12 namespace mozilla::dom
{
13 NS_IMPL_CYCLE_COLLECTION_INHERITED(InvokeEvent
, Event
, mInvoker
)
15 NS_IMPL_ADDREF_INHERITED(InvokeEvent
, Event
)
16 NS_IMPL_RELEASE_INHERITED(InvokeEvent
, Event
)
18 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(InvokeEvent
)
19 NS_INTERFACE_MAP_END_INHERITING(Event
)
21 JSObject
* InvokeEvent::WrapObjectInternal(JSContext
* aCx
,
22 JS::Handle
<JSObject
*> aGivenProto
) {
23 return InvokeEvent_Binding::Wrap(aCx
, this, aGivenProto
);
26 already_AddRefed
<InvokeEvent
> InvokeEvent::Constructor(
27 mozilla::dom::EventTarget
* aOwner
, const nsAString
& aType
,
28 const InvokeEventInit
& aEventInitDict
) {
29 RefPtr
<InvokeEvent
> e
= new InvokeEvent(aOwner
);
30 bool trusted
= e
->Init(aOwner
);
31 e
->InitEvent(aType
, aEventInitDict
.mBubbles
, aEventInitDict
.mCancelable
);
32 e
->mInvoker
= aEventInitDict
.mInvoker
;
33 e
->mAction
= aEventInitDict
.mAction
;
34 e
->SetTrusted(trusted
);
35 e
->SetComposed(aEventInitDict
.mComposed
);
39 already_AddRefed
<InvokeEvent
> InvokeEvent::Constructor(
40 const GlobalObject
& aGlobal
, const nsAString
& aType
,
41 const InvokeEventInit
& aEventInitDict
) {
42 nsCOMPtr
<mozilla::dom::EventTarget
> owner
=
43 do_QueryInterface(aGlobal
.GetAsSupports());
44 return Constructor(owner
, aType
, aEventInitDict
);
47 Element
* InvokeEvent::GetInvoker() {
48 EventTarget
* currentTarget
= GetCurrentTarget();
50 nsINode
* currentTargetNode
= currentTarget
->GetAsNode();
51 if (!currentTargetNode
) {
54 nsINode
* retargeted
= nsContentUtils::Retarget(
55 static_cast<nsINode
*>(mInvoker
), currentTargetNode
);
56 return retargeted
? retargeted
->AsElement() : nullptr;
58 MOZ_ASSERT(!mEvent
->mFlags
.mIsBeingDispatched
);
62 } // namespace mozilla::dom