Bug 915757: Split GetListenerManager into two functions for more const-correctness. r=smaug

This commit is contained in:
Kyle Huey 2013-09-16 09:06:02 +08:00
Родитель 6ada2899b2
Коммит 5186395798
38 изменённых файлов: 207 добавлений и 153 удалений

Просмотреть файл

@ -329,7 +329,7 @@ DocManager::AddListeners(nsIDocument* aDocument,
{ {
nsPIDOMWindow* window = aDocument->GetWindow(); nsPIDOMWindow* window = aDocument->GetWindow();
EventTarget* target = window->GetChromeEventHandler(); EventTarget* target = window->GetChromeEventHandler();
nsEventListenerManager* elm = target->GetListenerManager(true); nsEventListenerManager* elm = target->ListenerManager();
elm->AddEventListenerByType(this, NS_LITERAL_STRING("pagehide"), elm->AddEventListenerByType(this, NS_LITERAL_STRING("pagehide"),
dom::TrustedEventsAtCapture()); dom::TrustedEventsAtCapture());
@ -359,7 +359,7 @@ DocManager::RemoveListeners(nsIDocument* aDocument)
if (!target) if (!target)
return; return;
nsEventListenerManager* elm = target->GetListenerManager(true); nsEventListenerManager* elm = target->ListenerManager();
elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("pagehide"), elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("pagehide"),
dom::TrustedEventsAtCapture()); dom::TrustedEventsAtCapture());

Просмотреть файл

@ -45,7 +45,7 @@ nsCoreUtils::HasClickListener(nsIContent *aContent)
{ {
NS_ENSURE_TRUE(aContent, false); NS_ENSURE_TRUE(aContent, false);
nsEventListenerManager* listenerManager = nsEventListenerManager* listenerManager =
aContent->GetListenerManager(false); aContent->GetExistingListenerManager();
return listenerManager && return listenerManager &&
(listenerManager->HasListenersFor(nsGkAtoms::onclick) || (listenerManager->HasListenersFor(nsGkAtoms::onclick) ||

Просмотреть файл

@ -1054,15 +1054,19 @@ public:
nsCycleCollectionTraversalCallback &cb); nsCycleCollectionTraversalCallback &cb);
/** /**
* Get the eventlistener manager for aNode. If a new eventlistener manager * Get the eventlistener manager for aNode, creating it if it does not
* was created, aCreated is set to true. * already exist.
* *
* @param aNode The node for which to get the eventlistener manager. * @param aNode The node for which to get the eventlistener manager.
* @param aCreateIfNotFound If false, returns a listener manager only if
* one already exists.
*/ */
static nsEventListenerManager* GetListenerManager(nsINode* aNode, static nsEventListenerManager* ListenerManagerForNode(nsINode* aNode);
bool aCreateIfNotFound); /**
* Get the eventlistener manager for aNode, returning null if it does not
* already exist.
*
* @param aNode The node for which to get the eventlistener manager.
*/
static nsEventListenerManager* GetExistingListenerManagerForNode(const nsINode* aNode);
static void UnmarkGrayJSListenersInCCGenerationDocuments(uint32_t aGeneration); static void UnmarkGrayJSListenersInCCGenerationDocuments(uint32_t aGeneration);

Просмотреть файл

@ -798,7 +798,7 @@ public:
/** /**
* See nsIDOMEventTarget * See nsIDOMEventTarget
*/ */
NS_DECL_NSIDOMEVENTTARGET NS_REALLY_DECL_NSIDOMEVENTTARGET
using mozilla::dom::EventTarget::RemoveEventListener; using mozilla::dom::EventTarget::RemoveEventListener;
using nsIDOMEventTarget::AddEventListener; using nsIDOMEventTarget::AddEventListener;
virtual void AddEventListener(const nsAString& aType, virtual void AddEventListener(const nsAString& aType,

Просмотреть файл

@ -1777,7 +1777,7 @@ Element::GetEventListenerManagerForAttr(nsIAtom* aAttrName,
bool* aDefer) bool* aDefer)
{ {
*aDefer = true; *aDefer = true;
return GetListenerManager(true); return ListenerManager();
} }
Element::nsAttrInfo Element::nsAttrInfo

Просмотреть файл

@ -1225,7 +1225,7 @@ FragmentOrElement::MarkNodeChildren(nsINode* aNode)
JS::ExposeObjectToActiveJS(o); JS::ExposeObjectToActiveJS(o);
} }
nsEventListenerManager* elm = aNode->GetListenerManager(false); nsEventListenerManager* elm = aNode->GetExistingListenerManager();
if (elm) { if (elm) {
elm->MarkForCC(); elm->MarkForCC();
} }

Просмотреть файл

@ -144,7 +144,7 @@ MarkMessageManagers()
continue; continue;
} }
static_cast<nsInProcessTabChildGlobal*>(et)->MarkForCC(); static_cast<nsInProcessTabChildGlobal*>(et)->MarkForCC();
nsEventListenerManager* elm = et->GetListenerManager(false); nsEventListenerManager* elm = et->GetExistingListenerManager();
if (elm) { if (elm) {
elm->MarkForCC(); elm->MarkForCC();
} }
@ -188,13 +188,13 @@ MarkContentViewer(nsIContentViewer* aViewer, bool aCleanupJS,
doc->GetMarkedCCGeneration() != nsCCUncollectableMarker::sGeneration) { doc->GetMarkedCCGeneration() != nsCCUncollectableMarker::sGeneration) {
doc->MarkUncollectableForCCGeneration(nsCCUncollectableMarker::sGeneration); doc->MarkUncollectableForCCGeneration(nsCCUncollectableMarker::sGeneration);
if (aCleanupJS) { if (aCleanupJS) {
nsEventListenerManager* elm = doc->GetListenerManager(false); nsEventListenerManager* elm = doc->GetExistingListenerManager();
if (elm) { if (elm) {
elm->MarkForCC(); elm->MarkForCC();
} }
nsCOMPtr<EventTarget> win = do_QueryInterface(doc->GetInnerWindow()); nsCOMPtr<EventTarget> win = do_QueryInterface(doc->GetInnerWindow());
if (win) { if (win) {
elm = win->GetListenerManager(false); elm = win->GetExistingListenerManager();
if (elm) { if (elm) {
elm->MarkForCC(); elm->MarkForCC();
} }

Просмотреть файл

@ -3617,7 +3617,7 @@ nsContentUtils::HasMutationListeners(nsINode* aNode,
if (aNode->IsInDoc()) { if (aNode->IsInDoc()) {
nsCOMPtr<EventTarget> piTarget(do_QueryInterface(window)); nsCOMPtr<EventTarget> piTarget(do_QueryInterface(window));
if (piTarget) { if (piTarget) {
nsEventListenerManager* manager = piTarget->GetListenerManager(false); nsEventListenerManager* manager = piTarget->GetExistingListenerManager();
if (manager && manager->HasMutationListeners()) { if (manager && manager->HasMutationListeners()) {
return true; return true;
} }
@ -3628,7 +3628,7 @@ nsContentUtils::HasMutationListeners(nsINode* aNode,
// might not be in our chain. If we don't have a window, we might have a // might not be in our chain. If we don't have a window, we might have a
// mutation listener. Check quickly to see. // mutation listener. Check quickly to see.
while (aNode) { while (aNode) {
nsEventListenerManager* manager = aNode->GetListenerManager(false); nsEventListenerManager* manager = aNode->GetExistingListenerManager();
if (manager && manager->HasMutationListeners()) { if (manager && manager->HasMutationListeners()) {
return true; return true;
} }
@ -3750,13 +3750,8 @@ nsContentUtils::TraverseListenerManager(nsINode *aNode,
} }
nsEventListenerManager* nsEventListenerManager*
nsContentUtils::GetListenerManager(nsINode *aNode, nsContentUtils::ListenerManagerForNode(nsINode *aNode)
bool aCreateIfNotFound)
{ {
if (!aCreateIfNotFound && !aNode->HasFlag(NODE_HAS_LISTENERMANAGER)) {
return nullptr;
}
if (!sEventListenerManagersHash.ops) { if (!sEventListenerManagersHash.ops) {
// We're already shut down, don't bother creating an event listener // We're already shut down, don't bother creating an event listener
// manager. // manager.
@ -3764,17 +3759,6 @@ nsContentUtils::GetListenerManager(nsINode *aNode,
return nullptr; return nullptr;
} }
if (!aCreateIfNotFound) {
EventListenerManagerMapEntry *entry =
static_cast<EventListenerManagerMapEntry *>
(PL_DHashTableOperate(&sEventListenerManagersHash, aNode,
PL_DHASH_LOOKUP));
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
return entry->mListenerManager;
}
return nullptr;
}
EventListenerManagerMapEntry *entry = EventListenerManagerMapEntry *entry =
static_cast<EventListenerManagerMapEntry *> static_cast<EventListenerManagerMapEntry *>
(PL_DHashTableOperate(&sEventListenerManagersHash, aNode, (PL_DHashTableOperate(&sEventListenerManagersHash, aNode,
@ -3793,6 +3777,31 @@ nsContentUtils::GetListenerManager(nsINode *aNode,
return entry->mListenerManager; return entry->mListenerManager;
} }
nsEventListenerManager*
nsContentUtils::GetExistingListenerManagerForNode(const nsINode *aNode)
{
if (!aNode->HasFlag(NODE_HAS_LISTENERMANAGER)) {
return nullptr;
}
if (!sEventListenerManagersHash.ops) {
// We're already shut down, don't bother creating an event listener
// manager.
return nullptr;
}
EventListenerManagerMapEntry *entry =
static_cast<EventListenerManagerMapEntry *>
(PL_DHashTableOperate(&sEventListenerManagersHash, aNode,
PL_DHASH_LOOKUP));
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
return entry->mListenerManager;
}
return nullptr;
}
/* static */ /* static */
void void
nsContentUtils::RemoveListenerManager(nsINode *aNode) nsContentUtils::RemoveListenerManager(nsINode *aNode)

Просмотреть файл

@ -1614,7 +1614,7 @@ nsDocument::DeleteCycleCollectable()
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsDocument) NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsDocument)
if (Element::CanSkip(tmp, aRemovingAllowed)) { if (Element::CanSkip(tmp, aRemovingAllowed)) {
nsEventListenerManager* elm = tmp->GetListenerManager(false); nsEventListenerManager* elm = tmp->GetExistingListenerManager();
if (elm) { if (elm) {
elm->MarkForCC(); elm->MarkForCC();
} }
@ -6926,9 +6926,9 @@ nsDocument::GetViewportInfo(const ScreenIntSize& aDisplaySize)
} }
nsEventListenerManager* nsEventListenerManager*
nsDocument::GetListenerManager(bool aCreateIfNotFound) nsDocument::ListenerManager()
{ {
if (!mListenerManager && aCreateIfNotFound) { if (!mListenerManager) {
mListenerManager = mListenerManager =
new nsEventListenerManager(static_cast<EventTarget*>(this)); new nsEventListenerManager(static_cast<EventTarget*>(this));
SetFlags(NODE_HAS_LISTENERMANAGER); SetFlags(NODE_HAS_LISTENERMANAGER);
@ -6937,6 +6937,12 @@ nsDocument::GetListenerManager(bool aCreateIfNotFound)
return mListenerManager; return mListenerManager;
} }
nsEventListenerManager*
nsDocument::GetExistingListenerManager() const
{
return mListenerManager;
}
nsresult nsresult
nsDocument::PreHandleEvent(nsEventChainPreVisitor& aVisitor) nsDocument::PreHandleEvent(nsEventChainPreVisitor& aVisitor)
{ {
@ -7630,8 +7636,7 @@ nsDocument::CanSavePresentation(nsIRequest *aNewRequest)
// Check our event listener manager for unload/beforeunload listeners. // Check our event listener manager for unload/beforeunload listeners.
nsCOMPtr<EventTarget> piTarget = do_QueryInterface(mScriptGlobalObject); nsCOMPtr<EventTarget> piTarget = do_QueryInterface(mScriptGlobalObject);
if (piTarget) { if (piTarget) {
nsEventListenerManager* manager = nsEventListenerManager* manager = piTarget->GetExistingListenerManager();
piTarget->GetListenerManager(false);
if (manager && manager->HasUnloadListeners()) { if (manager && manager->HasUnloadListeners()) {
return false; return false;
} }

Просмотреть файл

@ -774,8 +774,8 @@ public:
// nsIDOMEventTarget // nsIDOMEventTarget
virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor) MOZ_OVERRIDE; virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor) MOZ_OVERRIDE;
virtual nsEventListenerManager* virtual nsEventListenerManager* ListenerManager() MOZ_OVERRIDE;
GetListenerManager(bool aCreateIfNotFound) MOZ_OVERRIDE; virtual nsEventListenerManager* GetExistingListenerManager() const MOZ_OVERRIDE;
// nsIScriptObjectPrincipal // nsIScriptObjectPrincipal
virtual nsIPrincipal* GetPrincipal() MOZ_OVERRIDE; virtual nsIPrincipal* GetPrincipal() MOZ_OVERRIDE;

Просмотреть файл

@ -1039,7 +1039,7 @@ nsINode::AddEventListener(const nsAString& aType,
aWantsUntrusted = true; aWantsUntrusted = true;
} }
nsEventListenerManager* listener_manager = GetListenerManager(true); nsEventListenerManager* listener_manager = ListenerManager();
NS_ENSURE_STATE(listener_manager); NS_ENSURE_STATE(listener_manager);
listener_manager->AddEventListener(aType, aListener, aUseCapture, listener_manager->AddEventListener(aType, aListener, aUseCapture,
aWantsUntrusted); aWantsUntrusted);
@ -1060,7 +1060,7 @@ nsINode::AddEventListener(const nsAString& aType,
wantsUntrusted = aWantsUntrusted.Value(); wantsUntrusted = aWantsUntrusted.Value();
} }
nsEventListenerManager* listener_manager = GetListenerManager(true); nsEventListenerManager* listener_manager = ListenerManager();
if (!listener_manager) { if (!listener_manager) {
aRv.Throw(NS_ERROR_UNEXPECTED); aRv.Throw(NS_ERROR_UNEXPECTED);
return; return;
@ -1096,7 +1096,7 @@ nsINode::RemoveEventListener(const nsAString& aType,
nsIDOMEventListener* aListener, nsIDOMEventListener* aListener,
bool aUseCapture) bool aUseCapture)
{ {
nsEventListenerManager* elm = GetListenerManager(false); nsEventListenerManager* elm = GetExistingListenerManager();
if (elm) { if (elm) {
elm->RemoveEventListener(aType, aListener, aUseCapture); elm->RemoveEventListener(aType, aListener, aUseCapture);
} }
@ -1158,9 +1158,15 @@ nsINode::DispatchDOMEvent(nsEvent* aEvent,
} }
nsEventListenerManager* nsEventListenerManager*
nsINode::GetListenerManager(bool aCreateIfNotFound) nsINode::ListenerManager()
{ {
return nsContentUtils::GetListenerManager(this, aCreateIfNotFound); return nsContentUtils::ListenerManagerForNode(this);
}
nsEventListenerManager*
nsINode::GetExistingListenerManager() const
{
return nsContentUtils::GetExistingListenerManagerForNode(this);
} }
nsIScriptContext* nsIScriptContext*
@ -2165,8 +2171,7 @@ size_t
nsINode::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const nsINode::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
{ {
size_t n = 0; size_t n = 0;
nsEventListenerManager* elm = nsEventListenerManager* elm = GetExistingListenerManager();
const_cast<nsINode*>(this)->GetListenerManager(false);
if (elm) { if (elm) {
n += elm->SizeOfIncludingThis(aMallocSizeOf); n += elm->SizeOfIncludingThis(aMallocSizeOf);
} }
@ -2184,13 +2189,13 @@ nsINode::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
#define EVENT(name_, id_, type_, struct_) \ #define EVENT(name_, id_, type_, struct_) \
EventHandlerNonNull* nsINode::GetOn##name_() { \ EventHandlerNonNull* nsINode::GetOn##name_() { \
nsEventListenerManager *elm = GetListenerManager(false); \ nsEventListenerManager *elm = GetExistingListenerManager(); \
return elm ? elm->GetEventHandler(nsGkAtoms::on##name_, EmptyString()) \ return elm ? elm->GetEventHandler(nsGkAtoms::on##name_, EmptyString()) \
: nullptr; \ : nullptr; \
} \ } \
void nsINode::SetOn##name_(EventHandlerNonNull* handler, \ void nsINode::SetOn##name_(EventHandlerNonNull* handler, \
ErrorResult& error) { \ ErrorResult& error) { \
nsEventListenerManager *elm = GetListenerManager(true); \ nsEventListenerManager *elm = ListenerManager(); \
if (elm) { \ if (elm) { \
error = elm->SetEventHandler(nsGkAtoms::on##name_, \ error = elm->SetEventHandler(nsGkAtoms::on##name_, \
EmptyString(), handler); \ EmptyString(), handler); \

Просмотреть файл

@ -231,7 +231,7 @@ nsNodeUtils::LastRelease(nsINode* aNode)
#ifdef DEBUG #ifdef DEBUG
if (nsContentUtils::IsInitialized()) { if (nsContentUtils::IsInitialized()) {
nsEventListenerManager* manager = nsEventListenerManager* manager =
nsContentUtils::GetListenerManager(aNode, false); nsContentUtils::GetExistingListenerManagerForNode(aNode);
if (!manager) { if (!manager) {
NS_ERROR("Huh, our bit says we have a listener manager list, " NS_ERROR("Huh, our bit says we have a listener manager list, "
"but there's nothing in the hash!?!!"); "but there's nothing in the hash!?!!");
@ -480,7 +480,7 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, bool aClone, bool aDeep,
nsPIDOMWindow* window = newDoc->GetInnerWindow(); nsPIDOMWindow* window = newDoc->GetInnerWindow();
if (window) { if (window) {
nsEventListenerManager* elm = aNode->GetListenerManager(false); nsEventListenerManager* elm = aNode->GetExistingListenerManager();
if (elm) { if (elm) {
window->SetMutationListeners(elm->MutationListenerBits()); window->SetMutationListeners(elm->MutationListenerBits());
if (elm->MayHavePaintEventListener()) { if (elm->MayHavePaintEventListener()) {

Просмотреть файл

@ -2173,7 +2173,7 @@ nsXMLHttpRequest::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult
NS_ASSERTION(!(mState & XML_HTTP_REQUEST_SYNCLOOPING), NS_ASSERTION(!(mState & XML_HTTP_REQUEST_SYNCLOOPING),
"We weren't supposed to support HTML parsing with XHR!"); "We weren't supposed to support HTML parsing with XHR!");
nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(mResponseXML); nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(mResponseXML);
nsEventListenerManager* manager = eventTarget->GetListenerManager(true); nsEventListenerManager* manager = eventTarget->ListenerManager();
manager->AddEventListenerByType(new nsXHRParseEndListener(this), manager->AddEventListenerByType(new nsXHRParseEndListener(this),
NS_LITERAL_STRING("DOMContentLoaded"), NS_LITERAL_STRING("DOMContentLoaded"),
dom::TrustedEventsAtSystemGroupBubble()); dom::TrustedEventsAtSystemGroupBubble());

Просмотреть файл

@ -16,7 +16,7 @@ EventTarget::RemoveEventListener(const nsAString& aType,
bool aUseCapture, bool aUseCapture,
ErrorResult& aRv) ErrorResult& aRv)
{ {
nsEventListenerManager* elm = GetListenerManager(false); nsEventListenerManager* elm = GetExistingListenerManager();
if (elm) { if (elm) {
elm->RemoveEventListener(aType, aListener, aUseCapture); elm->RemoveEventListener(aType, aListener, aUseCapture);
} }
@ -25,7 +25,7 @@ EventTarget::RemoveEventListener(const nsAString& aType,
EventHandlerNonNull* EventHandlerNonNull*
EventTarget::GetEventHandler(nsIAtom* aType, const nsAString& aTypeString) EventTarget::GetEventHandler(nsIAtom* aType, const nsAString& aTypeString)
{ {
nsEventListenerManager* elm = GetListenerManager(false); nsEventListenerManager* elm = GetExistingListenerManager();
return elm ? elm->GetEventHandler(aType, aTypeString) : nullptr; return elm ? elm->GetEventHandler(aType, aTypeString) : nullptr;
} }
@ -48,9 +48,7 @@ EventTarget::SetEventHandler(nsIAtom* aType, const nsAString& aTypeString,
EventHandlerNonNull* aHandler, EventHandlerNonNull* aHandler,
ErrorResult& rv) ErrorResult& rv)
{ {
rv = GetListenerManager(true)->SetEventHandler(aType, rv = ListenerManager()->SetEventHandler(aType, aTypeString, aHandler);
aTypeString,
aHandler);
} }
} // namespace dom } // namespace dom

Просмотреть файл

@ -154,7 +154,7 @@ nsDOMEventTargetHelper::RemoveEventListener(const nsAString& aType,
nsIDOMEventListener* aListener, nsIDOMEventListener* aListener,
bool aUseCapture) bool aUseCapture)
{ {
nsEventListenerManager* elm = GetListenerManager(false); nsEventListenerManager* elm = GetExistingListenerManager();
if (elm) { if (elm) {
elm->RemoveEventListener(aType, aListener, aUseCapture); elm->RemoveEventListener(aType, aListener, aUseCapture);
} }
@ -181,7 +181,7 @@ nsDOMEventTargetHelper::AddEventListener(const nsAString& aType,
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} }
nsEventListenerManager* elm = GetListenerManager(true); nsEventListenerManager* elm = ListenerManager();
NS_ENSURE_STATE(elm); NS_ENSURE_STATE(elm);
elm->AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted); elm->AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted);
return NS_OK; return NS_OK;
@ -205,7 +205,7 @@ nsDOMEventTargetHelper::AddEventListener(const nsAString& aType,
wantsUntrusted = aWantsUntrusted.Value(); wantsUntrusted = aWantsUntrusted.Value();
} }
nsEventListenerManager* elm = GetListenerManager(true); nsEventListenerManager* elm = ListenerManager();
if (!elm) { if (!elm) {
aRv.Throw(NS_ERROR_UNEXPECTED); aRv.Throw(NS_ERROR_UNEXPECTED);
return; return;
@ -320,15 +320,21 @@ nsDOMEventTargetHelper::DispatchDOMEvent(nsEvent* aEvent,
} }
nsEventListenerManager* nsEventListenerManager*
nsDOMEventTargetHelper::GetListenerManager(bool aCreateIfNotFound) nsDOMEventTargetHelper::ListenerManager()
{ {
if (!mListenerManager && aCreateIfNotFound) { if (!mListenerManager) {
mListenerManager = new nsEventListenerManager(this); mListenerManager = new nsEventListenerManager(this);
} }
return mListenerManager; return mListenerManager;
} }
nsEventListenerManager*
nsDOMEventTargetHelper::GetExistingListenerManager() const
{
return mListenerManager;
}
nsIScriptContext* nsIScriptContext*
nsDOMEventTargetHelper::GetContextForEventHandlers(nsresult* aRv) nsDOMEventTargetHelper::GetContextForEventHandlers(nsresult* aRv)
{ {

Просмотреть файл

@ -43,7 +43,7 @@ public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(nsDOMEventTargetHelper) NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(nsDOMEventTargetHelper)
NS_DECL_NSIDOMEVENTTARGET NS_REALLY_DECL_NSIDOMEVENTTARGET
using mozilla::dom::EventTarget::RemoveEventListener; using mozilla::dom::EventTarget::RemoveEventListener;
virtual void AddEventListener(const nsAString& aType, virtual void AddEventListener(const nsAString& aType,
nsIDOMEventListener* aListener, nsIDOMEventListener* aListener,
@ -222,8 +222,11 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsDOMEventTargetHelper,
virtual nsresult DispatchDOMEvent(nsEvent *aEvent, nsIDOMEvent *aDOMEvent, nsPresContext *aPresContext, nsEventStatus *aEventStatus) { \ virtual nsresult DispatchDOMEvent(nsEvent *aEvent, nsIDOMEvent *aDOMEvent, nsPresContext *aPresContext, nsEventStatus *aEventStatus) { \
return _to DispatchDOMEvent(aEvent, aDOMEvent, aPresContext, aEventStatus); \ return _to DispatchDOMEvent(aEvent, aDOMEvent, aPresContext, aEventStatus); \
} \ } \
virtual nsEventListenerManager * GetListenerManager(bool aMayCreate) { \ virtual nsEventListenerManager * ListenerManager() { \
return _to GetListenerManager(aMayCreate); \ return _to ListenerManager(); \
} \
virtual nsEventListenerManager * GetExistingListenerManager() const { \
return _to GetExistingListenerManager(); \
} \ } \
virtual nsIScriptContext * GetContextForEventHandlers(nsresult *aRv) { \ virtual nsIScriptContext * GetContextForEventHandlers(nsresult *aRv) { \
return _to GetContextForEventHandlers(aRv); \ return _to GetContextForEventHandlers(aRv); \
@ -235,6 +238,14 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsDOMEventTargetHelper,
#define NS_REALLY_FORWARD_NSIDOMEVENTTARGET(_class) \ #define NS_REALLY_FORWARD_NSIDOMEVENTTARGET(_class) \
using _class::AddEventListener; \ using _class::AddEventListener; \
using _class::RemoveEventListener; \ using _class::RemoveEventListener; \
NS_FORWARD_NSIDOMEVENTTARGET(_class::) NS_FORWARD_NSIDOMEVENTTARGET(_class::) \
virtual nsEventListenerManager* \
ListenerManager() { \
return _class::ListenerManager(); \
} \
virtual nsEventListenerManager* \
GetExistingListenerManager() const { \
return _class::GetExistingListenerManager(); \
}
#endif // nsDOMEventTargetHelper_h_ #endif // nsDOMEventTargetHelper_h_

Просмотреть файл

@ -178,8 +178,7 @@ public:
if (!MayHaveListenerManager() && !aCd.MayHaveNewListenerManager()) { if (!MayHaveListenerManager() && !aCd.MayHaveNewListenerManager()) {
return NS_OK; return NS_OK;
} }
mManager = mManager = mTarget->GetExistingListenerManager();
static_cast<nsEventListenerManager*>(mTarget->GetListenerManager(false));
} }
if (mManager) { if (mManager) {
NS_ASSERTION(aVisitor.mEvent->currentTarget == nullptr, NS_ASSERTION(aVisitor.mEvent->currentTarget == nullptr,

Просмотреть файл

@ -561,7 +561,7 @@ NS_AddSystemEventListener(mozilla::dom::EventTarget* aTarget,
bool aUseCapture, bool aUseCapture,
bool aWantsUntrusted) bool aWantsUntrusted)
{ {
nsEventListenerManager* listenerManager = aTarget->GetListenerManager(true); nsEventListenerManager* listenerManager = aTarget->ListenerManager();
NS_ENSURE_STATE(listenerManager); NS_ENSURE_STATE(listenerManager);
mozilla::dom::EventListenerFlags flags; mozilla::dom::EventListenerFlags flags;
flags.mInSystemGroup = true; flags.mInSystemGroup = true;

Просмотреть файл

@ -161,8 +161,7 @@ nsEventListenerService::GetListenerInfoFor(nsIDOMEventTarget* aEventTarget,
*aCount = 0; *aCount = 0;
*aOutArray = nullptr; *aOutArray = nullptr;
nsCOMArray<nsIEventListenerInfo> listenerInfos; nsCOMArray<nsIEventListenerInfo> listenerInfos;
nsEventListenerManager* elm = nsEventListenerManager* elm = aEventTarget->GetExistingListenerManager();
aEventTarget->GetListenerManager(false);
if (elm) { if (elm) {
elm->GetListenerInfo(&listenerInfos); elm->GetListenerInfo(&listenerInfos);
} }
@ -220,7 +219,7 @@ nsEventListenerService::HasListenersFor(nsIDOMEventTarget* aEventTarget,
const nsAString& aType, const nsAString& aType,
bool* aRetVal) bool* aRetVal)
{ {
nsEventListenerManager* elm = aEventTarget->GetListenerManager(false); nsEventListenerManager* elm = aEventTarget->GetExistingListenerManager();
*aRetVal = elm && elm->HasListenersFor(aType); *aRetVal = elm && elm->HasListenersFor(aType);
return NS_OK; return NS_OK;
} }
@ -234,7 +233,7 @@ nsEventListenerService::AddSystemEventListener(nsIDOMEventTarget *aTarget,
NS_PRECONDITION(aTarget, "Missing target"); NS_PRECONDITION(aTarget, "Missing target");
NS_PRECONDITION(aListener, "Missing listener"); NS_PRECONDITION(aListener, "Missing listener");
nsEventListenerManager* manager = aTarget->GetListenerManager(true); nsEventListenerManager* manager = aTarget->ListenerManager();
NS_ENSURE_STATE(manager); NS_ENSURE_STATE(manager);
EventListenerFlags flags = EventListenerFlags flags =
@ -253,7 +252,7 @@ nsEventListenerService::RemoveSystemEventListener(nsIDOMEventTarget *aTarget,
NS_PRECONDITION(aTarget, "Missing target"); NS_PRECONDITION(aTarget, "Missing target");
NS_PRECONDITION(aListener, "Missing listener"); NS_PRECONDITION(aListener, "Missing listener");
nsEventListenerManager* manager = aTarget->GetListenerManager(false); nsEventListenerManager* manager = aTarget->GetExistingListenerManager();
if (manager) { if (manager) {
EventListenerFlags flags = EventListenerFlags flags =
aUseCapture ? TrustedEventsAtSystemGroupCapture() : aUseCapture ? TrustedEventsAtSystemGroupCapture() :
@ -272,7 +271,7 @@ nsEventListenerService::AddListenerForAllEvents(nsIDOMEventTarget* aTarget,
bool aSystemEventGroup) bool aSystemEventGroup)
{ {
NS_ENSURE_STATE(aTarget && aListener); NS_ENSURE_STATE(aTarget && aListener);
nsEventListenerManager* manager = aTarget->GetListenerManager(true); nsEventListenerManager* manager = aTarget->ListenerManager();
NS_ENSURE_STATE(manager); NS_ENSURE_STATE(manager);
manager->AddListenerForAllEvents(aListener, aUseCapture, aWantsUntrusted, manager->AddListenerForAllEvents(aListener, aUseCapture, aWantsUntrusted,
aSystemEventGroup); aSystemEventGroup);
@ -286,7 +285,7 @@ nsEventListenerService::RemoveListenerForAllEvents(nsIDOMEventTarget* aTarget,
bool aSystemEventGroup) bool aSystemEventGroup)
{ {
NS_ENSURE_STATE(aTarget && aListener); NS_ENSURE_STATE(aTarget && aListener);
nsEventListenerManager* manager = aTarget->GetListenerManager(false); nsEventListenerManager* manager = aTarget->GetExistingListenerManager();
if (manager) { if (manager) {
manager->RemoveListenerForAllEvents(aListener, aUseCapture, aSystemEventGroup); manager->RemoveListenerForAllEvents(aListener, aUseCapture, aSystemEventGroup);
} }

Просмотреть файл

@ -839,7 +839,7 @@ nsGenericHTMLElement::GetEventListenerManagerForAttr(nsIAtom* aAttrName,
if ((win = document->GetInnerWindow())) { if ((win = document->GetInnerWindow())) {
nsCOMPtr<EventTarget> piTarget(do_QueryInterface(win)); nsCOMPtr<EventTarget> piTarget(do_QueryInterface(win));
return piTarget->GetListenerManager(true); return piTarget->ListenerManager();
} }
return nullptr; return nullptr;
@ -1008,8 +1008,7 @@ nsGenericHTMLElement::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
UnsetFlags(NODE_HAS_ACCESSKEY); UnsetFlags(NODE_HAS_ACCESSKEY);
} }
else if (IsEventAttributeName(aAttribute)) { else if (IsEventAttributeName(aAttribute)) {
nsEventListenerManager* manager = GetListenerManager(false); if (nsEventListenerManager* manager = GetExistingListenerManager()) {
if (manager) {
manager->RemoveEventHandler(aAttribute, EmptyString()); manager->RemoveEventHandler(aAttribute, EmptyString());
} }
} }

Просмотреть файл

@ -1560,8 +1560,7 @@ nsTextEditorState::UnbindFromFrame(nsTextControlFrame* aFrame)
mTextListener->SetFrame(nullptr); mTextListener->SetFrame(nullptr);
nsCOMPtr<EventTarget> target = do_QueryInterface(mTextCtrlElement); nsCOMPtr<EventTarget> target = do_QueryInterface(mTextCtrlElement);
nsEventListenerManager* manager = nsEventListenerManager* manager = target->GetExistingListenerManager();
target->GetListenerManager(false);
if (manager) { if (manager) {
manager->RemoveEventListenerByType(mTextListener, manager->RemoveEventListenerByType(mTextListener,
NS_LITERAL_STRING("keydown"), NS_LITERAL_STRING("keydown"),
@ -1968,7 +1967,7 @@ nsTextEditorState::InitializeKeyboardEventListeners()
{ {
//register key listeners //register key listeners
nsCOMPtr<EventTarget> target = do_QueryInterface(mTextCtrlElement); nsCOMPtr<EventTarget> target = do_QueryInterface(mTextCtrlElement);
nsEventListenerManager* manager = target->GetListenerManager(true); nsEventListenerManager* manager = target->ListenerManager();
if (manager) { if (manager) {
manager->AddEventListenerByType(mTextListener, manager->AddEventListenerByType(mTextListener,
NS_LITERAL_STRING("keydown"), NS_LITERAL_STRING("keydown"),

Просмотреть файл

@ -372,7 +372,7 @@ nsSMILTimeValueSpec::GetEventListenerManager(Element* aTarget)
if (!target) if (!target)
return nullptr; return nullptr;
return target->GetListenerManager(true); return target->ListenerManager();
} }
void void

Просмотреть файл

@ -664,7 +664,7 @@ nsSVGElement::UnsetAttrInternal(int32_t aNamespaceID, nsIAtom* aName,
mContentStyleRule = nullptr; mContentStyleRule = nullptr;
if (IsEventAttributeName(aName)) { if (IsEventAttributeName(aName)) {
nsEventListenerManager* manager = GetListenerManager(false); nsEventListenerManager* manager = GetExistingListenerManager();
if (manager) { if (manager) {
nsIAtom* eventName = GetEventNameForAttr(aName); nsIAtom* eventName = GetEventNameForAttr(aName);
manager->RemoveEventHandler(eventName, EmptyString()); manager->RemoveEventHandler(eventName, EmptyString());

Просмотреть файл

@ -499,8 +499,7 @@ nsXBLBinding::InstallEventHandlers()
nsXBLPrototypeHandler* handlerChain = mPrototypeBinding->GetPrototypeHandlers(); nsXBLPrototypeHandler* handlerChain = mPrototypeBinding->GetPrototypeHandlers();
if (handlerChain) { if (handlerChain) {
nsEventListenerManager* manager = nsEventListenerManager* manager = mBoundElement->ListenerManager();
mBoundElement->GetListenerManager(true);
if (!manager) if (!manager)
return; return;
@ -649,7 +648,7 @@ nsXBLBinding::UnhookEventHandlers()
if (handlerChain) { if (handlerChain) {
nsEventListenerManager* manager = nsEventListenerManager* manager =
mBoundElement->GetListenerManager(false); mBoundElement->GetExistingListenerManager();
if (!manager) { if (!manager) {
return; return;
} }

Просмотреть файл

@ -561,7 +561,7 @@ nsXBLService::AttachGlobalKeyHandler(EventTarget* aTarget)
piTarget = doc; // We're a XUL keyset. Attach to our document. piTarget = doc; // We're a XUL keyset. Attach to our document.
} }
nsEventListenerManager* manager = piTarget->GetListenerManager(true); nsEventListenerManager* manager = piTarget->ListenerManager();
if (!piTarget || !manager) if (!piTarget || !manager)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -611,7 +611,7 @@ nsXBLService::DetachGlobalKeyHandler(EventTarget* aTarget)
if (doc) if (doc)
piTarget = do_QueryInterface(doc); piTarget = do_QueryInterface(doc);
nsEventListenerManager* manager = piTarget->GetListenerManager(true); nsEventListenerManager* manager = piTarget->ListenerManager();
if (!piTarget || !manager) if (!piTarget || !manager)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;

Просмотреть файл

@ -500,7 +500,7 @@ nsXULElement::GetEventListenerManagerForAttr(nsIAtom* aAttrName, bool* aDefer)
nsCOMPtr<EventTarget> piTarget = do_QueryInterface(window); nsCOMPtr<EventTarget> piTarget = do_QueryInterface(window);
*aDefer = false; *aDefer = false;
return piTarget->GetListenerManager(true); return piTarget->ListenerManager();
} }
return nsStyledElement::GetEventListenerManagerForAttr(aAttrName, aDefer); return nsStyledElement::GetEventListenerManagerForAttr(aAttrName, aDefer);
@ -1675,7 +1675,7 @@ nsXULElement::AddPopupListener(nsIAtom* aName)
new nsXULPopupListener(this, isContext); new nsXULPopupListener(this, isContext);
// Add the popup as a listener on this element. // Add the popup as a listener on this element.
nsEventListenerManager* manager = GetListenerManager(true); nsEventListenerManager* manager = ListenerManager();
SetFlags(listenerFlag); SetFlags(listenerFlag);
if (isContext) { if (isContext) {

Просмотреть файл

@ -1573,8 +1573,7 @@ NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsGlobalWindow)
if (tmp->mCachedXBLPrototypeHandlers) { if (tmp->mCachedXBLPrototypeHandlers) {
tmp->mCachedXBLPrototypeHandlers->Enumerate(MarkXBLHandlers, nullptr); tmp->mCachedXBLPrototypeHandlers->Enumerate(MarkXBLHandlers, nullptr);
} }
nsEventListenerManager* elm = tmp->GetListenerManager(false); if (nsEventListenerManager* elm = tmp->GetExistingListenerManager()) {
if (elm) {
elm->MarkForCC(); elm->MarkForCC();
} }
tmp->UnmarkGrayTimers(); tmp->UnmarkGrayTimers();
@ -8037,8 +8036,7 @@ nsGlobalWindow::RemoveEventListener(const nsAString& aType,
nsIDOMEventListener* aListener, nsIDOMEventListener* aListener,
bool aUseCapture) bool aUseCapture)
{ {
nsRefPtr<nsEventListenerManager> elm = GetListenerManager(false); if (nsRefPtr<nsEventListenerManager> elm = GetExistingListenerManager()) {
if (elm) {
elm->RemoveEventListener(aType, aListener, aUseCapture); elm->RemoveEventListener(aType, aListener, aUseCapture);
} }
return NS_OK; return NS_OK;
@ -8093,7 +8091,7 @@ nsGlobalWindow::AddEventListener(const nsAString& aType,
aWantsUntrusted = true; aWantsUntrusted = true;
} }
nsEventListenerManager* manager = GetListenerManager(true); nsEventListenerManager* manager = ListenerManager();
NS_ENSURE_STATE(manager); NS_ENSURE_STATE(manager);
manager->AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted); manager->AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted);
return NS_OK; return NS_OK;
@ -8119,7 +8117,7 @@ nsGlobalWindow::AddEventListener(const nsAString& aType,
wantsUntrusted = aWantsUntrusted.Value(); wantsUntrusted = aWantsUntrusted.Value();
} }
nsEventListenerManager* manager = GetListenerManager(true); nsEventListenerManager* manager = ListenerManager();
if (!manager) { if (!manager) {
aRv.Throw(NS_ERROR_UNEXPECTED); aRv.Throw(NS_ERROR_UNEXPECTED);
return; return;
@ -8154,11 +8152,11 @@ nsGlobalWindow::AddSystemEventListener(const nsAString& aType,
} }
nsEventListenerManager* nsEventListenerManager*
nsGlobalWindow::GetListenerManager(bool aCreateIfNotFound) nsGlobalWindow::ListenerManager()
{ {
FORWARD_TO_INNER_CREATE(GetListenerManager, (aCreateIfNotFound), nullptr); FORWARD_TO_INNER_CREATE(ListenerManager, (), nullptr);
if (!mListenerManager && aCreateIfNotFound) { if (!mListenerManager) {
mListenerManager = mListenerManager =
new nsEventListenerManager(static_cast<EventTarget*>(this)); new nsEventListenerManager(static_cast<EventTarget*>(this));
} }
@ -8166,6 +8164,14 @@ nsGlobalWindow::GetListenerManager(bool aCreateIfNotFound)
return mListenerManager; return mListenerManager;
} }
nsEventListenerManager*
nsGlobalWindow::GetExistingListenerManager() const
{
FORWARD_TO_INNER(GetExistingListenerManager, (), nullptr);
return mListenerManager;
}
nsIScriptContext* nsIScriptContext*
nsGlobalWindow::GetContextForEventHandlers(nsresult* aRv) nsGlobalWindow::GetContextForEventHandlers(nsresult* aRv)
{ {
@ -11521,9 +11527,7 @@ nsGlobalWindow::SizeOfIncludingThis(nsWindowSizes* aWindowSizes) const
aWindowSizes->mDOMOther += aWindowSizes->mMallocSizeOf(this); aWindowSizes->mDOMOther += aWindowSizes->mMallocSizeOf(this);
if (IsInnerWindow()) { if (IsInnerWindow()) {
nsEventListenerManager* elm = if (nsEventListenerManager* elm = GetExistingListenerManager()) {
const_cast<nsGlobalWindow*>(this)->GetListenerManager(false);
if (elm) {
aWindowSizes->mDOMOther += aWindowSizes->mDOMOther +=
elm->SizeOfIncludingThis(aWindowSizes->mMallocSizeOf); elm->SizeOfIncludingThis(aWindowSizes->mMallocSizeOf);
} }
@ -12063,8 +12067,7 @@ nsGlobalWindow::DisableNetworkEvent(uint32_t aType)
#define ERROR_EVENT(name_, id_, type_, struct_) \ #define ERROR_EVENT(name_, id_, type_, struct_) \
NS_IMETHODIMP nsGlobalWindow::GetOn##name_(JSContext *cx, \ NS_IMETHODIMP nsGlobalWindow::GetOn##name_(JSContext *cx, \
JS::Value *vp) { \ JS::Value *vp) { \
nsEventListenerManager *elm = GetListenerManager(false); \ if (nsEventListenerManager *elm = GetExistingListenerManager()) { \
if (elm) { \
OnErrorEventHandlerNonNull* h = elm->GetOnErrorEventHandler(); \ OnErrorEventHandlerNonNull* h = elm->GetOnErrorEventHandler(); \
if (h) { \ if (h) { \
*vp = JS::ObjectValue(*h->Callable()); \ *vp = JS::ObjectValue(*h->Callable()); \
@ -12076,7 +12079,7 @@ nsGlobalWindow::DisableNetworkEvent(uint32_t aType)
} \ } \
NS_IMETHODIMP nsGlobalWindow::SetOn##name_(JSContext *cx, \ NS_IMETHODIMP nsGlobalWindow::SetOn##name_(JSContext *cx, \
const JS::Value &v) { \ const JS::Value &v) { \
nsEventListenerManager *elm = GetListenerManager(true); \ nsEventListenerManager *elm = ListenerManager(); \
if (!elm) { \ if (!elm) { \
return NS_ERROR_OUT_OF_MEMORY; \ return NS_ERROR_OUT_OF_MEMORY; \
} \ } \
@ -12092,8 +12095,7 @@ nsGlobalWindow::DisableNetworkEvent(uint32_t aType)
#define BEFOREUNLOAD_EVENT(name_, id_, type_, struct_) \ #define BEFOREUNLOAD_EVENT(name_, id_, type_, struct_) \
NS_IMETHODIMP nsGlobalWindow::GetOn##name_(JSContext *cx, \ NS_IMETHODIMP nsGlobalWindow::GetOn##name_(JSContext *cx, \
JS::Value *vp) { \ JS::Value *vp) { \
nsEventListenerManager *elm = GetListenerManager(false); \ if (nsEventListenerManager *elm = GetExistingListenerManager()) { \
if (elm) { \
BeforeUnloadEventHandlerNonNull* h = \ BeforeUnloadEventHandlerNonNull* h = \
elm->GetOnBeforeUnloadEventHandler(); \ elm->GetOnBeforeUnloadEventHandler(); \
if (h) { \ if (h) { \
@ -12106,7 +12108,7 @@ nsGlobalWindow::DisableNetworkEvent(uint32_t aType)
} \ } \
NS_IMETHODIMP nsGlobalWindow::SetOn##name_(JSContext *cx, \ NS_IMETHODIMP nsGlobalWindow::SetOn##name_(JSContext *cx, \
const JS::Value &v) { \ const JS::Value &v) { \
nsEventListenerManager *elm = GetListenerManager(true); \ nsEventListenerManager *elm = ListenerManager(); \
if (!elm) { \ if (!elm) { \
return NS_ERROR_OUT_OF_MEMORY; \ return NS_ERROR_OUT_OF_MEMORY; \
} \ } \

Просмотреть файл

@ -370,7 +370,7 @@ public:
NS_DECL_NSIDOMJSWINDOW NS_DECL_NSIDOMJSWINDOW
// nsIDOMEventTarget // nsIDOMEventTarget
NS_DECL_NSIDOMEVENTTARGET NS_REALLY_DECL_NSIDOMEVENTTARGET
using mozilla::dom::EventTarget::RemoveEventListener; using mozilla::dom::EventTarget::RemoveEventListener;
virtual void AddEventListener(const nsAString& aType, virtual void AddEventListener(const nsAString& aType,
nsIDOMEventListener* aListener, nsIDOMEventListener* aListener,
@ -547,7 +547,7 @@ public:
return static_cast<nsGlobalWindow *>(GetOuterWindow()); return static_cast<nsGlobalWindow *>(GetOuterWindow());
} }
nsGlobalWindow *GetCurrentInnerWindowInternal() nsGlobalWindow *GetCurrentInnerWindowInternal() const
{ {
return static_cast<nsGlobalWindow *>(mInnerWindow); return static_cast<nsGlobalWindow *>(mInnerWindow);
} }
@ -703,15 +703,14 @@ public:
#define EVENT(name_, id_, type_, struct_) \ #define EVENT(name_, id_, type_, struct_) \
mozilla::dom::EventHandlerNonNull* GetOn##name_() \ mozilla::dom::EventHandlerNonNull* GetOn##name_() \
{ \ { \
nsEventListenerManager *elm = GetListenerManager(false); \ nsEventListenerManager *elm = GetExistingListenerManager(); \
return elm ? elm->GetEventHandler(nsGkAtoms::on##name_, EmptyString()) \ return elm ? elm->GetEventHandler(nsGkAtoms::on##name_, EmptyString()) \
: nullptr; \ : nullptr; \
} \ } \
void SetOn##name_(mozilla::dom::EventHandlerNonNull* handler, \ void SetOn##name_(mozilla::dom::EventHandlerNonNull* handler, \
mozilla::ErrorResult& error) \ mozilla::ErrorResult& error) \
{ \ { \
nsEventListenerManager *elm = GetListenerManager(true); \ if (nsEventListenerManager *elm = ListenerManager()) { \
if (elm) { \
error = elm->SetEventHandler(nsGkAtoms::on##name_, EmptyString(), \ error = elm->SetEventHandler(nsGkAtoms::on##name_, EmptyString(), \
handler); \ handler); \
} else { \ } else { \
@ -721,14 +720,13 @@ public:
#define ERROR_EVENT(name_, id_, type_, struct_) \ #define ERROR_EVENT(name_, id_, type_, struct_) \
mozilla::dom::OnErrorEventHandlerNonNull* GetOn##name_() \ mozilla::dom::OnErrorEventHandlerNonNull* GetOn##name_() \
{ \ { \
nsEventListenerManager *elm = GetListenerManager(false); \ nsEventListenerManager *elm = GetExistingListenerManager(); \
return elm ? elm->GetOnErrorEventHandler() : nullptr; \ return elm ? elm->GetOnErrorEventHandler() : nullptr; \
} \ } \
void SetOn##name_(mozilla::dom::OnErrorEventHandlerNonNull* handler, \ void SetOn##name_(mozilla::dom::OnErrorEventHandlerNonNull* handler, \
mozilla::ErrorResult& error) \ mozilla::ErrorResult& error) \
{ \ { \
nsEventListenerManager *elm = GetListenerManager(true); \ if (nsEventListenerManager *elm = ListenerManager()) { \
if (elm) { \
error = elm->SetEventHandler(handler); \ error = elm->SetEventHandler(handler); \
} else { \ } else { \
error.Throw(NS_ERROR_OUT_OF_MEMORY); \ error.Throw(NS_ERROR_OUT_OF_MEMORY); \
@ -737,14 +735,13 @@ public:
#define BEFOREUNLOAD_EVENT(name_, id_, type_, struct_) \ #define BEFOREUNLOAD_EVENT(name_, id_, type_, struct_) \
mozilla::dom::BeforeUnloadEventHandlerNonNull* GetOn##name_() \ mozilla::dom::BeforeUnloadEventHandlerNonNull* GetOn##name_() \
{ \ { \
nsEventListenerManager *elm = GetListenerManager(false); \ nsEventListenerManager *elm = GetExistingListenerManager(); \
return elm ? elm->GetOnBeforeUnloadEventHandler() : nullptr; \ return elm ? elm->GetOnBeforeUnloadEventHandler() : nullptr; \
} \ } \
void SetOn##name_(mozilla::dom::BeforeUnloadEventHandlerNonNull* handler, \ void SetOn##name_(mozilla::dom::BeforeUnloadEventHandlerNonNull* handler, \
mozilla::ErrorResult& error) \ mozilla::ErrorResult& error) \
{ \ { \
nsEventListenerManager *elm = GetListenerManager(true); \ if (nsEventListenerManager *elm = ListenerManager()) { \
if (elm) { \
error = elm->SetEventHandler(handler); \ error = elm->SetEventHandler(handler); \
} else { \ } else { \
error.Throw(NS_ERROR_OUT_OF_MEMORY); \ error.Throw(NS_ERROR_OUT_OF_MEMORY); \

Просмотреть файл

@ -65,8 +65,7 @@ NS_IMPL_DOMTARGET_DEFAULTS(nsWindowRoot)
NS_IMETHODIMP NS_IMETHODIMP
nsWindowRoot::RemoveEventListener(const nsAString& aType, nsIDOMEventListener* aListener, bool aUseCapture) nsWindowRoot::RemoveEventListener(const nsAString& aType, nsIDOMEventListener* aListener, bool aUseCapture)
{ {
nsRefPtr<nsEventListenerManager> elm = GetListenerManager(false); if (nsRefPtr<nsEventListenerManager> elm = GetExistingListenerManager()) {
if (elm) {
elm->RemoveEventListener(aType, aListener, aUseCapture); elm->RemoveEventListener(aType, aListener, aUseCapture);
} }
return NS_OK; return NS_OK;
@ -106,7 +105,7 @@ nsWindowRoot::AddEventListener(const nsAString& aType,
"aWantsUntrusted to false or make the aWantsUntrusted " "aWantsUntrusted to false or make the aWantsUntrusted "
"explicit by making optional_argc non-zero."); "explicit by making optional_argc non-zero.");
nsEventListenerManager* elm = GetListenerManager(true); nsEventListenerManager* elm = ListenerManager();
NS_ENSURE_STATE(elm); NS_ENSURE_STATE(elm);
elm->AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted); elm->AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted);
return NS_OK; return NS_OK;
@ -120,7 +119,7 @@ nsWindowRoot::AddEventListener(const nsAString& aType,
ErrorResult& aRv) ErrorResult& aRv)
{ {
bool wantsUntrusted = !aWantsUntrusted.IsNull() && aWantsUntrusted.Value(); bool wantsUntrusted = !aWantsUntrusted.IsNull() && aWantsUntrusted.Value();
nsEventListenerManager* elm = GetListenerManager(true); nsEventListenerManager* elm = ListenerManager();
if (!elm) { if (!elm) {
aRv.Throw(NS_ERROR_UNEXPECTED); aRv.Throw(NS_ERROR_UNEXPECTED);
return; return;
@ -146,9 +145,9 @@ nsWindowRoot::AddSystemEventListener(const nsAString& aType,
} }
nsEventListenerManager* nsEventListenerManager*
nsWindowRoot::GetListenerManager(bool aCreateIfNotFound) nsWindowRoot::ListenerManager()
{ {
if (!mListenerManager && aCreateIfNotFound) { if (!mListenerManager) {
mListenerManager = mListenerManager =
new nsEventListenerManager(static_cast<EventTarget*>(this)); new nsEventListenerManager(static_cast<EventTarget*>(this));
} }
@ -156,6 +155,12 @@ nsWindowRoot::GetListenerManager(bool aCreateIfNotFound)
return mListenerManager; return mListenerManager;
} }
nsEventListenerManager*
nsWindowRoot::GetExistingListenerManager() const
{
return mListenerManager;
}
nsIScriptContext* nsIScriptContext*
nsWindowRoot::GetContextForEventHandlers(nsresult* aRv) nsWindowRoot::GetContextForEventHandlers(nsresult* aRv)
{ {

Просмотреть файл

@ -27,7 +27,7 @@ public:
virtual ~nsWindowRoot(); virtual ~nsWindowRoot();
NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_NSIDOMEVENTTARGET NS_REALLY_DECL_NSIDOMEVENTTARGET
using mozilla::dom::EventTarget::RemoveEventListener; using mozilla::dom::EventTarget::RemoveEventListener;
virtual void AddEventListener(const nsAString& aType, virtual void AddEventListener(const nsAString& aType,
nsIDOMEventListener* aListener, nsIDOMEventListener* aListener,

Просмотреть файл

@ -155,7 +155,7 @@ public:
NS_DECL_NSIDOMDEVICESTORAGE NS_DECL_NSIDOMDEVICESTORAGE
NS_DECL_NSIOBSERVER NS_DECL_NSIOBSERVER
NS_DECL_NSIDOMEVENTTARGET NS_REALLY_DECL_NSIDOMEVENTTARGET
virtual void virtual void
AddEventListener(const nsAString& aType, AddEventListener(const nsAString& aType,

Просмотреть файл

@ -3478,9 +3478,15 @@ nsDOMDeviceStorage::DispatchDOMEvent(nsEvent *aEvent,
} }
nsEventListenerManager * nsEventListenerManager *
nsDOMDeviceStorage::GetListenerManager(bool aMayCreate) nsDOMDeviceStorage::ListenerManager()
{ {
return nsDOMEventTargetHelper::GetListenerManager(aMayCreate); return nsDOMEventTargetHelper::ListenerManager();
}
nsEventListenerManager *
nsDOMDeviceStorage::GetExistingListenerManager() const
{
return nsDOMEventTargetHelper::GetExistingListenerManager();
} }
nsIScriptContext * nsIScriptContext *

Просмотреть файл

@ -45,7 +45,7 @@ interface nsIScriptContext;
interface nsIDOMEventListener; interface nsIDOMEventListener;
interface nsIDOMEvent; interface nsIDOMEvent;
[scriptable, builtinclass, uuid(31e92e56-4d23-4a4a-9cfe-a6d12cf434bc)] [scriptable, builtinclass, uuid(b128448c-7b53-4769-92cb-cd6eafee676c)]
interface nsIDOMEventTarget : nsISupports interface nsIDOMEventTarget : nsISupports
{ {
/** /**
@ -267,14 +267,21 @@ interface nsIDOMEventTarget : nsISupports
in nsPresContextPtr aPresContext, in nsPresContextPtr aPresContext,
in nsEventStatusPtr aEventStatus); in nsEventStatusPtr aEventStatus);
%{C++
// These are virtual, but everything after this is not accessible to JS so
// xpidl not understanding the vtable here doesn't matter.
/** /**
* Get the event listener manager, the guy you talk to to register for events * Get the event listener manager, creating it if it does not already exist.
* on this node.
* @param aMayCreate If PR_FALSE, returns a listener manager only if
* one already exists.
*/ */
[notxpcom, nostdcall] virtual nsEventListenerManager* ListenerManager() = 0;
nsEventListenerManagerPtr GetListenerManager(in boolean aMayCreate);
/**
* Get the event listener manager, returning null if it does not already
* exist.
*/
virtual nsEventListenerManager* GetExistingListenerManager() const = 0;
%}
/** /**
* Get the script context in which the event handlers should be run. * Get the script context in which the event handlers should be run.
@ -293,6 +300,11 @@ interface nsIDOMEventTarget : nsISupports
%{C++ %{C++
#define NS_REALLY_DECL_NSIDOMEVENTTARGET \
NS_DECL_NSIDOMEVENTTARGET \
virtual nsEventListenerManager* ListenerManager() MOZ_OVERRIDE; \
virtual nsEventListenerManager* GetExistingListenerManager() const MOZ_OVERRIDE;
#define NS_IMPL_DOMTARGET_DEFAULTS(_class) \ #define NS_IMPL_DOMTARGET_DEFAULTS(_class) \
mozilla::dom::EventTarget* _class::GetTargetForDOMEvent() { return this; } \ mozilla::dom::EventTarget* _class::GetTargetForDOMEvent() { return this; } \
mozilla::dom::EventTarget* _class::GetTargetForEventTargetChain() { return this; } \ mozilla::dom::EventTarget* _class::GetTargetForEventTargetChain() { return this; } \
@ -305,7 +317,7 @@ aClass::RemoveSystemEventListener(const nsAString& aType, \
nsIDOMEventListener *aListener, \ nsIDOMEventListener *aListener, \
bool aUseCapture) \ bool aUseCapture) \
{ \ { \
nsEventListenerManager* listenerManager = GetListenerManager(false); \ nsEventListenerManager* listenerManager = GetExistingListenerManager(); \
if (!listenerManager) { \ if (!listenerManager) { \
return NS_OK; \ return NS_OK; \
} \ } \

Просмотреть файл

@ -1235,7 +1235,7 @@ TabChild::~TabChild()
mGlobal = nullptr; mGlobal = nullptr;
if (mTabChildGlobal) { if (mTabChildGlobal) {
nsEventListenerManager* elm = mTabChildGlobal->GetListenerManager(false); nsEventListenerManager* elm = mTabChildGlobal->GetExistingListenerManager();
if (elm) { if (elm) {
elm->Disconnect(); elm->Disconnect();
} }

Просмотреть файл

@ -108,7 +108,7 @@ nsEditorEventListener::InstallToEditor()
NS_ENSURE_TRUE(piTarget, NS_ERROR_FAILURE); NS_ENSURE_TRUE(piTarget, NS_ERROR_FAILURE);
// register the event listeners with the listener manager // register the event listeners with the listener manager
nsEventListenerManager* elmP = piTarget->GetListenerManager(true); nsEventListenerManager* elmP = piTarget->ListenerManager();
NS_ENSURE_STATE(elmP); NS_ENSURE_STATE(elmP);
#ifdef HANDLE_NATIVE_TEXT_DIRECTION_SWITCH #ifdef HANDLE_NATIVE_TEXT_DIRECTION_SWITCH
@ -187,8 +187,7 @@ nsEditorEventListener::UninstallFromEditor()
return; return;
} }
nsEventListenerManager* elmP = nsEventListenerManager* elmP = piTarget->ListenerManager();
piTarget->GetListenerManager(true);
if (!elmP) { if (!elmP) {
return; return;
} }

Просмотреть файл

@ -866,7 +866,7 @@ nsDocShellTreeOwner::AddChromeListeners()
nsCOMPtr<EventTarget> target; nsCOMPtr<EventTarget> target;
GetDOMEventTarget(mWebBrowser, getter_AddRefs(target)); GetDOMEventTarget(mWebBrowser, getter_AddRefs(target));
nsEventListenerManager* elmP = target->GetListenerManager(true); nsEventListenerManager* elmP = target->ListenerManager();
if (elmP) { if (elmP) {
elmP->AddEventListenerByType(this, NS_LITERAL_STRING("dragover"), elmP->AddEventListenerByType(this, NS_LITERAL_STRING("dragover"),
dom::TrustedEventsAtSystemGroupBubble()); dom::TrustedEventsAtSystemGroupBubble());
@ -896,7 +896,7 @@ nsDocShellTreeOwner::RemoveChromeListeners()
if (!piTarget) if (!piTarget)
return NS_OK; return NS_OK;
nsEventListenerManager* elmP = piTarget->GetListenerManager(true); nsEventListenerManager* elmP = piTarget->ListenerManager();
if (elmP) if (elmP)
{ {
elmP->RemoveEventListenerByType(this, NS_LITERAL_STRING("dragover"), elmP->RemoveEventListenerByType(this, NS_LITERAL_STRING("dragover"),

Просмотреть файл

@ -116,13 +116,13 @@ GetPrefsFor(nsEventStructType aEventStructType)
static bool static bool
HasMouseListener(nsIContent* aContent) HasMouseListener(nsIContent* aContent)
{ {
nsEventListenerManager* elm = aContent->GetListenerManager(false); if (nsEventListenerManager* elm = aContent->GetExistingListenerManager()) {
if (!elm) { return elm->HasListenersFor(nsGkAtoms::onclick) ||
return false; elm->HasListenersFor(nsGkAtoms::onmousedown) ||
elm->HasListenersFor(nsGkAtoms::onmouseup);
} }
return elm->HasListenersFor(nsGkAtoms::onclick) ||
elm->HasListenersFor(nsGkAtoms::onmousedown) || return false;
elm->HasListenersFor(nsGkAtoms::onmouseup);
} }
static bool static bool

Просмотреть файл

@ -2206,7 +2206,7 @@ MayHavePaintEventListener(nsPIDOMWindow* aInnerWindow)
return false; return false;
nsEventListenerManager* manager = nullptr; nsEventListenerManager* manager = nullptr;
if ((manager = parentTarget->GetListenerManager(false)) && if ((manager = parentTarget->GetExistingListenerManager()) &&
manager->MayHavePaintEventListener()) { manager->MayHavePaintEventListener()) {
return true; return true;
} }
@ -2234,7 +2234,7 @@ MayHavePaintEventListener(nsPIDOMWindow* aInnerWindow)
EventTarget* tabChildGlobal; EventTarget* tabChildGlobal;
return root && return root &&
(tabChildGlobal = root->GetParentTarget()) && (tabChildGlobal = root->GetParentTarget()) &&
(manager = tabChildGlobal->GetListenerManager(false)) && (manager = tabChildGlobal->GetExistingListenerManager()) &&
manager->MayHavePaintEventListener(); manager->MayHavePaintEventListener();
} }