Adding new events code to JS event handler support

This commit is contained in:
joki%netscape.com 1998-07-17 04:29:16 +00:00
parent 20e203fb53
commit ad815f4e2a
8 changed files with 1644 additions and 2 deletions

View File

@ -0,0 +1,180 @@
interface Event {
const int VK_CANCEL = 0x03;
const int VK_BACK = 0x08;
const int VK_TAB = 0x09;
const int VK_CLEAR = 0x0C;
const int VK_RETURN = 0x0D;
const int VK_SHIFT = 0x10;
const int VK_CONTROL = 0x11;
const int VK_ALT = 0x12;
const int VK_PAUSE = 0x13;
const int VK_CAPS_LOCK = 0x14;
const int VK_ESCAPE = 0x1B;
const int VK_SPACE = 0x20;
const int VK_PAGE_UP = 0x21;
const int VK_PAGE_DOWN = 0x22;
const int VK_END = 0x23;
const int VK_HOME = 0x24;
const int VK_LEFT = 0x25;
const int VK_UP = 0x26;
const int VK_RIGHT = 0x27;
const int VK_DOWN = 0x28;
const int VK_PRINTSCREEN = 0x2C;
const int VK_INSERT = 0x2D;
const int VK_DELETE = 0x2E;
// VK_0 - VK_9 match their ascii values
const int VK_0 = 0x30;
const int VK_1 = 0x31;
const int VK_2 = 0x32;
const int VK_3 = 0x33;
const int VK_4 = 0x34;
const int VK_5 = 0x35;
const int VK_6 = 0x36;
const int VK_7 = 0x37;
const int VK_8 = 0x38;
const int VK_9 = 0x39;
const int VK_SEMICOLON = 0x3B;
const int VK_EQUALS = 0x3D;
// VK_A - VK_Z match their ascii values
const int VK_A = 0x41;
const int VK_B = 0x42;
const int VK_C = 0x43;
const int VK_D = 0x44;
const int VK_E = 0x45;
const int VK_F = 0x46;
const int VK_G = 0x47;
const int VK_H = 0x48;
const int VK_I = 0x49;
const int VK_J = 0x4A;
const int VK_K = 0x4B;
const int VK_L = 0x4C;
const int VK_M = 0x4D;
const int VK_N = 0x4E;
const int VK_O = 0x4F;
const int VK_P = 0x50;
const int VK_Q = 0x51;
const int VK_R = 0x52;
const int VK_S = 0x53;
const int VK_T = 0x54;
const int VK_U = 0x55;
const int VK_V = 0x56;
const int VK_W = 0x57;
const int VK_X = 0x58;
const int VK_Y = 0x59;
const int VK_Z = 0x5A;
const int VK_NUMPAD0 = 0x60;
const int VK_NUMPAD1 = 0x61;
const int VK_NUMPAD2 = 0x62;
const int VK_NUMPAD3 = 0x63;
const int VK_NUMPAD4 = 0x64;
const int VK_NUMPAD5 = 0x65;
const int VK_NUMPAD6 = 0x66;
const int VK_NUMPAD7 = 0x67;
const int VK_NUMPAD8 = 0x68;
const int VK_NUMPAD9 = 0x69;
const int VK_MULTIPLY = 0x6A;
const int VK_ADD = 0x6B;
const int VK_SEPARATOR = 0x6C;
const int VK_SUBTRACT = 0x6D;
const int VK_DECIMAL = 0x6E;
const int VK_DIVIDE = 0x6F;
const int VK_F1 = 0x70;
const int VK_F2 = 0x71;
const int VK_F3 = 0x72;
const int VK_F4 = 0x73;
const int VK_F5 = 0x74;
const int VK_F6 = 0x75;
const int VK_F7 = 0x76;
const int VK_F8 = 0x77;
const int VK_F9 = 0x78;
const int VK_F10 = 0x79;
const int VK_F11 = 0x7A;
const int VK_F12 = 0x7B;
const int VK_F13 = 0x7C;
const int VK_F14 = 0x7D;
const int VK_F15 = 0x7E;
const int VK_F16 = 0x7F;
const int VK_F17 = 0x80;
const int VK_F18 = 0x81;
const int VK_F19 = 0x82;
const int VK_F20 = 0x83;
const int VK_F21 = 0x84;
const int VK_F22 = 0x85;
const int VK_F23 = 0x86;
const int VK_F24 = 0x87;
const int VK_NUM_LOCK = 0x90;
const int VK_SCROLL_LOCK = 0x91;
const int VK_COMMA = 0xBC;
const int VK_PERIOD = 0xBE;
const int VK_SLASH = 0xBF;
const int VK_BACK_QUOTE = 0xC0;
const int VK_OPEN_BRACKET = 0xDB;
const int VK_BACK_SLASH = 0xDC;
const int VK_CLOSE_BRACKET = 0xDD;
const int VK_QUOTE = 0xDE;
attribute wstring type;
attribute Node target;
attribute int screenX;
attribute int screenY;
attribute int clientX;
attribute int clientY;
attribute boolean altKey;
attribute boolean ctrlKey;
attribute boolean shiftKey;
attribute boolean metaKey;
attribute unsigned long charCode;
attribute unsigned long keyCode;
attribute unsigned long button;
};
interface NSEvent {
const int EVENT_MOUSEDOWN = 0x00000001;
const int EVENT_MOUSEUP = 0x00000002;
const int EVENT_MOUSEOVER = 0x00000004;
const int EVENT_MOUSEOUT = 0x00000008;
const int EVENT_MOUSEMOVE = 0x00000010;
const int EVENT_MOUSEDRAG = 0x00000020;
const int EVENT_CLICK = 0x00000040;
const int EVENT_DBLCLICK = 0x00000080;
const int EVENT_KEYDOWN = 0x00000100;
const int EVENT_KEYUP = 0x00000200;
const int EVENT_KEYPRESS = 0x00000400;
const int EVENT_DRAGDROP = 0x00000800;
const int EVENT_FOCUS = 0x00001000;
const int EVENT_BLUR = 0x00002000;
const int EVENT_SELECT = 0x00004000;
const int EVENT_CHANGE = 0x00008000;
const int EVENT_RESET = 0x00010000;
const int EVENT_SUBMIT = 0x00020000;
const int EVENT_SCROLL = 0x00040000;
const int EVENT_LOAD = 0x00080000;
const int EVENT_UNLOAD = 0x00100000;
const int EVENT_XFER_DONE = 0x00200000;
const int EVENT_ABORT = 0x00400000;
const int EVENT_ERROR = 0x00800000;
const int EVENT_LOCATE = 0x01000000;
const int EVENT_MOVE = 0x02000000;
const int EVENT_RESIZE = 0x04000000;
const int EVENT_FORWARD = 0x08000000;
const int EVENT_HELP = 0x10000000;
const int EVENT_BACK = 0x20000000;
const int EVENT_ALT_MASK = 0x00000001;
const int EVENT_CONTROL_MASK = 0x00000002;
const int EVENT_SHIFT_MASK = 0x00000004;
const int EVENT_META_MASK = 0x00000008;
attribute int layerX;
attribute int layerY;
};

