2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-03-17 10:56:50 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_EventListenerService_h_
|
|
|
|
#define mozilla_EventListenerService_h_
|
|
|
|
|
|
|
|
#include "jsapi.h"
|
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsIDOMEventListener.h"
|
|
|
|
#include "nsIEventListenerService.h"
|
|
|
|
#include "nsString.h"
|
2015-04-28 23:10:05 +03:00
|
|
|
#include "nsTObserverArray.h"
|
|
|
|
#include "nsDataHashtable.h"
|
2015-07-17 18:07:37 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2015-04-28 23:10:05 +03:00
|
|
|
|
|
|
|
class nsIMutableArray;
|
2014-03-17 10:56:50 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2015-04-28 23:10:05 +03:00
|
|
|
namespace dom {
|
|
|
|
class EventTarget;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
2014-03-17 10:56:50 +04:00
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class Maybe;
|
|
|
|
|
2015-07-17 18:07:37 +03:00
|
|
|
class EventListenerChange final : public nsIEventListenerChange
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit EventListenerChange(dom::EventTarget* aTarget);
|
|
|
|
|
|
|
|
void AddChangedListenerName(nsIAtom* aEventName);
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIEVENTLISTENERCHANGE
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~EventListenerChange();
|
|
|
|
nsCOMPtr<dom::EventTarget> mTarget;
|
|
|
|
nsCOMPtr<nsIMutableArray> mChangedListenerNames;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class EventListenerInfo final : public nsIEventListenerInfo
|
2014-03-17 10:56:50 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
EventListenerInfo(const nsAString& aType,
|
|
|
|
already_AddRefed<nsIDOMEventListener> aListener,
|
|
|
|
bool aCapturing,
|
|
|
|
bool aAllowsUntrusted,
|
|
|
|
bool aInSystemEventGroup)
|
|
|
|
: mType(aType)
|
|
|
|
, mListener(aListener)
|
|
|
|
, mCapturing(aCapturing)
|
|
|
|
, mAllowsUntrusted(aAllowsUntrusted)
|
|
|
|
, mInSystemEventGroup(aInSystemEventGroup)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS(EventListenerInfo)
|
|
|
|
NS_DECL_NSIEVENTLISTENERINFO
|
|
|
|
|
|
|
|
protected:
|
2014-06-23 23:56:07 +04:00
|
|
|
virtual ~EventListenerInfo() {}
|
|
|
|
|
2014-03-17 10:56:50 +04:00
|
|
|
bool GetJSVal(JSContext* aCx,
|
|
|
|
Maybe<JSAutoCompartment>& aAc,
|
|
|
|
JS::MutableHandle<JS::Value> aJSVal);
|
|
|
|
|
|
|
|
nsString mType;
|
|
|
|
// nsReftPtr because that is what nsListenerStruct uses too.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsIDOMEventListener> mListener;
|
2014-03-17 10:56:50 +04:00
|
|
|
bool mCapturing;
|
|
|
|
bool mAllowsUntrusted;
|
|
|
|
bool mInSystemEventGroup;
|
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class EventListenerService final : public nsIEventListenerService
|
2014-03-17 10:56:50 +04:00
|
|
|
{
|
2015-04-28 23:10:05 +03:00
|
|
|
~EventListenerService();
|
2014-03-17 10:56:50 +04:00
|
|
|
public:
|
2015-04-28 23:10:05 +03:00
|
|
|
EventListenerService();
|
2014-03-17 10:56:50 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIEVENTLISTENERSERVICE
|
2015-04-28 23:10:05 +03:00
|
|
|
|
2015-07-17 18:07:37 +03:00
|
|
|
static void NotifyAboutMainThreadListenerChange(dom::EventTarget* aTarget,
|
|
|
|
nsIAtom* aName)
|
2015-04-28 23:10:05 +03:00
|
|
|
{
|
|
|
|
if (sInstance) {
|
2015-07-17 18:07:37 +03:00
|
|
|
sInstance->NotifyAboutMainThreadListenerChangeInternal(aTarget, aName);
|
2015-04-28 23:10:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NotifyPendingChanges();
|
|
|
|
private:
|
2015-07-17 18:07:37 +03:00
|
|
|
void NotifyAboutMainThreadListenerChangeInternal(dom::EventTarget* aTarget,
|
|
|
|
nsIAtom* aName);
|
2015-04-28 23:10:05 +03:00
|
|
|
nsTObserverArray<nsCOMPtr<nsIListenerChangeListener>> mChangeListeners;
|
|
|
|
nsCOMPtr<nsIMutableArray> mPendingListenerChanges;
|
2015-10-18 08:24:48 +03:00
|
|
|
nsDataHashtable<nsISupportsHashKey, RefPtr<EventListenerChange>> mPendingListenerChangesSet;
|
2015-04-28 23:10:05 +03:00
|
|
|
|
|
|
|
static EventListenerService* sInstance;
|
2014-03-17 10:56:50 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_EventListenerService_h_
|