Add a second pass of event processing for system events, using DOM3 event group functionality. Bug 124990. Patch by joki, r=saari and bryner, sr=jst.

This commit is contained in:
bryner%netscape.com 2002-11-09 00:25:25 +00:00
Родитель 0d53e0ecc0
Коммит 7b5407b246
40 изменённых файлов: 841 добавлений и 372 удалений

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

@ -192,6 +192,10 @@
#define NS_EVENTSTATEMANAGER_CID \
{ 0xa1fde862, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
// {66856477-6596-40eb-bb87-59ca2dabb6f7}
#define NS_DOMEVENTGROUP_CID \
{ 0x66856477, 0x6596, 0x40eb, { 0xbb, 0x87, 0x59, 0xca, 0x2d, 0xab, 0xb6, 0xf7 } }
// {64F300A1-C88C-11d3-97FB-00400553EEF0}
#define NS_XBLSERVICE_CID \
{ 0x64f300a1, 0xc88c, 0x11d3, { 0x97, 0xfb, 0x0, 0x40, 0x5, 0x53, 0xee, 0xf0 } }

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

@ -80,6 +80,7 @@
#include "nsIDOMDocumentXBL.h"
#include "nsIDOMNavigator.h"
#include "nsGenericElement.h"
#include "nsIDOMEventGroup.h"
#include "nsICSSStyleSheet.h"
@ -135,6 +136,7 @@
#endif
static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);
static NS_DEFINE_CID(kDOMEventGroupCID, NS_DOMEVENTGROUP_CID);
#include "nsILineBreakerFactory.h"
#include "nsIWordBreakerFactory.h"
@ -653,6 +655,7 @@ NS_INTERFACE_MAP_BEGIN(nsDocument)
NS_INTERFACE_MAP_ENTRY(nsIDOMDocument)
NS_INTERFACE_MAP_ENTRY(nsIDOMNSDocument)
NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentEvent)
NS_INTERFACE_MAP_ENTRY(nsIDOM3DocumentEvent)
NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentStyle)
NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentView)
NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentRange)
@ -661,6 +664,7 @@ NS_INTERFACE_MAP_BEGIN(nsDocument)
NS_INTERFACE_MAP_ENTRY(nsIScriptObjectPrincipal)
NS_INTERFACE_MAP_ENTRY(nsIDOMEventReceiver)
NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget)
NS_INTERFACE_MAP_ENTRY(nsIDOM3EventTarget)
NS_INTERFACE_MAP_ENTRY(nsIDOMNode)
NS_INTERFACE_MAP_ENTRY(nsIDOM3Node)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
@ -3455,6 +3459,16 @@ nsresult nsDocument::HandleEvent(nsIDOMEvent *aEvent)
return DispatchEvent(aEvent, &noDefault);
}
NS_IMETHODIMP
nsDocument::GetSystemEventGroup(nsIDOMEventGroup **aGroup)
{
nsCOMPtr<nsIEventListenerManager> manager;
if (NS_SUCCEEDED(GetListenerManager(getter_AddRefs(manager))) && manager) {
return manager->GetSystemEventGroupLM(aGroup);
}
return NS_ERROR_FAILURE;
}
nsresult nsDocument::HandleDOMEvent(nsIPresContext* aPresContext,
nsEvent* aEvent,
nsIDOMEvent** aDOMEvent,
@ -3475,26 +3489,29 @@ nsresult nsDocument::HandleDOMEvent(nsIPresContext* aPresContext,
else {
aDOMEvent = &domEvent;
}
aEvent->flags = aFlags;
aEvent->flags |= aFlags;
aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL);
aFlags |= NS_EVENT_FLAG_BUBBLE | NS_EVENT_FLAG_CAPTURE;
}
//Capturing stage
if (NS_EVENT_FLAG_BUBBLE != aFlags && nsnull != mScriptGlobalObject) {
mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_CAPTURE, aEventStatus);
if (NS_EVENT_FLAG_CAPTURE & aFlags && nsnull != mScriptGlobalObject) {
mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, aFlags & NS_EVENT_CAPTURE_MASK, aEventStatus);
}
//Local handling stage
if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH) &&
!(NS_EVENT_FLAG_BUBBLE & aFlags && NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags)) {
//Check for null mDOMSlots or ELM, check if we're a non-bubbling event in the bubbling state (bubbling state
//is indicated by the presence of the NS_EVENT_FLAG_BUBBLE flag and not the NS_EVENT_FLAG_INIT).
if (mListenerManager &&
!(NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags && NS_EVENT_FLAG_BUBBLE & aFlags && !(NS_EVENT_FLAG_INIT & aFlags))) {
aEvent->flags |= aFlags;
mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, this, aFlags, aEventStatus);
aEvent->flags &= ~aFlags;
}
//Bubbling stage
if (NS_EVENT_FLAG_CAPTURE != aFlags && nsnull != mScriptGlobalObject) {
mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_BUBBLE, aEventStatus);
if (NS_EVENT_FLAG_BUBBLE & aFlags && nsnull != mScriptGlobalObject) {
mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, aFlags & NS_EVENT_BUBBLE_MASK, aEventStatus);
}
if (NS_EVENT_FLAG_INIT & aFlags) {
@ -3550,28 +3567,13 @@ nsresult nsDocument::RemoveEventListenerByIID(nsIDOMEventListener *aListener, co
nsresult nsDocument::AddEventListener(const nsAString& aType, nsIDOMEventListener* aListener,
PRBool aUseCapture)
{
nsCOMPtr<nsIEventListenerManager> manager;
GetListenerManager(getter_AddRefs(manager));
if (manager) {
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
manager->AddEventListenerByType(aListener, aType, flags);
return NS_OK;
}
return NS_ERROR_FAILURE;
return AddGroupedEventListener(aType, aListener, aUseCapture, nsnull);
}
nsresult nsDocument::RemoveEventListener(const nsAString& aType, nsIDOMEventListener* aListener,
PRBool aUseCapture)
{
if (nsnull != mListenerManager) {
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
mListenerManager->RemoveEventListenerByType(aListener, aType, flags);
return NS_OK;
}
return NS_ERROR_FAILURE;
return RemoveGroupedEventListener(aType, aListener, aUseCapture, nsnull);
}
NS_IMETHODIMP
@ -3600,6 +3602,47 @@ nsDocument::DispatchEvent(nsIDOMEvent* aEvent, PRBool *_retval)
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsDocument::AddGroupedEventListener(const nsAString & aType, nsIDOMEventListener *aListener,
PRBool aUseCapture, nsIDOMEventGroup *aEvtGrp)
{
nsCOMPtr<nsIEventListenerManager> manager;
nsresult rv = GetListenerManager(getter_AddRefs(manager));
if (NS_SUCCEEDED(rv) && manager) {
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
manager->AddEventListenerByType(aListener, aType, flags, aEvtGrp);
return NS_OK;
}
return rv;
}
NS_IMETHODIMP
nsDocument::RemoveGroupedEventListener(const nsAString & aType, nsIDOMEventListener *aListener,
PRBool aUseCapture, nsIDOMEventGroup *aEvtGrp)
{
if (mListenerManager) {
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
mListenerManager->RemoveEventListenerByType(aListener, aType, flags, aEvtGrp);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsDocument::CanTrigger(const nsAString & type, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::IsRegisteredHere(const nsAString & type, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::CreateEvent(const nsAString& aEventType,
nsIDOMEvent** aReturn)
@ -3632,6 +3675,19 @@ nsDocument::CreateEvent(const nsAString& aEventType,
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsDocument::CreateEventGroup(nsIDOMEventGroup **aInstancePtrResult)
{
nsresult result;
nsCOMPtr<nsIDOMEventGroup> group(do_CreateInstance(kDOMEventGroupCID,&result));
if (NS_FAILED(result))
return result;
*aInstancePtrResult = group.get();
NS_ADDREF(*aInstancePtrResult);
return NS_OK;
}
NS_IMETHODIMP
nsDocument::FlushPendingNotifications(PRBool aFlushReflows,
PRBool aUpdateViews)

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

@ -51,6 +51,7 @@
#include "nsIDOMDocumentTraversal.h"
#include "nsIDocumentObserver.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOM3EventTarget.h"
#include "nsIDOMStyleSheetList.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDOMEventTarget.h"
@ -60,6 +61,7 @@
#include "nsIBindingManager.h"
#include "nsINodeInfo.h"
#include "nsIDOMDocumentEvent.h"
#include "nsIDOM3DocumentEvent.h"
#include "nsISupportsArray.h"
#include "nsCOMArray.h"
#include "nsHashtable.h"
@ -258,6 +260,7 @@ class nsDocument : public nsIDocument,
public nsIDOMXMLDocument, // inherits nsIDOMDocument
public nsIDOMNSDocument,
public nsIDOMDocumentEvent,
public nsIDOM3DocumentEvent,
public nsIDOMDocumentStyle,
public nsIDOMDocumentView,
public nsIDOMDocumentRange,
@ -266,6 +269,7 @@ class nsDocument : public nsIDocument,
public nsIDOM3Node,
public nsSupportsWeakReference,
public nsIDOMEventReceiver,
public nsIDOM3EventTarget,
public nsIScriptObjectPrincipal,
public nsIRadioGroupContainer
{
@ -558,6 +562,9 @@ public:
// nsIDOMDocumentEvent
NS_DECL_NSIDOMDOCUMENTEVENT
// nsIDOM3DocumentEvent
NS_DECL_NSIDOM3DOCUMENTEVENT
// nsIDOMDocumentStyle
NS_DECL_NSIDOMDOCUMENTSTYLE
@ -580,16 +587,13 @@ public:
const nsIID& aIID);
NS_IMETHOD GetListenerManager(nsIEventListenerManager** aInstancePtrResult);
NS_IMETHOD HandleEvent(nsIDOMEvent *aEvent);
NS_IMETHOD GetSystemEventGroup(nsIDOMEventGroup** aGroup);
// nsIDOMEventTarget interface
NS_IMETHOD AddEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture);
NS_IMETHOD RemoveEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture);
NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvent, PRBool *_retval);
// nsIDOMEventTarget
NS_DECL_NSIDOMEVENTTARGET
// nsIDOM3EventTarget
NS_DECL_NSIDOM3EVENTTARGET
NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext,
nsEvent* aEvent,

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

@ -97,6 +97,11 @@ NS_INTERFACE_MAP_BEGIN(nsGenericDOMDataNode)
nsDOMEventRTTearoff::Create(this));
NS_ENSURE_TRUE(foundInterface, NS_ERROR_OUT_OF_MEMORY);
} else
if (aIID.Equals(NS_GET_IID(nsIDOM3EventTarget))) {
foundInterface = NS_STATIC_CAST(nsIDOM3EventTarget *,
nsDOMEventRTTearoff::Create(this));
NS_ENSURE_TRUE(foundInterface, NS_ERROR_OUT_OF_MEMORY);
} else
NS_INTERFACE_MAP_ENTRY(nsIContent)
// No nsITextContent since all subclasses might not want that.
NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOM3Node, nsNode3Tearoff(this))
@ -788,21 +793,22 @@ nsGenericDOMDataNode::HandleDOMEvent(nsIPresContext* aPresContext,
externalDOMEvent = PR_TRUE;
}
aEvent->flags = aFlags;
aEvent->flags |= aFlags;
aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL);
aFlags |= NS_EVENT_FLAG_BUBBLE | NS_EVENT_FLAG_CAPTURE;
}
nsIContent *parent_weak = GetParentWeak();
//Capturing stage evaluation
if (NS_EVENT_FLAG_BUBBLE != aFlags) {
if (NS_EVENT_FLAG_CAPTURE & aFlags) {
//Initiate capturing phase. Special case first call to document
if (parent_weak) {
parent_weak->HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
NS_EVENT_FLAG_CAPTURE, aEventStatus);
aFlags & NS_EVENT_CAPTURE_MASK, aEventStatus);
} else if (mDocument) {
ret = mDocument->HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
NS_EVENT_FLAG_CAPTURE, aEventStatus);
aFlags & NS_EVENT_CAPTURE_MASK, aEventStatus);
}
}
@ -810,10 +816,12 @@ nsGenericDOMDataNode::HandleDOMEvent(nsIPresContext* aPresContext,
LookupListenerManager(getter_AddRefs(listener_manager));
//Local handling stage
if (listener_manager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH) &&
!(NS_EVENT_FLAG_BUBBLE & aFlags &&
NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags)
&& !(aEvent->flags & NS_EVENT_FLAG_NO_CONTENT_DISPATCH)) {
//Check for null ELM, check if we're a non-bubbling event in the bubbling state (bubbling state
//is indicated by the presence of the NS_EVENT_FLAG_BUBBLE flag and not the NS_EVENT_FLAG_INIT), and check
//if we're a no content dispatch event
if (listener_manager &&
!(NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags && NS_EVENT_FLAG_BUBBLE & aFlags && !(NS_EVENT_FLAG_INIT & aFlags)) &&
!(aEvent->flags & NS_EVENT_FLAG_NO_CONTENT_DISPATCH)) {
aEvent->flags |= aFlags;
listener_manager->HandleEvent(aPresContext, aEvent, aDOMEvent, nsnull,
aFlags, aEventStatus);
@ -821,9 +829,9 @@ nsGenericDOMDataNode::HandleDOMEvent(nsIPresContext* aPresContext,
}
//Bubbling stage
if (NS_EVENT_FLAG_CAPTURE != aFlags && parent_weak) {
if (NS_EVENT_FLAG_BUBBLE & aFlags && parent_weak) {
ret = parent_weak->HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
NS_EVENT_FLAG_BUBBLE, aEventStatus);
aFlags & NS_EVENT_BUBBLE_MASK, aEventStatus);
}
if (NS_EVENT_FLAG_INIT & aFlags) {

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

@ -554,6 +554,15 @@ nsDOMEventRTTearoff::QueryInterface(REFNSIID aIID, void** aInstancePtr)
return NS_OK;
}
else if (aIID.Equals(NS_GET_IID(nsIDOM3EventTarget))) {
nsIDOM3EventTarget *inst = this;
NS_ADDREF(inst);
*aInstancePtr = inst;
return NS_OK;
}
return mContent->QueryInterface(aIID, aInstancePtr);
}
@ -562,7 +571,6 @@ nsDOMEventRTTearoff::QueryInterface(REFNSIID aIID, void** aInstancePtr)
NS_IMPL_ADDREF(nsDOMEventRTTearoff)
NS_IMPL_RELEASE_WITH_DESTROY(nsDOMEventRTTearoff, LastRelease())
nsDOMEventRTTearoff *
nsDOMEventRTTearoff::Create(nsIContent *aContent)
{
@ -623,6 +631,16 @@ nsDOMEventRTTearoff::GetEventReceiver(nsIDOMEventReceiver **aReceiver)
return CallQueryInterface(listener_manager, aReceiver);
}
nsresult
nsDOMEventRTTearoff::GetDOM3EventTarget(nsIDOM3EventTarget **aTarget)
{
nsCOMPtr<nsIEventListenerManager> listener_manager;
nsresult rv = mContent->GetListenerManager(getter_AddRefs(listener_manager));
NS_ENSURE_SUCCESS(rv, rv);
return CallQueryInterface(listener_manager, aTarget);
}
NS_IMETHODIMP
nsDOMEventRTTearoff::AddEventListenerByIID(nsIDOMEventListener *aListener,
const nsIID& aIID)
@ -661,8 +679,17 @@ nsDOMEventRTTearoff::HandleEvent(nsIDOMEvent *aEvent)
return event_receiver->HandleEvent(aEvent);
}
// nsIDOMEventTarget
NS_IMETHODIMP
nsDOMEventRTTearoff::GetSystemEventGroup(nsIDOMEventGroup **aGroup)
{
nsCOMPtr<nsIEventListenerManager> manager;
if (NS_SUCCEEDED(GetListenerManager(getter_AddRefs(manager))) && manager) {
return manager->GetSystemEventGroupLM(aGroup);
}
return NS_ERROR_FAILURE;
}
// nsIDOMEventTarget
NS_IMETHODIMP
nsDOMEventRTTearoff::AddEventListener(const nsAString& type,
nsIDOMEventListener *listener,
@ -697,6 +724,44 @@ nsDOMEventRTTearoff::DispatchEvent(nsIDOMEvent *evt, PRBool* _retval)
return event_receiver->DispatchEvent(evt, _retval);
}
// nsIDOM3EventTarget
NS_IMETHODIMP
nsDOMEventRTTearoff::AddGroupedEventListener(const nsAString& aType,
nsIDOMEventListener *aListener,
PRBool aUseCapture,
nsIDOMEventGroup *aEvtGrp)
{
nsCOMPtr<nsIDOM3EventTarget> event_target;
nsresult rv = GetDOM3EventTarget(getter_AddRefs(event_target));
NS_ENSURE_SUCCESS(rv, rv);
return event_target->AddGroupedEventListener(aType, aListener, aUseCapture, aEvtGrp);
}
NS_IMETHODIMP
nsDOMEventRTTearoff::RemoveGroupedEventListener(const nsAString& aType,
nsIDOMEventListener *aListener,
PRBool aUseCapture,
nsIDOMEventGroup *aEvtGrp)
{
nsCOMPtr<nsIDOM3EventTarget> event_target;
nsresult rv = GetDOM3EventTarget(getter_AddRefs(event_target));
NS_ENSURE_SUCCESS(rv, rv);
return event_target->RemoveGroupedEventListener(aType, aListener, aUseCapture, aEvtGrp);
}
NS_IMETHODIMP
nsDOMEventRTTearoff::CanTrigger(const nsAString & type, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDOMEventRTTearoff::IsRegisteredHere(const nsAString & type, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
//----------------------------------------------------------------------
@ -1888,8 +1953,9 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext,
} else {
aDOMEvent = &domEvent;
}
aEvent->flags = aFlags;
aEvent->flags |= aFlags;
aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL);
aFlags |= NS_EVENT_FLAG_BUBBLE | NS_EVENT_FLAG_CAPTURE;
}
// Find out if we're anonymous.
@ -1968,17 +2034,19 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext,
}
//Capturing stage evaluation
if (NS_EVENT_FLAG_BUBBLE != aFlags && aEvent->message != NS_PAGE_LOAD &&
if (NS_EVENT_FLAG_CAPTURE & aFlags && aEvent->message != NS_PAGE_LOAD &&
aEvent->message != NS_SCRIPT_LOAD &&
aEvent->message != NS_IMAGE_ERROR && aEvent->message != NS_IMAGE_LOAD &&
aEvent->message != NS_SCROLL_EVENT) {
//Initiate capturing phase. Special case first call to document
if (parent) {
parent->HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
NS_EVENT_FLAG_CAPTURE, aEventStatus);
aFlags & NS_EVENT_CAPTURE_MASK,
aEventStatus);
} else if (mDocument != nsnull) {
ret = mDocument->HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
NS_EVENT_FLAG_CAPTURE, aEventStatus);
aFlags & NS_EVENT_CAPTURE_MASK,
aEventStatus);
}
}
@ -2011,10 +2079,10 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext,
}
//Local handling stage
if (lm && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH) &&
!(NS_EVENT_FLAG_BUBBLE & aFlags &&
NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags)
&& !(aEvent->flags & NS_EVENT_FLAG_NO_CONTENT_DISPATCH)) {
if (lm &&
!(NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags &&
NS_EVENT_FLAG_BUBBLE & aFlags && !(NS_EVENT_FLAG_INIT & aFlags)) &&
!(aEvent->flags & NS_EVENT_FLAG_NO_CONTENT_DISPATCH)) {
aEvent->flags |= aFlags;
nsCOMPtr<nsIDOMEventTarget> curTarg =
@ -2027,8 +2095,8 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext,
// We don't want scroll events to bubble further after it has been
// handled at the local stage.
if (aEvent->message == NS_SCROLL_EVENT && aFlags == NS_EVENT_FLAG_BUBBLE)
aEvent->flags = NS_EVENT_FLAG_CANT_BUBBLE;
if (aEvent->message == NS_SCROLL_EVENT && aFlags & NS_EVENT_FLAG_BUBBLE)
aEvent->flags |= NS_EVENT_FLAG_CANT_BUBBLE;
}
if (retarget) {
@ -2042,22 +2110,24 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext,
}
//Bubbling stage
if (NS_EVENT_FLAG_CAPTURE != aFlags && mDocument &&
if (NS_EVENT_FLAG_BUBBLE & aFlags && mDocument &&
aEvent->message != NS_PAGE_LOAD && aEvent->message != NS_SCRIPT_LOAD &&
aEvent->message != NS_IMAGE_ERROR && aEvent->message != NS_IMAGE_LOAD &&
!(aEvent->message == NS_SCROLL_EVENT &&
aEvent->flags == NS_EVENT_FLAG_CANT_BUBBLE)) {
aEvent->flags & NS_EVENT_FLAG_CANT_BUBBLE)) {
if (parent) {
// If there's a parent we pass the event to the parent...
ret = parent->HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
NS_EVENT_FLAG_BUBBLE, aEventStatus);
aFlags & NS_EVENT_BUBBLE_MASK,
aEventStatus);
} else {
// If there's no parent but there is a document (i.e. this is
// the root node) we pass the event to the document...
ret = mDocument->HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
NS_EVENT_FLAG_BUBBLE, aEventStatus);
aFlags & NS_EVENT_BUBBLE_MASK,
aEventStatus);
}
}
@ -3026,6 +3096,10 @@ nsGenericElement::QueryInterface(REFNSIID aIID, void** aInstancePtr)
inst = NS_STATIC_CAST(nsIDOMEventReceiver *,
nsDOMEventRTTearoff::Create(this));
NS_ENSURE_TRUE(inst, NS_ERROR_OUT_OF_MEMORY);
} else if (aIID.Equals(NS_GET_IID(nsIDOM3EventTarget))) {
inst = NS_STATIC_CAST(nsIDOM3EventTarget *,
nsDOMEventRTTearoff::Create(this));
NS_ENSURE_TRUE(inst, NS_ERROR_OUT_OF_MEMORY);
} else {
return NS_NOINTERFACE;
}

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

