This commit is contained in:
hyatt%netscape.com 2000-09-07 08:18:11 +00:00
Родитель 9c5667f4a7
Коммит f89d4eddd9
8 изменённых файлов: 308 добавлений и 8 удалений

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

@ -1327,6 +1327,8 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext,
nsEventStatus* aEventStatus)
{
nsresult ret = NS_OK;
PRBool retarget = PR_FALSE;
nsCOMPtr<nsIDOMEventTarget> oldTarget;
nsIDOMEvent* domEvent = nsnull;
if (NS_EVENT_FLAG_INIT & aFlags) {
@ -1337,6 +1339,53 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext,
aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL);
}
// Find out if we're anonymous.
nsCOMPtr<nsIContent> bindingParent;
GetBindingParent(getter_AddRefs(bindingParent));
if (bindingParent) {
// We're anonymous. We may potentially need to retarget
// our event if our parent is in a different scope.
if (mParent) {
nsCOMPtr<nsIContent> parentScope;
mParent->GetBindingParent(getter_AddRefs(parentScope));
if (parentScope != bindingParent)
retarget = PR_TRUE;
}
}
if (retarget) {
if (!*aDOMEvent) {
// We haven't made a DOMEvent yet. Force making one now.
nsCOMPtr<nsIEventListenerManager> listenerManager;
if (NS_FAILED(ret = GetListenerManager(getter_AddRefs(listenerManager)))) {
return ret;
}
nsAutoString empty;
if (NS_FAILED(ret = listenerManager->CreateEvent(aPresContext, aEvent, empty, aDOMEvent)))
return ret;
}
if (!*aDOMEvent) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(*aDOMEvent);
if (!privateEvent) {
return NS_ERROR_FAILURE;
}
(*aDOMEvent)->GetTarget(getter_AddRefs(oldTarget));
PRBool hasOriginal;
privateEvent->HasOriginalTarget(&hasOriginal);
if (!hasOriginal) {
privateEvent->SetOriginalTarget(oldTarget);
}
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(mParent);
privateEvent->SetTarget(target);
}
//Capturing stage evaluation
//Always pass capturing up the tree before local evaulation
if (NS_EVENT_FLAG_BUBBLE != aFlags) {
@ -1357,6 +1406,14 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext,
//}
}
if (retarget) {
// The event originated beneath us, and we performed a retargeting.
// We need to restore the original target of the event.
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(*aDOMEvent);
if (privateEvent)
privateEvent->SetTarget(oldTarget);
}
//Local handling stage
if (mDOMSlots && mDOMSlots->mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH) &&
!(NS_EVENT_FLAG_BUBBLE & aFlags && NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags)) {
@ -1366,6 +1423,15 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext,
aEvent->flags &= ~aFlags;
}
if (retarget) {
// The event originated beneath us, and we need to perform a retargeting.
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(*aDOMEvent);
if (privateEvent) {
nsCOMPtr<nsIDOMEventTarget> parentTarget(do_QueryInterface(mParent));
privateEvent->SetTarget(parentTarget);
}
}
//Bubbling stage
if (NS_EVENT_FLAG_CAPTURE != aFlags && mDocument) {
if (mParent) {
@ -1384,6 +1450,14 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext,
}
}
if (retarget) {
// The event originated beneath us, and we performed a retargeting.
// We need to restore the original target of the event.
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(*aDOMEvent);
if (privateEvent)
privateEvent->SetTarget(oldTarget);
}
if (NS_EVENT_FLAG_INIT & aFlags) {
// We're leaving the DOM event loop so if we created a DOM event,
// release here.
@ -1404,6 +1478,7 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext,
}
aDOMEvent = nsnull;
}
return ret;
}

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

@ -50,7 +50,7 @@ public:
NS_IMETHOD SetOriginalTarget(nsIDOMEventTarget* aTarget) = 0;
NS_IMETHOD IsDispatchStopped(PRBool* aIsDispatchPrevented) = 0;
NS_IMETHOD GetInternalNSEvent(nsEvent** aNSEvent) = 0;
NS_IMETHOD GetRealTarget(nsIDOMEventTarget** aRealTarget) = 0;
NS_IMETHOD HasOriginalTarget(PRBool* aResult)=0;
};
extern nsresult NS_NewDOMEvent(nsIDOMEvent** aInstancePtrResult, nsIPresContext* aPresContext, nsEvent *aEvent);

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