View File

@ -0,0 +1,51 @@
#!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
MODULE=raptor
IDLSRCS = \
Event.idl \
XPCOM_DESTDIR=$(DEPTH)\dom\public\coreEvents
JSSTUB_DESTDIR=$(DEPTH)\dom\src\events
GENXDIR=genx
GENJSDIR=genjs
!include <$(DEPTH)\config\rules.mak>
$(GENXDIR):
-mkdir $(GENXDIR)
$(GENJSDIR):
-mkdir $(GENJSDIR)
IDLC=$(DIST)\bin\idlc.exe
GENIID=$(DIST)\bin\geniid.pl
export:: $(GENXDIR) $(GENJSDIR) $(IDLSRCS)
@echo +++ make: generating xpcom headers
$(IDLC) -d $(GENXDIR) -x $(IDLSRCS)
@echo +++ make: generating JavaScript stubs
$(IDLC) -d $(GENJSDIR) -j $(IDLSRCS)
install::
for %g in ($(IDLSRCS:.idl=.h)) do $(MAKE_INSTALL:/=\) $(GENXDIR)\nsIDOM%g $(XPCOM_DESTDIR)
for %g in ($(IDLSRCS:.idl=.cpp)) do $(MAKE_INSTALL:/=\) $(GENJSDIR)\nsJS%g $(JSSTUB_DESTDIR)

View File

@ -18,7 +18,7 @@
DEPTH=..\..\..
IGNORE_MANIFEST=1
DIRS=coreDom html
DIRS=coreDom html events
MODULE=raptor
IDLSRCS = \
@ -27,7 +27,7 @@ IDLSRCS = \
GLOBAL_IDLSRC = Window.idl
XPCOM_DESTDIR=$(DEPTH)\dom\public
JSSTUB_DESTDIR=$(DEPTH)\dom\src
JSSTUB_DESTDIR=$(DEPTH)\dom\src\base
GENXDIR=genx
GENJSDIR=genjs

37
dom/src/events/Makefile Normal file
View File

@ -0,0 +1,37 @@
#!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=../../..
LIBRARY_NAME = jsdomevents_s
DEFINES = -D_IMPL_NS_DOM
CPPSRCS = \
nsJSEventListener.cpp \
nsJSEvent.cpp \
$(NULL)
MODULE = raptor
REQUIRES = xpcom raptor dom js
include $(DEPTH)/config/config.mk
TARGETS = $(LIBRARY)
include $(DEPTH)/config/rules.mk