@ -47,6 +47,7 @@
#include "nsIDOMNodeList.h"
#include "nsIDOMLinkStyle.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOM3EventTarget.h"
#include "nsIStyleSheetLinkingElement.h"
#include "nsICSSStyleSheet.h"
#include "nsICSSLoaderObserver.h"
@ -254,7 +255,8 @@ private:
* @see nsDOMEventRTTearoff::Create
*/
class nsDOMEventRTTearoff : public nsIDOMEventReceiver
class nsDOMEventRTTearoff : public nsIDOMEventReceiver,
public nsIDOM3EventTarget
{
private:
// This class uses a caching scheme so we don't let users of this
@ -276,6 +278,7 @@ private:
void LastRelease();
nsresult GetEventReceiver(nsIDOMEventReceiver **aReceiver);
nsresult GetDOM3EventTarget(nsIDOM3EventTarget **aTarget);
public:
virtual ~nsDOMEventRTTearoff();
@ -297,6 +300,9 @@ public:
// nsIDOMEventTarget
NS_DECL_NSIDOMEVENTTARGET
// nsIDOM3EventTarget
NS_DECL_NSIDOM3EVENTTARGET
// nsIDOMEventReceiver
NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener,
const nsIID& aIID);
@ -304,6 +310,7 @@ public:
const nsIID& aIID);
NS_IMETHOD GetListenerManager(nsIEventListenerManager** aResult);
NS_IMETHOD HandleEvent(nsIDOMEvent *aEvent);
NS_IMETHOD GetSystemEventGroup(nsIDOMEventGroup** aGroup);
private:
/**

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

@ -192,6 +192,10 @@
#define NS_EVENTSTATEMANAGER_CID \
{ 0xa1fde862, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
// {66856477-6596-40eb-bb87-59ca2dabb6f7}
#define NS_DOMEVENTGROUP_CID \
{ 0x66856477, 0x6596, 0x40eb, { 0xbb, 0x87, 0x59, 0xca, 0x2d, 0xab, 0xb6, 0xf7 } }
// {64F300A1-C88C-11d3-97FB-00400553EEF0}
#define NS_XBLSERVICE_CID \
{ 0x64f300a1, 0xc88c, 0x11d3, { 0x97, 0xfb, 0x0, 0x40, 0x5, 0x53, 0xee, 0xf0 } }

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

@ -69,6 +69,7 @@
#include "nsIController.h"
#include "nsIControllers.h"
#include "nsIDOMDOMImplementation.h"
#include "nsIDOMEventGroup.h"
#include "nsIDOMRange.h"
#include "nsIDocument.h"
#include "nsIDocumentEncoder.h"
@ -287,6 +288,7 @@ extern nsresult NS_NewNodeInfoManager(nsINodeInfoManager** aResult);
extern nsresult NS_NewContentPolicy(nsIContentPolicy** aResult);
extern nsresult NS_NewFrameLoader(nsIFrameLoader** aResult);
extern nsresult NS_NewSyncLoadDOMService(nsISyncLoadDOMService** aResult);
extern nsresult NS_NewDOMEventGroup(nsIDOMEventGroup** aResult);
#ifdef MOZ_XUL
extern nsresult NS_NewXULElementFactory(nsIElementFactory** aResult);
@ -320,6 +322,7 @@ ctor_(nsISupports* aOuter, REFNSIID aIID, void** aResult) \
MAKE_CTOR(CreateNameSpaceManager, nsINameSpaceManager, NS_NewNameSpaceManager)
MAKE_CTOR(CreateEventListenerManager, nsIEventListenerManager, NS_NewEventListenerManager)
MAKE_CTOR(CreateEventStateManager, nsIEventStateManager, NS_NewEventStateManager)
MAKE_CTOR(CreateDOMEventGroup, nsIDOMEventGroup, NS_NewDOMEventGroup)
MAKE_CTOR(CreateDocumentViewer, nsIDocumentViewer, NS_NewDocumentViewer)
MAKE_CTOR(CreateHTMLStyleSheet, nsIHTMLStyleSheet, NS_NewHTMLStyleSheet)
MAKE_CTOR(CreateStyleSet, nsIStyleSet, NS_NewStyleSet)
@ -505,6 +508,11 @@ static const nsModuleComponentInfo gComponents[] = {
nsnull,
CreateEventStateManager },
{ "DOM Event group",
NS_DOMEVENTGROUP_CID,
nsnull,
CreateDOMEventGroup },
{ "Document Viewer",
NS_DOCUMENT_VIEWER_CID,
nsnull,

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

@ -47,6 +47,7 @@ class nsIPresContext;
class nsIDOMEventListener;
class nsIScriptContext;
class nsIDOMEventTarget;
class nsIDOMEventGroup;
/*
* Event listener manager interface.
@ -81,7 +82,8 @@ public:
*/
NS_IMETHOD AddEventListenerByType(nsIDOMEventListener *aListener,
const nsAString& type,
PRInt32 flags) = 0;
PRInt32 flags,
nsIDOMEventGroup* aEvtGrp) = 0;
/**
* Removes events listeners of all types.
@ -89,7 +91,8 @@ public:
*/
NS_IMETHOD RemoveEventListenerByType(nsIDOMEventListener *aListener,
const nsAString& type,
PRInt32 flags) = 0;
PRInt32 flags,
nsIDOMEventGroup* aEvtGrp) = 0;
/**
* Creates a script event listener for the given script object with
@ -173,6 +176,13 @@ public:
* Allows us to quickly determine if we have mutation listeners registered.
*/
NS_IMETHOD HasMutationListeners(PRBool* aListener) = 0;
/**
* Gets the EventGroup registered for use by system event listeners.
* This is a special EventGroup which is used in the secondary DOM Event
* Loop pass for evaluation of system event listeners.
*/
NS_IMETHOD GetSystemEventGroupLM(nsIDOMEventGroup** aGroup) = 0;
};
extern nsresult

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

