зеркало из https://github.com/mozilla/pjs.git
Adding parts of dom event flow to layout.
This commit is contained in:
Родитель
f316f35cc8
Коммит
b3d796cf86
|
@ -0,0 +1,23 @@
|
|||
#!nmake
|
||||
#
|
||||
# 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.
|
||||
|
||||
DEPTH=..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
DIRS=public src
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
|
@ -0,0 +1,54 @@
|
|||
#!nmake
|
||||
#
|
||||
# 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.
|
||||
|
||||
DEPTH=..\..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
include <$(DEPTH)\config\config.mak>
|
||||
|
||||
LIBRARY_NAME=raptorevents_s
|
||||
MODULE=raptor
|
||||
REQUIRES=xpcom raptor dom
|
||||
|
||||
DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN
|
||||
|
||||
CPPSRCS= nsEventListenerManager.cpp \
|
||||
nsDOMEvent.cpp \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS= .\$(OBJDIR)\nsEventListenerManager.obj \
|
||||
.\$(OBJDIR)\nsDOMEvent.obj \
|
||||
$(NULL)
|
||||
|
||||
|
||||
EXPORTS= nsEventListenerManager.h
|
||||
|
||||
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor \
|
||||
-I$(PUBLIC)\dom
|
||||
|
||||
LCFLAGS = \
|
||||
$(LCFLAGS) \
|
||||
$(DEFINES) \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
libs:: $(LIBRARY)
|
||||
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib
|
|
@ -0,0 +1,131 @@
|
|||
/* -*- 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 "nsDOMEvent.h"
|
||||
|
||||
static NS_DEFINE_IID(kIDOMEventIID, NS_IDOMEVENT_IID);
|
||||
static NS_DEFINE_IID(kINSEventIID, NS_INSEVENT_IID);
|
||||
|
||||
nsDOMEvent::nsDOMEvent() {
|
||||
}
|
||||
|
||||
nsDOMEvent::~nsDOMEvent() {
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsDOMEvent)
|
||||
NS_IMPL_RELEASE(nsDOMEvent)
|
||||
|
||||
nsresult nsDOMEvent::QueryInterface(const nsIID& aIID,
|
||||
void** aInstancePtrResult)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
||||
if (nsnull == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(kIDOMEventIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsIDOMEvent*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kINSEventIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsINSEvent*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
// nsIDOMEventInterface
|
||||
NS_METHOD nsDOMEvent::GetType(nsString& aType)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode*& aTarget)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetScreenX(PRInt32& aX)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetScreenY(PRInt32& aY)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetClientX(PRInt32& aX)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetClientY(PRInt32& aY)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetAltKey(PRBool& aIsDown)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetCtrlKey(PRBool& aIsDown)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetShiftKey(PRBool& aIsDown)
|
||||
{
|
||||
aIsDown = es.isShift;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetMetaKey(PRBool& aIsDown)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetCharCode(PRUint32& aCharCode)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetKeyCode(PRUint32& aKeyCode)
|
||||
{
|
||||
aKeyCode = es.keyCode;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetButton(PRUint32& aButton)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
// nsINSEventInterface
|
||||
NS_METHOD nsDOMEvent::GetLayerX(PRInt32& aX)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetLayerY(PRInt32& aY)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
/* -*- 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 nsDOMEvent_h__
|
||||
#define nsDOMEvent_h__
|
||||
|
||||
#include "nsIDOMEvent.h"
|
||||
#include "nsINSEvent.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsPoint.h"
|
||||
|
||||
class nsDOMEvent : public nsIDOMEvent, public nsINSEvent {
|
||||
|
||||
public:
|
||||
|
||||
enum nsEventStatus {
|
||||
nsEventStatus_eIgnore, // The event is ignored, do default processing
|
||||
nsEventStatus_eConsumeNoDefault, // The event is consumed, don't do default processing
|
||||
nsEventStatus_eConsumeDoDefault // The event is consumed, but do default processing
|
||||
};
|
||||
|
||||
nsDOMEvent();
|
||||
virtual ~nsDOMEvent();
|
||||
|
||||
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef();
|
||||
NS_IMETHOD_(nsrefcnt) Release();
|
||||
|
||||
// nsIDOMEventInterface
|
||||
NS_IMETHOD GetType(nsString& aType);
|
||||
|
||||
NS_IMETHOD GetTarget(nsIDOMNode*& aTarget);
|
||||
|
||||
NS_IMETHOD GetScreenX(PRInt32& aX);
|
||||
NS_IMETHOD GetScreenY(PRInt32& aY);
|
||||
|
||||
NS_IMETHOD GetClientX(PRInt32& aX);
|
||||
NS_IMETHOD GetClientY(PRInt32& aY);
|
||||
|
||||
NS_IMETHOD GetAltKey(PRBool& aIsDown);
|
||||
NS_IMETHOD GetCtrlKey(PRBool& aIsDown);
|
||||
NS_IMETHOD GetShiftKey(PRBool& aIsDown);
|
||||
NS_IMETHOD GetMetaKey(PRBool& aIsDown);
|
||||
|
||||
NS_IMETHOD GetCharCode(PRUint32& aCharCode);
|
||||
NS_IMETHOD GetKeyCode(PRUint32& aKeyCode);
|
||||
NS_IMETHOD GetButton(PRUint32& aButton);
|
||||
|
||||
// nsINSEventInterface
|
||||
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;
|
||||
|
||||
protected:
|
||||
|
||||
PRUint32 mRefCnt : 31;
|
||||
|
||||
};
|
||||
#endif // nsDOMEvent_h__
|
|
@ -0,0 +1,326 @@
|
|||
/* -*- 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 "nsGUIEvent.h"
|
||||
#include "nsDOMEvent.h"
|
||||
#include "nsEventListenerManager.h"
|
||||
#include "nsIDOMEventListener.h"
|
||||
#include "nsIDOMMouseListener.h"
|
||||
#include "nsIDOMMouseMotionListener.h"
|
||||
#include "nsIDOMKeyListener.h"
|
||||
#include "nsIDOMFocusListener.h"
|
||||
#include "nsIDOMLoadListener.h"
|
||||
#include "nsIDOMDragListener.h"
|
||||
|
||||
static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID);
|
||||
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
|
||||
static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID);
|
||||
static NS_DEFINE_IID(kIDOMMouseMotionListenerIID, NS_IDOMMOUSEMOTIONLISTENER_IID);
|
||||
static NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID);
|
||||
static NS_DEFINE_IID(kIDOMFocusListenerIID, NS_IDOMFOCUSLISTENER_IID);
|
||||
static NS_DEFINE_IID(kIDOMLoadListenerIID, NS_IDOMLOADLISTENER_IID);
|
||||
static NS_DEFINE_IID(kIDOMDragListenerIID, NS_IDOMDRAGLISTENER_IID);
|
||||
static NS_DEFINE_IID(kIDOMEventIID, NS_IDOMEVENT_IID);
|
||||
|
||||
nsEventListenerManager::nsEventListenerManager() {
|
||||
mEventListeners = nsnull;
|
||||
mMouseListeners = nsnull;
|
||||
mMouseMotionListeners = nsnull;
|
||||
mKeyListeners = nsnull;
|
||||
mLoadListeners = nsnull;
|
||||
mFocusListeners = nsnull;
|
||||
mDragListeners = nsnull;
|
||||
}
|
||||
|
||||
nsEventListenerManager::~nsEventListenerManager() {
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsEventListenerManager)
|
||||
NS_IMPL_RELEASE(nsEventListenerManager)
|
||||
|
||||
nsresult nsEventListenerManager::QueryInterface(const nsIID& aIID,
|
||||
void** aInstancePtrResult)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
||||
if (nsnull == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(kIEventListenerManagerIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsIEventListenerManager*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
nsresult nsEventListenerManager::TranslateGUI2DOM(nsGUIEvent*& aGUIEvent, nsIDOMEvent** aDOMEvent)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult nsEventListenerManager::GetEventListeners(nsVoidArray *aListeners, const nsIID& aIID)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets events listeners of all types.
|
||||
* @param an event listener
|
||||
*/
|
||||
|
||||
nsresult nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener, const nsIID& aIID)
|
||||
{
|
||||
if (aIID.Equals(kIDOMMouseListenerIID)) {
|
||||
if (nsnull == mMouseListeners) {
|
||||
mMouseListeners = new nsVoidArray();
|
||||
mMouseListeners->InsertElementAt((void*)aListener, mMouseListeners->Count());
|
||||
}
|
||||
}
|
||||
if (aIID.Equals(kIDOMMouseMotionListenerIID)) {
|
||||
if (nsnull == mMouseMotionListeners) {
|
||||
mMouseMotionListeners = new nsVoidArray();
|
||||
mMouseMotionListeners->InsertElementAt((void*)aListener, mMouseMotionListeners->Count());
|
||||
}
|
||||
}
|
||||
if (aIID.Equals(kIDOMKeyListenerIID)) {
|
||||
if (nsnull == mKeyListeners) {
|
||||
mKeyListeners = new nsVoidArray();
|
||||
mKeyListeners->InsertElementAt((void*)aListener, mKeyListeners->Count());
|
||||
}
|
||||
}
|
||||
if (aIID.Equals(kIDOMLoadListenerIID)) {
|
||||
if (nsnull == mLoadListeners) {
|
||||
mLoadListeners = new nsVoidArray();
|
||||
mLoadListeners->InsertElementAt((void*)aListener, mLoadListeners->Count());
|
||||
}
|
||||
}
|
||||
if (aIID.Equals(kIDOMFocusListenerIID)) {
|
||||
if (nsnull == mFocusListeners) {
|
||||
mFocusListeners = new nsVoidArray();
|
||||
mFocusListeners->InsertElementAt((void*)aListener, mFocusListeners->Count());
|
||||
}
|
||||
}
|
||||
if (aIID.Equals(kIDOMDragListenerIID)) {
|
||||
if (nsnull == mDragListeners) {
|
||||
mDragListeners = new nsVoidArray();
|
||||
mDragListeners->InsertElementAt((void*)aListener, mDragListeners->Count());
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes event listeners of all types.
|
||||
* @param an event listener
|
||||
*/
|
||||
|
||||
nsresult nsEventListenerManager::RemoveEventListener(nsIDOMEventListener *aListener, const nsIID& aIID)
|
||||
{
|
||||
if (aIID.Equals(kIDOMMouseListenerIID)) {
|
||||
if (nsnull == mMouseListeners) {
|
||||
mMouseListeners = new nsVoidArray();
|
||||
mMouseListeners->RemoveElement((void*)aListener);
|
||||
}
|
||||
}
|
||||
if (aIID.Equals(kIDOMMouseMotionListenerIID)) {
|
||||
if (nsnull == mMouseMotionListeners) {
|
||||
mMouseMotionListeners = new nsVoidArray();
|
||||
mMouseMotionListeners->RemoveElement((void*)aListener);
|
||||
}
|
||||
}
|
||||
if (aIID.Equals(kIDOMKeyListenerIID)) {
|
||||
if (nsnull == mKeyListeners) {
|
||||
mKeyListeners = new nsVoidArray();
|
||||
mKeyListeners->RemoveElement((void*)aListener);
|
||||
}
|
||||
}
|
||||
if (aIID.Equals(kIDOMLoadListenerIID)) {
|
||||
if (nsnull == mLoadListeners) {
|
||||
mLoadListeners = new nsVoidArray();
|
||||
mLoadListeners->RemoveElement((void*)aListener);
|
||||
}
|
||||
}
|
||||
if (aIID.Equals(kIDOMFocusListenerIID)) {
|
||||
if (nsnull == mFocusListeners) {
|
||||
mFocusListeners = new nsVoidArray();
|
||||
mFocusListeners->RemoveElement((void*)aListener);
|
||||
}
|
||||
}
|
||||
if (aIID.Equals(kIDOMDragListenerIID)) {
|
||||
if (nsnull == mDragListeners) {
|
||||
mDragListeners = new nsVoidArray();
|
||||
mDragListeners->RemoveElement((void*)aListener);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes a check for event listeners and processing by them if they exist.
|
||||
* @param an event listener
|
||||
*/
|
||||
|
||||
nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext,
|
||||
nsGUIEvent* aEvent,
|
||||
nsEventStatus& aEventStatus)
|
||||
{
|
||||
nsIDOMEvent *domEvent;
|
||||
|
||||
switch(aEvent->message) {
|
||||
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
||||
case NS_MOUSE_MIDDLE_BUTTON_DOWN:
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NS_MOUSE_LEFT_BUTTON_UP:
|
||||
case NS_MOUSE_MIDDLE_BUTTON_UP:
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NS_MOUSE_LEFT_DOUBLECLICK:
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Captures all events designated for descendant objects at the current level.
|
||||
* @param an event listener
|
||||
*/
|
||||
|
||||
nsresult nsEventListenerManager::CaptureEvent(nsIDOMEventListener *aListener)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases all events designated for descendant objects at the current level.
|
||||
* @param an event listener
|
||||
*/
|
||||
|
||||
nsresult nsEventListenerManager::ReleaseEvent(nsIDOMEventListener *aListener)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
/* -*- 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 nsEventListenerManager_h__
|
||||
#define nsEventListenerManager_h__
|
||||
|
||||
#include "nsIEventListenerManager.h"
|
||||
class nsIDOMEvent;
|
||||
|
||||
/*
|
||||
* Event listener manager
|
||||
*/
|
||||
|
||||
class nsEventListenerManager : public nsIEventListenerManager {
|
||||
|
||||
public:
|
||||
nsEventListenerManager();
|
||||
virtual ~nsEventListenerManager();
|
||||
|
||||
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef();
|
||||
NS_IMETHOD_(nsrefcnt) Release();
|
||||
|
||||
/**
|
||||
* Retrieves events listeners of all types.
|
||||
* @param
|
||||
*/
|
||||
|
||||
virtual nsresult GetEventListeners(nsVoidArray *aListeners, const nsIID& aIID);
|
||||
|
||||
/**
|
||||
* Sets events listeners of all types.
|
||||
* @param an event listener
|
||||
*/
|
||||
|
||||
virtual nsresult AddEventListener(nsIDOMEventListener *aListener, const nsIID& aIID);
|
||||
|
||||
virtual nsresult RemoveEventListener(nsIDOMEventListener *aListener, const nsIID& aIID);
|
||||
|
||||
virtual nsresult CaptureEvent(nsIDOMEventListener *aListener);
|
||||
virtual nsresult ReleaseEvent(nsIDOMEventListener *aListener);
|
||||
|
||||
virtual nsresult HandleEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, nsEventStatus& aEventStatus);
|
||||
|
||||
protected:
|
||||
|
||||
PRUint32 mRefCnt : 31;
|
||||
|
||||
virtual nsresult TranslateGUI2DOM(nsGUIEvent*& aGUIEvent, nsIDOMEvent** aDOMEvent);
|
||||
|
||||
nsVoidArray* mEventListeners;
|
||||
nsVoidArray* mMouseListeners;
|
||||
nsVoidArray* mMouseMotionListeners;
|
||||
nsVoidArray* mKeyListeners;
|
||||
nsVoidArray* mLoadListeners;
|
||||
nsVoidArray* mFocusListeners;
|
||||
nsVoidArray* mDragListeners;
|
||||
|
||||
};
|
||||
|
||||
#endif // nsEventListenerManager_h__
|
|
@ -0,0 +1,23 @@
|
|||
#!nmake
|
||||
#
|
||||
# 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.
|
||||
|
||||
DEPTH=..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
DIRS=public src
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
|
@ -0,0 +1,46 @@
|
|||
#!gmake
|
||||
#
|
||||
# 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.
|
||||
|
||||
DEPTH=../../..
|
||||
|
||||
include $(DEPTH)/config/config.mk
|
||||
|
||||
LIBRARY_NAME = raptorevents_s
|
||||
|
||||
DEFINES += -D_IMPL_NS_HTML
|
||||
|
||||
INCLUDES += \
|
||||
-I$(PUBLIC)/dom
|
||||
$(NULL)
|
||||
|
||||
# Note the sophisticated alphabetical ordering :-|
|
||||
CPPSRCS = \
|
||||
nsEventListenerManager.cpp \
|
||||
nsDOMEvent.cpp \
|
||||
$(NULL)
|
||||
|
||||
MODULE = raptor
|
||||
|
||||
|
||||
EXPORTS = \
|
||||
nsEventListenerManager.h \
|
||||
$(NULL)
|
||||
|
||||
REQUIRES = xpcom raptor dom
|
||||
|
||||
include $(DEPTH)/config/rules.mk
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
#!nmake
|
||||
#
|
||||
# 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.
|
||||
|
||||
DEPTH=..\..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
include <$(DEPTH)\config\config.mak>
|
||||
|
||||
LIBRARY_NAME=raptorevents_s
|
||||
MODULE=raptor
|
||||
REQUIRES=xpcom raptor dom
|
||||
|
||||
DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN
|
||||
|
||||
CPPSRCS= nsEventListenerManager.cpp \
|
||||
nsDOMEvent.cpp \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS= .\$(OBJDIR)\nsEventListenerManager.obj \
|
||||
.\$(OBJDIR)\nsDOMEvent.obj \
|
||||
$(NULL)
|
||||
|
||||
|
||||
EXPORTS= nsEventListenerManager.h
|
||||
|
||||
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor \
|
||||
-I$(PUBLIC)\dom
|
||||
|
||||
LCFLAGS = \
|
||||
$(LCFLAGS) \
|
||||
$(DEFINES) \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
libs:: $(LIBRARY)
|
||||
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib
|
|
@ -0,0 +1,131 @@
|
|||
/* -*- 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 "nsDOMEvent.h"
|
||||
|
||||
static NS_DEFINE_IID(kIDOMEventIID, NS_IDOMEVENT_IID);
|
||||
static NS_DEFINE_IID(kINSEventIID, NS_INSEVENT_IID);
|
||||
|
||||
nsDOMEvent::nsDOMEvent() {
|
||||
}
|
||||
|
||||
nsDOMEvent::~nsDOMEvent() {
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsDOMEvent)
|
||||
NS_IMPL_RELEASE(nsDOMEvent)
|
||||
|
||||
nsresult nsDOMEvent::QueryInterface(const nsIID& aIID,
|
||||
void** aInstancePtrResult)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
||||
if (nsnull == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(kIDOMEventIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsIDOMEvent*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kINSEventIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsINSEvent*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
// nsIDOMEventInterface
|
||||
NS_METHOD nsDOMEvent::GetType(nsString& aType)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode*& aTarget)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetScreenX(PRInt32& aX)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetScreenY(PRInt32& aY)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetClientX(PRInt32& aX)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetClientY(PRInt32& aY)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetAltKey(PRBool& aIsDown)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetCtrlKey(PRBool& aIsDown)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetShiftKey(PRBool& aIsDown)
|
||||
{
|
||||
aIsDown = es.isShift;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetMetaKey(PRBool& aIsDown)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetCharCode(PRUint32& aCharCode)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetKeyCode(PRUint32& aKeyCode)
|
||||
{
|
||||
aKeyCode = es.keyCode;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetButton(PRUint32& aButton)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
// nsINSEventInterface
|
||||
NS_METHOD nsDOMEvent::GetLayerX(PRInt32& aX)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetLayerY(PRInt32& aY)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
/* -*- 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 nsDOMEvent_h__
|
||||
#define nsDOMEvent_h__
|
||||
|
||||
#include "nsIDOMEvent.h"
|
||||
#include "nsINSEvent.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsPoint.h"
|
||||
|
||||
class nsDOMEvent : public nsIDOMEvent, public nsINSEvent {
|
||||
|
||||
public:
|
||||
|
||||
enum nsEventStatus {
|
||||
nsEventStatus_eIgnore, // The event is ignored, do default processing
|
||||
nsEventStatus_eConsumeNoDefault, // The event is consumed, don't do default processing
|
||||
nsEventStatus_eConsumeDoDefault // The event is consumed, but do default processing
|
||||
};
|
||||
|
||||
nsDOMEvent();
|
||||
virtual ~nsDOMEvent();
|
||||
|
||||
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef();
|
||||
NS_IMETHOD_(nsrefcnt) Release();
|
||||
|
||||
// nsIDOMEventInterface
|
||||
NS_IMETHOD GetType(nsString& aType);
|
||||
|
||||
NS_IMETHOD GetTarget(nsIDOMNode*& aTarget);
|
||||
|
||||
NS_IMETHOD GetScreenX(PRInt32& aX);
|
||||
NS_IMETHOD GetScreenY(PRInt32& aY);
|
||||
|
||||
NS_IMETHOD GetClientX(PRInt32& aX);
|
||||
NS_IMETHOD GetClientY(PRInt32& aY);
|
||||
|
||||
NS_IMETHOD GetAltKey(PRBool& aIsDown);
|
||||
NS_IMETHOD GetCtrlKey(PRBool& aIsDown);
|
||||
NS_IMETHOD GetShiftKey(PRBool& aIsDown);
|
||||
NS_IMETHOD GetMetaKey(PRBool& aIsDown);
|
||||
|
||||
NS_IMETHOD GetCharCode(PRUint32& aCharCode);
|
||||
NS_IMETHOD GetKeyCode(PRUint32& aKeyCode);
|
||||
NS_IMETHOD GetButton(PRUint32& aButton);
|
||||
|
||||
// nsINSEventInterface
|
||||
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;
|
||||
|
||||
protected:
|
||||
|
||||
PRUint32 mRefCnt : 31;
|
||||
|
||||
};
|
||||
#endif // nsDOMEvent_h__
|
|
@ -0,0 +1,326 @@
|
|||
/* -*- 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 "nsGUIEvent.h"
|
||||
#include "nsDOMEvent.h"
|
||||
#include "nsEventListenerManager.h"
|
||||
#include "nsIDOMEventListener.h"
|
||||
#include "nsIDOMMouseListener.h"
|
||||
#include "nsIDOMMouseMotionListener.h"
|
||||
#include "nsIDOMKeyListener.h"
|
||||
#include "nsIDOMFocusListener.h"
|
||||
#include "nsIDOMLoadListener.h"
|
||||
#include "nsIDOMDragListener.h"
|
||||
|
||||
static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID);
|
||||
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
|
||||
static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID);
|
||||
static NS_DEFINE_IID(kIDOMMouseMotionListenerIID, NS_IDOMMOUSEMOTIONLISTENER_IID);
|
||||
static NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID);
|
||||
static NS_DEFINE_IID(kIDOMFocusListenerIID, NS_IDOMFOCUSLISTENER_IID);
|
||||
static NS_DEFINE_IID(kIDOMLoadListenerIID, NS_IDOMLOADLISTENER_IID);
|
||||
static NS_DEFINE_IID(kIDOMDragListenerIID, NS_IDOMDRAGLISTENER_IID);
|
||||
static NS_DEFINE_IID(kIDOMEventIID, NS_IDOMEVENT_IID);
|
||||
|
||||
nsEventListenerManager::nsEventListenerManager() {
|
||||
mEventListeners = nsnull;
|
||||
mMouseListeners = nsnull;
|
||||
mMouseMotionListeners = nsnull;
|
||||
mKeyListeners = nsnull;
|
||||
mLoadListeners = nsnull;
|
||||
mFocusListeners = nsnull;
|
||||
mDragListeners = nsnull;
|
||||
}
|
||||
|
||||
nsEventListenerManager::~nsEventListenerManager() {
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsEventListenerManager)
|
||||
NS_IMPL_RELEASE(nsEventListenerManager)
|
||||
|
||||
nsresult nsEventListenerManager::QueryInterface(const nsIID& aIID,
|
||||
void** aInstancePtrResult)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
||||
if (nsnull == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(kIEventListenerManagerIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsIEventListenerManager*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
nsresult nsEventListenerManager::TranslateGUI2DOM(nsGUIEvent*& aGUIEvent, nsIDOMEvent** aDOMEvent)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult nsEventListenerManager::GetEventListeners(nsVoidArray *aListeners, const nsIID& aIID)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets events listeners of all types.
|
||||
* @param an event listener
|
||||
*/
|
||||
|
||||
nsresult nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener, const nsIID& aIID)
|
||||
{
|
||||
if (aIID.Equals(kIDOMMouseListenerIID)) {
|
||||
if (nsnull == mMouseListeners) {
|
||||
mMouseListeners = new nsVoidArray();
|
||||
mMouseListeners->InsertElementAt((void*)aListener, mMouseListeners->Count());
|
||||
}
|
||||
}
|
||||
if (aIID.Equals(kIDOMMouseMotionListenerIID)) {
|
||||
if (nsnull == mMouseMotionListeners) {
|
||||
mMouseMotionListeners = new nsVoidArray();
|
||||
mMouseMotionListeners->InsertElementAt((void*)aListener, mMouseMotionListeners->Count());
|
||||
}
|
||||
}
|
||||
if (aIID.Equals(kIDOMKeyListenerIID)) {
|
||||
if (nsnull == mKeyListeners) {
|
||||
mKeyListeners = new nsVoidArray();
|
||||
mKeyListeners->InsertElementAt((void*)aListener, mKeyListeners->Count());
|
||||
}
|
||||
}
|
||||
if (aIID.Equals(kIDOMLoadListenerIID)) {
|
||||
if (nsnull == mLoadListeners) {
|
||||
mLoadListeners = new nsVoidArray();
|
||||
mLoadListeners->InsertElementAt((void*)aListener, mLoadListeners->Count());
|
||||
}
|
||||
}
|
||||
if (aIID.Equals(kIDOMFocusListenerIID)) {
|
||||
if (nsnull == mFocusListeners) {
|
||||
mFocusListeners = new nsVoidArray();
|
||||
mFocusListeners->InsertElementAt((void*)aListener, mFocusListeners->Count());
|
||||
}
|
||||
}
|
||||
if (aIID.Equals(kIDOMDragListenerIID)) {
|
||||
if (nsnull == mDragListeners) {
|
||||
mDragListeners = new nsVoidArray();
|
||||
mDragListeners->InsertElementAt((void*)aListener, mDragListeners->Count());
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes event listeners of all types.
|
||||
* @param an event listener
|
||||
*/
|
||||
|
||||
nsresult nsEventListenerManager::RemoveEventListener(nsIDOMEventListener *aListener, const nsIID& aIID)
|
||||
{
|
||||
if (aIID.Equals(kIDOMMouseListenerIID)) {
|
||||
if (nsnull == mMouseListeners) {
|
||||
mMouseListeners = new nsVoidArray();
|
||||
mMouseListeners->RemoveElement((void*)aListener);
|
||||
}
|
||||
}
|
||||
if (aIID.Equals(kIDOMMouseMotionListenerIID)) {
|
||||
if (nsnull == mMouseMotionListeners) {
|
||||
mMouseMotionListeners = new nsVoidArray();
|
||||
mMouseMotionListeners->RemoveElement((void*)aListener);
|
||||
}
|
||||
}
|
||||
if (aIID.Equals(kIDOMKeyListenerIID)) {
|
||||
if (nsnull == mKeyListeners) {
|
||||
mKeyListeners = new nsVoidArray();
|
||||
mKeyListeners->RemoveElement((void*)aListener);
|
||||
}
|
||||
}
|
||||
if (aIID.Equals(kIDOMLoadListenerIID)) {
|
||||
if (nsnull == mLoadListeners) {
|
||||
mLoadListeners = new nsVoidArray();
|
||||
mLoadListeners->RemoveElement((void*)aListener);
|
||||
}
|
||||
}
|
||||
if (aIID.Equals(kIDOMFocusListenerIID)) {
|
||||
if (nsnull == mFocusListeners) {
|
||||
mFocusListeners = new nsVoidArray();
|
||||
mFocusListeners->RemoveElement((void*)aListener);
|
||||
}
|
||||
}
|
||||
if (aIID.Equals(kIDOMDragListenerIID)) {
|
||||
if (nsnull == mDragListeners) {
|
||||
mDragListeners = new nsVoidArray();
|
||||
mDragListeners->RemoveElement((void*)aListener);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes a check for event listeners and processing by them if they exist.
|
||||
* @param an event listener
|
||||
*/
|
||||
|
||||
nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext,
|
||||
nsGUIEvent* aEvent,
|
||||
nsEventStatus& aEventStatus)
|
||||
{
|
||||
nsIDOMEvent *domEvent;
|
||||
|
||||
switch(aEvent->message) {
|
||||
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
||||
case NS_MOUSE_MIDDLE_BUTTON_DOWN:
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NS_MOUSE_LEFT_BUTTON_UP:
|
||||
case NS_MOUSE_MIDDLE_BUTTON_UP:
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NS_MOUSE_LEFT_DOUBLECLICK:
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Captures all events designated for descendant objects at the current level.
|
||||
* @param an event listener
|
||||
*/
|
||||
|
||||
nsresult nsEventListenerManager::CaptureEvent(nsIDOMEventListener *aListener)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases all events designated for descendant objects at the current level.
|
||||
* @param an event listener
|
||||
*/
|
||||
|
||||
nsresult nsEventListenerManager::ReleaseEvent(nsIDOMEventListener *aListener)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
/* -*- 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 nsEventListenerManager_h__
|
||||
#define nsEventListenerManager_h__
|
||||
|
||||
#include "nsIEventListenerManager.h"
|
||||
class nsIDOMEvent;
|
||||
|
||||
/*
|
||||
* Event listener manager
|
||||
*/
|
||||
|
||||
class nsEventListenerManager : public nsIEventListenerManager {
|
||||
|
||||
public:
|
||||
nsEventListenerManager();
|
||||
virtual ~nsEventListenerManager();
|
||||
|
||||
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef();
|
||||
NS_IMETHOD_(nsrefcnt) Release();
|
||||
|
||||
/**
|
||||
* Retrieves events listeners of all types.
|
||||
* @param
|
||||
*/
|
||||
|
||||
virtual nsresult GetEventListeners(nsVoidArray *aListeners, const nsIID& aIID);
|
||||
|
||||
/**
|
||||
* Sets events listeners of all types.
|
||||
* @param an event listener
|
||||
*/
|
||||
|
||||
virtual nsresult AddEventListener(nsIDOMEventListener *aListener, const nsIID& aIID);
|
||||
|
||||
virtual nsresult RemoveEventListener(nsIDOMEventListener *aListener, const nsIID& aIID);
|
||||
|
||||
virtual nsresult CaptureEvent(nsIDOMEventListener *aListener);
|
||||
virtual nsresult ReleaseEvent(nsIDOMEventListener *aListener);
|
||||
|
||||
virtual nsresult HandleEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, nsEventStatus& aEventStatus);
|
||||
|
||||
protected:
|
||||
|
||||
PRUint32 mRefCnt : 31;
|
||||
|
||||
virtual nsresult TranslateGUI2DOM(nsGUIEvent*& aGUIEvent, nsIDOMEvent** aDOMEvent);
|
||||
|
||||
nsVoidArray* mEventListeners;
|
||||
nsVoidArray* mMouseListeners;
|
||||
nsVoidArray* mMouseMotionListeners;
|
||||
nsVoidArray* mKeyListeners;
|
||||
nsVoidArray* mLoadListeners;
|
||||
nsVoidArray* mFocusListeners;
|
||||
nsVoidArray* mDragListeners;
|
||||
|
||||
};
|
||||
|
||||
#endif // nsEventListenerManager_h__
|
Загрузка…
Ссылка в новой задаче