Event handling additions for DOM suport. Adding additional event pathway through HandleDOMEvent

This commit is contained in:
joki 1998-06-23 21:53:02 +00:00
Родитель 9374c4bd49
Коммит ad7c15864e
44 изменённых файлов: 773 добавлений и 205 удалений

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

@ -30,6 +30,7 @@ class nsISizeOfHandler;
class nsString;
class nsString;
class nsVoidArray;
class nsIDOMEvent;
// IID for the nsIContent interface
#define NS_ICONTENT_IID \
@ -132,6 +133,7 @@ public:
NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsIDOMEvent* aDOMEvent,
nsEventStatus& aEventStatus) = 0;
};

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

@ -35,6 +35,7 @@ class nsIStyleSheet;
class nsIURL;
class nsIViewManager;
class nsString;
class nsIDOMEvent;
// IID for the nsIDocument interface
#define NS_IDOCUMENT_IID \
@ -174,6 +175,7 @@ public:
NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsIDOMEvent* aDOMEvent,
nsEventStatus& aEventStatus) = 0;
};

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

@ -704,13 +704,14 @@ nsresult nsDocument::GetListenerManager(nsIEventListenerManager **aInstancePtrRe
nsresult nsDocument::HandleDOMEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsIDOMEvent* aDOMEvent,
nsEventStatus& aEventStatus)
{
//Capturing stage
//Local handling stage
if (nsnull != mListenerManager) {
mListenerManager->HandleEvent(aPresContext, aEvent, aEventStatus);
mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aEventStatus);
}
//Bubbling stage

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

@ -208,6 +208,7 @@ public:
NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsIDOMEvent* aDOMEvent,
nsEventStatus& aEventStatus);
protected:

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

@ -20,6 +20,7 @@ IGNORE_MANIFEST=1
EXPORTS = \
nsIEventListenerManager.h \
nsIEventStateManager.h \
$(NULL)
MODULE=raptor

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

@ -25,6 +25,7 @@
class nsIPresContext;
class nsIDOMEventListener;
class nsIDOMEvent;
/*
* Event listener manager interface.
@ -66,6 +67,7 @@ public:
virtual nsresult HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsIDOMEvent* aDOMEvent,
nsEventStatus& aEventStatus) = 0;
/**

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

@ -0,0 +1,58 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsIEventStateManager_h__
#define nsIEventStateManager_h__
#include "nsGUIEvent.h"
#include "nsISupports.h"
#include "nsVoidArray.h"
class nsIPresContext;
class nsIDOMEventState;
class nsIDOMEvent;
/*
* Event listener manager interface.
*/
#define NS_IEVENTSTATEMANAGER_IID \
{ /* c8488290-07ce-11d2-bd88-00805f8ae3f4 */ \
0xc8488290, 0x07ce, 0x11d2, \
{0xbd, 0x88, 0x00, 0x80, 0x5f, 0x8a, 0xe3, 0xf4} }
class nsIEventStateManager : public nsISupports {
public:
/**
* Gets the current event target.
* @param
*/
NS_IMETHOD GetEventTarget(nsISupports **aResult) = 0;
/**
* Gets the current event target.
* @param
*/
NS_IMETHOD SetEventTarget(nsISupports *aSupports) = 0;
};
#endif // nsIEventStateManager_h__

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

@ -22,23 +22,25 @@ include <$(DEPTH)\config\config.mak>
LIBRARY_NAME=raptorevents_s
MODULE=raptor
REQUIRES=xpcom raptor dom
REQUIRES=xpcom raptor dom js
DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN
CPPSRCS= nsEventListenerManager.cpp \
nsEventStateManager.cpp \
nsDOMEvent.cpp \
$(NULL)
CPP_OBJS= .\$(OBJDIR)\nsEventListenerManager.obj \
.\$(OBJDIR)\nsEventStateManager.obj \
.\$(OBJDIR)\nsDOMEvent.obj \
$(NULL)
EXPORTS= nsEventListenerManager.h
EXPORTS= nsEventListenerManager.h nsEventStateManager.h
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor \
-I$(PUBLIC)\dom
-I$(PUBLIC)\dom -I$(PUBLIC)\js
LCFLAGS = \
$(LCFLAGS) \

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

@ -17,7 +17,9 @@
*/
#include "nsDOMEvent.h"
#include "nsIDOMNode.h"
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kIDOMEventIID, NS_IDOMEVENT_IID);
static NS_DEFINE_IID(kINSEventIID, NS_INSEVENT_IID);
@ -56,9 +58,9 @@ NS_METHOD nsDOMEvent::GetType(nsString& aType)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode*& aTarget)
NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode** aTarget)
{
return NS_ERROR_NOT_IMPLEMENTED;
return kTarget->QueryInterface(kIDOMNodeIID, (void**)aTarget);
}
NS_METHOD nsDOMEvent::GetScreenX(PRInt32& aX)
@ -73,33 +75,39 @@ NS_METHOD nsDOMEvent::GetScreenY(PRInt32& aY)
NS_METHOD nsDOMEvent::GetClientX(PRInt32& aX)
{
return NS_ERROR_NOT_IMPLEMENTED;
//XXX these are not client coords yet
aX = kEvent->point.x;
return NS_OK;
}
NS_METHOD nsDOMEvent::GetClientY(PRInt32& aY)
{
return NS_ERROR_NOT_IMPLEMENTED;
//XXX these are not client coords yet
aY = kEvent->point.y;
return NS_OK;
}
NS_METHOD nsDOMEvent::GetAltKey(PRBool& aIsDown)
{
return NS_ERROR_NOT_IMPLEMENTED;
aIsDown = ((nsInputEvent*)kEvent)->isAlt;
return NS_OK;
}
NS_METHOD nsDOMEvent::GetCtrlKey(PRBool& aIsDown)
{
return NS_ERROR_NOT_IMPLEMENTED;
aIsDown = ((nsInputEvent*)kEvent)->isControl;
return NS_OK;
}
NS_METHOD nsDOMEvent::GetShiftKey(PRBool& aIsDown)
{
aIsDown = es.isShift;
aIsDown = ((nsInputEvent*)kEvent)->isShift;
return NS_OK;
}
NS_METHOD nsDOMEvent::GetMetaKey(PRBool& aIsDown)
{
return NS_ERROR_NOT_IMPLEMENTED;
return NS_OK;
}
NS_METHOD nsDOMEvent::GetCharCode(PRUint32& aCharCode)
@ -109,13 +117,40 @@ NS_METHOD nsDOMEvent::GetCharCode(PRUint32& aCharCode)
NS_METHOD nsDOMEvent::GetKeyCode(PRUint32& aKeyCode)
{
aKeyCode = es.keyCode;
switch (kEvent->message) {
case NS_KEY_UP:
case NS_KEY_DOWN:
aKeyCode = ((nsKeyEvent*)kEvent)->keyCode;
break;
default:
return NS_ERROR_FAILURE;
break;
}
return NS_OK;
}
NS_METHOD nsDOMEvent::GetButton(PRUint32& aButton)
{
return NS_ERROR_NOT_IMPLEMENTED;
switch (kEvent->message) {
case NS_MOUSE_LEFT_BUTTON_UP:
case NS_MOUSE_LEFT_BUTTON_DOWN:
case NS_MOUSE_LEFT_DOUBLECLICK:
aButton = 1;
break;
case NS_MOUSE_MIDDLE_BUTTON_UP:
case NS_MOUSE_MIDDLE_BUTTON_DOWN:
aButton = 2;
break;
case NS_MOUSE_RIGHT_BUTTON_UP:
case NS_MOUSE_RIGHT_BUTTON_DOWN:
case NS_MOUSE_RIGHT_DOUBLECLICK:
aButton = 3;
break;
default:
return NS_ERROR_FAILURE;
break;
}
return NS_OK;
}
// nsINSEventInterface
@ -129,3 +164,14 @@ NS_METHOD nsDOMEvent::GetLayerY(PRInt32& aY)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_METHOD nsDOMEvent::SetGUIEvent(nsGUIEvent *aEvent)
{
kEvent = aEvent;
return NS_OK;
}
NS_METHOD nsDOMEvent::SetEventTarget(nsISupports *aTarget)
{
kTarget = aTarget;
return NS_OK;
}

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