@ -53,6 +53,7 @@ CPPSRCS = \
nsDOMEvent.cpp \
nsDOMMutationEvent.cpp \
nsPrivateTextRange.cpp \
nsDOMEventGroup.cpp \
$(NULL)
# we don't want the shared lib, but we want to force the creation of a static lib.

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

@ -399,15 +399,15 @@ nsDOMEvent::SetTrusted(PRBool aTrusted)
NS_IMETHODIMP
nsDOMEvent::GetEventPhase(PRUint16* aEventPhase)
{
if (mEvent->flags & NS_EVENT_FLAG_CAPTURE) {
if (mEvent->flags & NS_EVENT_FLAG_INIT) {
*aEventPhase = nsIDOMMouseEvent::AT_TARGET;
}
else if (mEvent->flags & NS_EVENT_FLAG_CAPTURE) {
*aEventPhase = nsIDOMMouseEvent::CAPTURING_PHASE;
}
else if (mEvent->flags & NS_EVENT_FLAG_BUBBLE) {
*aEventPhase = nsIDOMMouseEvent::BUBBLING_PHASE;
}
else if (mEvent->flags & NS_EVENT_FLAG_INIT) {
*aEventPhase = nsIDOMMouseEvent::AT_TARGET;
}
else {
*aEventPhase = 0;
}

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

@ -89,11 +89,18 @@
#include "nsIDOMNSDocument.h"
#include "nsIWidget.h"
#include "nsContentUtils.h"
#include "nsIDOMEventGroup.h"
#include "nsContentCID.h"
static NS_DEFINE_CID(kDOMScriptObjectFactoryCID,
NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
static NS_DEFINE_CID(kDOMEventGroupCID, NS_DOMEVENTGROUP_CID);
// Strong references to event groups
nsIDOMEventGroup* gSystemEventGroup;
nsIDOMEventGroup* gDOM2EventGroup;
PRUint32 nsEventListenerManager::mInstanceCount = 0;
nsEventListenerManager::nsEventListenerManager()
{
@ -106,6 +113,7 @@ nsEventListenerManager::nsEventListenerManager()
mTarget = nsnull;
NS_INIT_ISUPPORTS();
++mInstanceCount;
}
static PRBool PR_CALLBACK
@ -139,10 +147,16 @@ GenericListenersHashEnum(nsHashKey *aKey, void *aData, void* closure)
}
return PR_TRUE;
}
nsEventListenerManager::~nsEventListenerManager()
{
RemoveAllListeners(PR_FALSE);
--mInstanceCount;
if(mInstanceCount == 0) {
NS_IF_RELEASE(gSystemEventGroup);
NS_IF_RELEASE(gDOM2EventGroup);
}
}
nsresult nsEventListenerManager::RemoveAllListeners(PRBool aScriptOnly)
@ -198,6 +212,7 @@ NS_INTERFACE_MAP_BEGIN(nsEventListenerManager)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIEventListenerManager)
NS_INTERFACE_MAP_ENTRY(nsIEventListenerManager)
NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget)
NS_INTERFACE_MAP_ENTRY(nsIDOM3EventTarget)
NS_INTERFACE_MAP_ENTRY(nsIDOMEventReceiver)
NS_INTERFACE_MAP_END
@ -392,7 +407,8 @@ nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener,
EventArrayType aType,
PRInt32 aSubType,
nsHashKey* aKey,
PRInt32 aFlags)
PRInt32 aFlags,
nsIDOMEventGroup* aEvtGrp)
{
NS_ENSURE_TRUE(aListener, NS_ERROR_FAILURE);
@ -423,15 +439,28 @@ nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener,
window->SetMutationListeners(aSubType);
}
}
PRBool isSame = PR_FALSE;
PRUint16 group = 0;
nsCOMPtr<nsIDOMEventGroup> sysGroup;
GetSystemEventGroupLM(getter_AddRefs(sysGroup));
if (sysGroup) {
sysGroup->IsSameEventGroup(aEvtGrp, &isSame);
if (isSame) {
group = NS_EVENT_FLAG_SYSTEM_EVENT;
}
}
PRBool found = PR_FALSE;
nsListenerStruct* ls;
nsresult rv;
nsCOMPtr<nsIScriptEventListener> sel = do_QueryInterface(aListener, &rv);
for (int i=0; i<listeners->Count(); i++) {
ls = (nsListenerStruct*)listeners->ElementAt(i);
if (ls->mListener == aListener && ls->mFlags == aFlags) {
if (ls->mListener == aListener && ls->mFlags == aFlags && ls->mGroupFlags == group) {
ls->mSubType |= aSubType;
found = PR_TRUE;
break;
@ -460,6 +489,7 @@ nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener,
ls->mSubType = aSubType;
ls->mSubTypeCapture = NS_EVENT_BITS_NONE;
ls->mHandlerIsString = 0;
ls->mGroupFlags = group;
listeners->AppendElement((void*)ls);
NS_ADDREF(aListener);
}
@ -486,7 +516,8 @@ nsEventListenerManager::RemoveEventListener(nsIDOMEventListener *aListener,
EventArrayType aType,
PRInt32 aSubType,
nsHashKey* aKey,
PRInt32 aFlags)
PRInt32 aFlags,
nsIDOMEventGroup* aEvtGrp)
{
nsVoidArray* listeners = GetListenersByType(aType, aKey, PR_FALSE);
@ -549,7 +580,7 @@ nsEventListenerManager::RemoveEventListener(nsIDOMEventListener *aListener,
nsresult nsEventListenerManager::AddEventListenerByIID(nsIDOMEventListener *aListener,
const nsIID& aIID, PRInt32 aFlags)
{
AddEventListener(aListener, GetTypeForIID(aIID), NS_EVENT_BITS_NONE, nsnull, aFlags);
AddEventListener(aListener, GetTypeForIID(aIID), NS_EVENT_BITS_NONE, nsnull, aFlags, nsnull);
return NS_OK;
}
@ -558,7 +589,7 @@ nsEventListenerManager::RemoveEventListenerByIID(nsIDOMEventListener *aListener,
const nsIID& aIID,
PRInt32 aFlags)
{
RemoveEventListener(aListener, GetTypeForIID(aIID), NS_EVENT_BITS_NONE, nsnull, aFlags);
RemoveEventListener(aListener, GetTypeForIID(aIID), NS_EVENT_BITS_NONE, nsnull, aFlags, nsnull);
return NS_OK;
}
@ -765,7 +796,8 @@ nsresult nsEventListenerManager::GetIdentifiersForType(nsIAtom* aType, EventArra
NS_IMETHODIMP
nsEventListenerManager::AddEventListenerByType(nsIDOMEventListener *aListener,
const nsAString& aType,
PRInt32 aFlags)
PRInt32 aFlags,
nsIDOMEventGroup* aEvtGrp)
{
PRInt32 subType;
EventArrayType arrayType;
@ -773,12 +805,12 @@ nsEventListenerManager::AddEventListenerByType(nsIDOMEventListener *aListener,
dont_AddRef(NS_NewAtom(NS_LITERAL_STRING("on") + aType));
if (NS_OK == GetIdentifiersForType(atom, &arrayType, &subType)) {
AddEventListener(aListener, arrayType, subType, nsnull, aFlags);
AddEventListener(aListener, arrayType, subType, nsnull, aFlags, aEvtGrp);
}
else {
const nsPromiseFlatString& flatString = PromiseFlatString(aType);
nsStringKey key(flatString);
AddEventListener(aListener, eEventArrayType_Hash, NS_EVENT_BITS_NONE, &key, aFlags);
AddEventListener(aListener, eEventArrayType_Hash, NS_EVENT_BITS_NONE, &key, aFlags, aEvtGrp);
}
return NS_OK;
@ -787,7 +819,8 @@ nsEventListenerManager::AddEventListenerByType(nsIDOMEventListener *aListener,
NS_IMETHODIMP
nsEventListenerManager::RemoveEventListenerByType(nsIDOMEventListener *aListener,
const nsAString& aType,
PRInt32 aFlags)
PRInt32 aFlags,
nsIDOMEventGroup* aEvtGrp)
{
PRInt32 subType;
EventArrayType arrayType;
@ -795,12 +828,12 @@ nsEventListenerManager::RemoveEventListenerByType(nsIDOMEventListener *aListener
dont_AddRef(NS_NewAtom(NS_LITERAL_STRING("on") + aType));
if (NS_OK == GetIdentifiersForType(atom, &arrayType, &subType)) {
RemoveEventListener(aListener, arrayType, subType, nsnull, aFlags);
RemoveEventListener(aListener, arrayType, subType, nsnull, aFlags, aEvtGrp);
}
else {
const nsPromiseFlatString& flatString = PromiseFlatString(aType);
nsStringKey key(flatString);
RemoveEventListener(aListener, eEventArrayType_Hash, NS_EVENT_BITS_NONE, &key, aFlags);
RemoveEventListener(aListener, eEventArrayType_Hash, NS_EVENT_BITS_NONE, &key, aFlags, aEvtGrp);
}
return NS_OK;
@ -852,7 +885,7 @@ nsEventListenerManager::SetJSEventListener(nsIScriptContext *aContext,
getter_AddRefs(scriptListener));
if (NS_SUCCEEDED(rv)) {
AddEventListener(scriptListener, arrayType, NS_EVENT_BITS_NONE, nsnull,
NS_EVENT_FLAG_BUBBLE | NS_PRIV_EVENT_FLAG_SCRIPT);
NS_EVENT_FLAG_BUBBLE | NS_PRIV_EVENT_FLAG_SCRIPT, nsnull);
ls = FindJSEventListener(arrayType);
}
@ -1205,6 +1238,10 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
NS_ENSURE_ARG_POINTER(aEventStatus);
nsresult ret = NS_OK;
if (aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH) {
return ret;
}
if (aFlags & NS_EVENT_FLAG_INIT) {
aFlags |= (NS_EVENT_FLAG_BUBBLE | NS_EVENT_FLAG_CAPTURE);
}
@ -1212,6 +1249,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
if (*aEventStatus == nsEventStatus_eConsumeNoDefault) {
aEvent->flags |= NS_EVENT_FLAG_NO_DEFAULT;
}
PRUint16 currentGroup = aFlags & NS_EVENT_FLAG_SYSTEM_EVENT;
/* Without this addref, certain events, notably ones bound to
keys which cause window deletion, can destroy this object
@ -1230,7 +1268,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
if (NS_SUCCEEDED(ret)) {
for (int i=0; !mListenersRemoved && listeners && i<listeners->Count(); i++) {
nsListenerStruct *ls = (nsListenerStruct*)listeners->ElementAt(i);
if (ls->mFlags & aFlags) {
if (ls->mFlags & aFlags && ls->mGroupFlags == currentGroup) {
ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, NS_EVENT_BITS_NONE, aFlags);
}
}
@ -1261,7 +1299,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
for (int i=0; !mListenersRemoved && listeners && i<listeners->Count(); i++) {
nsListenerStruct *ls = (nsListenerStruct*)listeners->ElementAt(i);
if (ls->mFlags & aFlags) {
if (ls->mFlags & aFlags && ls->mGroupFlags == currentGroup) {
nsCOMPtr<nsIDOMMouseListener> mouseListener (do_QueryInterface(ls->mListener));
if (mouseListener) {
switch(aEvent->message) {
@ -1366,7 +1404,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
for (int i=0; !mListenersRemoved && listeners && i<listeners->Count(); i++) {
nsListenerStruct *ls = (nsListenerStruct*)listeners->ElementAt(i);
if (ls->mFlags & aFlags) {
if (ls->mFlags & aFlags && ls->mGroupFlags == currentGroup) {
nsCOMPtr<nsIDOMMouseMotionListener> mousemlistener (do_QueryInterface(ls->mListener));
if (mousemlistener) {
switch(aEvent->message) {
@ -1461,7 +1499,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
for (int i=0; !mListenersRemoved && listeners && i<listeners->Count(); i++) {
nsListenerStruct *ls = (nsListenerStruct*)listeners->ElementAt(i);
if (ls->mFlags & aFlags) {
if (ls->mFlags & aFlags && ls->mGroupFlags == currentGroup) {
nsCOMPtr<nsIDOMContextMenuListener> contextMenuListener (do_QueryInterface(ls->mListener));
if (contextMenuListener) {
switch(aEvent->message) {
@ -1511,7 +1549,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
for(int i=0; !mListenersRemoved && listeners && i<listeners->Count();i++) {
nsListenerStruct *ls = (nsListenerStruct*)listeners->ElementAt(i);
if (ls->mFlags & aFlags) {
if (ls->mFlags & aFlags && ls->mGroupFlags == currentGroup) {
nsCOMPtr<nsIDOMCompositionListener> compositionListener (do_QueryInterface(ls->mListener));
if (compositionListener) {
switch (aEvent->message) {
@ -1574,7 +1612,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
for (int i=0; !mListenersRemoved && listeners && i<listeners->Count(); i++) {
nsListenerStruct *ls = (nsListenerStruct*)listeners->ElementAt(i);
if (ls->mFlags & aFlags) {
if (ls->mFlags & aFlags && ls->mGroupFlags == currentGroup) {
nsCOMPtr<nsIDOMTextListener> textListener (do_QueryInterface(ls->mListener));
if (textListener) {
ret = textListener->HandleText(*aDOMEvent);
@ -1607,7 +1645,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
for (int i=0; !mListenersRemoved && listeners && i<listeners->Count(); i++) {
nsListenerStruct *ls = (nsListenerStruct*)listeners->ElementAt(i);
if (ls->mFlags & aFlags) {
if (ls->mFlags & aFlags && ls->mGroupFlags == currentGroup) {
nsCOMPtr<nsIDOMKeyListener> keyListener (do_QueryInterface(ls->mListener));
if (keyListener) {
switch(aEvent->message) {
@ -1670,7 +1708,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
for (int i=0; !mListenersRemoved && listeners && i<listeners->Count(); i++) {
nsListenerStruct *ls = (nsListenerStruct*)listeners->ElementAt(i);
if (ls->mFlags & aFlags) {
if (ls->mFlags & aFlags && ls->mGroupFlags == currentGroup) {
nsCOMPtr<nsIDOMFocusListener> focusListener (do_QueryInterface(ls->mListener));
if (focusListener) {
switch(aEvent->message) {
@ -1727,7 +1765,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
for (int i=0; !mListenersRemoved && listeners && i<listeners->Count(); i++) {
nsListenerStruct *ls = (nsListenerStruct*)listeners->ElementAt(i);
if (ls->mFlags & aFlags) {
if (ls->mFlags & aFlags && ls->mGroupFlags == currentGroup) {
nsCOMPtr<nsIDOMFormListener> formListener(do_QueryInterface(ls->mListener));
if (formListener) {
switch(aEvent->message) {
@ -1812,7 +1850,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
for (int i=0; !mListenersRemoved && listeners && i<listeners->Count(); i++) {
nsListenerStruct *ls = (nsListenerStruct*)listeners->ElementAt(i);
if (ls->mFlags & aFlags) {
if (ls->mFlags & aFlags && ls->mGroupFlags == currentGroup) {
nsCOMPtr<nsIDOMLoadListener> loadListener(do_QueryInterface(ls->mListener));
if (loadListener) {
switch(aEvent->message) {
@ -1881,7 +1919,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
for (int i=0; !mListenersRemoved && listeners && i<listeners->Count(); i++) {
nsListenerStruct *ls = (nsListenerStruct*)listeners->ElementAt(i);
if (ls->mFlags & aFlags) {
if (ls->mFlags & aFlags && ls->mGroupFlags == currentGroup) {
nsCOMPtr<nsIDOMPaintListener> paintListener(do_QueryInterface(ls->mListener));
if (paintListener) {
switch(aEvent->message) {
@ -1948,7 +1986,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
for (int i=0; !mListenersRemoved && listeners && i<listeners->Count(); i++) {
nsListenerStruct *dragStruct = (nsListenerStruct*)listeners->ElementAt(i);
if (dragStruct->mFlags & aFlags) {
if (dragStruct->mFlags & aFlags && dragStruct->mGroupFlags == currentGroup) {
nsCOMPtr<nsIDOMDragListener> dragListener ( do_QueryInterface(dragStruct->mListener) );
if ( dragListener ) {
switch (aEvent->message) {
@ -2021,7 +2059,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
for (int i=0; !mListenersRemoved && listeners && i<listeners->Count(); i++) {
nsListenerStruct *ls = (nsListenerStruct*)listeners->ElementAt(i);
if (ls->mFlags & aFlags) {
if (ls->mFlags & aFlags && ls->mGroupFlags == currentGroup) {
nsCOMPtr<nsIDOMScrollListener> scrollListener(do_QueryInterface(ls->mListener));
if (scrollListener) {
switch(aEvent->message) {
@ -2089,7 +2127,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
for (int i=0; !mListenersRemoved && listeners && i<listeners->Count(); i++) {
nsListenerStruct *ls = (nsListenerStruct*)listeners->ElementAt(i);
if (ls->mFlags & aFlags) {
if (ls->mFlags & aFlags && ls->mGroupFlags == currentGroup) {
nsCOMPtr<nsIDOMXULListener> xulListener(do_QueryInterface(ls->mListener));
if (xulListener) {
switch(aEvent->message) {
@ -2202,7 +2240,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
for (int i=0; !mListenersRemoved && listeners && i<listeners->Count(); i++) {
nsListenerStruct *ls = (nsListenerStruct*)listeners->ElementAt(i);
if (ls->mFlags & aFlags) {
if (ls->mFlags & aFlags && ls->mGroupFlags == currentGroup) {
nsCOMPtr<nsIDOMMutationListener> mutationListener = do_QueryInterface(ls->mListener);
if (mutationListener) {
switch(aEvent->message) {
@ -2583,6 +2621,42 @@ nsEventListenerManager::SetListenerTarget(nsISupports* aTarget)
return NS_OK;
}
NS_IMETHODIMP
nsEventListenerManager::GetSystemEventGroupLM(nsIDOMEventGroup **aGroup)
{
if (!gSystemEventGroup) {
nsresult result;
nsCOMPtr<nsIDOMEventGroup> group(do_CreateInstance(kDOMEventGroupCID,&result));
if (NS_FAILED(result))
return result;
gSystemEventGroup = group;
NS_ADDREF(gSystemEventGroup);
}
*aGroup = gSystemEventGroup;
NS_ADDREF(*aGroup);
return NS_OK;
}
nsresult
nsEventListenerManager::GetDOM2EventGroup(nsIDOMEventGroup **aGroup)
{
if (!gDOM2EventGroup) {
nsresult result;
nsCOMPtr<nsIDOMEventGroup> group(do_CreateInstance(kDOMEventGroupCID,&result));
if (NS_FAILED(result))
return result;
gDOM2EventGroup = group;
NS_ADDREF(gDOM2EventGroup);
}
*aGroup = gDOM2EventGroup;
NS_ADDREF(*aGroup);
return NS_OK;
}
// nsIDOMEventTarget interface
NS_IMETHODIMP
nsEventListenerManager::AddEventListener(const nsAString& aType,
@ -2591,7 +2665,7 @@ nsEventListenerManager::AddEventListener(const nsAString& aType,
{
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
return AddEventListenerByType(aListener, aType, flags);
return AddEventListenerByType(aListener, aType, flags, nsnull);
}
NS_IMETHODIMP
@ -2601,7 +2675,7 @@ nsEventListenerManager::RemoveEventListener(const nsAString& aType,
{
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
return RemoveEventListenerByType(aListener, aType, flags);
return RemoveEventListenerByType(aListener, aType, flags, nsnull);
}
NS_IMETHODIMP
@ -2637,6 +2711,41 @@ nsEventListenerManager::DispatchEvent(nsIDOMEvent* aEvent, PRBool *_retval)
return NS_ERROR_FAILURE;
}
// nsIDOM3EventTarget interface
NS_IMETHODIMP
nsEventListenerManager::AddGroupedEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture,
nsIDOMEventGroup* aEvtGrp)
{
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
return AddEventListenerByType(aListener, aType, flags, aEvtGrp);
}
NS_IMETHODIMP
nsEventListenerManager::RemoveGroupedEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture,
nsIDOMEventGroup* aEvtGrp)
{
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
return RemoveEventListenerByType(aListener, aType, flags, aEvtGrp);
}
NS_IMETHODIMP
nsEventListenerManager::CanTrigger(const nsAString & type, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsEventListenerManager::IsRegisteredHere(const nsAString & type, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
// nsIDOMEventReceiver interface
NS_IMETHODIMP
nsEventListenerManager::AddEventListenerByIID(nsIDOMEventListener *aListener,
@ -2667,6 +2776,12 @@ nsEventListenerManager::HandleEvent(nsIDOMEvent *aEvent)
return DispatchEvent(aEvent, &noDefault);
}
NS_IMETHODIMP
nsEventListenerManager::GetSystemEventGroup(nsIDOMEventGroup **aGroup)
{
return GetSystemEventGroupLM(aGroup);
}
void nsEventListenerManager::GetCoordinatesFor(nsIDOMElement *aCurrentEl,
nsIPresContext *aPresContext,
nsIPresShell *aPresShell,

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

@ -44,6 +44,7 @@
#include "nsCOMPtr.h"
#include "nsIPrincipal.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOM3EventTarget.h"
#include "nsHashtable.h"
#include "nsIScriptContext.h"
@ -56,6 +57,7 @@ typedef struct {
PRUint8 mSubType;
PRUint8 mHandlerIsString;
PRUint8 mSubTypeCapture;
PRUint16 mGroupFlags;
} nsListenerStruct;
//These define the internal type of the EventListenerManager
@ -96,7 +98,8 @@ enum EventArrayType {
*/
class nsEventListenerManager : public nsIEventListenerManager,
public nsIDOMEventReceiver
public nsIDOMEventReceiver,
public nsIDOM3EventTarget
{
public:
@ -115,10 +118,12 @@ public:
const nsIID& aIID, PRInt32 aFlags);
NS_IMETHOD AddEventListenerByType(nsIDOMEventListener *aListener,
const nsAString& type,
PRInt32 aFlags);
PRInt32 aFlags,
nsIDOMEventGroup* aEvtGroup);
NS_IMETHOD RemoveEventListenerByType(nsIDOMEventListener *aListener,
const nsAString& type,
PRInt32 aFlags) ;
PRInt32 aFlags,
nsIDOMEventGroup* aEvtGroup);
NS_IMETHOD AddScriptEventListener(nsIScriptContext *aContext,
nsISupports *aObject,
nsIAtom *aName,
@ -158,18 +163,17 @@ public:
return NS_OK;
}
NS_IMETHOD GetSystemEventGroupLM(nsIDOMEventGroup** aGroup);
static nsresult GetIdentifiersForType(nsIAtom* aType,
EventArrayType* aArrayType,
PRInt32* aSubType);
// nsIDOMEventTarget interface
NS_IMETHOD AddEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture);
NS_IMETHOD RemoveEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture);
NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvent, PRBool *_retval);
// nsIDOMEventTarget
NS_DECL_NSIDOMEVENTTARGET
// nsIDOM3EventTarget
NS_DECL_NSIDOM3EVENTTARGET
// nsIDOMEventReceiver interface
NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener,
@ -178,6 +182,7 @@ public:
const nsIID& aIID);
NS_IMETHOD GetListenerManager(nsIEventListenerManager** aInstancePtrResult);
NS_IMETHOD HandleEvent(nsIDOMEvent *aEvent);
NS_IMETHOD GetSystemEventGroup(nsIDOMEventGroup** aGroup);
static void Shutdown();
@ -200,18 +205,21 @@ protected:
EventArrayType aType,
PRInt32 aSubType,
nsHashKey* aKey,
PRInt32 aFlags);
PRInt32 aFlags,
nsIDOMEventGroup* aEvtGrp);
nsresult RemoveEventListener(nsIDOMEventListener *aListener,
EventArrayType aType,
PRInt32 aSubType,
nsHashKey* aKey,
PRInt32 aFlags);
PRInt32 aFlags,
nsIDOMEventGroup* aEvtGrp);
void ReleaseListeners(nsVoidArray** aListeners, PRBool aScriptOnly);
nsresult FlipCaptureBit(PRInt32 aEventTypes, PRBool aInitCapture);
nsVoidArray* GetListenersByType(EventArrayType aType, nsHashKey* aKey, PRBool aCreate);
EventArrayType GetTypeForIID(const nsIID& aIID);
void GetCoordinatesFor(nsIDOMElement *aCurrentEl, nsIPresContext *aPresContext,
nsIPresShell *aPresShell, nsPoint& aTargetPt);
nsresult GetDOM2EventGroup(nsIDOMEventGroup** aGroup);
PRUint8 mManagerType;
EventArrayType mSingleListenerType;
@ -219,6 +227,7 @@ protected:
nsVoidArray* mMultiListeners;
nsHashtable* mGenericListeners;
PRBool mListenersRemoved;
static PRUint32 mInstanceCount;
nsCOMPtr<nsIPrincipal> mPrincipal;
nsISupports* mTarget; //WEAK

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