@ -151,7 +151,8 @@ public:
NS_IMETHOD SetOriginalTarget(nsIDOMEventTarget* aOriginalTarget);
NS_IMETHOD IsDispatchStopped(PRBool* aIsDispatchStopped);
NS_IMETHOD GetInternalNSEvent(nsEvent** aNSEvent);
NS_IMETHOD GetRealTarget(nsIDOMEventTarget** aTarget);
NS_IMETHOD HasOriginalTarget(PRBool* aResult);
NS_IMETHOD IsHandled(PRBool* aHandled);
NS_IMETHOD SetHandled(PRBool aHandled);

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

@ -3178,6 +3178,9 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext,
{
nsresult ret = NS_OK;
PRBool retarget = PR_FALSE;
nsCOMPtr<nsIDOMEventTarget> oldTarget;
nsIDOMEvent* domEvent = nsnull;
if (NS_EVENT_FLAG_INIT & aFlags) {
aDOMEvent = &domEvent;
@ -3223,6 +3226,52 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext,
}
}
// Find out if we're anonymous.
nsCOMPtr<nsIContent> bindingParent;
GetBindingParent(getter_AddRefs(bindingParent));
if (bindingParent) {
// We're anonymous. We may potentially need to retarget
// our event if our parent is in a different scope.
if (mParent) {
nsCOMPtr<nsIContent> parentScope;
mParent->GetBindingParent(getter_AddRefs(parentScope));
if (parentScope != bindingParent)
retarget = PR_TRUE;
}
}
if (retarget) {
if (!*aDOMEvent) {
// We haven't made a DOMEvent yet. Force making one now.
nsCOMPtr<nsIEventListenerManager> listenerManager;
if (NS_FAILED(ret = GetListenerManager(getter_AddRefs(listenerManager)))) {
return ret;
}
nsAutoString empty;
if (NS_FAILED(ret = listenerManager->CreateEvent(aPresContext, aEvent, empty, aDOMEvent)))
return ret;
}
if (!*aDOMEvent) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(*aDOMEvent);
if (!privateEvent) {
return NS_ERROR_FAILURE;
}
(*aDOMEvent)->GetTarget(getter_AddRefs(oldTarget));
PRBool hasOriginal;
privateEvent->HasOriginalTarget(&hasOriginal);
if (!hasOriginal)
privateEvent->SetOriginalTarget(oldTarget);
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(mParent);
privateEvent->SetTarget(target);
}
// Node capturing stage
if (NS_EVENT_FLAG_BUBBLE != aFlags) {
if (mParent) {
@ -3236,6 +3285,14 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext,
}
if (retarget) {
// The event originated beneath us, and we performed a retargeting.
// We need to restore the original target of the event.
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(*aDOMEvent);
if (privateEvent)
privateEvent->SetTarget(oldTarget);
}
//Local handling stage
if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH)) {
aEvent->flags |= aFlags;
@ -3243,6 +3300,15 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext,
aEvent->flags &= ~aFlags;
}
if (retarget) {
// The event originated beneath us, and we need to perform a retargeting.
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(*aDOMEvent);
if (privateEvent) {
nsCOMPtr<nsIDOMEventTarget> parentTarget(do_QueryInterface(mParent));
privateEvent->SetTarget(parentTarget);
}
}
//Bubbling stage
if (NS_EVENT_FLAG_CAPTURE != aFlags) {
if (mParent != nsnull) {
@ -3258,6 +3324,14 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext,
}
}
if (retarget) {
// The event originated beneath us, and we performed a retargeting.
// We need to restore the original target of the event.
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(*aDOMEvent);
if (privateEvent)
privateEvent->SetTarget(oldTarget);
}
if (NS_EVENT_FLAG_INIT & aFlags) {
// We're leaving the DOM event loop so if we created a DOM event,
// release here.

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

@ -1327,6 +1327,8 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext,
nsEventStatus* aEventStatus)
{
nsresult ret = NS_OK;
PRBool retarget = PR_FALSE;
nsCOMPtr<nsIDOMEventTarget> oldTarget;
nsIDOMEvent* domEvent = nsnull;
if (NS_EVENT_FLAG_INIT & aFlags) {
@ -1337,6 +1339,53 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext,
aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL);
}
// Find out if we're anonymous.
nsCOMPtr<nsIContent> bindingParent;
GetBindingParent(getter_AddRefs(bindingParent));
if (bindingParent) {
// We're anonymous. We may potentially need to retarget
// our event if our parent is in a different scope.
if (mParent) {
nsCOMPtr<nsIContent> parentScope;
mParent->GetBindingParent(getter_AddRefs(parentScope));
if (parentScope != bindingParent)
retarget = PR_TRUE;
}
}
if (retarget) {
if (!*aDOMEvent) {
// We haven't made a DOMEvent yet. Force making one now.
nsCOMPtr<nsIEventListenerManager> listenerManager;
if (NS_FAILED(ret = GetListenerManager(getter_AddRefs(listenerManager)))) {
return ret;
}
nsAutoString empty;
if (NS_FAILED(ret = listenerManager->CreateEvent(aPresContext, aEvent, empty, aDOMEvent)))
return ret;
}
if (!*aDOMEvent) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(*aDOMEvent);
if (!privateEvent) {
return NS_ERROR_FAILURE;
}
(*aDOMEvent)->GetTarget(getter_AddRefs(oldTarget));
PRBool hasOriginal;
privateEvent->HasOriginalTarget(&hasOriginal);
if (!hasOriginal) {
privateEvent->SetOriginalTarget(oldTarget);
}
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(mParent);
privateEvent->SetTarget(target);
}
//Capturing stage evaluation
//Always pass capturing up the tree before local evaulation
if (NS_EVENT_FLAG_BUBBLE != aFlags) {
@ -1357,6 +1406,14 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext,
//}
}
if (retarget) {
// The event originated beneath us, and we performed a retargeting.
// We need to restore the original target of the event.
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(*aDOMEvent);
if (privateEvent)
privateEvent->SetTarget(oldTarget);
}
//Local handling stage
if (mDOMSlots && mDOMSlots->mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH) &&
!(NS_EVENT_FLAG_BUBBLE & aFlags && NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags)) {
@ -1366,6 +1423,15 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext,
aEvent->flags &= ~aFlags;
}
if (retarget) {
// The event originated beneath us, and we need to perform a retargeting.
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(*aDOMEvent);
if (privateEvent) {
nsCOMPtr<nsIDOMEventTarget> parentTarget(do_QueryInterface(mParent));
privateEvent->SetTarget(parentTarget);
}
}
//Bubbling stage
if (NS_EVENT_FLAG_CAPTURE != aFlags && mDocument) {
if (mParent) {
@ -1384,6 +1450,14 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext,
}
}
if (retarget) {
// The event originated beneath us, and we performed a retargeting.
// We need to restore the original target of the event.
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(*aDOMEvent);
if (privateEvent)
privateEvent->SetTarget(oldTarget);
}
if (NS_EVENT_FLAG_INIT & aFlags) {
// We're leaving the DOM event loop so if we created a DOM event,
// release here.
@ -1404,6 +1478,7 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext,
}
aDOMEvent = nsnull;
}
return ret;
}

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

