From 3e98b75bda82b2b703e8ce1b55920acc21fa04b5 Mon Sep 17 00:00:00 2001 From: Olli Pettay Date: Mon, 15 Jun 2009 13:21:06 +0300 Subject: [PATCH] Bug 493266 - Optimize setting currentTarget, r+sr=bz --- content/events/src/nsEventDispatcher.cpp | 17 ++++++++--------- content/events/src/nsEventListenerManager.cpp | 8 ++++++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/content/events/src/nsEventDispatcher.cpp b/content/events/src/nsEventDispatcher.cpp index 4308010ce10..0c931e3f0b4 100644 --- a/content/events/src/nsEventDispatcher.cpp +++ b/content/events/src/nsEventDispatcher.cpp @@ -218,15 +218,14 @@ nsEventTargetChainItem::HandleEvent(nsEventChainPostVisitor& aVisitor, mTarget->GetListenerManager(PR_FALSE, getter_AddRefs(mManager)); } if (mManager) { - nsPIDOMEventTarget* currentTarget = CurrentTarget()->GetTargetForDOMEvent(); - aVisitor.mEvent->currentTarget = currentTarget; - if (aVisitor.mEvent->currentTarget) { - mManager->HandleEvent(aVisitor.mPresContext, aVisitor.mEvent, - &aVisitor.mDOMEvent, - currentTarget, aFlags, - &aVisitor.mEventStatus); - aVisitor.mEvent->currentTarget = nsnull; - } + NS_ASSERTION(aVisitor.mEvent->currentTarget == nsnull, + "CurrentTarget should be null!"); + mManager->HandleEvent(aVisitor.mPresContext, aVisitor.mEvent, + &aVisitor.mDOMEvent, + CurrentTarget(), aFlags, + &aVisitor.mEventStatus); + NS_ASSERTION(aVisitor.mEvent->currentTarget == nsnull, + "CurrentTarget should be null!"); } return NS_OK; } diff --git a/content/events/src/nsEventListenerManager.cpp b/content/events/src/nsEventListenerManager.cpp index c1e5a37d525..d03afb67dc6 100644 --- a/content/events/src/nsEventListenerManager.cpp +++ b/content/events/src/nsEventListenerManager.cpp @@ -1176,6 +1176,12 @@ found: EmptyString(), aDOMEvent); } if (*aDOMEvent) { + if (!aEvent->currentTarget) { + aEvent->currentTarget = aCurrentTarget->GetTargetForDOMEvent(); + if (!aEvent->currentTarget) { + break; + } + } nsRefPtr kungFuDeathGrip = ls->mListener; if (useTypeInterface) { pusher.Pop(); @@ -1192,6 +1198,8 @@ found: } } + aEvent->currentTarget = nsnull; + if (!hasListener) { mNoListenerForEvent = aEvent->message; mNoListenerForEventAtom = aEvent->userType;