a=edburns

This checkin mainly does two things:

1. Correctly populates the java.awt.event.MouseEvent subclass with the
  correct modifiers, x, y, and clickCount for the mozilla mouse event.

2. Adds a performance optimization: previously, every mouse event was
  causing a new instance of java.util.Properties to be created.  Now,
  only one Properties instance is created per-page, and it is cleared on
  each mouse event.

Also, I made the DOMMouseListenerImpl constructor initialize the
refCount to 0.  This allows the object to be correctly deleted.

M classes_spec/org/mozilla/webclient/test/EMWindow.java
M classes_spec/org/mozilla/webclient/wrapper_native/WCMouseListenerImpl.java
M src_moz/DOMMouseListenerImpl.cpp
M src_moz/DOMMouseListenerImpl.h
M src_moz/WindowControlImpl.cpp
M src_moz/jni_util.cpp
M src_moz/jni_util.h
M src_moz/jni_util_export.cpp
M src_moz/jni_util_export.h

M classes_spec/org/mozilla/webclient/test/EMWindow.java

* Added test code for MouseListener properties: buttons, modifiers, etc.

M classes_spec/org/mozilla/webclient/wrapper_native/WCMouseListenerImpl.java

* Added support for mouse modifiers.  Pull values out of the hash table,
  put them in the MouseEvent constructor.

M src_moz/DOMMouseListenerImpl.cpp

* Modified constructors so they initialize all ivars.

* changed usage model of properties object to share the lifetime of the
  DOMMouseListenerImpl instance.  Needed to make use of the new function
  util_ClearPropertiesObject() to do this.  Now we have only one call to
  util_DestroyPropertiesObject(), in the DOMMouseListenerImpl
  destructor.

M src_moz/DOMMouseListenerImpl.h

>     virtual ~DOMMouseListenerImpl();
>
98a101
> protected:
100a104,105
>
> void JNICALL addMouseEventDataToProperties(nsIDOMEvent *aMouseEvent);

M src_moz/WindowControlImpl.cpp

* Initialize new WebShellInitConext member propertiesClass to nsnull

M src_moz/jni_util.cpp

* Added util_ClearPropertiesObject() an optimization.

* Store the jclass for java/util/Properties in an element in
  WebShellInitContext.  This prevents us from having to do FindClass
  each time a mouse event occurs.

* Added a parameter to util_StoreIntoPropertiesObject.

M src_moz/jni_util.h

* Added propertiesClass to WebShellInitContext

* Added new method ClearPropertiesObject

* Added new last argument to DestroyPropertiesObject

M src_moz/jni_util_export.cpp
M src_moz/jni_util_export.h

* Added function pointer for util_ClearPropertiesObject.
This commit is contained in:
edburns%acm.org 2000-06-08 02:16:06 +00:00
Родитель 865466897e
Коммит 276931ce74
9 изменённых файлов: 375 добавлений и 916 удалений

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