@ -50,7 +50,7 @@ public:
NS_IMETHOD SetOriginalTarget(nsIDOMEventTarget* aTarget) = 0;
NS_IMETHOD IsDispatchStopped(PRBool* aIsDispatchPrevented) = 0;
NS_IMETHOD GetInternalNSEvent(nsEvent** aNSEvent) = 0;
NS_IMETHOD GetRealTarget(nsIDOMEventTarget** aRealTarget) = 0;
NS_IMETHOD HasOriginalTarget(PRBool* aResult)=0;
};
extern nsresult NS_NewDOMEvent(nsIDOMEvent** aInstancePtrResult, nsIPresContext* aPresContext, nsEvent *aEvent);

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

@ -151,7 +151,8 @@ public:
NS_IMETHOD SetOriginalTarget(nsIDOMEventTarget* aOriginalTarget);
NS_IMETHOD IsDispatchStopped(PRBool* aIsDispatchStopped);
NS_IMETHOD GetInternalNSEvent(nsEvent** aNSEvent);
NS_IMETHOD GetRealTarget(nsIDOMEventTarget** aTarget);
NS_IMETHOD HasOriginalTarget(PRBool* aResult);
NS_IMETHOD IsHandled(PRBool* aHandled);
NS_IMETHOD SetHandled(PRBool aHandled);

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

