Bug 536092 - Micro optimizations for event handling, r=jst

--HG--
extra : rebase_source : d34faef862a532109f05750ccb7220bd1ddf6e19
This commit is contained in:
Olli Pettay 2010-03-31 15:44:18 +03:00
parent e18e7c3dbf
commit c0986d9bda
5 changed files with 27 additions and 28 deletions

View File

@ -2918,15 +2918,17 @@ nsGenericElement::doPreHandleEvent(nsIContent* aContent,
// check for an anonymous parent
// XXX XBL2/sXBL issue
nsIDocument* ownerDoc = aContent->GetOwnerDoc();
if (ownerDoc) {
nsIContent* insertionParent = ownerDoc->BindingManager()->
GetInsertionParent(aContent);
NS_ASSERTION(!(aVisitor.mEventTargetAtParent && insertionParent &&
aVisitor.mEventTargetAtParent != insertionParent),
"Retargeting and having insertion parent!");
if (insertionParent) {
parent = insertionParent;
if (aContent->HasFlag(NODE_MAY_BE_IN_BINDING_MNGR)) {
nsIDocument* ownerDoc = aContent->GetOwnerDoc();
if (ownerDoc) {
nsIContent* insertionParent = ownerDoc->BindingManager()->
GetInsertionParent(aContent);
NS_ASSERTION(!(aVisitor.mEventTargetAtParent && insertionParent &&
aVisitor.mEventTargetAtParent != insertionParent),
"Retargeting and having insertion parent!");
if (insertionParent) {
parent = insertionParent;
}
}
}

View File

@ -259,12 +259,11 @@ NS_METHOD nsDOMEvent::GetType(nsAString& aType)
}
static nsresult
GetDOMEventTarget(nsISupports* aTarget,
GetDOMEventTarget(nsPIDOMEventTarget* aTarget,
nsIDOMEventTarget** aDOMTarget)
{
nsCOMPtr<nsPIDOMEventTarget> piTarget = do_QueryInterface(aTarget);
nsISupports* realTarget =
piTarget ? piTarget->GetTargetForDOMEvent() : aTarget;
nsPIDOMEventTarget* realTarget =
aTarget ? aTarget->GetTargetForDOMEvent() : aTarget;
if (realTarget) {
return CallQueryInterface(realTarget, aDOMTarget);
}
@ -1066,7 +1065,7 @@ NS_METHOD nsDOMEvent::SetTarget(nsIDOMEventTarget* aTarget)
}
#endif
mEvent->target = aTarget;
mEvent->target = do_QueryInterface(aTarget);
return NS_OK;
}

View File

@ -96,7 +96,7 @@ public:
return !!(mTarget);
}
nsISupports* GetNewTarget()
nsPIDOMEventTarget* GetNewTarget()
{
return mNewTarget;
}
@ -280,7 +280,7 @@ nsEventTargetChainItem::HandleEventTargetChain(nsEventChainPostVisitor& aVisitor
{
PRUint32 createdELMs = nsEventListenerManager::sCreatedCount;
// Save the target so that it can be restored later.
nsCOMPtr<nsISupports> firstTarget = aVisitor.mEvent->target;
nsCOMPtr<nsPIDOMEventTarget> firstTarget = aVisitor.mEvent->target;
// Capture
nsEventTargetChainItem* item = this;
@ -300,7 +300,7 @@ nsEventTargetChainItem::HandleEventTargetChain(nsEventChainPostVisitor& aVisitor
// item is at anonymous boundary. Need to retarget for the child items.
nsEventTargetChainItem* nextTarget = item->mChild;
while (nextTarget) {
nsISupports* newTarget = nextTarget->GetNewTarget();
nsPIDOMEventTarget* newTarget = nextTarget->GetNewTarget();
if (newTarget) {
aVisitor.mEvent->target = newTarget;
break;
@ -333,7 +333,7 @@ nsEventTargetChainItem::HandleEventTargetChain(nsEventChainPostVisitor& aVisitor
aVisitor.mEvent->flags &= ~NS_EVENT_FLAG_CAPTURE;
item = item->mParent;
while (item) {
nsISupports* newTarget = item->GetNewTarget();
nsPIDOMEventTarget* newTarget = item->GetNewTarget();
if (newTarget) {
// Item is at anonymous boundary. Need to retarget for the current item
// and for parent items.
@ -454,6 +454,7 @@ nsEventDispatcher::Dispatch(nsISupports* aTarget,
NS_ENSURE_TRUE(!NS_IS_EVENT_IN_DISPATCH(aEvent),
NS_ERROR_ILLEGAL_VALUE);
NS_ASSERTION(!aTargets || !aEvent->message, "Wrong parameters!");
nsCOMPtr<nsPIDOMEventTarget> target = do_QueryInterface(aTarget);
if (aEvent->flags & NS_EVENT_FLAG_ONLY_CHROME_DISPATCH) {
nsCOMPtr<nsINode> node = do_QueryInterface(aTarget);
@ -471,13 +472,12 @@ nsEventDispatcher::Dispatch(nsISupports* aTarget,
// If we can't dispatch the event to chrome, do nothing.
NS_ENSURE_TRUE(win && win->GetChromeEventHandler(), NS_OK);
// Set the target to be the original dispatch target,
aEvent->target = aTarget;
aEvent->target = target;
// but use chrome event handler for event target chain.
aTarget = win->GetChromeEventHandler();
}
}
nsCOMPtr<nsPIDOMEventTarget> target = do_QueryInterface(aTarget);
#ifdef DEBUG
if (!nsContentUtils::IsSafeToRunScript()) {
nsresult rv = NS_ERROR_FAILURE;
@ -532,9 +532,7 @@ nsEventDispatcher::Dispatch(nsISupports* aTarget,
// which are dispatched to |window| but have document as their target.
//
// Make sure that the event target points to the right object.
nsCOMPtr<nsPIDOMEventTarget> t = do_QueryInterface(aEvent->target);
NS_ENSURE_STATE(t);
aEvent->target = t->GetTargetForEventTargetChain();
aEvent->target = aEvent->target->GetTargetForEventTargetChain();
NS_ENSURE_STATE(aEvent->target);
}
aEvent->originalTarget = aEvent->target;

View File

@ -10371,8 +10371,7 @@ nsEventListenerThisTranslator::TranslateThis(nsISupports *aInitialThis,
nsCOMPtr<nsIDOMEventTarget> target;
event->GetCurrentTarget(getter_AddRefs(target));
*_retval = target;
NS_IF_ADDREF(*_retval);
*_retval = target.forget().get();
return NS_OK;
}

View File

@ -51,6 +51,7 @@
#include "nsIAtom.h"
#include "nsIDOMKeyEvent.h"
#include "nsIDOMDataTransfer.h"
#include "nsPIDOMEventTarget.h"
#include "nsWeakPtr.h"
#include "nsIWidget.h"
#include "nsTArray.h"
@ -526,9 +527,9 @@ public:
// Event targets, needed by DOM Events
// Using nsISupports, not nsIDOMEventTarget because in some cases
// nsIDOMEventTarget is implemented as a tearoff.
nsCOMPtr<nsISupports> target;
nsCOMPtr<nsISupports> currentTarget;
nsCOMPtr<nsISupports> originalTarget;
nsCOMPtr<nsPIDOMEventTarget> target;
nsCOMPtr<nsPIDOMEventTarget> currentTarget;
nsCOMPtr<nsPIDOMEventTarget> originalTarget;
};
/**