@ -4375,10 +4375,10 @@ nsEventStateManager::DispatchNewEvent(nsISupports* aTarget, nsIDOMEvent* aEvent,
privEvt->SetTarget(eventTarget);
//Key and mouse events have additional security to prevent event spoofing
nsEvent * internalEvent;
privEvt->GetInternalNSEvent(&internalEvent);
if (internalEvent && (internalEvent->eventStructType == NS_KEY_EVENT ||
internalEvent->eventStructType == NS_MOUSE_EVENT)) {
nsEvent * innerEvent;
privEvt->GetInternalNSEvent(&innerEvent);
if (innerEvent && (innerEvent->eventStructType == NS_KEY_EVENT ||
innerEvent->eventStructType == NS_MOUSE_EVENT)) {
//Check security state to determine if dispatcher is trusted
nsCOMPtr<nsIScriptSecurityManager>
securityManager(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID));
@ -4397,8 +4397,6 @@ nsEventStateManager::DispatchNewEvent(nsISupports* aTarget, nsIDOMEvent* aEvent,
privEvt->SetTrusted(PR_TRUE);
}
nsEvent* innerEvent;
privEvt->GetInternalNSEvent(&innerEvent);
if (innerEvent) {
nsEventStatus status = nsEventStatus_eIgnore;
nsCOMPtr<nsIScriptGlobalObject> target(do_QueryInterface(aTarget));

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

@ -1419,7 +1419,7 @@ nsGenericHTMLElement::HandleDOMEventForAnchors(nsIContent* aOuter,
(*aEventStatus != nsEventStatus_eConsumeNoDefault &&
(aEvent->message == NS_MOUSE_ENTER_SYNTH ||
aEvent->message == NS_MOUSE_EXIT_SYNTH))) &&
!(aFlags & NS_EVENT_FLAG_CAPTURE)) {
!(aFlags & NS_EVENT_FLAG_CAPTURE) && !(aFlags & NS_EVENT_FLAG_SYSTEM_EVENT)) {
// If we're here, then aOuter should be an nsILink. We'll use the
// nsILink interface to get a canonified URL that has been

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

@ -472,7 +472,7 @@ nsHTMLButtonElement::HandleDOMEvent(nsIPresContext* aPresContext,
aEventStatus);
if ((NS_OK == ret) && (nsEventStatus_eIgnore == *aEventStatus) &&
!(aFlags & NS_EVENT_FLAG_CAPTURE)) {
!(aFlags & NS_EVENT_FLAG_CAPTURE) && !(aFlags & NS_EVENT_FLAG_SYSTEM_EVENT)) {
switch (aEvent->message) {
case NS_KEY_PRESS:

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

@ -717,7 +717,8 @@ nsHTMLFormElement::HandleDOMEvent(nsIPresContext* aPresContext,
aEventStatus);
if (NS_SUCCEEDED(rv) && (*aEventStatus == nsEventStatus_eIgnore) &&
!(aFlags & NS_EVENT_FLAG_CAPTURE)) {
!(aFlags & NS_EVENT_FLAG_CAPTURE) &&
!(aFlags & NS_EVENT_FLAG_SYSTEM_EVENT)) {
switch (aEvent->message) {
case NS_FORM_RESET:

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

@ -1356,7 +1356,7 @@ nsHTMLInputElement::HandleDOMEvent(nsIPresContext* aPresContext,
nsCOMPtr<nsIDOMHTMLInputElement> selectedRadioButton;
if (!(aFlags & NS_EVENT_FLAG_CAPTURE) &&
if (!(aFlags & NS_EVENT_FLAG_CAPTURE) && !(aFlags & NS_EVENT_FLAG_SYSTEM_EVENT) &&
aEvent->message == NS_MOUSE_LEFT_CLICK) {
GetChecked(&originalCheckedValue);
checkWasSet = PR_TRUE;
@ -1428,7 +1428,7 @@ nsHTMLInputElement::HandleDOMEvent(nsIPresContext* aPresContext,
aEvent->flags |= noContentDispatch ? NS_EVENT_FLAG_NO_CONTENT_DISPATCH : NS_EVENT_FLAG_NONE;
// now check to see if the event was "cancelled"
if (nsEventStatus_eConsumeNoDefault == *aEventStatus && checkWasSet
if (nsEventStatus_eConsumeNoDefault == *aEventStatus && checkWasSet && !(aFlags & NS_EVENT_FLAG_SYSTEM_EVENT)
&& (type == NS_FORM_INPUT_CHECKBOX || type == NS_FORM_INPUT_RADIO)) {
// if it was cancelled and a radio button, then set the old
// selected btn to TRUE. if it is a checkbox then set it to its
@ -1467,7 +1467,8 @@ nsHTMLInputElement::HandleDOMEvent(nsIPresContext* aPresContext,
GetType(&type);
if ((NS_OK == rv) && (nsEventStatus_eIgnore == *aEventStatus) &&
!(aFlags & NS_EVENT_FLAG_CAPTURE)) {
!(aFlags & NS_EVENT_FLAG_CAPTURE) &&
!(aFlags & NS_EVENT_FLAG_SYSTEM_EVENT)) {
switch (aEvent->message) {
case NS_FOCUS_CONTENT:

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

@ -1936,7 +1936,7 @@ nsHTMLSelectElement::HandleDOMEvent(nsIPresContext* aPresContext,
// the focused element. So the ComboboxControlFrame tracks the focus
// at a class level (Bug 32920)
if ((nsEventStatus_eIgnore == *aEventStatus) &&
!(aFlags & NS_EVENT_FLAG_CAPTURE) &&
!(aFlags & NS_EVENT_FLAG_CAPTURE) && !(aFlags & NS_EVENT_FLAG_SYSTEM_EVENT) &&
(aEvent->message == NS_BLUR_CONTENT) && formControlFrame) {
formControlFrame->SetFocus(PR_FALSE, PR_TRUE);
}

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

@ -528,7 +528,7 @@ nsXMLElement::HandleDOMEvent(nsIPresContext* aPresContext,
aEventStatus);
if (mIsLink && (NS_OK == ret) && (nsEventStatus_eIgnore == *aEventStatus) &&
!(aFlags & NS_EVENT_FLAG_CAPTURE)) {
!(aFlags & NS_EVENT_FLAG_CAPTURE) && !(aFlags & NS_EVENT_FLAG_SYSTEM_EVENT)) {
switch (aEvent->message) {
case NS_MOUSE_LEFT_BUTTON_DOWN:
{

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

@ -654,18 +654,32 @@ nsXULElement::QueryInterface(REFNSIID iid, void** result)
else if (iid.Equals(NS_GET_IID(nsIScriptEventHandlerOwner))) {
*result = NS_STATIC_CAST(nsIScriptEventHandlerOwner*, this);
}
else if (iid.Equals(NS_GET_IID(nsIDOMEventReceiver))) {
*result = NS_STATIC_CAST(nsIDOMEventReceiver*, this);
else if (iid.Equals(NS_GET_IID(nsIDOMEventReceiver)) ||
iid.Equals(NS_GET_IID(nsIDOMEventTarget))) {
nsISupports *inst = NS_STATIC_CAST(nsIDOMEventReceiver *,
nsDOMEventRTTearoff::Create(this));
NS_ENSURE_TRUE(inst, NS_ERROR_OUT_OF_MEMORY);
NS_ADDREF(inst);
*result = inst;
return NS_OK;
}
else if (iid.Equals(NS_GET_IID(nsIDOMEventTarget))) {
*result = NS_STATIC_CAST(nsIDOMEventTarget*, this);
else if (iid.Equals(NS_GET_IID(nsIDOM3EventTarget))) {
nsISupports *inst = NS_STATIC_CAST(nsIDOM3EventTarget *,
nsDOMEventRTTearoff::Create(this));
NS_ENSURE_TRUE(inst, NS_ERROR_OUT_OF_MEMORY);
NS_ADDREF(inst);
*result = inst;
return NS_OK;
}
else if (iid.Equals(NS_GET_IID(nsIChromeEventHandler))) {
*result = NS_STATIC_CAST(nsIChromeEventHandler*, this);
}
else if (iid.Equals(NS_GET_IID(nsIDOM3Node))) {
*result = new nsNode3Tearoff(this);
NS_ENSURE_TRUE(*result, NS_ERROR_OUT_OF_MEMORY);
nsISupports *inst = new nsNode3Tearoff(this);
NS_ENSURE_TRUE(inst, NS_ERROR_OUT_OF_MEMORY);
NS_ADDREF(inst);
*result = inst;
return NS_OK;
}
else if (iid.Equals(NS_GET_IID(nsIClassInfo))) {
nsISupports *inst = nsContentUtils::
@ -1767,90 +1781,6 @@ nsXULElement::AddScriptEventListener(nsIAtom* aName,
return rv;
}
//----------------------------------------------------------------------
// nsIDOMEventReceiver interface
NS_IMETHODIMP
nsXULElement::AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID)
{
nsIEventListenerManager *manager;
if (NS_OK == GetListenerManager(&manager)) {
manager->AddEventListenerByIID(aListener, aIID, NS_EVENT_FLAG_BUBBLE);
NS_RELEASE(manager);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXULElement::RemoveEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID)
{
if (mListenerManager) {
mListenerManager->RemoveEventListenerByIID(aListener, aIID, NS_EVENT_FLAG_BUBBLE);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXULElement::AddEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture)
{
nsIEventListenerManager *manager;
if (NS_OK == GetListenerManager(&manager)) {
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
manager->AddEventListenerByType(aListener, aType, flags);
NS_RELEASE(manager);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXULElement::RemoveEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture)
{
if (mListenerManager) {
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
mListenerManager->RemoveEventListenerByType(aListener, aType, flags);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXULElement::DispatchEvent(nsIDOMEvent* aEvent, PRBool *_retval)
{
// Do nothing if element isn't in the document
if (!mDocument)
return NS_OK;
// Obtain a presentation context
PRInt32 count = mDocument->GetNumberOfShells();
if (count == 0)
return NS_OK;
nsCOMPtr<nsIPresShell> shell;
mDocument->GetShellAt(0, getter_AddRefs(shell));
// Retrieve the context
nsCOMPtr<nsIPresContext> aPresContext;
shell->GetPresContext(getter_AddRefs(aPresContext));
nsCOMPtr<nsIEventStateManager> esm;
if (NS_SUCCEEDED(aPresContext->GetEventStateManager(getter_AddRefs(esm)))) {
return esm->DispatchNewEvent(NS_STATIC_CAST(nsIStyledContent*, this), aEvent, _retval);
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXULElement::GetListenerManager(nsIEventListenerManager** aResult)
{
@ -1870,12 +1800,6 @@ nsXULElement::GetListenerManager(nsIEventListenerManager** aResult)
return NS_OK;
}
NS_IMETHODIMP
nsXULElement::HandleEvent(nsIDOMEvent *aEvent)
{
PRBool noDefault;
return DispatchEvent(aEvent, &noDefault);
}
NS_IMETHODIMP
nsXULElement::DoneCreatingElement()
@ -2480,7 +2404,9 @@ nsXULElement::RemoveChildAt(PRInt32 aIndex, PRBool aNotify)
if (event) {
event->InitEvent(NS_LITERAL_STRING("select"), PR_FALSE, PR_TRUE);
PRBool noDefault;
DispatchEvent(event, &noDefault);
nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(NS_STATIC_CAST(nsIContent *, this)));
NS_ENSURE_TRUE(target, NS_ERROR_FAILURE);
target->DispatchEvent(event, &noDefault);
}
}
@ -3310,8 +3236,9 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext,
else
aDOMEvent = &domEvent;
aEvent->flags = aFlags;
aEvent->flags |= aFlags;
aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL);
aFlags |= NS_EVENT_FLAG_BUBBLE | NS_EVENT_FLAG_CAPTURE;
if (!externalDOMEvent) {
// In order for the event to have a proper target for events that don't go through
@ -3351,8 +3278,10 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext,
// the frame. If we don't have a frame (e.g., we're a
// menu), then that breaks.
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(domEvent);
if (privateEvent)
privateEvent->SetTarget(this);
if (privateEvent) {
nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(NS_STATIC_CAST(nsIContent *, this)));
privateEvent->SetTarget(target);
}
else
return NS_ERROR_FAILURE;
@ -3443,14 +3372,14 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext,
}
//Capturing stage evaluation
if (NS_EVENT_FLAG_BUBBLE != aFlags) {
if (NS_EVENT_FLAG_CAPTURE & aFlags) {
//Initiate capturing phase. Special case first call to document
if (parent) {
parent->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_CAPTURE, aEventStatus);
parent->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, aFlags & NS_EVENT_CAPTURE_MASK, aEventStatus);
}
else if (mDocument != nsnull) {
ret = mDocument->HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
NS_EVENT_FLAG_CAPTURE, aEventStatus);
aFlags & NS_EVENT_CAPTURE_MASK, aEventStatus);
}
}
@ -3466,7 +3395,8 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext,
//Local handling stage
if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH)) {
aEvent->flags |= aFlags;
mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, this, aFlags, aEventStatus);
nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(NS_STATIC_CAST(nsIContent *, this)));
mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, target, aFlags, aEventStatus);
aEvent->flags &= ~aFlags;
}
@ -3480,17 +3410,17 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext,
}
//Bubbling stage
if (NS_EVENT_FLAG_CAPTURE != aFlags) {
if (NS_EVENT_FLAG_BUBBLE & aFlags) {
if (parent != nsnull) {
// We have a parent. Let them field the event.
ret = parent->HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
NS_EVENT_FLAG_BUBBLE, aEventStatus);
aFlags & NS_EVENT_BUBBLE_MASK, aEventStatus);
}
else if (mDocument != nsnull) {
// We must be the document root. The event should bubble to the
// document.
ret = mDocument->HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
NS_EVENT_FLAG_BUBBLE, aEventStatus);
aFlags & NS_EVENT_BUBBLE_MASK, aEventStatus);
}
}
@ -4665,9 +4595,10 @@ nsXULElement::AddPopupListener(nsIAtom* aName)
// Add the popup as a listener on this element.
nsCOMPtr<nsIDOMEventListener> eventListener = do_QueryInterface(popupListener);
AddEventListener(NS_LITERAL_STRING("mousedown"), eventListener, PR_FALSE);
AddEventListener(NS_LITERAL_STRING("contextmenu"), eventListener, PR_FALSE);
nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(NS_STATIC_CAST(nsIContent *, this)));
NS_ENSURE_TRUE(target, NS_ERROR_FAILURE);
target->AddEventListener(NS_LITERAL_STRING("mousedown"), eventListener, PR_FALSE);
target->AddEventListener(NS_LITERAL_STRING("contextmenu"), eventListener, PR_FALSE);
return NS_OK;
}

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

@ -58,6 +58,7 @@
#include "nsICSSParser.h"
#include "nsIDOMElement.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOM3EventTarget.h"
#include "nsIDOMXULElement.h"
#include "nsIDOMXULMultSelectCntrlEl.h"
#include "nsIEventListenerManager.h"
@ -378,7 +379,6 @@ public:
class nsXULElement : public nsIXULContent,
public nsIDOMXULElement,
public nsIDOMEventReceiver,
public nsIScriptEventHandlerOwner,
public nsIChromeEventHandler
{
@ -464,6 +464,7 @@ public:
NS_IMETHOD GetBindingParent(nsIContent** aContent);
NS_IMETHOD SetBindingParent(nsIContent* aParent);
NS_IMETHOD_(PRBool) IsContentOfType(PRUint32 aFlags);
NS_IMETHOD GetListenerManager(nsIEventListenerManager** aResult);
// nsIXMLContent
NS_IMETHOD MaybeTriggerAutoLink(nsIWebShell *aShell);
@ -496,19 +497,6 @@ public:
// nsIDOMXULElement
NS_DECL_NSIDOMXULELEMENT
// nsIDOMEventTarget interface (from nsIDOMEventReceiver)
NS_IMETHOD AddEventListener(const nsAString& aType, nsIDOMEventListener* aListener,
PRBool aUseCapture);
NS_IMETHOD RemoveEventListener(const nsAString& aType, nsIDOMEventListener* aListener,
PRBool aUseCapture);
NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvent, PRBool* _retval);
// nsIDOMEventReceiver
NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID);
NS_IMETHOD RemoveEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID);
NS_IMETHOD GetListenerManager(nsIEventListenerManager** aInstancePtrResult);
NS_IMETHOD HandleEvent(nsIDOMEvent *aEvent);
// nsIScriptEventHandlerOwner
NS_IMETHOD CompileEventHandler(nsIScriptContext* aContext,
void* aTarget,

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

@ -587,6 +587,7 @@ NS_INTERFACE_MAP_BEGIN(nsXULDocument)
NS_INTERFACE_MAP_ENTRY(nsIDOM3Node)
NS_INTERFACE_MAP_ENTRY(nsIDOMNSDocument)
NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentEvent)
NS_INTERFACE_MAP_ENTRY(nsIDOM3DocumentEvent)
NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentView)
NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentXBL)
NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentStyle)
@ -595,7 +596,7 @@ NS_INTERFACE_MAP_BEGIN(nsXULDocument)
NS_INTERFACE_MAP_ENTRY(nsIHTMLContentContainer)
NS_INTERFACE_MAP_ENTRY(nsIDOMEventReceiver)
NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget)
NS_INTERFACE_MAP_ENTRY(nsIDOMEventCapturer)
NS_INTERFACE_MAP_ENTRY(nsIDOM3EventTarget)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_ENTRY(nsIStreamLoaderObserver)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(XULDocument)
@ -2597,25 +2598,26 @@ nsXULDocument::HandleDOMEvent(nsIPresContext* aPresContext,
else {
aDOMEvent = &domEvent;
}
aEvent->flags = aFlags;
aEvent->flags |= aFlags;
aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL);
aFlags |= NS_EVENT_FLAG_BUBBLE | NS_EVENT_FLAG_CAPTURE;
}
//Capturing stage
if (NS_EVENT_FLAG_BUBBLE != aFlags && mScriptGlobalObject) {
mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_CAPTURE, aEventStatus);
if (NS_EVENT_FLAG_CAPTURE & aFlags && mScriptGlobalObject) {
mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, aFlags & NS_EVENT_CAPTURE_MASK, aEventStatus);
}
//Local handling stage
if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH)) {
if (mListenerManager) {
aEvent->flags |= aFlags;
mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, this, aFlags, aEventStatus);
aEvent->flags &= ~aFlags;
}
//Bubbling stage
if (NS_EVENT_FLAG_CAPTURE != aFlags && mScriptGlobalObject) {
mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_BUBBLE, aEventStatus);
if (NS_EVENT_FLAG_BUBBLE & aFlags && mScriptGlobalObject) {
mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, aFlags & NS_EVENT_BUBBLE_MASK, aEventStatus);
}
if (NS_EVENT_FLAG_INIT & aFlags) {
@ -4796,7 +4798,7 @@ nsXULDocument::ParseTagString(const nsAString& aTagName, nsIAtom*& aName,
}
// nsIDOMEventCapturer and nsIDOMEventReceiver Interface Implementations
// nsIDOMEventReceiver Interface Implementations
NS_IMETHODIMP
nsXULDocument::AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID)
@ -4826,16 +4828,7 @@ nsXULDocument::AddEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture)
{
nsIEventListenerManager *manager;
if (NS_OK == GetListenerManager(&manager)) {
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
manager->AddEventListenerByType(aListener, aType, flags);
NS_RELEASE(manager);
return NS_OK;
}
return NS_ERROR_FAILURE;
return AddGroupedEventListener(aType, aListener, aUseCapture, nsnull);
}
NS_IMETHODIMP
@ -4843,13 +4836,7 @@ nsXULDocument::RemoveEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture)
{
if (mListenerManager) {
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
mListenerManager->RemoveEventListenerByType(aListener, aType, flags);
return NS_OK;
}
return NS_ERROR_FAILURE;
return RemoveGroupedEventListener(aType, aListener, aUseCapture, nsnull);
}
NS_IMETHODIMP
@ -4878,6 +4865,47 @@ nsXULDocument::DispatchEvent(nsIDOMEvent* aEvent, PRBool *_retval)
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXULDocument::AddGroupedEventListener(const nsAString & aType, nsIDOMEventListener *aListener,
PRBool aUseCapture, nsIDOMEventGroup *aEvtGrp)
{
nsCOMPtr<nsIEventListenerManager> manager;
nsresult rv = GetListenerManager(getter_AddRefs(manager));
if (NS_SUCCEEDED(rv) && manager) {
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
manager->AddEventListenerByType(aListener, aType, flags, aEvtGrp);
return NS_OK;
}
return rv;
}
NS_IMETHODIMP
nsXULDocument::RemoveGroupedEventListener(const nsAString & aType, nsIDOMEventListener *aListener,
PRBool aUseCapture, nsIDOMEventGroup *aEvtGrp)
{
if (mListenerManager) {
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
mListenerManager->RemoveEventListenerByType(aListener, aType, flags, aEvtGrp);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXULDocument::CanTrigger(const nsAString & type, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsXULDocument::IsRegisteredHere(const nsAString & type, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsXULDocument::CreateEvent(const nsAString& aEventType,
nsIDOMEvent** aReturn)
@ -4906,6 +4934,12 @@ nsXULDocument::CreateEvent(const nsAString& aEventType,
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXULDocument::CreateEventGroup(nsIDOMEventGroup **_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsXULDocument::GetListenerManager(nsIEventListenerManager** aResult)
{
@ -4932,25 +4966,12 @@ nsXULDocument::HandleEvent(nsIDOMEvent *aEvent)
return DispatchEvent(aEvent, &noDefault);
}
nsresult
nsXULDocument::CaptureEvent(const nsAString& aType)
NS_IMETHODIMP
nsXULDocument::GetSystemEventGroup(nsIDOMEventGroup **aGroup)
{
nsIEventListenerManager *mManager;
if (NS_OK == GetListenerManager(&mManager)) {
//mManager->CaptureEvent(aListener);
NS_RELEASE(mManager);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
nsresult
nsXULDocument::ReleaseEvent(const nsAString& aType)
{
if (mListenerManager) {
//mListenerManager->ReleaseEvent(aListener);
return NS_OK;
nsCOMPtr<nsIEventListenerManager> manager;
if (NS_SUCCEEDED(GetListenerManager(getter_AddRefs(manager))) && manager) {
return manager->GetSystemEventGroupLM(aGroup);
}
return NS_ERROR_FAILURE;
}

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

@ -47,7 +47,8 @@
#include "nsIArena.h"
#include "nsICSSLoader.h"
#include "nsIContent.h"
#include "nsIDOMEventCapturer.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOM3EventTarget.h"
#include "nsIDOMNSDocument.h"
#include "nsIDOMDocumentStyle.h"
#include "nsIDOMDocumentView.h"
@ -84,6 +85,7 @@
#include "nsIBindingManager.h"
#include "nsINodeInfo.h"
#include "nsIDOMDocumentEvent.h"
#include "nsIDOM3DocumentEvent.h"
#include "nsScriptLoader.h"
#include "pldhash.h"
@ -119,6 +121,7 @@ class nsXULDocument : public nsIDocument,
public nsIXULDocument,
public nsIDOMXULDocument,
public nsIDOMDocumentEvent,
public nsIDOM3DocumentEvent,
public nsIDOMDocumentView,
public nsIDOMDocumentXBL,
public nsIDOMDocumentRange,
@ -126,7 +129,8 @@ class nsXULDocument : public nsIDocument,
public nsIDOMNSDocument,
public nsIDOM3Node,
public nsIDOMDocumentStyle,
public nsIDOMEventCapturer,
public nsIDOMEventReceiver,
public nsIDOM3EventTarget,
public nsIHTMLContentContainer,
public nsIStreamLoaderObserver,
public nsSupportsWeakReference
@ -375,24 +379,18 @@ public:
NS_IMETHOD OnPrototypeLoadDone();
NS_IMETHOD OnHide();
// nsIDOMEventCapturer interface
NS_IMETHOD CaptureEvent(const nsAString& aType);
NS_IMETHOD ReleaseEvent(const nsAString& aType);
// nsIDOMEventReceiver interface (yuck. inherited from nsIDOMEventCapturer)
// nsIDOMEventReceiver interface
NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID);
NS_IMETHOD RemoveEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID);
NS_IMETHOD GetListenerManager(nsIEventListenerManager** aInstancePtrResult);
NS_IMETHOD HandleEvent(nsIDOMEvent *aEvent);
NS_IMETHOD GetSystemEventGroup(nsIDOMEventGroup** aGroup);
// nsIDOMEventTarget interface
NS_IMETHOD AddEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture);
NS_IMETHOD RemoveEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture);
NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvent, PRBool *_retval);
NS_DECL_NSIDOMEVENTTARGET
// nsIDOM3EventTarget interface
NS_DECL_NSIDOM3EVENTTARGET
// nsIDOMDocument interface
NS_DECL_NSIDOMDOCUMENT
@ -400,6 +398,9 @@ public:
// nsIDOMDocumentEvent interface
NS_DECL_NSIDOMDOCUMENTEVENT
// nsIDOM3DocumentEvent interface
NS_DECL_NSIDOM3DOCUMENTEVENT
// nsIDOMDocumentView interface
NS_DECL_NSIDOMDOCUMENTVIEW

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

@ -50,6 +50,7 @@ class nsIDOMLoadListener;
class nsIDOMDragListener;
class nsIEventListenerManager;
class nsIDOMEvent;
class nsIDOMEventGroup;
/*
* DOM event source class. Object that allow event registration and
@ -72,5 +73,6 @@ public:
const nsIID& aIID) = 0;
NS_IMETHOD GetListenerManager(nsIEventListenerManager** aResult) = 0;
NS_IMETHOD HandleEvent(nsIDOMEvent *aEvent) = 0;
NS_IMETHOD GetSystemEventGroup(nsIDOMEventGroup** aGroup) = 0;
};
#endif // nsIDOMEventReceiver_h__

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

@ -107,6 +107,7 @@ interface nsIDOMHistory;
interface nsIDOMEvent;
interface nsIDOMEventTarget;
interface nsIDOMEventListener;
interface nsIDOMEventGroup;
// HTML
interface nsIDOMHTMLElement;

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

@ -8,3 +8,7 @@ nsIDOMMouseEvent.idl
nsIDOMMutationEvent.idl
nsIDOMUIEvent.idl
nsIDOMNSUIEvent.idl
nsIDOM3DocumentEvent.idl
nsIDOM3EventTarget.idl
nsIDOMEventGroup.idl
nsIDOMCustomEvent.idl

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

@ -34,6 +34,10 @@ SDK_XPIDLSRCS = \
nsIDOMEvent.idl \
nsIDOMEventTarget.idl \
nsIDOMEventListener.idl \
nsIDOM3DocumentEvent.idl \
nsIDOM3EventTarget.idl \
nsIDOMEventGroup.idl \
nsIDOMCustomEvent.idl \
$(NULL)
XPIDLSRCS = \

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

@ -293,6 +293,7 @@ NS_INTERFACE_MAP_BEGIN(GlobalWindowImpl)
NS_INTERFACE_MAP_ENTRY(nsIScriptObjectPrincipal)
NS_INTERFACE_MAP_ENTRY(nsIDOMEventReceiver)
NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget)
NS_INTERFACE_MAP_ENTRY(nsIDOM3EventTarget)
NS_INTERFACE_MAP_ENTRY(nsPIDOMWindow)
NS_INTERFACE_MAP_ENTRY(nsIDOMViewCSS)
NS_INTERFACE_MAP_ENTRY(nsIDOMAbstractView)
@ -678,7 +679,7 @@ GlobalWindowImpl::HandleDOMEvent(nsIPresContext* aPresContext,
* the system.
*/
if (gEntropyCollector &&
(NS_EVENT_FLAG_BUBBLE != aFlags) &&
(NS_EVENT_FLAG_CAPTURE & aFlags) &&
(aEvent->message == NS_MOUSE_MOVE)) {
//I'd like to not come in here if there is a mChromeEventHandler
//present, but there is always one when the message is
@ -703,7 +704,7 @@ GlobalWindowImpl::HandleDOMEvent(nsIPresContext* aPresContext,
// if the window is deactivated while in full screen mode,
// restore OS chrome, and hide it again upon re-activation
if (mFullScreen && (NS_EVENT_FLAG_CAPTURE != aFlags)) {
if (mFullScreen && (NS_EVENT_FLAG_BUBBLE & aFlags)) {
if (aEvent->message == NS_DEACTIVATE || aEvent->message == NS_ACTIVATE) {
nsCOMPtr<nsIFullScreen> fullScreen =
do_GetService("@mozilla.org/browser/fullscreen;1");
@ -725,12 +726,13 @@ GlobalWindowImpl::HandleDOMEvent(nsIPresContext* aPresContext,
else {
aDOMEvent = &domEvent;
}
aEvent->flags = aFlags;
aEvent->flags |= aFlags;
aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL);
aFlags |= NS_EVENT_FLAG_BUBBLE | NS_EVENT_FLAG_CAPTURE;
// Execute bindingdetached handlers before we tear ourselves
// down.
if (aEvent->message == NS_PAGE_UNLOAD && mDocument) {
if (aEvent->message == NS_PAGE_UNLOAD && mDocument && !(aFlags & NS_EVENT_FLAG_SYSTEM_EVENT)) {
nsCOMPtr<nsIDocument> doc(do_QueryInterface(mDocument));
nsCOMPtr<nsIBindingManager> bindingManager;
doc->GetBindingManager(getter_AddRefs(bindingManager));
@ -749,20 +751,19 @@ GlobalWindowImpl::HandleDOMEvent(nsIPresContext* aPresContext,
}
// Capturing stage
if ((NS_EVENT_FLAG_BUBBLE != aFlags) && mChromeEventHandler) {
if ((NS_EVENT_FLAG_CAPTURE & aFlags) && mChromeEventHandler) {
// Check chrome document capture here.
// XXX The chrome can not handle this, see bug 51211
if (aEvent->message != NS_IMAGE_LOAD) {
mChromeEventHandler->HandleChromeEvent(aPresContext, aEvent, aDOMEvent,
NS_EVENT_FLAG_CAPTURE,
aFlags & NS_EVENT_CAPTURE_MASK,
aEventStatus);
}
}
// Local handling stage
if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH) &&
!((NS_EVENT_FLAG_BUBBLE & aFlags) &&
(NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags))) {
if (mListenerManager &&
!(NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags && NS_EVENT_FLAG_BUBBLE & aFlags && !(NS_EVENT_FLAG_INIT & aFlags))) {
aEvent->flags |= aFlags;
mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, this,
aFlags, aEventStatus);
@ -773,7 +774,7 @@ GlobalWindowImpl::HandleDOMEvent(nsIPresContext* aPresContext,
mIsDocumentLoaded = PR_TRUE;
// Bubbling stage
if ((NS_EVENT_FLAG_CAPTURE != aFlags) && mChromeEventHandler) {
if ((NS_EVENT_FLAG_BUBBLE & aFlags) && mChromeEventHandler) {
// Bubble to a chrome document if it exists
// XXX Need a way to know if an event should really bubble or not.
// For now filter out load and unload, since they cause problems.
@ -783,7 +784,7 @@ GlobalWindowImpl::HandleDOMEvent(nsIPresContext* aPresContext,
(aEvent->message != NS_FOCUS_CONTENT) &&
(aEvent->message != NS_BLUR_CONTENT)) {
mChromeEventHandler->HandleChromeEvent(aPresContext, aEvent,
aDOMEvent, NS_EVENT_FLAG_BUBBLE,
aDOMEvent, aFlags & NS_EVENT_BUBBLE_MASK,
aEventStatus);
}
}
@ -3608,15 +3609,7 @@ GlobalWindowImpl::AddEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture)
{
nsCOMPtr<nsIEventListenerManager> manager;
if (NS_SUCCEEDED(GetListenerManager(getter_AddRefs(manager)))) {
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
manager->AddEventListenerByType(aListener, aType, flags);
return NS_OK;
}
return NS_ERROR_FAILURE;
return AddGroupedEventListener(aType, aListener, aUseCapture, nsnull);
}
NS_IMETHODIMP
@ -3624,13 +3617,7 @@ GlobalWindowImpl::RemoveEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture)
{
if (mListenerManager) {
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
mListenerManager->RemoveEventListenerByType(aListener, aType, flags);
return NS_OK;
}
return NS_ERROR_FAILURE;
return RemoveGroupedEventListener(aType, aListener, aUseCapture, nsnull);
}
NS_IMETHODIMP
@ -3661,6 +3648,50 @@ GlobalWindowImpl::DispatchEvent(nsIDOMEvent* aEvent, PRBool* _retval)
return NS_ERROR_FAILURE;
}
//*****************************************************************************
// GlobalWindowImpl::nsIDOM3EventTarget
//*****************************************************************************
NS_IMETHODIMP
GlobalWindowImpl::AddGroupedEventListener(const nsAString & aType, nsIDOMEventListener *aListener,
PRBool aUseCapture, nsIDOMEventGroup *aEvtGrp)
{
nsCOMPtr<nsIEventListenerManager> manager;
if (NS_SUCCEEDED(GetListenerManager(getter_AddRefs(manager)))) {
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
manager->AddEventListenerByType(aListener, aType, flags, aEvtGrp);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
GlobalWindowImpl::RemoveGroupedEventListener(const nsAString & aType, nsIDOMEventListener *aListener,
PRBool aUseCapture, nsIDOMEventGroup *aEvtGrp)
{
if (mListenerManager) {
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
mListenerManager->RemoveEventListenerByType(aListener, aType, flags, aEvtGrp);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
GlobalWindowImpl::CanTrigger(const nsAString & type, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
GlobalWindowImpl::IsRegisteredHere(const nsAString & type, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
//*****************************************************************************
// GlobalWindowImpl::nsIDOMEventReceiver
//*****************************************************************************
@ -3705,13 +3736,6 @@ GlobalWindowImpl::GetListenerManager(nsIEventListenerManager **aResult)
return CallQueryInterface(mListenerManager, aResult);
}
//XXX I need another way around the circular link problem.
NS_IMETHODIMP
GlobalWindowImpl::GetNewListenerManager(nsIEventListenerManager **aResult)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
GlobalWindowImpl::HandleEvent(nsIDOMEvent *aEvent)
{
@ -3719,6 +3743,16 @@ GlobalWindowImpl::HandleEvent(nsIDOMEvent *aEvent)
return DispatchEvent(aEvent, &noDefault);
}
NS_IMETHODIMP
GlobalWindowImpl::GetSystemEventGroup(nsIDOMEventGroup **aGroup)
{
nsCOMPtr<nsIEventListenerManager> manager;
if (NS_SUCCEEDED(GetListenerManager(getter_AddRefs(manager))) && manager) {
return manager->GetSystemEventGroupLM(aGroup);
}
return NS_ERROR_FAILURE;
}
//*****************************************************************************
// GlobalWindowImpl::nsPIDOMWindow
//*****************************************************************************

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

@ -58,6 +58,7 @@
#include "nsIDocShellTreeItem.h"
#include "nsIDOMViewCSS.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOM3EventTarget.h"
#include "nsIDOMNavigator.h"
#include "nsIDOMNSLocation.h"
#include "nsIDOMWindowInternal.h"
@ -116,6 +117,7 @@ class GlobalWindowImpl : public nsIScriptGlobalObject,
public nsIDOMJSWindow,
public nsIScriptObjectPrincipal,
public nsIDOMEventReceiver,
public nsIDOM3EventTarget,
public nsPIDOMWindow,
public nsIDOMViewCSS,
public nsSupportsWeakReference,
@ -156,13 +158,10 @@ public:
NS_DECL_NSIDOMJSWINDOW
// nsIDOMEventTarget
NS_IMETHOD AddEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture);
NS_IMETHOD RemoveEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture);
NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvent, PRBool *_retval);
NS_DECL_NSIDOMEVENTTARGET
// nsIDOM3EventTarget
NS_DECL_NSIDOM3EVENTTARGET
// nsIDOMEventReceiver
NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener,
@ -170,8 +169,8 @@ public:
NS_IMETHOD RemoveEventListenerByIID(nsIDOMEventListener *aListener,
const nsIID& aIID);
NS_IMETHOD GetListenerManager(nsIEventListenerManager** aInstancePtrResult);
NS_IMETHOD GetNewListenerManager(nsIEventListenerManager **aInstancePtrResult);
NS_IMETHOD HandleEvent(nsIDOMEvent *aEvent);
NS_IMETHOD GetSystemEventGroup(nsIDOMEventGroup** aGroup);
// nsPIDOMWindow
NS_IMETHOD GetPrivateParent(nsPIDOMWindow** aResult);

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

@ -55,32 +55,18 @@ nsWindowRoot::~nsWindowRoot()
{
}
NS_IMPL_ISUPPORTS4(nsWindowRoot, nsIDOMEventReceiver, nsIChromeEventHandler, nsPIWindowRoot, nsIDOMEventTarget)
NS_IMPL_ISUPPORTS5(nsWindowRoot, nsIDOMEventReceiver, nsIChromeEventHandler, nsPIWindowRoot, nsIDOMEventTarget, nsIDOM3EventTarget)
NS_IMETHODIMP
nsWindowRoot::AddEventListener(const nsAString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture)
{
nsCOMPtr<nsIEventListenerManager> manager;
GetListenerManager(getter_AddRefs(manager));
if (manager) {
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
manager->AddEventListenerByType(aListener, aType, flags);
return NS_OK;
}
return NS_ERROR_FAILURE;
return AddGroupedEventListener(aType, aListener, aUseCapture, nsnull);
}
NS_IMETHODIMP
nsWindowRoot::RemoveEventListener(const nsAString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture)
{
nsCOMPtr<nsIEventListenerManager> manager;
GetListenerManager(getter_AddRefs(manager));
if (manager) {
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
manager->RemoveEventListenerByType(aListener, aType, flags);
return NS_OK;
}
return NS_ERROR_FAILURE;
return RemoveGroupedEventListener(aType, aListener, aUseCapture, nsnull);
}
NS_IMETHODIMP
@ -112,6 +98,44 @@ nsWindowRoot::DispatchEvent(nsIDOMEvent* aEvt, PRBool *_retval)
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsWindowRoot::AddGroupedEventListener(const nsAString & aType, nsIDOMEventListener *aListener,
PRBool aUseCapture, nsIDOMEventGroup *aEvtGrp)
{
nsCOMPtr<nsIEventListenerManager> manager;
if (NS_SUCCEEDED(GetListenerManager(getter_AddRefs(manager)))) {
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
manager->AddEventListenerByType(aListener, aType, flags, aEvtGrp);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsWindowRoot::RemoveGroupedEventListener(const nsAString & aType, nsIDOMEventListener *aListener,
PRBool aUseCapture, nsIDOMEventGroup *aEvtGrp)
{
if (mListenerManager) {
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
mListenerManager->RemoveEventListenerByType(aListener, aType, flags, aEvtGrp);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsWindowRoot::CanTrigger(const nsAString & type, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsWindowRoot::IsRegisteredHere(const nsAString & type, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsWindowRoot::AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID)
{
@ -157,6 +181,16 @@ nsWindowRoot::HandleEvent(nsIDOMEvent *aEvent)
return DispatchEvent(aEvent, &noDefault);
}
NS_IMETHODIMP
nsWindowRoot::GetSystemEventGroup(nsIDOMEventGroup **aGroup)
{
nsCOMPtr<nsIEventListenerManager> manager;
if (NS_SUCCEEDED(GetListenerManager(getter_AddRefs(manager))) && manager) {
return manager->GetSystemEventGroupLM(aGroup);
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsWindowRoot::HandleChromeEvent(nsIPresContext* aPresContext,
nsEvent* aEvent, nsIDOMEvent** aDOMEvent, PRUint32 aFlags,
nsEventStatus* aEventStatus)

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

@ -30,13 +30,14 @@ class nsIDOMEvent;
#include "nsGUIEvent.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOM3EventTarget.h"
#include "nsIChromeEventHandler.h"
#include "nsIEventListenerManager.h"
#include "nsPIWindowRoot.h"
#include "nsIFocusController.h"
#include "nsIDOMEventTarget.h"
class nsWindowRoot : public nsIDOMEventReceiver, public nsIChromeEventHandler, public nsPIWindowRoot
class nsWindowRoot : public nsIDOMEventReceiver, public nsIDOM3EventTarget, public nsIChromeEventHandler, public nsPIWindowRoot
{
public:
nsWindowRoot(nsIDOMWindow* aWindow);
@ -44,6 +45,7 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMEVENTTARGET
NS_DECL_NSIDOM3EVENTTARGET
NS_IMETHOD HandleChromeEvent(nsIPresContext* aPresContext,
nsEvent* aEvent, nsIDOMEvent** aDOMEvent,
@ -53,6 +55,7 @@ public:
NS_IMETHOD RemoveEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID);
NS_IMETHOD GetListenerManager(nsIEventListenerManager** aInstancePtrResult);
NS_IMETHOD HandleEvent(nsIDOMEvent *aEvent);
NS_IMETHOD GetSystemEventGroup(nsIDOMEventGroup** aGroup);
// nsPIWindowRoot
NS_IMETHOD GetFocusController(nsIFocusController** aResult);

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

@ -62,6 +62,7 @@
#include "nsIDOMAttr.h"
#include "nsIDocument.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOM3EventTarget.h"
#include "nsIDOMKeyEvent.h"
#include "nsIDOMKeyListener.h"
#include "nsIDOMMouseListener.h"
@ -71,6 +72,8 @@
#include "nsIDOMHTMLAnchorElement.h"
#include "nsISelectionController.h"
#include "nsIDOMHTMLHtmlElement.h"
#include "nsGUIEvent.h"
#include "nsIDOMEventGroup.h"
#include "TransactionFactory.h"
@ -409,6 +412,13 @@ printf("nsTextEditor.cpp: failed to get TextEvent Listener\n");
}
// register the event listeners with the DOM event reveiver
nsCOMPtr<nsIDOM3EventTarget> dom3Targ(do_QueryInterface(erP));
nsCOMPtr<nsIDOMEventGroup> sysGroup;
if (NS_SUCCEEDED(erP->GetSystemEventGroup(getter_AddRefs(sysGroup)))) {
result = dom3Targ->AddGroupedEventListener(NS_LITERAL_STRING("keypress"), mKeyListenerP, PR_FALSE, sysGroup);
NS_ASSERTION(NS_SUCCEEDED(result), "failed to register key listener in system group");
}
result = erP->AddEventListenerByIID(mKeyListenerP, NS_GET_IID(nsIDOMKeyListener));
NS_ASSERTION(NS_SUCCEEDED(result), "failed to register key listener");
if (NS_SUCCEEDED(result))

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

@ -55,6 +55,7 @@
#include "nsIDOMKeyEvent.h"
#include "nsIDOMMouseEvent.h"
#include "nsIDOMNSUIEvent.h"
#include "nsIPrivateDOMEvent.h"
#include "nsIPrivateTextEvent.h"
#include "nsIPrivateCompositionEvent.h"
#include "nsIEditorMailSupport.h"
@ -63,6 +64,7 @@
#include "nsIPref.h"
#include "nsILookAndFeel.h"
#include "nsIPresContext.h"
#include "nsGUIEvent.h"
// for repainting hack only
#include "nsIView.h"
#include "nsIViewManager.h"
@ -180,6 +182,22 @@ nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
return NS_OK;
}
// DOM event handling happens in two passes, the client pass and the system
// pass. All system handlers need to move eventually to the system pass
// but due to inconsistencies that would create with XBL handlers they
// need to stay here for now and continue to process command keys. Character
// generation, however, should be handled in the second system pass to allow
// proper cancellation of character generating events.
PRBool isSystemPass = PR_FALSE;
nsCOMPtr<nsIPrivateDOMEvent> privDOMEvent(do_QueryInterface(aKeyEvent));
if (privDOMEvent) {
nsEvent* innerEvent;
privDOMEvent->GetInternalNSEvent(&innerEvent);
if (innerEvent) {
isSystemPass = innerEvent->flags & NS_EVENT_FLAG_SYSTEM_EVENT;
}
}
// we should check a flag here to see if we should be using built-in key bindings
// mEditor->GetFlags(&flags);
// if (flags & ...)
@ -202,8 +220,9 @@ nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
if (!textEditor) return NS_ERROR_NO_INTERFACE;
// if there is no charCode, then it's a key that doesn't map to a character,
// so look for special keys using keyCode
if (0 != keyCode)
// so look for special keys using keyCode.
// Also, process these keys only during the Client Pass of the event loop.
if (0 != keyCode && !isSystemPass)
{
PRBool isAnyModifierKeyButShift;
nsresult rv;

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

@ -50,6 +50,7 @@
#include "nsIDOMAttr.h"
#include "nsIDocument.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOM3EventTarget.h"
#include "nsIDOMKeyEvent.h"
#include "nsIDOMKeyListener.h"
#include "nsIDOMMouseListener.h"
@ -60,6 +61,7 @@
#include "nsIDOMHTMLImageElement.h"
#include "nsISelectionController.h"
#include "nsGUIEvent.h"
#include "nsIDOMEventGroup.h"
#include "nsIIndependentSelection.h" //domselections answer to frameselection
@ -156,6 +158,12 @@ nsPlaintextEditor::~nsPlaintextEditor()
nsresult result = GetDOMEventReceiver(getter_AddRefs(erP));
if (NS_SUCCEEDED(result) && erP)
{
nsCOMPtr<nsIDOM3EventTarget> dom3Targ(do_QueryInterface(erP));
nsCOMPtr<nsIDOMEventGroup> sysGroup;
if (NS_SUCCEEDED(erP->GetSystemEventGroup(getter_AddRefs(sysGroup)))) {
result = dom3Targ->RemoveGroupedEventListener(NS_LITERAL_STRING("keypress"), mKeyListenerP, PR_FALSE, sysGroup);
}
if (mKeyListenerP) {
erP->RemoveEventListenerByIID(mKeyListenerP, NS_GET_IID(nsIDOMKeyListener));
}
@ -421,6 +429,13 @@ printf("nsTextEditor.cpp: failed to get TextEvent Listener\n");
}
// register the event listeners with the DOM event reveiver
nsCOMPtr<nsIDOM3EventTarget> dom3Targ(do_QueryInterface(erP));
nsCOMPtr<nsIDOMEventGroup> sysGroup;
if (NS_SUCCEEDED(erP->GetSystemEventGroup(getter_AddRefs(sysGroup)))) {
result = dom3Targ->AddGroupedEventListener(NS_LITERAL_STRING("keypress"), mKeyListenerP, PR_FALSE, sysGroup);
NS_ASSERTION(NS_SUCCEEDED(result), "failed to register key listener in system group");
}
result = erP->AddEventListenerByIID(mKeyListenerP, NS_GET_IID(nsIDOMKeyListener));
NS_ASSERTION(NS_SUCCEEDED(result), "failed to register key listener");
if (NS_SUCCEEDED(result))

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

@ -6252,6 +6252,20 @@ PresShell::HandleEventInternal(nsEvent* aEvent, nsIView *aView, PRUint32 aFlags,
}
}
//Continue with second dispatch to system event handlers
if (mCurrentEventContent) {
rv = mCurrentEventContent->HandleDOMEvent(mPresContext, aEvent, nsnull,
aFlags | NS_EVENT_FLAG_SYSTEM_EVENT, aStatus);
}
else {
nsIContent* targetContent;
if (NS_OK == mCurrentEventFrame->GetContentForEvent(mPresContext, aEvent, &targetContent) && nsnull != targetContent) {
rv = targetContent->HandleDOMEvent(mPresContext, aEvent, nsnull,
aFlags | NS_EVENT_FLAG_SYSTEM_EVENT, aStatus);
NS_RELEASE(targetContent);
}
}
//3. Give event to the Frames for browser default processing.
// XXX The event isn't translated into the local coordinate space
// of the frame...

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

@ -99,6 +99,9 @@
#include "nsIStyleRule.h"//observe documents to send onchangenotifications
#include "nsIDOMEventListener.h"//observe documents to send onchangenotifications
#include "nsGUIEvent.h"
#include "nsIDOMEventGroup.h"
#include "nsIDOM3EventTarget.h"
#include "nsIDOMNSUIEvent.h"
#include "nsIDOMFocusListener.h" //onchange events
#include "nsIDOMCharacterData.h" //for selection setting helper func
@ -316,6 +319,15 @@ nsTextInputListener::KeyPress(nsIDOMEvent* aKeyEvent)
return NS_OK;
}
nsCOMPtr<nsIDOMNSUIEvent> nsUIEvent = do_QueryInterface(aKeyEvent);
if(nsUIEvent)
{
PRBool defaultPrevented;
nsUIEvent->GetPreventDefault(&defaultPrevented);
if(defaultPrevented)
return NS_OK;
}
mFrame->SetValueChanged(PR_TRUE);
return NS_OK;
@ -1422,7 +1434,17 @@ nsTextControlFrame::PreDestroy(nsIPresContext* aPresContext)
if (erP)
{
erP->RemoveEventListenerByIID(NS_STATIC_CAST(nsIDOMFocusListener *,mTextListener), NS_GET_IID(nsIDOMFocusListener));
erP->RemoveEventListenerByIID(NS_STATIC_CAST(nsIDOMKeyListener*,mTextListener), NS_GET_IID(nsIDOMKeyListener));
// register the event listeners with the DOM event reveiver
nsCOMPtr<nsIDOMEventGroup> sysGroup;
nsresult rv = erP->GetSystemEventGroup(getter_AddRefs(sysGroup));
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIDOM3EventTarget> dom3Targ(do_QueryInterface(erP));
if (dom3Targ) {
rv = dom3Targ->RemoveGroupedEventListener(NS_LITERAL_STRING("keypress"),
NS_STATIC_CAST(nsIDOMKeyListener *,mTextListener),
PR_FALSE, sysGroup);
}
}
}
}
@ -3147,8 +3169,21 @@ nsTextControlFrame::SetInitialChildList(nsIPresContext* aPresContext,
if (NS_SUCCEEDED(mContent->QueryInterface(NS_GET_IID(nsIDOMEventReceiver), getter_AddRefs(erP))) && erP)
{
// register the event listeners with the DOM event reveiver
rv = erP->AddEventListenerByIID(NS_STATIC_CAST(nsIDOMKeyListener *,mTextListener), NS_GET_IID(nsIDOMKeyListener));
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to register key listener");
nsCOMPtr<nsIDOMEventGroup> sysGroup;
rv = erP->GetSystemEventGroup(getter_AddRefs(sysGroup));
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIDOM3EventTarget> dom3Targ(do_QueryInterface(erP));
if (dom3Targ) {
rv = dom3Targ->AddGroupedEventListener(NS_LITERAL_STRING("keypress"),
NS_STATIC_CAST(nsIDOMKeyListener *,mTextListener),
PR_FALSE, sysGroup);
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to register key listener");
}
}
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to register event listeners on nsTextControlFrame");
rv = erP->AddEventListenerByIID(NS_STATIC_CAST(nsIDOMFocusListener *,mTextListener), NS_GET_IID(nsIDOMFocusListener));
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to register focus listener");
nsCOMPtr<nsIPresShell> shell;

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

@ -6252,6 +6252,20 @@ PresShell::HandleEventInternal(nsEvent* aEvent, nsIView *aView, PRUint32 aFlags,
}
}
//Continue with second dispatch to system event handlers
if (mCurrentEventContent) {
rv = mCurrentEventContent->HandleDOMEvent(mPresContext, aEvent, nsnull,
aFlags | NS_EVENT_FLAG_SYSTEM_EVENT, aStatus);
}
else {
nsIContent* targetContent;
if (NS_OK == mCurrentEventFrame->GetContentForEvent(mPresContext, aEvent, &targetContent) && nsnull != targetContent) {
rv = targetContent->HandleDOMEvent(mPresContext, aEvent, nsnull,
aFlags | NS_EVENT_FLAG_SYSTEM_EVENT, aStatus);
NS_RELEASE(targetContent);
}
}
//3. Give event to the Frames for browser default processing.
// XXX The event isn't translated into the local coordinate space
// of the frame...

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

@ -99,6 +99,9 @@
#include "nsIStyleRule.h"//observe documents to send onchangenotifications
#include "nsIDOMEventListener.h"//observe documents to send onchangenotifications
#include "nsGUIEvent.h"
#include "nsIDOMEventGroup.h"
#include "nsIDOM3EventTarget.h"
#include "nsIDOMNSUIEvent.h"
#include "nsIDOMFocusListener.h" //onchange events
#include "nsIDOMCharacterData.h" //for selection setting helper func
@ -316,6 +319,15 @@ nsTextInputListener::KeyPress(nsIDOMEvent* aKeyEvent)
return NS_OK;
}
nsCOMPtr<nsIDOMNSUIEvent> nsUIEvent = do_QueryInterface(aKeyEvent);
if(nsUIEvent)
{
PRBool defaultPrevented;
nsUIEvent->GetPreventDefault(&defaultPrevented);
if(defaultPrevented)
return NS_OK;
}
mFrame->SetValueChanged(PR_TRUE);
return NS_OK;
@ -1422,7 +1434,17 @@ nsTextControlFrame::PreDestroy(nsIPresContext* aPresContext)
if (erP)
{
erP->RemoveEventListenerByIID(NS_STATIC_CAST(nsIDOMFocusListener *,mTextListener), NS_GET_IID(nsIDOMFocusListener));
erP->RemoveEventListenerByIID(NS_STATIC_CAST(nsIDOMKeyListener*,mTextListener), NS_GET_IID(nsIDOMKeyListener));
// register the event listeners with the DOM event reveiver
nsCOMPtr<nsIDOMEventGroup> sysGroup;
nsresult rv = erP->GetSystemEventGroup(getter_AddRefs(sysGroup));
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIDOM3EventTarget> dom3Targ(do_QueryInterface(erP));
if (dom3Targ) {
rv = dom3Targ->RemoveGroupedEventListener(NS_LITERAL_STRING("keypress"),
NS_STATIC_CAST(nsIDOMKeyListener *,mTextListener),
PR_FALSE, sysGroup);
}
}
}
}
@ -3147,8 +3169,21 @@ nsTextControlFrame::SetInitialChildList(nsIPresContext* aPresContext,
if (NS_SUCCEEDED(mContent->QueryInterface(NS_GET_IID(nsIDOMEventReceiver), getter_AddRefs(erP))) && erP)
{
// register the event listeners with the DOM event reveiver
rv = erP->AddEventListenerByIID(NS_STATIC_CAST(nsIDOMKeyListener *,mTextListener), NS_GET_IID(nsIDOMKeyListener));
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to register key listener");
nsCOMPtr<nsIDOMEventGroup> sysGroup;
rv = erP->GetSystemEventGroup(getter_AddRefs(sysGroup));
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIDOM3EventTarget> dom3Targ(do_QueryInterface(erP));
if (dom3Targ) {
rv = dom3Targ->AddGroupedEventListener(NS_LITERAL_STRING("keypress"),
NS_STATIC_CAST(nsIDOMKeyListener *,mTextListener),
PR_FALSE, sysGroup);
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to register key listener");
}
}
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to register event listeners on nsTextControlFrame");
rv = erP->AddEventListenerByIID(NS_STATIC_CAST(nsIDOMFocusListener *,mTextListener), NS_GET_IID(nsIDOMFocusListener));
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to register focus listener");
nsCOMPtr<nsIPresShell> shell;

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

@ -98,6 +98,9 @@ class nsIContent;
#define NS_EVENT_FLAG_NO_CONTENT_DISPATCH 0x0100
#define NS_EVENT_FLAG_SYSTEM_EVENT 0x0200
#define NS_EVENT_CAPTURE_MASK (~(NS_EVENT_FLAG_INIT | NS_EVENT_FLAG_BUBBLE))
#define NS_EVENT_BUBBLE_MASK (~(NS_EVENT_FLAG_INIT | NS_EVENT_FLAG_CAPTURE))
#define NS_APP_EVENT_FLAG_NONE 0x0000
#define NS_APP_EVENT_FLAG_HANDLED 0x0001 // Similar to NS_EVENT_FLAG_NO_DEFAULT, but it allows focus
@ -394,6 +397,8 @@ enum nsDragDropEventStatus {
* GUI MESSAGES
*/
//@{
#define NS_EVENT_NULL 0
#define NS_WINDOW_START 100