@ -3178,6 +3178,9 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext,
{
nsresult ret = NS_OK;
PRBool retarget = PR_FALSE;
nsCOMPtr<nsIDOMEventTarget> oldTarget;
nsIDOMEvent* domEvent = nsnull;
if (NS_EVENT_FLAG_INIT & aFlags) {
aDOMEvent = &domEvent;
@ -3223,6 +3226,52 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext,
}
}
// Find out if we're anonymous.
nsCOMPtr<nsIContent> bindingParent;
GetBindingParent(getter_AddRefs(bindingParent));
if (bindingParent) {
// We're anonymous. We may potentially need to retarget
// our event if our parent is in a different scope.
if (mParent) {
nsCOMPtr<nsIContent> parentScope;
mParent->GetBindingParent(getter_AddRefs(parentScope));
if (parentScope != bindingParent)
retarget = PR_TRUE;
}
}
if (retarget) {
if (!*aDOMEvent) {
// We haven't made a DOMEvent yet. Force making one now.
nsCOMPtr<nsIEventListenerManager> listenerManager;
if (NS_FAILED(ret = GetListenerManager(getter_AddRefs(listenerManager)))) {
return ret;
}
nsAutoString empty;
if (NS_FAILED(ret = listenerManager->CreateEvent(aPresContext, aEvent, empty, aDOMEvent)))
return ret;
}
if (!*aDOMEvent) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(*aDOMEvent);
if (!privateEvent) {
return NS_ERROR_FAILURE;
}
(*aDOMEvent)->GetTarget(getter_AddRefs(oldTarget));
PRBool hasOriginal;
privateEvent->HasOriginalTarget(&hasOriginal);
if (!hasOriginal)
privateEvent->SetOriginalTarget(oldTarget);
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(mParent);
privateEvent->SetTarget(target);
}
// Node capturing stage
if (NS_EVENT_FLAG_BUBBLE != aFlags) {
if (mParent) {
@ -3236,6 +3285,14 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext,
}
if (retarget) {
// The event originated beneath us, and we performed a retargeting.
// We need to restore the original target of the event.
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(*aDOMEvent);
if (privateEvent)
privateEvent->SetTarget(oldTarget);
}
//Local handling stage
if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH)) {
aEvent->flags |= aFlags;
@ -3243,6 +3300,15 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext,
aEvent->flags &= ~aFlags;
}
if (retarget) {
// The event originated beneath us, and we need to perform a retargeting.
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(*aDOMEvent);
if (privateEvent) {
nsCOMPtr<nsIDOMEventTarget> parentTarget(do_QueryInterface(mParent));
privateEvent->SetTarget(parentTarget);
}
}
//Bubbling stage
if (NS_EVENT_FLAG_CAPTURE != aFlags) {
if (mParent != nsnull) {
@ -3258,6 +3324,14 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext,
}
}
if (retarget) {
// The event originated beneath us, and we performed a retargeting.
// We need to restore the original target of the event.
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(*aDOMEvent);
if (privateEvent)
privateEvent->SetTarget(oldTarget);
}
if (NS_EVENT_FLAG_INIT & aFlags) {
// We're leaving the DOM event loop so if we created a DOM event,
// release here.