Bug 1673931 - Hide dependency on EventListenerManager from DOMEventTargetHelper.h. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D96551

Depends on D96550
This commit is contained in:
Simon Giesecke 2020-11-23 16:10:04 +00:00
parent 4e35a182cf
commit 49ca733d11
2 changed files with 72 additions and 49 deletions

View File

@ -7,13 +7,12 @@
#include "nsContentUtils.h"
#include "mozilla/dom/Document.h"
#include "mozilla/Sprintf.h"
#include "nsGlobalWindow.h"
#include "mozilla/dom/Event.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/DOMEventTargetHelper.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/EventListenerManager.h"
#include "mozilla/Likely.h"
#include "MainThreadUtils.h"
namespace mozilla {
@ -87,6 +86,42 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMEventTargetHelper)
NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE(DOMEventTargetHelper,
LastRelease())
DOMEventTargetHelper::DOMEventTargetHelper()
: mParentObject(nullptr),
mOwnerWindow(nullptr),
mHasOrHasHadOwnerWindow(false),
mIsKeptAlive(false) {}
DOMEventTargetHelper::DOMEventTargetHelper(nsPIDOMWindowInner* aWindow)
: mParentObject(nullptr),
mOwnerWindow(nullptr),
mHasOrHasHadOwnerWindow(false),
mIsKeptAlive(false) {
nsIGlobalObject* global = aWindow ? aWindow->AsGlobal() : nullptr;
BindToOwner(global);
}
DOMEventTargetHelper::DOMEventTargetHelper(nsIGlobalObject* aGlobalObject)
: mParentObject(nullptr),
mOwnerWindow(nullptr),
mHasOrHasHadOwnerWindow(false),
mIsKeptAlive(false) {
BindToOwner(aGlobalObject);
}
DOMEventTargetHelper::DOMEventTargetHelper(DOMEventTargetHelper* aOther)
: mParentObject(nullptr),
mOwnerWindow(nullptr),
mHasOrHasHadOwnerWindow(false),
mIsKeptAlive(false) {
if (!aOther) {
BindToOwner(static_cast<nsIGlobalObject*>(nullptr));
return;
}
BindToOwner(aOther->GetParentObject());
mHasOrHasHadOwnerWindow = aOther->HasOrHasHadOwner();
}
DOMEventTargetHelper::~DOMEventTargetHelper() {
if (mParentObject) {
mParentObject->RemoveEventTargetObject(this);
@ -310,4 +345,12 @@ nsresult DOMEventTargetHelper::CheckCurrentGlobalCorrectness() const {
return NS_OK;
}
bool DOMEventTargetHelper::HasListenersFor(const nsAString& aType) const {
return mListenerManager && mListenerManager->HasListenersFor(aType);
}
bool DOMEventTargetHelper::HasListenersFor(nsAtom* aTypeWithOn) const {
return mListenerManager && mListenerManager->HasListenersFor(aTypeWithOn);
}
} // namespace mozilla

View File

@ -7,21 +7,33 @@
#ifndef mozilla_DOMEventTargetHelper_h_
#define mozilla_DOMEventTargetHelper_h_
#include "nsCOMPtr.h"
#include "nsGkAtoms.h"
#include "nsCycleCollectionParticipant.h"
#include "nsPIDOMWindow.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptContext.h"
#include "MainThreadUtils.h"
#include "mozilla/Attributes.h"
#include "mozilla/EventListenerManager.h"
#include "mozilla/LinkedList.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/EventTarget.h"
#include "mozilla/LinkedList.h"
#include "mozilla/RefPtr.h"
#include "nsAtom.h"
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsDebug.h"
#include "nsGkAtoms.h"
#include "nsID.h"
#include "nsIGlobalObject.h"
#include "nsIScriptGlobalObject.h"
#include "nsISupports.h"
#include "nsISupportsUtils.h"
#include "nsPIDOMWindow.h"
#include "nsStringFwd.h"
#include "nsTArray.h"
class nsCycleCollectionTraversalCallback;
namespace mozilla {
class ErrorResult;
class EventChainPostVisitor;
class EventChainPreVisitor;
class EventListenerManager;
namespace dom {
class Document;
@ -38,38 +50,10 @@ class Event;
class DOMEventTargetHelper : public dom::EventTarget,
public LinkedListElement<DOMEventTargetHelper> {
public:
DOMEventTargetHelper()
: mParentObject(nullptr),
mOwnerWindow(nullptr),
mHasOrHasHadOwnerWindow(false),
mIsKeptAlive(false) {}
explicit DOMEventTargetHelper(nsPIDOMWindowInner* aWindow)
: mParentObject(nullptr),
mOwnerWindow(nullptr),
mHasOrHasHadOwnerWindow(false),
mIsKeptAlive(false) {
nsIGlobalObject* global = aWindow ? aWindow->AsGlobal() : nullptr;
BindToOwner(global);
}
explicit DOMEventTargetHelper(nsIGlobalObject* aGlobalObject)
: mParentObject(nullptr),
mOwnerWindow(nullptr),
mHasOrHasHadOwnerWindow(false),
mIsKeptAlive(false) {
BindToOwner(aGlobalObject);
}
explicit DOMEventTargetHelper(DOMEventTargetHelper* aOther)
: mParentObject(nullptr),
mOwnerWindow(nullptr),
mHasOrHasHadOwnerWindow(false),
mIsKeptAlive(false) {
if (!aOther) {
BindToOwner(static_cast<nsIGlobalObject*>(nullptr));
return;
}
BindToOwner(aOther->GetParentObject());
mHasOrHasHadOwnerWindow = aOther->HasOrHasHadOwner();
}
DOMEventTargetHelper();
explicit DOMEventTargetHelper(nsPIDOMWindowInner* aWindow);
explicit DOMEventTargetHelper(nsIGlobalObject* aGlobalObject);
explicit DOMEventTargetHelper(DOMEventTargetHelper* aOther);
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(DOMEventTargetHelper)
@ -113,13 +97,9 @@ class DOMEventTargetHelper : public dom::EventTarget,
return static_cast<DOMEventTargetHelper*>(target);
}
bool HasListenersFor(const nsAString& aType) const {
return mListenerManager && mListenerManager->HasListenersFor(aType);
}
bool HasListenersFor(const nsAString& aType) const;
bool HasListenersFor(nsAtom* aTypeWithOn) const {
return mListenerManager && mListenerManager->HasListenersFor(aTypeWithOn);
}
bool HasListenersFor(nsAtom* aTypeWithOn) const;
virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindingsInternal() override {
return nsPIDOMWindowOuter::GetFromCurrentInner(GetOwner());