@ -45,14 +45,13 @@ import org.mozilla.util.Assert;
import org.w3c.dom.Document;
/**
*
* This is a test application for using the BrowserControl.
*
* @version $Id: EMWindow.java,v 1.13 2000-06-05 19:11:22 edburns%acm.org Exp $
* @version $Id: EMWindow.java,v 1.14 2000-06-08 02:16:06 edburns%acm.org Exp $
*
* @see org.mozilla.webclient.BrowserControlFactory
@ -236,7 +235,6 @@ public class EMWindow extends Frame implements DialogClient, ActionListener, Doc
EventRegistration eventRegistration =
(EventRegistration)
browserControl.queryInterface(BrowserControl.EVENT_REGISTRATION_NAME);
System.out.println("debug: edburns: adding DocumentLoadListener");
eventRegistration.addDocumentLoadListener(this);
eventRegistration.addMouseListener(this);
@ -310,9 +308,7 @@ public void delete()
}
BrowserControlFactory.deleteBrowserControl(browserControl);
browserControl = null;
System.out.println("debug: edburns: about to hide");
this.hide();
System.out.println("debug: edburns: about to dispose");
this.dispose();
urlField = null;
browserCanvas = null;
@ -530,9 +526,11 @@ public void eventDispatched(WebclientEvent event)
forwardButton.setEnabled(history.canForward());
statusLabel.setText("Done.");
currentDocument = currentPage.getDOM();
// add the new document to the domViewer
if (null != domViewer) {
domViewer.setDocument(currentDocument);
}
break;
}
}
@ -544,12 +542,20 @@ public void eventDispatched(WebclientEvent event)
public void mouseClicked(java.awt.event.MouseEvent e)
{
System.out.println("mouseClicked");
int modifiers = e.getModifiers();
if (0 != (modifiers & InputEvent.BUTTON1_MASK)) {
System.out.println("Button1 ");
}
if (0 != (modifiers & InputEvent.BUTTON2_MASK)) {
System.out.println("Button2 ");
}
if (0 != (modifiers & InputEvent.BUTTON3_MASK)) {
System.out.println("Button3 ");
}
}
public void mouseEntered(java.awt.event.MouseEvent e)
{
System.out.println("mouseEntered");
if (e instanceof WCMouseEvent) {
WCMouseEvent wcMouseEvent = (WCMouseEvent) e;
Properties eventProps =
@ -557,6 +563,18 @@ public void mouseEntered(java.awt.event.MouseEvent e)
if (null == eventProps) {
return;
}
if (e.isAltDown()) {
System.out.println("Alt ");
}
if (e.isControlDown()) {
System.out.println("Ctrl ");
}
if (e.isShiftDown()) {
System.out.println("Shift ");
}
if (e.isMetaDown()) {
System.out.println("Meta ");
}
String href = eventProps.getProperty("href");
if (null != href) {
// if it's a relative URL
@ -569,7 +587,6 @@ public void mouseEntered(java.awt.event.MouseEvent e)
href = currentURL.substring(0, lastSlashIndex) + "/"+ href;
}
}
System.out.println(href);
statusLabel.setText(href);
}
}
@ -578,19 +595,17 @@ public void mouseEntered(java.awt.event.MouseEvent e)
public void mouseExited(java.awt.event.MouseEvent e)
{
statusLabel.setText("");
System.out.println("mouseExited");
}
public void mousePressed(java.awt.event.MouseEvent e)
{
System.out.println("mousePressed");
}
public void mouseReleased(java.awt.event.MouseEvent e)
{
System.out.println("mouseReleased");
}
//
// Package methods
//

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

@ -28,11 +28,14 @@ import org.mozilla.util.ParameterCheck;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.event.InputEvent;
import java.awt.Component;
import org.mozilla.webclient.WCMouseEvent;
import org.mozilla.webclient.WebclientEvent;
import org.mozilla.webclient.WebclientEventListener;
import java.util.Properties;
/**
* This class wraps the user provided instance of
@ -109,48 +112,90 @@ public void eventDispatched(WebclientEvent event)
{
ParameterCheck.nonNull(event);
WCMouseEvent mouseEvent;
Properties props = (Properties) event.getEventData();
int modifiers = 0, x = -1, y = -1, clickCount = 0;
String str;
boolean bool;
if (null != (str = props.getProperty("ClientX"))) {
x = Integer.valueOf(str).intValue();
}
if (null != (str = props.getProperty("ClientY"))) {
y = Integer.valueOf(str).intValue();
}
if (null != (str = props.getProperty("ClickCount"))) {
clickCount = Integer.valueOf(str).intValue();
}
if (null != (str = props.getProperty("Button"))) {
int button = Integer.valueOf(str).intValue();
if (1 == button) {
modifiers += InputEvent.BUTTON1_MASK;
}
if (2 == button) {
modifiers += InputEvent.BUTTON2_MASK;
}
if (3 == button) {
modifiers += InputEvent.BUTTON3_MASK;
}
}
if (null != (str = props.getProperty("Alt"))) {
bool = Boolean.valueOf(str).booleanValue();
if (bool) {
modifiers += InputEvent.ALT_MASK;
}
}
if (null != (str = props.getProperty("Ctrl"))) {
bool = Boolean.valueOf(str).booleanValue();
if (bool) {
modifiers += InputEvent.CTRL_MASK;
}
}
if (null != (str = props.getProperty("Meta"))) {
bool = Boolean.valueOf(str).booleanValue();
if (bool) {
modifiers += InputEvent.META_MASK;
}
}
if (null != (str = props.getProperty("Shift"))) {
bool = Boolean.valueOf(str).booleanValue();
if (bool) {
modifiers += InputEvent.SHIFT_MASK;
}
}
switch ((int) event.getType()) {
case (int) WCMouseEvent.MOUSE_DOWN_EVENT_MASK:
mouseEvent =
new WCMouseEvent((Component) event.getSource(),
MouseEvent.MOUSE_PRESSED, -1,
-1, -1, -1, -1, false, event);
modifiers, x, y, clickCount, false, event);
mouseListener.mousePressed(mouseEvent);
break;
case (int) WCMouseEvent.MOUSE_UP_EVENT_MASK:
mouseEvent =
new WCMouseEvent((Component) event.getSource(),
MouseEvent.MOUSE_RELEASED, -1,
-1, -1, -1, -1, false, event);
modifiers, x, y, clickCount, false, event);
mouseListener.mouseReleased(mouseEvent);
break;
case (int) WCMouseEvent.MOUSE_CLICK_EVENT_MASK:
mouseEvent =
new WCMouseEvent((Component) event.getSource(),
MouseEvent.MOUSE_CLICKED, -1,
-1, -1, -1, 1, false, event);
mouseListener.mouseClicked(mouseEvent);
break;
case (int) WCMouseEvent.MOUSE_DOUBLE_CLICK_EVENT_MASK:
mouseEvent =
new WCMouseEvent((Component) event.getSource(),
MouseEvent.MOUSE_CLICKED, -1,
-1, -1, -1, 2, false, event);
modifiers, x, y, clickCount, false, event);
mouseListener.mouseClicked(mouseEvent);
break;
case (int) WCMouseEvent.MOUSE_OVER_EVENT_MASK:
mouseEvent =
new WCMouseEvent((Component) event.getSource(),
MouseEvent.MOUSE_ENTERED, -1,
-1, -1, -1, -1, false, event);
modifiers, x, y, clickCount, false, event);
mouseListener.mouseEntered(mouseEvent);
break;
case (int) WCMouseEvent.MOUSE_OUT_EVENT_MASK:
mouseEvent =
new WCMouseEvent((Component) event.getSource(),
MouseEvent.MOUSE_EXITED, -1,
-1, -1, -1, -1, false, event);
modifiers, x, y, clickCount, false, event);
mouseListener.mouseExited(mouseEvent);
break;
}

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

@ -79,16 +79,40 @@ static jobject FALSE_VALUE = nsnull;
jboolean initPropertiesKeys();
NS_IMPL_ADDREF(DOMMouseListenerImpl);
NS_IMPL_RELEASE(DOMMouseListenerImpl);
//NS_IMPL_ADDREF(DOMMouseListenerImpl);
//NS_IMPL_RELEASE(DOMMouseListenerImpl);
DOMMouseListenerImpl::DOMMouseListenerImpl(){
NS_IMETHODIMP_(nsrefcnt) DOMMouseListenerImpl::AddRef()
{
mRefCnt++;
return mRefCnt;
}
NS_IMETHODIMP_(nsrefcnt) DOMMouseListenerImpl::Release()
{
mRefCnt--;
if (mRefCnt == 0) {
mRefCnt = 1; /* stabilize */
NS_DELETEXPCOM(this);
return 0;
}
return mRefCnt;
}
DOMMouseListenerImpl::DOMMouseListenerImpl() : mJNIEnv(nsnull),
mInitContext(nsnull), mTarget(nsnull),
inverseDepth(-1), properties(nsnull), currentDOMEvent(nsnull)
{
}
DOMMouseListenerImpl::DOMMouseListenerImpl(JNIEnv *env,
WebShellInitContext *yourInitContext,
jobject yourTarget) :
mJNIEnv(env), mInitContext(yourInitContext), mTarget(yourTarget)
mJNIEnv(env), mInitContext(yourInitContext), mTarget(yourTarget),
inverseDepth(-1), properties(nsnull), currentDOMEvent(nsnull)
{
if (nsnull == gVm) { // declared in jni_util.h
::util_GetJavaVM(env, &gVm); // save this vm reference away for the callback!
@ -101,7 +125,18 @@ DOMMouseListenerImpl::DOMMouseListenerImpl(JNIEnv *env,
util_InitializeEventMaskValuesFromClass("org/mozilla/webclient/WCMouseEvent",
maskNames, maskValues);
}
mRefCnt = 1; // PENDING(edburns): not sure about how right this is to do.
mRefCnt = 0; // PENDING(edburns): not sure about how right this is to do.
}
DOMMouseListenerImpl::~DOMMouseListenerImpl()
{
if (properties) {
JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2);
util_DestroyPropertiesObject(env, properties, (jobject) mInitContext);
properties = nsnull;
}
currentDOMEvent = nsnull;
}
NS_IMETHODIMP DOMMouseListenerImpl::QueryInterface(REFNSIID aIID, void** aInstance)
@ -134,7 +169,7 @@ nsresult DOMMouseListenerImpl::MouseDown(nsIDOMEvent *aMouseEvent)
{
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
PR_LOG(prLogModuleInfo, 4,
("!DOMMouseListenerImpl::MouseDown\n"));
}
#endif
@ -146,7 +181,6 @@ nsresult DOMMouseListenerImpl::MouseDown(nsIDOMEvent *aMouseEvent)
mTarget,
maskValues[MOUSE_DOWN_EVENT_MASK],
properties);
util_DestroyPropertiesObject(mInitContext->env, properties, nsnull);
return NS_OK;
}
@ -154,7 +188,7 @@ nsresult DOMMouseListenerImpl::MouseUp(nsIDOMEvent *aMouseEvent)
{
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
PR_LOG(prLogModuleInfo, 4,
("!DOMMouseListenerImpl::MouseUp\n"));
}
#endif
@ -166,7 +200,6 @@ nsresult DOMMouseListenerImpl::MouseUp(nsIDOMEvent *aMouseEvent)
mTarget,
maskValues[MOUSE_UP_EVENT_MASK],
properties);
util_DestroyPropertiesObject(mInitContext->env, properties, nsnull);
return NS_OK;
}
@ -174,7 +207,7 @@ nsresult DOMMouseListenerImpl::MouseClick(nsIDOMEvent *aMouseEvent)
{
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
PR_LOG(prLogModuleInfo, 4,
("!DOMMouseListenerImpl::MouseClick\n"));
}
#endif
@ -186,7 +219,6 @@ nsresult DOMMouseListenerImpl::MouseClick(nsIDOMEvent *aMouseEvent)
mTarget,
maskValues[MOUSE_CLICK_EVENT_MASK],
properties);
util_DestroyPropertiesObject(mInitContext->env, properties, nsnull);
return NS_OK;
}
@ -194,7 +226,7 @@ nsresult DOMMouseListenerImpl::MouseDblClick(nsIDOMEvent *aMouseEvent)
{
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
PR_LOG(prLogModuleInfo, 4,
("!DOMMouseListenerImpl::MouseDoubleClick\n"));
}
#endif
@ -206,7 +238,6 @@ nsresult DOMMouseListenerImpl::MouseDblClick(nsIDOMEvent *aMouseEvent)
mTarget,
maskValues[MOUSE_DOUBLE_CLICK_EVENT_MASK],
properties);
util_DestroyPropertiesObject(mInitContext->env, properties, nsnull);
return NS_OK;
}
@ -214,7 +245,7 @@ nsresult DOMMouseListenerImpl::MouseOver(nsIDOMEvent *aMouseEvent)
{
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
PR_LOG(prLogModuleInfo, 4,
("!DOMMouseListenerImpl::MouseOver\n"));
}
#endif
@ -226,7 +257,6 @@ nsresult DOMMouseListenerImpl::MouseOver(nsIDOMEvent *aMouseEvent)
mTarget,
maskValues[MOUSE_OVER_EVENT_MASK],
properties);
util_DestroyPropertiesObject(mInitContext->env, properties, nsnull);
return NS_OK;
}
@ -235,7 +265,7 @@ nsresult DOMMouseListenerImpl::MouseOut(nsIDOMEvent *aMouseEvent)
{
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
PR_LOG(prLogModuleInfo, 4,
("!DOMMouseListenerImpl::MouseOut\n"));
}
#endif
@ -247,7 +277,6 @@ nsresult DOMMouseListenerImpl::MouseOut(nsIDOMEvent *aMouseEvent)
mTarget,
maskValues[MOUSE_OUT_EVENT_MASK],
properties);
util_DestroyPropertiesObject(mInitContext->env, properties, nsnull);
return NS_OK;
}
@ -266,116 +295,142 @@ jobject JNICALL DOMMouseListenerImpl::getPropertiesFromEvent(nsIDOMEvent *event)
}
inverseDepth = 0;
JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2);
properties = util_CreatePropertiesObject(env, nsnull);
dom_iterateToRoot(currentNode, DOMMouseListenerImpl::takeActionOnNode,
(void *)this);
if (properties) {
// Add to the properties table, the modifiers and such
nsCOMPtr<nsIDOMMouseEvent> mouseEvent;
rv = aMouseEvent->QueryInterface(nsIDOMMouseEvent::GetIID(),
getter_AddRefs(mouseEvent));
if (NS_FAILED(rv)) {
if (properties) {
util_ClearPropertiesObject(env, properties, (jobject) mInitContext);
}
else {
if (!(properties =
util_CreatePropertiesObject(env, (jobject)mInitContext))) {
return properties;
}
// initialize the standard properties keys
if (!PROPERTIES_KEYS_INITED) {
// if the initialization failed, don't modify the properties
if (!initPropertiesKeys()) {
return properties;
}
}
PRInt32 intVal;
PRUint16 int16Val;
PRBool boolVal;
char buf[20];
jstring strVal;
JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2);
// PENDING(edburns): perhaps use a macro to speed this up?
rv = mouseEvent->GetScreenX(&intVal);
if (NS_SUCCEEDED(rv)) {
itoa(intVal, buf, 10);
strVal = ::util_NewStringUTF(env, buf);
::util_StoreIntoPropertiesObject(env, properties, SCREEN_X_KEY,
(jobject) strVal);
}
rv = mouseEvent->GetScreenY(&intVal);
if (NS_SUCCEEDED(rv)) {
itoa(intVal, buf, 10);
strVal = ::util_NewStringUTF(env, buf);
::util_StoreIntoPropertiesObject(env, properties, SCREEN_Y_KEY,
(jobject) strVal);
}
rv = mouseEvent->GetClientX(&intVal);
if (NS_SUCCEEDED(rv)) {
itoa(intVal, buf, 10);
strVal = ::util_NewStringUTF(env, buf);
::util_StoreIntoPropertiesObject(env, properties, CLIENT_X_KEY,
(jobject) strVal);
}
rv = mouseEvent->GetClientY(&intVal);
if (NS_SUCCEEDED(rv)) {
itoa(intVal, buf, 10);
strVal = ::util_NewStringUTF(env, buf);
::util_StoreIntoPropertiesObject(env, properties, CLIENT_Y_KEY,
(jobject) strVal);
}
int16Val = 0;
rv = mouseEvent->GetButton(&int16Val);
if (NS_SUCCEEDED(rv)) {
itoa(int16Val, buf, 10);
strVal = ::util_NewStringUTF(env, buf);
::util_StoreIntoPropertiesObject(env, properties, BUTTON_KEY,
(jobject) strVal);
}
int16Val = 0;
rv = mouseEvent->GetClickCount(&int16Val);
if (NS_SUCCEEDED(rv)) {
itoa(int16Val, buf, 10);
strVal = ::util_NewStringUTF(env, buf);
::util_StoreIntoPropertiesObject(env, properties, CLICK_COUNT_KEY,
(jobject) strVal);
}
rv = mouseEvent->GetAltKey(&boolVal);
if (NS_SUCCEEDED(rv)) {
strVal = boolVal ? (jstring) TRUE_VALUE : (jstring) FALSE_VALUE;
::util_StoreIntoPropertiesObject(env, properties, ALT_KEY,
(jobject) strVal);
}
rv = mouseEvent->GetCtrlKey(&boolVal);
if (NS_SUCCEEDED(rv)) {
strVal = boolVal ? (jstring) TRUE_VALUE : (jstring) FALSE_VALUE;
::util_StoreIntoPropertiesObject(env, properties, CTRL_KEY,
(jobject) strVal);
}
rv = mouseEvent->GetShiftKey(&boolVal);
if (NS_SUCCEEDED(rv)) {
strVal = boolVal ? (jstring) TRUE_VALUE : (jstring) FALSE_VALUE;
::util_StoreIntoPropertiesObject(env, properties, SHIFT_KEY,
(jobject) strVal);
}
rv = mouseEvent->GetMetaKey(&boolVal);
if (NS_SUCCEEDED(rv)) {
strVal = boolVal ? (jstring) TRUE_VALUE : (jstring) FALSE_VALUE;
::util_StoreIntoPropertiesObject(env, properties, META_KEY,
(jobject) strVal);
}
}
dom_iterateToRoot(currentNode, DOMMouseListenerImpl::takeActionOnNode,
(void *)this);
addMouseEventDataToProperties(aMouseEvent);
return properties;
}
void JNICALL DOMMouseListenerImpl::addMouseEventDataToProperties(nsIDOMEvent *aMouseEvent)
{
if (!properties) {
return;
}
nsresult rv;
// Add modifiers, keys, mouse buttons, etc, to the properties table
nsCOMPtr<nsIDOMMouseEvent> mouseEvent;
rv = aMouseEvent->QueryInterface(nsIDOMMouseEvent::GetIID(),
getter_AddRefs(mouseEvent));
if (NS_FAILED(rv)) {
return;
}
// initialize the standard properties keys
if (!PROPERTIES_KEYS_INITED) {
// if the initialization failed, don't modify the properties
if (!initPropertiesKeys()) {
return;
}
}
PRInt32 intVal;
PRUint16 int16Val;
PRBool boolVal;
char buf[20];
jstring strVal;
JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2);
// PENDING(edburns): perhaps use a macro to speed this up?
rv = mouseEvent->GetScreenX(&intVal);
if (NS_SUCCEEDED(rv)) {
itoa(intVal, buf, 10);
strVal = ::util_NewStringUTF(env, buf);
::util_StoreIntoPropertiesObject(env, properties, SCREEN_X_KEY,
(jobject) strVal,
(jobject) mInitContext);
}
rv = mouseEvent->GetScreenY(&intVal);
if (NS_SUCCEEDED(rv)) {
itoa(intVal, buf, 10);
strVal = ::util_NewStringUTF(env, buf);
::util_StoreIntoPropertiesObject(env, properties, SCREEN_Y_KEY,
(jobject) strVal,
(jobject) mInitContext);
}
rv = mouseEvent->GetClientX(&intVal);
if (NS_SUCCEEDED(rv)) {
itoa(intVal, buf, 10);
strVal = ::util_NewStringUTF(env, buf);
::util_StoreIntoPropertiesObject(env, properties, CLIENT_X_KEY,
(jobject) strVal,
(jobject) mInitContext);
}
rv = mouseEvent->GetClientY(&intVal);
if (NS_SUCCEEDED(rv)) {
itoa(intVal, buf, 10);
strVal = ::util_NewStringUTF(env, buf);
::util_StoreIntoPropertiesObject(env, properties, CLIENT_Y_KEY,
(jobject) strVal,
(jobject) mInitContext);
}
int16Val = 0;
rv = mouseEvent->GetButton(&int16Val);
if (NS_SUCCEEDED(rv)) {
itoa(int16Val, buf, 10);
strVal = ::util_NewStringUTF(env, buf);
::util_StoreIntoPropertiesObject(env, properties, BUTTON_KEY,
(jobject) strVal,
(jobject) mInitContext);
}
int16Val = 0;
rv = mouseEvent->GetClickCount(&int16Val);
if (NS_SUCCEEDED(rv)) {
itoa(int16Val, buf, 10);
strVal = ::util_NewStringUTF(env, buf);
::util_StoreIntoPropertiesObject(env, properties, CLICK_COUNT_KEY,
(jobject) strVal,
(jobject) mInitContext);
}
rv = mouseEvent->GetAltKey(&boolVal);
if (NS_SUCCEEDED(rv)) {
strVal = boolVal ? (jstring) TRUE_VALUE : (jstring) FALSE_VALUE;
::util_StoreIntoPropertiesObject(env, properties, ALT_KEY,
(jobject) strVal,
(jobject) mInitContext);
}
rv = mouseEvent->GetCtrlKey(&boolVal);
if (NS_SUCCEEDED(rv)) {
strVal = boolVal ? (jstring) TRUE_VALUE : (jstring) FALSE_VALUE;
::util_StoreIntoPropertiesObject(env, properties, CTRL_KEY,
(jobject) strVal,
(jobject) mInitContext);
}
rv = mouseEvent->GetShiftKey(&boolVal);
if (NS_SUCCEEDED(rv)) {
strVal = boolVal ? (jstring) TRUE_VALUE : (jstring) FALSE_VALUE;
::util_StoreIntoPropertiesObject(env, properties, SHIFT_KEY,
(jobject) strVal,
(jobject) mInitContext);
}
rv = mouseEvent->GetMetaKey(&boolVal);
if (NS_SUCCEEDED(rv)) {
strVal = boolVal ? (jstring) TRUE_VALUE : (jstring) FALSE_VALUE;
::util_StoreIntoPropertiesObject(env, properties, META_KEY,
(jobject) strVal,
(jobject) mInitContext);
}
}
nsresult JNICALL DOMMouseListenerImpl::takeActionOnNode(nsCOMPtr<nsIDOMNode> currentNode,
void *myObject)
{
@ -413,7 +468,7 @@ nsresult JNICALL DOMMouseListenerImpl::takeActionOnNode(nsCOMPtr<nsIDOMNode> cur
if (prLogModuleInfo) {
nsAutoCString nodeInfoCStr(nodeName);
PR_LOG(prLogModuleInfo, 3, ("%s", (const char *)nodeInfoCStr));
PR_LOG(prLogModuleInfo, 4, ("%s", (const char *)nodeInfoCStr));
}
rv = currentNode->GetNodeValue(nodeInfo);
@ -426,7 +481,7 @@ nsresult JNICALL DOMMouseListenerImpl::takeActionOnNode(nsCOMPtr<nsIDOMNode> cur
if (prLogModuleInfo) {
nsAutoCString nodeInfoCStr(nodeValue);
PR_LOG(prLogModuleInfo, 3, ("%s", (const char *)nodeInfoCStr));
PR_LOG(prLogModuleInfo, 4, ("%s", (const char *)nodeInfoCStr));
}
jNodeName = ::util_NewString(env, nodeName.GetUnicode(),
@ -435,7 +490,9 @@ nsresult JNICALL DOMMouseListenerImpl::takeActionOnNode(nsCOMPtr<nsIDOMNode> cur
nodeValue.Length());
util_StoreIntoPropertiesObject(env, (jobject) curThis->properties,
(jobject) jNodeName, (jobject) jNodeValue);
(jobject) jNodeName,
(jobject) jNodeValue,
(jobject) curThis->mInitContext);
if (jNodeName) {
::util_DeleteString(env, jNodeName);
}
@ -473,7 +530,7 @@ nsresult JNICALL DOMMouseListenerImpl::takeActionOnNode(nsCOMPtr<nsIDOMNode> cur
if (prLogModuleInfo) {
nsAutoCString nodeInfoCStr(nodeName);
PR_LOG(prLogModuleInfo, 3,
PR_LOG(prLogModuleInfo, 4,
("attribute[%d], %s", i, (const char *)nodeInfoCStr));
}
@ -487,7 +544,7 @@ nsresult JNICALL DOMMouseListenerImpl::takeActionOnNode(nsCOMPtr<nsIDOMNode> cur
if (prLogModuleInfo) {
nsAutoCString nodeInfoCStr(nodeValue);
PR_LOG(prLogModuleInfo, 3,
PR_LOG(prLogModuleInfo, 4,
("attribute[%d] %s", i,(const char *)nodeInfoCStr));
}
jNodeName = ::util_NewString(env, nodeName.GetUnicode(),
@ -496,7 +553,9 @@ nsresult JNICALL DOMMouseListenerImpl::takeActionOnNode(nsCOMPtr<nsIDOMNode> cur
nodeValue.Length());
util_StoreIntoPropertiesObject(env, (jobject) curThis->properties,
(jobject) jNodeName, (jobject) jNodeValue);
(jobject) jNodeName,
(jobject) jNodeValue,
(jobject) curThis->mInitContext);
if (jNodeName) {
::util_DeleteString(env, jNodeName);
}
@ -517,41 +576,65 @@ jboolean initPropertiesKeys()
{
JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2);
if (nsnull == (SCREEN_X_KEY = (jobject) ::util_NewStringUTF(env, "ScreenX"))) {
if (nsnull == (SCREEN_X_KEY =
::util_NewGlobalRef(env, (jobject)
::util_NewStringUTF(env, "ScreenX")))) {
return JNI_FALSE;
}
if (nsnull == (SCREEN_Y_KEY = (jobject) ::util_NewStringUTF(env, "ScreenY"))) {
if (nsnull == (SCREEN_Y_KEY =
::util_NewGlobalRef(env, (jobject)
::util_NewStringUTF(env, "ScreenY")))) {
return JNI_FALSE;
}
if (nsnull == (CLIENT_X_KEY = (jobject) ::util_NewStringUTF(env, "ClientX"))) {
if (nsnull == (CLIENT_X_KEY =
::util_NewGlobalRef(env, (jobject)
::util_NewStringUTF(env, "ClientX")))) {
return JNI_FALSE;
}
if (nsnull == (CLIENT_Y_KEY = (jobject) ::util_NewStringUTF(env, "ClientY"))) {
if (nsnull == (CLIENT_Y_KEY =
::util_NewGlobalRef(env, (jobject)
::util_NewStringUTF(env, "ClientY")))) {
return JNI_FALSE;
}
if (nsnull == (ALT_KEY = (jobject) ::util_NewStringUTF(env, "Alt"))) {
if (nsnull == (ALT_KEY =
::util_NewGlobalRef(env, (jobject)
::util_NewStringUTF(env, "Alt")))) {
return JNI_FALSE;
}
if (nsnull == (CTRL_KEY = (jobject) ::util_NewStringUTF(env, "Ctrl"))) {
if (nsnull == (CTRL_KEY =
::util_NewGlobalRef(env, (jobject)
::util_NewStringUTF(env, "Ctrl")))) {
return JNI_FALSE;
}
if (nsnull == (SHIFT_KEY = (jobject) ::util_NewStringUTF(env, "Shift"))) {
if (nsnull == (SHIFT_KEY =
::util_NewGlobalRef(env, (jobject)
::util_NewStringUTF(env, "Shift")))) {
return JNI_FALSE;
}
if (nsnull == (META_KEY = (jobject) ::util_NewStringUTF(env, "Meta"))) {
if (nsnull == (META_KEY =
::util_NewGlobalRef(env, (jobject)
::util_NewStringUTF(env, "Meta")))) {
return JNI_FALSE;
}
if (nsnull == (BUTTON_KEY = (jobject) ::util_NewStringUTF(env, "Button"))) {
if (nsnull == (BUTTON_KEY =
::util_NewGlobalRef(env, (jobject)
::util_NewStringUTF(env, "Button")))) {
return JNI_FALSE;
}
if (nsnull == (CLICK_COUNT_KEY =
::util_NewStringUTF(env, "ClickCount"))) {
::util_NewGlobalRef(env, (jobject)
::util_NewStringUTF(env,
"ClickCount")))) {
return JNI_FALSE;
}
if (nsnull == (TRUE_VALUE = (jobject) ::util_NewStringUTF(env, "true"))) {
if (nsnull == (TRUE_VALUE =
::util_NewGlobalRef(env, (jobject)
::util_NewStringUTF(env, "true")))) {
return JNI_FALSE;
}
if (nsnull == (FALSE_VALUE = (jobject) ::util_NewStringUTF(env, "false"))) {
if (nsnull == (FALSE_VALUE =
::util_NewGlobalRef(env, (jobject)
::util_NewStringUTF(env, "false")))) {
return JNI_FALSE;
}

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

@ -1,145 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is RaptorCanvas.
*
* The Initial Developer of the Original Code is Kirk Baker and
* Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are
* Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All
* Rights Reserved.
*
* Contributor(s): Ed Burns <edburns@acm.org>
*
*/
#ifndef DOMMouseListenerImpl_h
#define DOMMouseListenerImpl_h
#include "nsISupports.h"
#include "nsISupportsUtils.h"
#include "nsString.h"
#include "nsIDOMMouseListener.h"
#include "nsIDOMNode.h"
#include "jni_util.h"
class nsIURI;
/**
* This class is the shim between the mozilla listener event system for
* mouse events and the java MouseListener interface.
* For each of the Mouse* methods, we call the appropriate method in java.
* See the implementation of MouseOver for an example.
* For each mouseEvent, we create a Properties object containing
* information about the event. We use methods in dom_util to do this.
*/
class DOMMouseListenerImpl : public nsIDOMMouseListener {
NS_DECL_ISUPPORTS
public:
typedef enum {
MOUSE_DOWN_EVENT_MASK = 0,
MOUSE_UP_EVENT_MASK,
MOUSE_CLICK_EVENT_MASK,
MOUSE_DOUBLE_CLICK_EVENT_MASK,
MOUSE_OVER_EVENT_MASK,
MOUSE_OUT_EVENT_MASK,
NUMBER_OF_MASK_NAMES
} EVENT_MASK_NAMES;
#ifdef XP_UNIX
static jlong maskValues [NUMBER_OF_MASK_NAMES];
#else
static jlong maskValues [DOMMouseListenerImpl::EVENT_MASK_NAMES::NUMBER_OF_MASK_NAMES];
#endif
static char *maskNames [];
DOMMouseListenerImpl(JNIEnv *yourJNIEnv,
WebShellInitContext *yourInitContext,
jobject yourTarget);
DOMMouseListenerImpl();
/* nsIDOMEventListener methods */
nsresult HandleEvent(nsIDOMEvent* aEvent);
/* nsIDOMMouseListener methods */
nsresult MouseDown(nsIDOMEvent *aMouseEvent);
nsresult MouseUp(nsIDOMEvent *aMouseEvent);
nsresult MouseClick(nsIDOMEvent *aMouseEvent);
nsresult MouseDblClick(nsIDOMEvent *aMouseEvent);
nsresult MouseOver(nsIDOMEvent *aMouseEvent);
nsresult MouseOut(nsIDOMEvent *aMouseEvent);
//
// Local methods
//
jobject JNICALL getPropertiesFromEvent(nsIDOMEvent *aMouseEvent);
static nsresult JNICALL takeActionOnNode(nsCOMPtr<nsIDOMNode> curNode,
void *yourObject);
protected:
JNIEnv *mJNIEnv;
WebShellInitContext *mInitContext;
jobject mTarget;
//
// The following arguments are used in the takeActionOnNode method.
//
/**
* 0 is the leaf depth. That's why we call it the inverse depth.
*/
PRInt32 inverseDepth;
/**
* The properties table, created during a mouseEvent handler
*/
jobject properties;
/**
* the nsIDOMEvent in the current event
*/
nsCOMPtr<nsIDOMEvent> currentDOMEvent;
//
// End of ivars used in takeActionOnNode
//
};
#endif // DOMMouseListenerImpl_h

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

@ -95,6 +95,7 @@ JNIEXPORT jint JNICALL Java_org_mozilla_webclient_wrapper_1native_WindowControlI
initContext->h = height;
initContext->searchContext = nsnull;
initContext->currentDocument = nsnull;
initContext->propertiesClass = nsnull;
#ifdef XP_UNIX
initContext->gtkWinPtr =
@ -149,6 +150,7 @@ Java_org_mozilla_webclient_wrapper_1native_WindowControlImpl_nativeDestroyInitCo
initContext->gtkWinPtr = nsnull;
initContext->searchContext = nsnull;
initContext->currentDocument = nsnull;
initContext->propertiesClass = nsnull;
delete initContext;
}

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

@ -36,9 +36,9 @@ JavaVM *gVm = nsnull; // declared in ns_globals.h, which is included in
// Local cache variables of JNI data items
//
static jclass gPropertiesClass = nsnull;
static jmethodID gPropertiesInitMethodID = nsnull;
static jmethodID gPropertiesSetPropertyMethodID = nsnull;
static jmethodID gPropertiesClearMethodID = nsnull;
void util_ThrowExceptionToJava (JNIEnv * env, const char * message)
{
@ -368,30 +368,37 @@ void util_SetIntValueForInstance(JNIEnv *env, jobject obj,
#endif;
}
jobject util_CreatePropertiesObject(JNIEnv *env, jobject reserved_NotUsed)
jobject util_CreatePropertiesObject(JNIEnv *env, jobject initContextObj)
{
jobject result = nsnull;
#ifdef BAL_INTERFACE
if (nsnull != externalCreatePropertiesObject) {
result = externalCreatePropertiesObject(env, reserved_NotUsed);
result = externalCreatePropertiesObject(env, initContextObj);
}
#else
// For some reason, we have to do FindClass each time. If we try to
// cache the class, it crashes. I think this may have something to
// do with threading issues.
if (nsnull == (gPropertiesClass
= ::util_FindClass(env, "java/util/Properties"))) {
return result;
}
if (nsnull == gPropertiesInitMethodID) {
if (nsnull == (gPropertiesInitMethodID =
env->GetMethodID(gPropertiesClass, "<init>", "()V"))) {
PR_ASSERT(initContextObj);
WebShellInitContext *initContext = (WebShellInitContext *) initContextObj;
if (nsnull == initContext->propertiesClass) {
if (nsnull == (initContext->propertiesClass =
::util_FindClass(env, "java/util/Properties"))) {
return result;
}
}
result = env->NewObject(gPropertiesClass, gPropertiesInitMethodID);
if (nsnull == gPropertiesInitMethodID) {
PR_ASSERT(initContext->propertiesClass);
if (nsnull == (gPropertiesInitMethodID =
env->GetMethodID(initContext->propertiesClass,
"<init>", "()V"))) {
return result;
}
}
PR_ASSERT(gPropertiesInitMethodID);
result = ::util_NewGlobalRef(env,
env->NewObject(initContext->propertiesClass,
gPropertiesInitMethodID));
#endif
return result;
@ -406,21 +413,52 @@ void util_DestroyPropertiesObject(JNIEnv *env, jobject propertiesObject,
reserved_NotUsed);
}
#else
::util_DeleteGlobalRef(env, propertiesObject);
#endif
}
void util_ClearPropertiesObject(JNIEnv *env, jobject propertiesObject,
jobject initContextObj)
{
#ifdef BAL_INTERFACE
if (nsnull != externalClearPropertiesObject) {
externalClearPropertiesObject(env, propertiesObject, initContextObj);
}
#else
PR_ASSERT(initContextObj);
WebShellInitContext *initContext = (WebShellInitContext *) initContextObj;
if (nsnull == gPropertiesClearMethodID) {
PR_ASSERT(initContext->propertiesClass);
if (nsnull == (gPropertiesClearMethodID =
env->GetMethodID(initContext->propertiesClass, "clear", "()V"))) {
return;
}
}
PR_ASSERT(gPropertiesClearMethodID);
env->CallVoidMethod(propertiesObject, gPropertiesClearMethodID);
return;
#endif
}
void util_StoreIntoPropertiesObject(JNIEnv *env, jobject propertiesObject,
jobject name, jobject value)
jobject name, jobject value,
jobject initContextObj)
{
#ifdef BAL_INTERFACE
if (nsnull != externalStoreIntoPropertiesObject) {
externalStoreIntoPropertiesObject(env, propertiesObject, name, value);
externalStoreIntoPropertiesObject(env, propertiesObject, name, value,
initContextObj);
}
#else
PR_ASSERT(initContextObj);
WebShellInitContext *initContext = (WebShellInitContext *) initContextObj;
if (nsnull == gPropertiesSetPropertyMethodID) {
PR_ASSERT(gPropertiesClass);
PR_ASSERT(initContext->propertiesClass);
if (nsnull == (gPropertiesSetPropertyMethodID =
env->GetMethodID(gPropertiesClass,
env->GetMethodID(initContext->propertiesClass,
"setProperty",
"(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;"))) {
return;

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

@ -86,6 +86,7 @@ struct WebShellInitContext {
int gtkWinPtr;
nsCOMPtr<nsISearchContext> searchContext;
nsCOMPtr<nsIDOMDocument> currentDocument;
jclass propertiesClass;
};
enum {
@ -202,6 +203,15 @@ jobject util_CreatePropertiesObject(JNIEnv *env, jobject reserved_NotUsed);
void util_DestroyPropertiesObject(JNIEnv *env, jobject propertiesObject,
jobject reserved_NotUsed);
/**
* A JNI wrapper to clear the object from CreatePropertiesObject
*/
void util_ClearPropertiesObject(JNIEnv *env, jobject propertiesObject,
jobject reserved_NotUsed);
/**
* A JNI wrapper for storing a name/value pair into the Properties
@ -210,7 +220,8 @@ void util_DestroyPropertiesObject(JNIEnv *env, jobject propertiesObject,
*/
void util_StoreIntoPropertiesObject(JNIEnv *env, jobject propertiesObject,
jobject name, jobject value);
jobject name, jobject value,
jobject reserved);
//

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

@ -1,258 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is RaptorCanvas.
*
* The Initial Developer of the Original Code is Kirk Baker and
* Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are
* Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All
* Rights Reserved.
*
* Contributor(s): Ed Burns <edburns@acm.org>
*
*/
#include "jni_util_export.h"
#include "jni_util.h"
#include "bal_util.h"
#include "nscore.h" // for nsnull
#include "ns_globals.h" // for prLogModuleInfo
#include "nsHashtable.h" // PENDING(edburns): size optimization?
static nsHashtable *gClassMappingTable = nsnull;
fpEventOccurredType externalEventOccurred = nsnull; // jni_util_export.h
fpInstanceOfType externalInstanceOf = nsnull; // jni_util_export.h
fpInitializeEventMaskType externalInitializeEventMask = nsnull; // jni_util_export.h
fpCreatePropertiesObjectType externalCreatePropertiesObject = nsnull; // jni_util_export.h
fpDestroyPropertiesObjectType externalDestroyPropertiesObject = nsnull; // jni_util_export.h
fpStoreIntoPropertiesObjectType externalStoreIntoPropertiesObject = nsnull; // jni_util_export.h
JNIEXPORT const char * JNICALL util_GetStringUTFChars(JNIEnv *env,
jstring inString)
{
const char *result = nsnull;
#ifdef BAL_INTERFACE
char *nonConstResult;
bal_str_newFromJstring(&nonConstResult, inString);
result = (const char *)nonConstResult;
#else
result = (const char *) env->GetStringUTFChars(inString, 0);
#endif
return result;
}
JNIEXPORT void JNICALL util_ReleaseStringUTFChars(JNIEnv *env,
jstring inString,
const char *stringFromGet)
{
#ifdef BAL_INTERFACE
bal_str_release(stringFromGet);
#else
env->ReleaseStringUTFChars(inString, stringFromGet);
#endif
}
JNIEXPORT const jchar * JNICALL util_GetStringChars(JNIEnv *env,
jstring inString)
{
const jchar *result = nsnull;
#ifdef BAL_INTERFACE
// ASSUMES typedef wchar_t jchar;
// ASSUMES typedef wchar_t *jstring;
result = (const jchar *) inString;
#else
result = (const jchar *) env->GetStringChars(inString, 0);
#endif
return result;
}
JNIEXPORT void JNICALL util_ReleaseStringChars(JNIEnv *env, jstring inString,
const jchar *stringFromGet)
{
#ifdef BAL_INTERFACE
// NO action necessary, see NewStringChars
#else
env->ReleaseStringChars(inString, stringFromGet);
#endif
}
JNIEXPORT jstring JNICALL util_NewStringUTF(JNIEnv *env, const char *inString)
{
jstring result = nsnull;
#ifdef BAL_INTERFACE
bal_jstring_newFromAscii(&result, inString);
#else
result = env->NewStringUTF(inString);
#endif
return result;
}
JNIEXPORT void JNICALL util_DeleteStringUTF(JNIEnv *env, jstring toDelete)
{
#ifdef BAL_INTERFACE
util_DeleteString(env, toDelete);
#else
// do nothing, java takes care of it
#endif
}
JNIEXPORT jstring JNICALL util_NewString(JNIEnv *env, const jchar *inString,
jsize len)
{
jstring result = nsnull;
#ifdef BAL_INTERFACE
bal_jstring_newFromJcharArray(&result, inString, len);
#else
result = env->NewString(inString, len);
#endif
return result;
}
JNIEXPORT void JNICALL util_DeleteString(JNIEnv *env, jstring toDelete)
{
#ifdef BAL_INTERFACE
bal_jstring_release(toDelete);
#else
// do nothing, java takes care of it
#endif
}
JNIEXPORT jint JNICALL util_StoreClassMapping(const char* jniClassName,
jclass yourClassType)
{
if (nsnull == gClassMappingTable) {
if (nsnull == (gClassMappingTable = new nsHashtable(20, PR_TRUE))) {
return -1;
}
}
nsStringKey key(jniClassName);
gClassMappingTable->Put(&key, yourClassType);
return 0;
}
JNIEXPORT jclass JNICALL util_GetClassMapping(const char* jniClassName)
{
jclass result = nsnull;
if (nsnull == gClassMappingTable) {
return nsnull;
}
nsStringKey key(jniClassName);
result = (jclass) gClassMappingTable->Get(&key);
return result;
}
JNIEXPORT void JNICALL util_SetEventOccurredFunction(fpEventOccurredType fp)
{
externalEventOccurred = fp;
}
JNIEXPORT void JNICALL util_SetInstanceOfFunction(fpInstanceOfType fp)
{
externalInstanceOf = fp;
}
JNIEXPORT void JNICALL util_SetInitializeEventMaskFunction(fpInitializeEventMaskType fp)
{
externalInitializeEventMask = fp;
}
JNIEXPORT void JNICALL util_SetCreatePropertiesObjectFunction(fpCreatePropertiesObjectType fp)
{
externalCreatePropertiesObject = fp;
}
JNIEXPORT void JNICALL util_SetDestroyPropertiesObjectFunction(fpDestroyPropertiesObjectType fp)
{
externalDestroyPropertiesObject = fp;
}
JNIEXPORT void JNICALL util_SetStoreIntoPropertiesObjectFunction(fpStoreIntoPropertiesObjectType fp)
{
externalStoreIntoPropertiesObject = fp;
}
JNIEXPORT void JNICALL
util_InitializeEventMaskValuesFromClass(const char *className,
char *maskNames[],
jlong maskValues[])
{
int i = 0;
JNIEnv *env = nsnull;
if (nsnull == className) {
return;
}
if (nsnull != gVm) {
env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2);
}
jclass clazz = ::util_FindClass(env, className);
if (nsnull == clazz) {
return;
}
#ifdef BAL_INTERFACE
if (nsnull != externalInitializeEventMask) {
externalInitializeEventMask(env, clazz,
(const char **) maskNames, maskValues);
}
#else
if (nsnull == env) {
return;
}
jfieldID fieldID;
while (nsnull != maskNames[i]) {
fieldID = ::util_GetStaticFieldID(env, clazz,
maskNames[i], "J");
if (nsnull == fieldID) {
return;
}
maskValues[i] = ::util_GetStaticLongField(env, clazz,
fieldID);
i++;
}
#endif
}

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

@ -1,332 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is RaptorCanvas.
*
* The Initial Developer of the Original Code is Kirk Baker and
* Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are
* Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All
* Rights Reserved.
*
* Contributor(s): Ed Burns <edburns@acm.org>
*
*/
/**
* Exported Util methods, called from webclient uno.
*/
#ifndef jni_util_export_h
#define jni_util_export_h
#ifdef __cplusplus
extern "C" {
#endif
#include <jni.h>
JNIEXPORT const char * JNICALL util_GetStringUTFChars(JNIEnv *env,
jstring inString);
JNIEXPORT void JNICALL util_ReleaseStringUTFChars(JNIEnv *env,
jstring inString,
const char *stringFromGet);
JNIEXPORT const jchar * JNICALL util_GetStringChars(JNIEnv *env,
jstring inString);
JNIEXPORT void JNICALL util_ReleaseStringChars(JNIEnv *env, jstring inString,
const jchar *stringFromGet);
JNIEXPORT jstring JNICALL util_NewStringUTF(JNIEnv *env,
const char * inString);
JNIEXPORT void JNICALL util_DeleteStringUTF(JNIEnv *env, jstring toDelete);
JNIEXPORT jstring JNICALL util_NewString(JNIEnv *env, const jchar *inString,
jsize len);
JNIEXPORT void JNICALL util_DeleteString(JNIEnv *env, jstring toDelete);
//
// BAL methods
//
/*
* The following methods are used by non Java JNI clients, such as
* StarOfficeDesktop.
*/
/**
* This method is used to store a mapping from a jniClass Name, such as
* "org/mozilla/webclient/DocumentLoadListener" to some external class
* type, such as
* org::mozilla::webclient::wrapper_native::uno::DocumentLoadListener.
* This table is used in util_IsInstanceOf.
* @see util_SetInstanceOfFunction
* @ret 0 on success
*/
JNIEXPORT jint JNICALL util_StoreClassMapping(const char* jniClassName,
jclass yourClassType);
JNIEXPORT jclass JNICALL util_GetClassMapping(const char* jniClassName);
/**
* Function declaration for the user defined InstanceOf function. It
* tells whether the second argument, which is an instance, is an
* instance of the type in the third argument.
* @see util_SetInstanceOfFunction
*/
typedef JNIEXPORT jboolean (JNICALL *fpInstanceOfType) (JNIEnv *env,
jobject obj,
jclass clazz);
/**
* Function declaration for the user defined EventOccurred function. It
* is called when an event occurrs. The second argument is the context
* for the event, passed in by the user as the second argument to
* NativeEventThreadImpl_nativeAddListener(). The third arcument is the
* listener object, passed in as the last argument to
* NativeEventThreadImpl_nativeAddListener(). The fourth argument is a
* listener specific type field, to indicate what kind of sub-event
* within the listener has occurred. The last argument is a listener
* sub-event specific argument. For example, when the event class is
* DocumentLoadListener, and the sub-event is "STATUS_URL_LOAD", the
* last argument is a string with a status message, ie "Contacting host
* blah...", etc.
*/
typedef JNIEXPORT void (JNICALL * fpEventOccurredType) (JNIEnv *env,
jobject nativeEventThread,
jobject webclientEventListener,
jlong eventType,
jobject eventData);
/**
* Called at app initialization to external user to provide a function
* that will fill in the event mask values for the given listener class.
* @param nullTermMaskNameArray a NULL terminated const char * array for
* the mask names.
* @param maskValueArray a parallel array for the values that match the
* corresponding elements in nullTermMaskNameArray
*/
typedef JNIEXPORT void (JNICALL * fpInitializeEventMaskType)
(JNIEnv *env,
jclass listenerClass,
const char **nullTermMaskNameArray,
jlong *maskValueArray);
/**
* Called when webclient wants to create a "Properties" object. Right
* now, no parameters are actually used.
*/
typedef JNIEXPORT jobject (JNICALL * fpCreatePropertiesObjectType)
(JNIEnv *env, jobject reserved_NotUsed);
/**
* Called after webclient is done using a "Properties" object it created
* with fpCreatePropertiesObject
* @param propertiesObject the propertiesObject created with
* fpCreatePropertiesObject
*/
typedef JNIEXPORT void (JNICALL * fpDestroyPropertiesObjectType)
(JNIEnv *env, jobject propertiesObject, jobject reserved_NotUsed);
/**
* Called after webclient has called fpCreatePropertiesObjectType when
* webclient wants to store values into the properties object.
* @param env not used
* @param propertiesObject obtained from fpCreatePropertiesObjectType
* @param name the name of the property
* @param the value of the property
*/
typedef JNIEXPORT void (JNICALL * fpStoreIntoPropertiesObjectType)
(JNIEnv *env, jobject propertiesObject, jobject name, jobject value);
/**
* This function must be called at app initialization.
* @see fpInstanceOfType
*/
JNIEXPORT void JNICALL util_SetInstanceOfFunction(fpInstanceOfType fp);
/**
* This function must be called at app initialization.
* @see fpEventOccurredType
*/
JNIEXPORT void JNICALL util_SetEventOccurredFunction(fpEventOccurredType fp);
/**
* This function must be called at app initialization.
* @see fpInitializeEventMaskType
*/
JNIEXPORT void JNICALL util_SetInitializeEventMaskFunction(fpInitializeEventMaskType fp);
/**
* This function must be called at app initialization.
* @see fpCreatePropertiesObjectType
*/
JNIEXPORT void JNICALL util_SetCreatePropertiesObjectFunction(fpCreatePropertiesObjectType fp);
/**
* This function must be called at app initialization.
* @see fpDestroyPropertiesObjectType
*/
JNIEXPORT void JNICALL util_SetDestroyPropertiesObjectFunction(fpDestroyPropertiesObjectType fp);
/**
* This function must be called at app initialization.
* @see fpStoreIntoPropertiesObjectType
*/
JNIEXPORT void JNICALL util_SetStoreIntoPropertiesObjectFunction(fpStoreIntoPropertiesObjectType fp);
/**
* defined in jni_util_export.cpp
* The function pointer set with util_SetEventOccurredFunction.
*/
extern fpEventOccurredType externalEventOccurred;
/**
* defined in jni_util_export.cpp
* The function pointer set with util_SetInstanceOfFunction.
*/
extern fpInstanceOfType externalInstanceOf;
/**
* defined in jni_util_export.cpp
* The function pointer set with util_SetInitializeEventMaskFunction
*/
extern fpInitializeEventMaskType externalInitializeEventMask;
/**
* defined in jni_util_export.cpp
* The function pointer set with util_SetCreatePropertiesObjectFunction
*/
extern fpCreatePropertiesObjectType externalCreatePropertiesObject;
/**
* defined in jni_util_export.cpp
* The function pointer set with util_SetDestroyPropertiesObjectFunction
*/
extern fpDestroyPropertiesObjectType externalDestroyPropertiesObject;
/**
* defined in jni_util_export.cpp
* The function pointer set with util_SetStoreIntoPropertiesObjectFunction
*/
extern fpStoreIntoPropertiesObjectType externalStoreIntoPropertiesObject;
/**
* Called by the mozilla event listener implementation class at
* construction time.
*/
JNIEXPORT void JNICALL
util_InitializeEventMaskValuesFromClass(const char *className,
char *maskNames[],
jlong maskValues[]);
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif // jni_util_export_h