bug 40330
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. git-svn-id: svn://10.0.0.236/trunk@71756 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -75,6 +75,8 @@ static char *maskNames [];
|
||||
|
||||
DOMMouseListenerImpl();
|
||||
|
||||
virtual ~DOMMouseListenerImpl();
|
||||
|
||||
/* nsIDOMEventListener methods */
|
||||
nsresult HandleEvent(nsIDOMEvent* aEvent);
|
||||
|
||||
@@ -96,9 +98,12 @@ static char *maskNames [];
|
||||
//
|
||||
// Local methods
|
||||
//
|
||||
protected:
|
||||
|
||||
jobject JNICALL getPropertiesFromEvent(nsIDOMEvent *aMouseEvent);
|
||||
|
||||
void JNICALL addMouseEventDataToProperties(nsIDOMEvent *aMouseEvent);
|
||||
|
||||
static nsresult JNICALL takeActionOnNode(nsCOMPtr<nsIDOMNode> curNode,
|
||||
void *yourObject);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
//
|
||||
|
||||
@@ -44,6 +44,8 @@ fpCreatePropertiesObjectType externalCreatePropertiesObject = nsnull; // jni_uti
|
||||
|
||||
fpDestroyPropertiesObjectType externalDestroyPropertiesObject = nsnull; // jni_util_export.h
|
||||
|
||||
fpClearPropertiesObjectType externalClearPropertiesObject = nsnull; // jni_util_export.h
|
||||
|
||||
fpStoreIntoPropertiesObjectType externalStoreIntoPropertiesObject = nsnull; // jni_util_export.h
|
||||
|
||||
JNIEXPORT const char * JNICALL util_GetStringUTFChars(JNIEnv *env,
|
||||
@@ -203,6 +205,11 @@ JNIEXPORT void JNICALL util_SetDestroyPropertiesObjectFunction(fpDestroyProperti
|
||||
externalDestroyPropertiesObject = fp;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL util_SetClearPropertiesObjectFunction(fpClearPropertiesObjectType fp)
|
||||
{
|
||||
externalClearPropertiesObject = fp;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL util_SetStoreIntoPropertiesObjectFunction(fpStoreIntoPropertiesObjectType fp)
|
||||
{
|
||||
externalStoreIntoPropertiesObject = fp;
|
||||
|
||||
@@ -173,6 +173,19 @@ typedef JNIEXPORT jobject (JNICALL * fpCreatePropertiesObjectType)
|
||||
typedef JNIEXPORT void (JNICALL * fpDestroyPropertiesObjectType)
|
||||
(JNIEnv *env, jobject propertiesObject, jobject reserved_NotUsed);
|
||||
|
||||
/**
|
||||
|
||||
* Called when webclient wants to clear a "Properties" object it created
|
||||
* with fpCreatePropertiesObject
|
||||
|
||||
* @param propertiesObject the propertiesObject created with
|
||||
* fpCreatePropertiesObject
|
||||
|
||||
*/
|
||||
|
||||
typedef JNIEXPORT void (JNICALL * fpClearPropertiesObjectType)
|
||||
(JNIEnv *env, jobject propertiesObject, jobject reserved_NotUsed);
|
||||
|
||||
/**
|
||||
|
||||
* Called after webclient has called fpCreatePropertiesObjectType when
|
||||
@@ -189,7 +202,8 @@ typedef JNIEXPORT void (JNICALL * fpDestroyPropertiesObjectType)
|
||||
*/
|
||||
|
||||
typedef JNIEXPORT void (JNICALL * fpStoreIntoPropertiesObjectType)
|
||||
(JNIEnv *env, jobject propertiesObject, jobject name, jobject value);
|
||||
(JNIEnv *env, jobject propertiesObject, jobject name, jobject value,
|
||||
jobject reserved);
|
||||
|
||||
/**
|
||||
|
||||
@@ -241,6 +255,16 @@ JNIEXPORT void JNICALL util_SetCreatePropertiesObjectFunction(fpCreateProperties
|
||||
|
||||
JNIEXPORT void JNICALL util_SetDestroyPropertiesObjectFunction(fpDestroyPropertiesObjectType fp);
|
||||
|
||||
/**
|
||||
|
||||
* This function must be called at app initialization.
|
||||
|
||||
* @see fpDestroyPropertiesObjectType
|
||||
|
||||
*/
|
||||
|
||||
JNIEXPORT void JNICALL util_SetClearPropertiesObjectFunction(fpDestroyPropertiesObjectType fp);
|
||||
|
||||
/**
|
||||
|
||||
* This function must be called at app initialization.
|
||||
@@ -303,6 +327,16 @@ extern fpCreatePropertiesObjectType externalCreatePropertiesObject;
|
||||
|
||||
extern fpDestroyPropertiesObjectType externalDestroyPropertiesObject;
|
||||
|
||||
/**
|
||||
|
||||
* defined in jni_util_export.cpp
|
||||
|
||||
* The function pointer set with util_SetClearPropertiesObjectFunction
|
||||
|
||||
*/
|
||||
|
||||
extern fpClearPropertiesObjectType externalClearPropertiesObject;
|
||||
|
||||
/**
|
||||
|
||||
* defined in jni_util_export.cpp
|
||||
|
||||
Reference in New Issue
Block a user