@ -23,6 +23,8 @@
#include "nsINSEvent.h"
#include "nsISupports.h"
#include "nsPoint.h"
#include "nsGUIEvent.h"
class nsIContent;
class nsDOMEvent : public nsIDOMEvent, public nsINSEvent {
@ -44,7 +46,7 @@ public:
// nsIDOMEventInterface
NS_IMETHOD GetType(nsString& aType);
NS_IMETHOD GetTarget(nsIDOMNode*& aTarget);
NS_IMETHOD GetTarget(nsIDOMNode** aTarget);
NS_IMETHOD GetScreenX(PRInt32& aX);
NS_IMETHOD GetScreenY(PRInt32& aY);
@ -65,22 +67,14 @@ public:
NS_IMETHOD GetLayerX(PRInt32& aX);
NS_IMETHOD GetLayerY(PRInt32& aY);
struct nsDOMEventStruct {
PRUint32 message;
nsPoint point;
PRUint32 time;
void* nativeMsg;
PRBool isShift;
PRBool isControl;
PRBool isAlt;
PRUint32 clickCount;
PRUint32 keyCode;
} es;
NS_IMETHOD SetGUIEvent(nsGUIEvent *aEvent);
NS_IMETHOD SetEventTarget(nsISupports *aTarget);
protected:
PRUint32 mRefCnt : 31;
nsGUIEvent *kEvent;
nsISupports *kTarget;
};
#endif // nsDOMEvent_h__

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