View File

@ -0,0 +1,48 @@
#!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
LIBRARY_NAME=jsdomevents_s
MODULE=raptor
REQUIRES=xpcom raptor js
DEFINES=-D_IMPL_NS_DOM -DWIN32_LEAN_AND_MEAN
CPPSRCS = \
nsJSEventListener.cpp \
nsJSEvent.cpp \
$(NULL)
CPP_OBJS= \
.\$(OBJDIR)\nsJSEventListener.obj .\$(OBJDIR)\nsJSEvent.obj
LINCS=-I$(XPDIST)\public\xpcom -I$(XPDIST)\public\raptor -I$(XPDIST)\public\dom -I$(XPDIST)\public\js
LCFLAGS = \
$(LCFLAGS) \
$(DEFINES) \
$(NULL)
include <$(DEPTH)\config\rules.mak>
libs:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
clobber::
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

1160
dom/src/events/nsJSEvent.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,121 @@
/* -*- Mode: C++; tab-width: 4; 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 "nsJSEventListener.h"
#include "nsString.h"
/*
* nsJSEventListener implementation
*/
nsJSEventListener::nsJSEventListener(JSContext *aContext, JSObject *aObj)
{
mContext = aContext;
mJSObj = aObj;
}
nsJSEventListener::~nsJSEventListener()
{
}
nsresult nsJSEventListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
static NS_DEFINE_IID(kIScriptEventListenerIID, NS_ISCRIPTEVENTLISTENER_IID);
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
if (aIID.Equals(kIDOMEventListenerIID)) {
*aInstancePtr = (void*)(nsIDOMEventListener*)this;
AddRef();
return NS_OK;
}
if (aIID.Equals(kIScriptEventListenerIID)) {
*aInstancePtr = (void*)(nsIScriptEventListener*)this;
AddRef();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*)(nsISupports*)(nsIDOMEventListener*)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsJSEventListener)
NS_IMPL_RELEASE(nsJSEventListener)
nsresult nsJSEventListener::ProcessEvent(nsIDOMEvent* aEvent)
{
jsval funval, result;
JSFunction *fun;
jsval argv[1];
JSObject *mEventObj;
char* mEventChars;
nsString mEventString;
if (NS_OK != aEvent->GetType(mEventString)) {
//JS can't handle this event yet or can't handle it at all
return NS_OK;
}
mEventChars = mEventString.ToNewCString();
if (!JS_LookupProperty(mContext, mJSObj, mEventChars, &funval)) {
delete mEventChars;
return NS_ERROR_FAILURE;
}
delete mEventChars;
if (JS_TypeOfValue(mContext, funval) != JSTYPE_FUNCTION) {
return NS_OK;
}
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(mContext);
if (NS_OK != NS_NewScriptEvent(mScriptCX, aEvent, nsnull, (void**)&mEventObj)) {
return NS_ERROR_FAILURE;
}
argv[0] = OBJECT_TO_JSVAL(mEventObj);
if (PR_TRUE == JS_CallFunctionValue(mContext, mJSObj, funval, 1, argv, &result)) {
return NS_OK;
}
return NS_ERROR_FAILURE;
}
/*
* Factory functions
*/
extern "C" NS_DOM nsresult NS_NewScriptEventListener(nsIDOMEventListener ** aInstancePtrResult, nsIScriptContext *aContext, void *aObj)
{
JSContext *mCX = (JSContext*)aContext->GetNativeContext();
nsJSEventListener* it = new nsJSEventListener(mCX, (JSObject*)aObj);
if (NULL == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
return it->QueryInterface(kIDOMEventListenerIID, (void **) aInstancePtrResult);
}

View File

@ -0,0 +1,45 @@
/* -*- Mode: C++; tab-width: 4; 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 nsJSEventListener_h__
#define nsJSEventListener_h__
#include "nsIDOMEvent.h"
#include "nsIScriptEventListener.h"
#include "nsIDOMMouseListener.h"
#include "jsapi.h"
//nsIDOMMouseListener interface
class nsJSEventListener : public nsIDOMEventListener, public nsIScriptEventListener {
public:
nsJSEventListener(JSContext *aContext, JSObject *aObj);
virtual ~nsJSEventListener();
NS_DECL_ISUPPORTS
//nsIDOMEventListener interface
virtual nsresult ProcessEvent(nsIDOMEvent* aEvent);
//nsIJSEventListener interface
protected:
JSContext *mContext;
JSObject *mJSObj;
};
#endif //nsJSEventListener_h__