From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- dom/events/InvokeEvent.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 dom/events/InvokeEvent.cpp (limited to 'dom/events/InvokeEvent.cpp') diff --git a/dom/events/InvokeEvent.cpp b/dom/events/InvokeEvent.cpp new file mode 100644 index 0000000000..4b7dc1e6da --- /dev/null +++ b/dom/events/InvokeEvent.cpp @@ -0,0 +1,58 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "mozilla/dom/InvokeEvent.h" +#include "mozilla/dom/EventTarget.h" +#include "mozilla/dom/InvokeEventBinding.h" +#include "nsContentUtils.h" + +namespace mozilla::dom { +NS_IMPL_CYCLE_COLLECTION_INHERITED(InvokeEvent, Event, mInvoker) + +NS_IMPL_ADDREF_INHERITED(InvokeEvent, Event) +NS_IMPL_RELEASE_INHERITED(InvokeEvent, Event) + +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(InvokeEvent) +NS_INTERFACE_MAP_END_INHERITING(Event) + +JSObject* InvokeEvent::WrapObjectInternal(JSContext* aCx, + JS::Handle aGivenProto) { + return InvokeEvent_Binding::Wrap(aCx, this, aGivenProto); +} + +already_AddRefed InvokeEvent::Constructor( + mozilla::dom::EventTarget* aOwner, const nsAString& aType, + const InvokeEventInit& aEventInitDict) { + RefPtr e = new InvokeEvent(aOwner); + bool trusted = e->Init(aOwner); + e->InitEvent(aType, aEventInitDict.mBubbles, aEventInitDict.mCancelable); + e->mInvoker = aEventInitDict.mInvoker; + e->mAction = aEventInitDict.mAction; + e->SetTrusted(trusted); + e->SetComposed(aEventInitDict.mComposed); + return e.forget(); +} + +already_AddRefed InvokeEvent::Constructor( + const GlobalObject& aGlobal, const nsAString& aType, + const InvokeEventInit& aEventInitDict) { + nsCOMPtr owner = + do_QueryInterface(aGlobal.GetAsSupports()); + return Constructor(owner, aType, aEventInitDict); +} + +Element* InvokeEvent::GetInvoker() { + EventTarget* currentTarget = GetCurrentTarget(); + if (currentTarget) { + nsINode* retargeted = nsContentUtils::Retarget( + static_cast(mInvoker), currentTarget->GetAsNode()); + return retargeted->AsElement(); + } + MOZ_ASSERT(!mEvent->mFlags.mIsBeingDispatched); + return mInvoker; +} + +} // namespace mozilla::dom -- cgit v1.2.3