@ -18,6 +18,7 @@
#include "nsISupports.h"
#include "nsGUIEvent.h"
#include "nsIPresContext.h"
#include "nsDOMEvent.h"
#include "nsEventListenerManager.h"
#include "nsIDOMEventListener.h"
@ -27,6 +28,7 @@
#include "nsIDOMFocusListener.h"
#include "nsIDOMLoadListener.h"
#include "nsIDOMDragListener.h"
#include "nsIEventStateManager.h"
static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID);
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
@ -69,39 +71,26 @@ nsresult nsEventListenerManager::QueryInterface(const nsIID& aIID,
return NS_NOINTERFACE;
}
nsresult nsEventListenerManager::TranslateGUI2DOM(nsGUIEvent*& aGUIEvent, nsIDOMEvent** aDOMEvent)
nsresult nsEventListenerManager::TranslateGUI2DOM(nsGUIEvent*& aGUIEvent,
nsIPresContext& aPresContext,
nsIDOMEvent** aDOMEvent)
{
nsIEventStateManager *mManager;
nsISupports *mTarget;
nsDOMEvent* it = new nsDOMEvent();
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (NS_OK == it->QueryInterface(kIDOMEventIID, (void **) aDOMEvent)) {
switch(aGUIEvent->message) {
case NS_MOUSE_LEFT_BUTTON_DOWN:
case NS_MOUSE_MIDDLE_BUTTON_DOWN:
case NS_MOUSE_RIGHT_BUTTON_DOWN:
case NS_MOUSE_LEFT_BUTTON_UP:
case NS_MOUSE_MIDDLE_BUTTON_UP:
case NS_MOUSE_RIGHT_BUTTON_UP:
case NS_MOUSE_LEFT_DOUBLECLICK:
case NS_MOUSE_RIGHT_DOUBLECLICK:
case NS_MOUSE_ENTER:
case NS_MOUSE_EXIT:
case NS_MOUSE_MOVE:
break;
case NS_KEY_UP:
case NS_KEY_DOWN:
it->es.keyCode = ((nsKeyEvent*)aGUIEvent)->keyCode;
it->es.isShift = ((nsKeyEvent*)aGUIEvent)->isShift;
break;
}
return NS_OK;
it->SetGUIEvent(aGUIEvent);
if (NS_OK == aPresContext.GetEventStateManager(&mManager)) {
mManager->GetEventTarget(&mTarget);
NS_RELEASE(mManager);
}
it->SetEventTarget(mTarget);
return NS_ERROR_FAILURE;
return it->QueryInterface(kIDOMEventIID, (void **) aDOMEvent);
}
nsresult nsEventListenerManager::GetEventListeners(nsVoidArray *aListeners, const nsIID& aIID)
@ -208,9 +197,10 @@ nsresult nsEventListenerManager::RemoveEventListener(nsIDOMEventListener *aListe
nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsIDOMEvent* aDOMEvent,
nsEventStatus& aEventStatus)
{
nsIDOMEvent *domEvent;
nsresult mRet;
switch(aEvent->message) {
case NS_MOUSE_LEFT_BUTTON_DOWN:
@ -218,9 +208,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext,
case NS_MOUSE_RIGHT_BUTTON_DOWN:
if (nsnull != mMouseListeners) {
for (int i=0; i<mMouseListeners->Count(); i++) {
TranslateGUI2DOM(aEvent, &domEvent);
if (nsnull != domEvent && !((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseDown(domEvent)) {
aEventStatus = nsEventStatus_eConsumeNoDefault;
if (nsnull == aDOMEvent) {
TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent);
}
if (nsnull != aDOMEvent) {
mRet = ((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseDown(aDOMEvent);
aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault;
}
}
}
@ -230,9 +223,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext,
case NS_MOUSE_RIGHT_BUTTON_UP:
if (nsnull != mMouseListeners) {
for (int i=0; i<mMouseListeners->Count(); i++) {
TranslateGUI2DOM(aEvent, &domEvent);
if (nsnull != domEvent && !((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseUp(domEvent)) {
aEventStatus = nsEventStatus_eConsumeNoDefault;
if (nsnull == aDOMEvent) {
TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent);
}
if (nsnull != aDOMEvent) {
mRet = ((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseUp(aDOMEvent);
aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault;
}
}
}
@ -241,9 +237,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext,
case NS_MOUSE_RIGHT_DOUBLECLICK:
if (nsnull != mMouseListeners) {
for (int i=0; i<mMouseListeners->Count(); i++) {
TranslateGUI2DOM(aEvent, &domEvent);
if (nsnull != domEvent && !((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseDblClick(domEvent)) {
aEventStatus = nsEventStatus_eConsumeNoDefault;
if (nsnull == aDOMEvent) {
TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent);
}
if (nsnull != aDOMEvent) {
mRet = ((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseDblClick(aDOMEvent);
aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault;
}
}
}
@ -251,9 +250,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext,
case NS_MOUSE_ENTER:
if (nsnull != mMouseListeners) {
for (int i=0; i<mMouseListeners->Count(); i++) {
TranslateGUI2DOM(aEvent, &domEvent);
if (nsnull != domEvent && !((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseOver(domEvent)) {
aEventStatus = nsEventStatus_eConsumeNoDefault;
if (nsnull == aDOMEvent) {
TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent);
}
if (nsnull != aDOMEvent) {
mRet = ((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseOver(aDOMEvent);
aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault;
}
}
}
@ -261,9 +263,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext,
case NS_MOUSE_EXIT:
if (nsnull != mMouseListeners) {
for (int i=0; i<mMouseListeners->Count(); i++) {
TranslateGUI2DOM(aEvent, &domEvent);
if (nsnull != domEvent && !((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseOut(domEvent)) {
aEventStatus = nsEventStatus_eConsumeNoDefault;
if (nsnull == aDOMEvent) {
TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent);
}
if (nsnull != aDOMEvent) {
mRet = ((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseOut(aDOMEvent);
aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault;
}
}
}
@ -271,9 +276,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext,
case NS_MOUSE_MOVE:
if (nsnull != mMouseMotionListeners) {
for (int i=0; i<mMouseMotionListeners->Count(); i++) {
TranslateGUI2DOM(aEvent, &domEvent);
if (nsnull != domEvent && !((nsIDOMMouseMotionListener*)(mMouseMotionListeners->ElementAt(i)))->MouseMove(domEvent)) {
aEventStatus = nsEventStatus_eConsumeNoDefault;
if (nsnull == aDOMEvent) {
TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent);
}
if (nsnull != aDOMEvent) {
mRet = ((nsIDOMMouseMotionListener*)(mMouseMotionListeners->ElementAt(i)))->MouseMove(aDOMEvent);
aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault;
}
}
}
@ -281,20 +289,26 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext,
case NS_KEY_UP:
if (nsnull != mKeyListeners) {
for (int i=0; i<mKeyListeners->Count(); i++) {
TranslateGUI2DOM(aEvent, &domEvent);
if (nsnull != domEvent && !((nsIDOMKeyListener*)(mKeyListeners->ElementAt(i)))->KeyDown(domEvent)) {
aEventStatus = nsEventStatus_eConsumeNoDefault;
if (nsnull == aDOMEvent) {
TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent);
}
if (nsnull != aDOMEvent) {
mRet = ((nsIDOMKeyListener*)(mKeyListeners->ElementAt(i)))->KeyUp(aDOMEvent);
aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault;
}
}
}
break;
case NS_KEY_DOWN:
if (nsnull != mKeyListeners) {
for (int i=0; i<mKeyListeners->Count(); i++) {
TranslateGUI2DOM(aEvent, &domEvent);
if (nsnull != domEvent && !((nsIDOMKeyListener*)(mKeyListeners->ElementAt(i)))->KeyUp(domEvent)) {
aEventStatus = nsEventStatus_eConsumeNoDefault;
if (nsnull == aDOMEvent) {
TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent);
}
if (nsnull != aDOMEvent) {
mRet = ((nsIDOMKeyListener*)(mKeyListeners->ElementAt(i)))->KeyDown(aDOMEvent);
aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault;
}
}
}
break;

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

@ -55,13 +55,15 @@ public:
virtual nsresult CaptureEvent(nsIDOMEventListener *aListener);
virtual nsresult ReleaseEvent(nsIDOMEventListener *aListener);
virtual nsresult HandleEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, nsEventStatus& aEventStatus);
virtual nsresult HandleEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus);
protected:
PRUint32 mRefCnt : 31;
virtual nsresult TranslateGUI2DOM(nsGUIEvent*& aGUIEvent, nsIDOMEvent** aDOMEvent);
virtual nsresult nsEventListenerManager::TranslateGUI2DOM(nsGUIEvent*& aGUIEvent,
nsIPresContext& aPresContext,
nsIDOMEvent** aDOMEvent);
nsVoidArray* mEventListeners;
nsVoidArray* mMouseListeners;

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

@ -0,0 +1,66 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsISupports.h"
#include "nsIEventStateManager.h"
#include "nsEventStateManager.h"
static NS_DEFINE_IID(kIEventStateManagerIID, NS_IEVENTSTATEMANAGER_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
nsEventStateManager::nsEventStateManager() {
mEventTarget = nsnull;
}
nsEventStateManager::~nsEventStateManager() {
}
NS_IMPL_ADDREF(nsEventStateManager)
NS_IMPL_RELEASE(nsEventStateManager)
NS_IMPL_QUERY_INTERFACE(nsEventStateManager, kIEventStateManagerIID);
NS_METHOD nsEventStateManager::GetEventTarget(nsISupports **aResult)
{
NS_PRECONDITION(nsnull != aResult, "null ptr");
if (nsnull == aResult) {
return NS_ERROR_NULL_POINTER;
}
*aResult = mEventTarget;
NS_IF_ADDREF(mEventTarget);
return NS_OK;
}
NS_METHOD nsEventStateManager::SetEventTarget(nsISupports *aSupports)
{
mEventTarget = aSupports;
return NS_OK;
}
nsresult NS_NewEventStateManager(nsIEventStateManager** aInstancePtrResult)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "nsnull ptr");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
nsIEventStateManager* manager = new nsEventStateManager();
if (nsnull == manager) {
return NS_ERROR_OUT_OF_MEMORY;
}
return manager->QueryInterface(kIEventStateManagerIID, (void **) aInstancePtrResult);
}

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

@ -0,0 +1,52 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsEventStateManager_h__
#define nsEventStateManager_h__
#include "nsIEventStateManager.h"
class nsIDOMEvent;
/*
* Event listener manager
*/
class nsEventStateManager : public nsIEventStateManager {
public:
nsEventStateManager();
virtual ~nsEventStateManager();
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
NS_IMETHOD GetEventTarget(nsISupports **aResult);
NS_IMETHOD SetEventTarget(nsISupports *aSupports);
protected:
PRUint32 mRefCnt : 31;
nsISupports* mEventTarget;
};
extern nsresult NS_NewEventStateManager(nsIEventStateManager** aInstancePtrResult);
#endif // nsEventStateManager_h__

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

@ -23,6 +23,7 @@
#include "nsIImageGroup.h"
#include "nsIFrame.h"
#include "nsIRenderingContext.h"
#include "nsEventStateManager.h"
#define NOISY_IMAGES
@ -42,6 +43,7 @@ nsPresContext::nsPresContext()
mImageGroup = nsnull;
mLinkHandler = nsnull;
mContainer = nsnull;
mEventManager = nsnull;
}
nsPresContext::~nsPresContext()
@ -69,6 +71,7 @@ nsPresContext::~nsPresContext()
NS_IF_RELEASE(mLinkHandler);
NS_IF_RELEASE(mContainer);
NS_IF_RELEASE(mEventManager);
}
nsrefcnt
@ -362,3 +365,24 @@ nsPresContext::GetContainer(nsISupports** aResult)
NS_IF_ADDREF(mContainer);
return NS_OK;
}
NS_METHOD
nsPresContext::GetEventStateManager(nsIEventStateManager** aManager)
{
NS_PRECONDITION(nsnull != aManager, "null ptr");
if (nsnull == aManager) {
return NS_ERROR_NULL_POINTER;
}
if (nsnull == mEventManager) {
nsresult rv = NS_NewEventStateManager(&mEventManager);
if (NS_OK != rv) {
return rv;
}
}
*aManager = mEventManager;
NS_IF_ADDREF(mEventManager);
return NS_OK;
}

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

@ -35,6 +35,7 @@ class nsIPresShell;
class nsIStyleContext;
class nsIAtom;
class nsString;
class nsIEventStateManager;
#define NS_IPRESCONTEXT_IID \
{ 0x0a5d12e0, 0x944e, 0x11d1, \
@ -157,6 +158,8 @@ public:
//be sure to Relase() after you are done with the Get()
virtual nsIDeviceContext * GetDeviceContext() const = 0;
NS_IMETHOD GetEventStateManager(nsIEventStateManager** aManager) = 0;
};
// Bit values for LoadImage's aImageStatus

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

@ -30,6 +30,7 @@ class nsISizeOfHandler;
class nsString;
class nsString;
class nsVoidArray;
class nsIDOMEvent;
// IID for the nsIContent interface
#define NS_ICONTENT_IID \
@ -132,6 +133,7 @@ public:
NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsIDOMEvent* aDOMEvent,
nsEventStatus& aEventStatus) = 0;
};

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

@ -35,6 +35,7 @@ class nsIStyleSheet;
class nsIURL;
class nsIViewManager;
class nsString;
class nsIDOMEvent;
// IID for the nsIDocument interface
#define NS_IDOCUMENT_IID \
@ -174,6 +175,7 @@ public:
NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsIDOMEvent* aDOMEvent,
nsEventStatus& aEventStatus) = 0;
};

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

@ -35,6 +35,7 @@ class nsIPresShell;
class nsIStyleContext;
class nsIAtom;
class nsString;
class nsIEventStateManager;
#define NS_IPRESCONTEXT_IID \
{ 0x0a5d12e0, 0x944e, 0x11d1, \
@ -157,6 +158,8 @@ public:
//be sure to Relase() after you are done with the Get()
virtual nsIDeviceContext * GetDeviceContext() const = 0;
NS_IMETHOD GetEventStateManager(nsIEventStateManager** aManager) = 0;
};
// Bit values for LoadImage's aImageStatus

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

@ -35,6 +35,7 @@ class nsIPresShell;
class nsIStyleContext;
class nsIAtom;
class nsString;
class nsIEventStateManager;
#define NS_IPRESCONTEXT_IID \
{ 0x0a5d12e0, 0x944e, 0x11d1, \
@ -157,6 +158,8 @@ public:
//be sure to Relase() after you are done with the Get()
virtual nsIDeviceContext * GetDeviceContext() const = 0;
NS_IMETHOD GetEventStateManager(nsIEventStateManager** aManager) = 0;
};
// Bit values for LoadImage's aImageStatus

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

@ -704,13 +704,14 @@ nsresult nsDocument::GetListenerManager(nsIEventListenerManager **aInstancePtrRe
nsresult nsDocument::HandleDOMEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsIDOMEvent* aDOMEvent,
nsEventStatus& aEventStatus)
{
//Capturing stage
//Local handling stage
if (nsnull != mListenerManager) {
mListenerManager->HandleEvent(aPresContext, aEvent, aEventStatus);
mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aEventStatus);
}
//Bubbling stage

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

@ -208,6 +208,7 @@ public:
NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsIDOMEvent* aDOMEvent,
nsEventStatus& aEventStatus);
protected:

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

@ -32,6 +32,7 @@
#include <stdarg.h>
#include "nsIPtr.h"
#include "nsISizeOfHandler.h"
#include "nsIEventStateManager.h"
#define DO_SELECTION 0
@ -533,7 +534,12 @@ NS_METHOD nsFrame::HandleEvent(nsIPresContext& aPresContext,
{
aEventStatus = nsEventStatus_eIgnore;
mContent->HandleDOMEvent(aPresContext, aEvent, aEventStatus);
nsIEventStateManager *mManager;
if (NS_OK == aPresContext.GetEventStateManager(&mManager)) {
mManager->SetEventTarget((nsISupports*)mContent);
NS_RELEASE(mManager);
}
mContent->HandleDOMEvent(aPresContext, aEvent, nsnull, aEventStatus);
#if DO_SELECTION

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

@ -23,6 +23,7 @@
#include "nsIImageGroup.h"
#include "nsIFrame.h"
#include "nsIRenderingContext.h"
#include "nsEventStateManager.h"
#define NOISY_IMAGES
@ -42,6 +43,7 @@ nsPresContext::nsPresContext()
mImageGroup = nsnull;
mLinkHandler = nsnull;
mContainer = nsnull;
mEventManager = nsnull;
}
nsPresContext::~nsPresContext()
@ -69,6 +71,7 @@ nsPresContext::~nsPresContext()
NS_IF_RELEASE(mLinkHandler);
NS_IF_RELEASE(mContainer);
NS_IF_RELEASE(mEventManager);
}
nsrefcnt
@ -362,3 +365,24 @@ nsPresContext::GetContainer(nsISupports** aResult)
NS_IF_ADDREF(mContainer);
return NS_OK;
}
NS_METHOD
nsPresContext::GetEventStateManager(nsIEventStateManager** aManager)
{
NS_PRECONDITION(nsnull != aManager, "null ptr");
if (nsnull == aManager) {
return NS_ERROR_NULL_POINTER;
}
if (nsnull == mEventManager) {
nsresult rv = NS_NewEventStateManager(&mEventManager);
if (NS_OK != rv) {
return rv;
}
}
*aManager = mEventManager;
NS_IF_ADDREF(mEventManager);
return NS_OK;
}

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

@ -59,19 +59,21 @@ public:
virtual float GetPixelsToTwips() const;
virtual float GetTwipsToPixels() const;
virtual nsIDeviceContext* GetDeviceContext() const;
NS_IMETHOD GetEventStateManager(nsIEventStateManager** aManager);
protected:
nsPresContext();
virtual ~nsPresContext();
nsIPresShell* mShell;
nsRect mVisibleArea;
nsIDeviceContext* mDeviceContext;
nsIImageGroup* mImageGroup;
nsILinkHandler* mLinkHandler;
nsISupports* mContainer;
nsFont mDefaultFont;
nsVoidArray mImageLoaders;
nsIPresShell* mShell;
nsRect mVisibleArea;
nsIDeviceContext* mDeviceContext;
nsIImageGroup* mImageGroup;
nsILinkHandler* mLinkHandler;
nsISupports* mContainer;
nsFont mDefaultFont;
nsVoidArray mImageLoaders;
nsIEventStateManager* mEventManager;
};
#endif /* nsPresContext_h___ */

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

@ -82,7 +82,7 @@ public:
void List(FILE* out = stdout, PRInt32 aIndent = 0) const {;}
NS_IMETHOD SizeOf(nsISizeOfHandler* aHandler) const { return NS_OK; }
NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, nsEventStatus& aEventStatus)
NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus)
{return NS_OK;}
NS_DECL_ISUPPORTS

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

@ -36,6 +36,6 @@ LOBJS = \
$(DIST)/lib/libraptorhtmlforms_s.a \
$(DIST)/lib/libraptorhtmlstyle_s.a \
$(DIST)/lib/libraptorhtmltable_s.a \
$(DIST)/lib/libraptorevents_s.a \
$(DIST)/lib/libraptorevents_s.a \
include $(DEPTH)/config/rules.mk

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

@ -21,6 +21,7 @@ MODULE = raptor
EXPORTS = \
nsIEventListenerManager.h \
nsIEventStateManager.h \
$(NULL)
include $(DEPTH)/config/config.mk

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

@ -20,6 +20,7 @@ IGNORE_MANIFEST=1
EXPORTS = \
nsIEventListenerManager.h \
nsIEventStateManager.h \
$(NULL)
MODULE=raptor

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

@ -25,6 +25,7 @@
class nsIPresContext;
class nsIDOMEventListener;
class nsIDOMEvent;
/*
* Event listener manager interface.
@ -66,6 +67,7 @@ public:
virtual nsresult HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsIDOMEvent* aDOMEvent,
nsEventStatus& aEventStatus) = 0;
/**

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

@ -0,0 +1,58 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsIEventStateManager_h__
#define nsIEventStateManager_h__
#include "nsGUIEvent.h"
#include "nsISupports.h"
#include "nsVoidArray.h"
class nsIPresContext;
class nsIDOMEventState;
class nsIDOMEvent;
/*
* Event listener manager interface.
*/
#define NS_IEVENTSTATEMANAGER_IID \
{ /* c8488290-07ce-11d2-bd88-00805f8ae3f4 */ \
0xc8488290, 0x07ce, 0x11d2, \
{0xbd, 0x88, 0x00, 0x80, 0x5f, 0x8a, 0xe3, 0xf4} }
class nsIEventStateManager : public nsISupports {
public:
/**
* Gets the current event target.
* @param
*/
NS_IMETHOD GetEventTarget(nsISupports **aResult) = 0;
/**
* Gets the current event target.
* @param
*/
NS_IMETHOD SetEventTarget(nsISupports *aSupports) = 0;
};
#endif // nsIEventStateManager_h__

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

@ -23,6 +23,7 @@ DEFINES += -D_IMPL_NS_HTML
CPPSRCS = \
nsEventListenerManager.cpp \
nsEventStateManager.cpp \
nsDOMEvent.cpp \
$(NULL)
@ -30,9 +31,10 @@ MODULE = raptor
EXPORTS = \
nsEventListenerManager.h \
nsEventStateManager.h \
$(NULL)
REQUIRES = xpcom raptor dom
REQUIRES = xpcom raptor dom js
include $(DEPTH)/config/config.mk

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

@ -22,23 +22,25 @@ include <$(DEPTH)\config\config.mak>
LIBRARY_NAME=raptorevents_s
MODULE=raptor
REQUIRES=xpcom raptor dom
REQUIRES=xpcom raptor dom js
DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN
CPPSRCS= nsEventListenerManager.cpp \
nsEventStateManager.cpp \
nsDOMEvent.cpp \
$(NULL)
CPP_OBJS= .\$(OBJDIR)\nsEventListenerManager.obj \
.\$(OBJDIR)\nsEventStateManager.obj \
.\$(OBJDIR)\nsDOMEvent.obj \
$(NULL)
EXPORTS= nsEventListenerManager.h
EXPORTS= nsEventListenerManager.h nsEventStateManager.h
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor \
-I$(PUBLIC)\dom
-I$(PUBLIC)\dom -I$(PUBLIC)\js
LCFLAGS = \
$(LCFLAGS) \

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

@ -17,7 +17,9 @@
*/
#include "nsDOMEvent.h"
#include "nsIDOMNode.h"
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kIDOMEventIID, NS_IDOMEVENT_IID);
static NS_DEFINE_IID(kINSEventIID, NS_INSEVENT_IID);
@ -56,9 +58,9 @@ NS_METHOD nsDOMEvent::GetType(nsString& aType)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode*& aTarget)
NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode** aTarget)
{
return NS_ERROR_NOT_IMPLEMENTED;
return kTarget->QueryInterface(kIDOMNodeIID, (void**)aTarget);
}
NS_METHOD nsDOMEvent::GetScreenX(PRInt32& aX)
@ -73,33 +75,39 @@ NS_METHOD nsDOMEvent::GetScreenY(PRInt32& aY)
NS_METHOD nsDOMEvent::GetClientX(PRInt32& aX)
{
return NS_ERROR_NOT_IMPLEMENTED;
//XXX these are not client coords yet
aX = kEvent->point.x;
return NS_OK;
}
NS_METHOD nsDOMEvent::GetClientY(PRInt32& aY)
{
return NS_ERROR_NOT_IMPLEMENTED;
//XXX these are not client coords yet
aY = kEvent->point.y;
return NS_OK;
}
NS_METHOD nsDOMEvent::GetAltKey(PRBool& aIsDown)
{
return NS_ERROR_NOT_IMPLEMENTED;
aIsDown = ((nsInputEvent*)kEvent)->isAlt;
return NS_OK;
}
NS_METHOD nsDOMEvent::GetCtrlKey(PRBool& aIsDown)
{
return NS_ERROR_NOT_IMPLEMENTED;
aIsDown = ((nsInputEvent*)kEvent)->isControl;
return NS_OK;
}
NS_METHOD nsDOMEvent::GetShiftKey(PRBool& aIsDown)
{
aIsDown = es.isShift;
aIsDown = ((nsInputEvent*)kEvent)->isShift;
return NS_OK;
}
NS_METHOD nsDOMEvent::GetMetaKey(PRBool& aIsDown)
{
return NS_ERROR_NOT_IMPLEMENTED;
return NS_OK;
}
NS_METHOD nsDOMEvent::GetCharCode(PRUint32& aCharCode)
@ -109,13 +117,40 @@ NS_METHOD nsDOMEvent::GetCharCode(PRUint32& aCharCode)
NS_METHOD nsDOMEvent::GetKeyCode(PRUint32& aKeyCode)
{
aKeyCode = es.keyCode;
switch (kEvent->message) {
case NS_KEY_UP:
case NS_KEY_DOWN:
aKeyCode = ((nsKeyEvent*)kEvent)->keyCode;
break;
default:
return NS_ERROR_FAILURE;
break;
}
return NS_OK;
}
NS_METHOD nsDOMEvent::GetButton(PRUint32& aButton)
{
return NS_ERROR_NOT_IMPLEMENTED;
switch (kEvent->message) {
case NS_MOUSE_LEFT_BUTTON_UP:
case NS_MOUSE_LEFT_BUTTON_DOWN:
case NS_MOUSE_LEFT_DOUBLECLICK:
aButton = 1;
break;
case NS_MOUSE_MIDDLE_BUTTON_UP:
case NS_MOUSE_MIDDLE_BUTTON_DOWN:
aButton = 2;
break;
case NS_MOUSE_RIGHT_BUTTON_UP:
case NS_MOUSE_RIGHT_BUTTON_DOWN:
case NS_MOUSE_RIGHT_DOUBLECLICK:
aButton = 3;
break;
default:
return NS_ERROR_FAILURE;
break;
}
return NS_OK;
}
// nsINSEventInterface
@ -129,3 +164,14 @@ NS_METHOD nsDOMEvent::GetLayerY(PRInt32& aY)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_METHOD nsDOMEvent::SetGUIEvent(nsGUIEvent *aEvent)
{
kEvent = aEvent;
return NS_OK;
}
NS_METHOD nsDOMEvent::SetEventTarget(nsISupports *aTarget)
{
kTarget = aTarget;
return NS_OK;
}

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

@ -23,6 +23,8 @@
#include "nsINSEvent.h"
#include "nsISupports.h"
#include "nsPoint.h"
#include "nsGUIEvent.h"
class nsIContent;
class nsDOMEvent : public nsIDOMEvent, public nsINSEvent {
@ -44,7 +46,7 @@ public:
// nsIDOMEventInterface
NS_IMETHOD GetType(nsString& aType);
NS_IMETHOD GetTarget(nsIDOMNode*& aTarget);
NS_IMETHOD GetTarget(nsIDOMNode** aTarget);
NS_IMETHOD GetScreenX(PRInt32& aX);
NS_IMETHOD GetScreenY(PRInt32& aY);
@ -65,22 +67,14 @@ public:
NS_IMETHOD GetLayerX(PRInt32& aX);
NS_IMETHOD GetLayerY(PRInt32& aY);
struct nsDOMEventStruct {
PRUint32 message;
nsPoint point;
PRUint32 time;
void* nativeMsg;
PRBool isShift;
PRBool isControl;
PRBool isAlt;
PRUint32 clickCount;
PRUint32 keyCode;
} es;
NS_IMETHOD SetGUIEvent(nsGUIEvent *aEvent);
NS_IMETHOD SetEventTarget(nsISupports *aTarget);
protected:
PRUint32 mRefCnt : 31;
nsGUIEvent *kEvent;
nsISupports *kTarget;
};
#endif // nsDOMEvent_h__

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

@ -18,6 +18,7 @@
#include "nsISupports.h"
#include "nsGUIEvent.h"
#include "nsIPresContext.h"
#include "nsDOMEvent.h"
#include "nsEventListenerManager.h"
#include "nsIDOMEventListener.h"
@ -27,6 +28,7 @@
#include "nsIDOMFocusListener.h"
#include "nsIDOMLoadListener.h"
#include "nsIDOMDragListener.h"
#include "nsIEventStateManager.h"
static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID);
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
@ -69,39 +71,26 @@ nsresult nsEventListenerManager::QueryInterface(const nsIID& aIID,
return NS_NOINTERFACE;
}
nsresult nsEventListenerManager::TranslateGUI2DOM(nsGUIEvent*& aGUIEvent, nsIDOMEvent** aDOMEvent)
nsresult nsEventListenerManager::TranslateGUI2DOM(nsGUIEvent*& aGUIEvent,
nsIPresContext& aPresContext,
nsIDOMEvent** aDOMEvent)
{
nsIEventStateManager *mManager;
nsISupports *mTarget;
nsDOMEvent* it = new nsDOMEvent();
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (NS_OK == it->QueryInterface(kIDOMEventIID, (void **) aDOMEvent)) {
switch(aGUIEvent->message) {
case NS_MOUSE_LEFT_BUTTON_DOWN:
case NS_MOUSE_MIDDLE_BUTTON_DOWN:
case NS_MOUSE_RIGHT_BUTTON_DOWN:
case NS_MOUSE_LEFT_BUTTON_UP:
case NS_MOUSE_MIDDLE_BUTTON_UP:
case NS_MOUSE_RIGHT_BUTTON_UP:
case NS_MOUSE_LEFT_DOUBLECLICK:
case NS_MOUSE_RIGHT_DOUBLECLICK:
case NS_MOUSE_ENTER:
case NS_MOUSE_EXIT:
case NS_MOUSE_MOVE:
break;
case NS_KEY_UP:
case NS_KEY_DOWN:
it->es.keyCode = ((nsKeyEvent*)aGUIEvent)->keyCode;
it->es.isShift = ((nsKeyEvent*)aGUIEvent)->isShift;
break;
}
return NS_OK;
it->SetGUIEvent(aGUIEvent);
if (NS_OK == aPresContext.GetEventStateManager(&mManager)) {
mManager->GetEventTarget(&mTarget);
NS_RELEASE(mManager);
}
it->SetEventTarget(mTarget);
return NS_ERROR_FAILURE;
return it->QueryInterface(kIDOMEventIID, (void **) aDOMEvent);
}
nsresult nsEventListenerManager::GetEventListeners(nsVoidArray *aListeners, const nsIID& aIID)
@ -208,9 +197,10 @@ nsresult nsEventListenerManager::RemoveEventListener(nsIDOMEventListener *aListe
nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsIDOMEvent* aDOMEvent,
nsEventStatus& aEventStatus)
{
nsIDOMEvent *domEvent;
nsresult mRet;
switch(aEvent->message) {
case NS_MOUSE_LEFT_BUTTON_DOWN:
@ -218,9 +208,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext,
case NS_MOUSE_RIGHT_BUTTON_DOWN:
if (nsnull != mMouseListeners) {
for (int i=0; i<mMouseListeners->Count(); i++) {
TranslateGUI2DOM(aEvent, &domEvent);
if (nsnull != domEvent && !((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseDown(domEvent)) {
aEventStatus = nsEventStatus_eConsumeNoDefault;
if (nsnull == aDOMEvent) {
TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent);
}
if (nsnull != aDOMEvent) {
mRet = ((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseDown(aDOMEvent);
aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault;
}
}
}
@ -230,9 +223,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext,
case NS_MOUSE_RIGHT_BUTTON_UP:
if (nsnull != mMouseListeners) {
for (int i=0; i<mMouseListeners->Count(); i++) {
TranslateGUI2DOM(aEvent, &domEvent);
if (nsnull != domEvent && !((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseUp(domEvent)) {
aEventStatus = nsEventStatus_eConsumeNoDefault;
if (nsnull == aDOMEvent) {
TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent);
}
if (nsnull != aDOMEvent) {
mRet = ((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseUp(aDOMEvent);
aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault;
}
}
}
@ -241,9 +237,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext,
case NS_MOUSE_RIGHT_DOUBLECLICK:
if (nsnull != mMouseListeners) {
for (int i=0; i<mMouseListeners->Count(); i++) {
TranslateGUI2DOM(aEvent, &domEvent);
if (nsnull != domEvent && !((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseDblClick(domEvent)) {
aEventStatus = nsEventStatus_eConsumeNoDefault;
if (nsnull == aDOMEvent) {
TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent);
}
if (nsnull != aDOMEvent) {
mRet = ((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseDblClick(aDOMEvent);
aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault;
}
}
}
@ -251,9 +250,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext,
case NS_MOUSE_ENTER:
if (nsnull != mMouseListeners) {
for (int i=0; i<mMouseListeners->Count(); i++) {
TranslateGUI2DOM(aEvent, &domEvent);
if (nsnull != domEvent && !((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseOver(domEvent)) {
aEventStatus = nsEventStatus_eConsumeNoDefault;
if (nsnull == aDOMEvent) {
TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent);
}
if (nsnull != aDOMEvent) {
mRet = ((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseOver(aDOMEvent);
aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault;
}
}
}
@ -261,9 +263,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext,
case NS_MOUSE_EXIT:
if (nsnull != mMouseListeners) {
for (int i=0; i<mMouseListeners->Count(); i++) {
TranslateGUI2DOM(aEvent, &domEvent);
if (nsnull != domEvent && !((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseOut(domEvent)) {
aEventStatus = nsEventStatus_eConsumeNoDefault;
if (nsnull == aDOMEvent) {
TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent);
}
if (nsnull != aDOMEvent) {
mRet = ((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseOut(aDOMEvent);
aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault;
}
}
}
@ -271,9 +276,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext,
case NS_MOUSE_MOVE:
if (nsnull != mMouseMotionListeners) {
for (int i=0; i<mMouseMotionListeners->Count(); i++) {
TranslateGUI2DOM(aEvent, &domEvent);
if (nsnull != domEvent && !((nsIDOMMouseMotionListener*)(mMouseMotionListeners->ElementAt(i)))->MouseMove(domEvent)) {
aEventStatus = nsEventStatus_eConsumeNoDefault;
if (nsnull == aDOMEvent) {
TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent);
}
if (nsnull != aDOMEvent) {
mRet = ((nsIDOMMouseMotionListener*)(mMouseMotionListeners->ElementAt(i)))->MouseMove(aDOMEvent);
aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault;
}
}
}
@ -281,20 +289,26 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext,
case NS_KEY_UP:
if (nsnull != mKeyListeners) {
for (int i=0; i<mKeyListeners->Count(); i++) {
TranslateGUI2DOM(aEvent, &domEvent);
if (nsnull != domEvent && !((nsIDOMKeyListener*)(mKeyListeners->ElementAt(i)))->KeyDown(domEvent)) {
aEventStatus = nsEventStatus_eConsumeNoDefault;
if (nsnull == aDOMEvent) {
TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent);
}
if (nsnull != aDOMEvent) {
mRet = ((nsIDOMKeyListener*)(mKeyListeners->ElementAt(i)))->KeyUp(aDOMEvent);
aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault;
}
}
}
break;
case NS_KEY_DOWN:
if (nsnull != mKeyListeners) {
for (int i=0; i<mKeyListeners->Count(); i++) {
TranslateGUI2DOM(aEvent, &domEvent);
if (nsnull != domEvent && !((nsIDOMKeyListener*)(mKeyListeners->ElementAt(i)))->KeyUp(domEvent)) {
aEventStatus = nsEventStatus_eConsumeNoDefault;
if (nsnull == aDOMEvent) {
TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent);
}
if (nsnull != aDOMEvent) {
mRet = ((nsIDOMKeyListener*)(mKeyListeners->ElementAt(i)))->KeyDown(aDOMEvent);
aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault;
}
}
}
break;

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

@ -55,13 +55,15 @@ public:
virtual nsresult CaptureEvent(nsIDOMEventListener *aListener);
virtual nsresult ReleaseEvent(nsIDOMEventListener *aListener);
virtual nsresult HandleEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, nsEventStatus& aEventStatus);
virtual nsresult HandleEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus);
protected:
PRUint32 mRefCnt : 31;
virtual nsresult TranslateGUI2DOM(nsGUIEvent*& aGUIEvent, nsIDOMEvent** aDOMEvent);
virtual nsresult nsEventListenerManager::TranslateGUI2DOM(nsGUIEvent*& aGUIEvent,
nsIPresContext& aPresContext,
nsIDOMEvent** aDOMEvent);
nsVoidArray* mEventListeners;
nsVoidArray* mMouseListeners;

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

@ -0,0 +1,66 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsISupports.h"
#include "nsIEventStateManager.h"
#include "nsEventStateManager.h"
static NS_DEFINE_IID(kIEventStateManagerIID, NS_IEVENTSTATEMANAGER_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
nsEventStateManager::nsEventStateManager() {
mEventTarget = nsnull;
}
nsEventStateManager::~nsEventStateManager() {
}
NS_IMPL_ADDREF(nsEventStateManager)
NS_IMPL_RELEASE(nsEventStateManager)
NS_IMPL_QUERY_INTERFACE(nsEventStateManager, kIEventStateManagerIID);
NS_METHOD nsEventStateManager::GetEventTarget(nsISupports **aResult)
{
NS_PRECONDITION(nsnull != aResult, "null ptr");
if (nsnull == aResult) {
return NS_ERROR_NULL_POINTER;
}
*aResult = mEventTarget;
NS_IF_ADDREF(mEventTarget);
return NS_OK;
}
NS_METHOD nsEventStateManager::SetEventTarget(nsISupports *aSupports)
{
mEventTarget = aSupports;
return NS_OK;
}
nsresult NS_NewEventStateManager(nsIEventStateManager** aInstancePtrResult)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "nsnull ptr");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
nsIEventStateManager* manager = new nsEventStateManager();
if (nsnull == manager) {
return NS_ERROR_OUT_OF_MEMORY;
}
return manager->QueryInterface(kIEventStateManagerIID, (void **) aInstancePtrResult);
}

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

@ -0,0 +1,52 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsEventStateManager_h__
#define nsEventStateManager_h__
#include "nsIEventStateManager.h"
class nsIDOMEvent;
/*
* Event listener manager
*/
class nsEventStateManager : public nsIEventStateManager {
public:
nsEventStateManager();
virtual ~nsEventStateManager();
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
NS_IMETHOD GetEventTarget(nsISupports **aResult);
NS_IMETHOD SetEventTarget(nsISupports *aSupports);
protected:
PRUint32 mRefCnt : 31;
nsISupports* mEventTarget;
};
extern nsresult NS_NewEventStateManager(nsIEventStateManager** aInstancePtrResult);
#endif // nsEventStateManager_h__

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

@ -596,18 +596,19 @@ nsresult nsHTMLContent::RemoveEventListener(nsIDOMEventListener *aListener, cons
nsresult nsHTMLContent::HandleDOMEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsIDOMEvent* aDOMEvent,
nsEventStatus& aEventStatus)
{
//Capturing stage
//Local handling stage
if (nsnull != mListenerManager) {
mListenerManager->HandleEvent(aPresContext, aEvent, aEventStatus);
mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aEventStatus);
}
//Bubbling stage
if (mParent != nsnull) {
return mParent->HandleDOMEvent(aPresContext, aEvent, aEventStatus);
return mParent->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, aEventStatus);
}
return NS_OK;

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

@ -135,6 +135,7 @@ public:
NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsIDOMEvent* aDOMEvent,
nsEventStatus& aEventStatus);
protected:

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

@ -565,11 +565,12 @@ void nsHTMLTagContent::TriggerLink(nsIPresContext& aPresContext,
nsresult nsHTMLTagContent::HandleDOMEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsIDOMEvent* aDOMEvent,
nsEventStatus& aEventStatus)
{
nsresult ret = NS_OK;
ret = nsHTMLContent::HandleDOMEvent(aPresContext, aEvent, aEventStatus);
ret = nsHTMLContent::HandleDOMEvent(aPresContext, aEvent, aDOMEvent, aEventStatus);
if (NS_OK == ret && nsEventStatus_eIgnore == aEventStatus) {
switch (aEvent->message) {

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

@ -116,6 +116,7 @@ public:
NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsIDOMEvent* aDOMEvent,
nsEventStatus& aEventStatus);
// Utility routines for making attribute parsing easier

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

@ -35,6 +35,7 @@
#include "nsStyleConsts.h"
#include "nsIViewManager.h"
#include "nsHTMLAtoms.h"
#include "nsIEventStateManager.h"
class RootFrame : public nsContainerFrame {
public:
@ -150,41 +151,48 @@ NS_METHOD RootFrame::HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus)
{
mContent->HandleDOMEvent(aPresContext, aEvent, aEventStatus);
nsIEventStateManager *mManager;
if (NS_OK == aPresContext.GetEventStateManager(&mManager)) {
mManager->SetEventTarget((nsISupports*)mContent);
NS_RELEASE(mManager);
}
mContent->HandleDOMEvent(aPresContext, aEvent, nsnull, aEventStatus);
switch (aEvent->message) {
case NS_MOUSE_MOVE:
case NS_MOUSE_ENTER:
{
nsIFrame* target = this;
PRInt32 cursor;
if (aEventStatus != nsEventStatus_eConsumeNoDefault) {
switch (aEvent->message) {
case NS_MOUSE_MOVE:
case NS_MOUSE_ENTER:
{
nsIFrame* target = this;
PRInt32 cursor;
GetCursorAt(aPresContext, aEvent->point, &target, cursor);
if (cursor == NS_STYLE_CURSOR_INHERIT) {
cursor = NS_STYLE_CURSOR_DEFAULT;
GetCursorAt(aPresContext, aEvent->point, &target, cursor);
if (cursor == NS_STYLE_CURSOR_INHERIT) {
cursor = NS_STYLE_CURSOR_DEFAULT;
}
nsCursor c;
switch (cursor) {
default:
case NS_STYLE_CURSOR_DEFAULT:
c = eCursor_standard;
break;
case NS_STYLE_CURSOR_HAND:
c = eCursor_hyperlink;
break;
case NS_STYLE_CURSOR_IBEAM:
c = eCursor_select;
break;
}
nsIWidget* window;
target->GetWindow(window);
window->SetCursor(c);
NS_RELEASE(window);
}
nsCursor c;
switch (cursor) {
default:
case NS_STYLE_CURSOR_DEFAULT:
c = eCursor_standard;
break;
case NS_STYLE_CURSOR_HAND:
c = eCursor_hyperlink;
break;
case NS_STYLE_CURSOR_IBEAM:
c = eCursor_select;
break;
}
nsIWidget* window;
target->GetWindow(window);
window->SetCursor(c);
NS_RELEASE(window);
break;
}
break;
}
aEventStatus = nsEventStatus_eIgnore;
return NS_OK;
}
@ -470,6 +478,7 @@ public:
NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsIDOMEvent* aDOMEvent,
nsEventStatus& aEventStatus);
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
@ -507,9 +516,10 @@ RootPart::CreateFrame(nsIPresContext* aPresContext,
nsresult
RootPart::HandleDOMEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsIDOMEvent* aDOMEvent,
nsEventStatus& aEventStatus)
{
return mDocument->HandleDOMEvent(aPresContext, aEvent, aEventStatus);
return mDocument->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, aEventStatus);
}
nsresult