nsresult EmbedEventListener::addKeyEventDataToProperties(nsCOMPtr<nsIDOMKeyEvent> keyEvent) { // if the initialization failed, don't modify the mProperties if (!mProperties || !util_StringConstantsAreInitialized()) { return NS_ERROR_INVALID_ARG; } nsresult rv; // Add modifiers, keys, etc, to the mProperties table PRUint32 int32Val; PRBool boolVal; char buf[20]; jstring strVal; JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); // PENDING(edburns): perhaps use a macro to speed this up? rv = keyEvent->GetCharCode(&int32Val); if (NS_SUCCEEDED(rv)) { buf[0] = (char) int32Val; buf[1]= nsnull; strVal = ::util_NewStringUTF(env, buf); ::util_StoreIntoPropertiesObject(env, mProperties, CHAR_CODE, (jobject) strVal, (jobject) &(mOwner->GetWrapperFactory()->shareContext)); } rv = keyEvent->GetKeyCode(&int32Val); if (NS_SUCCEEDED(rv)) { memset(buf, 0, 20); WC_ITOA(int32Val, buf, 10); strVal = ::util_NewStringUTF(env, buf); ::util_StoreIntoPropertiesObject(env, mProperties, KEY_CODE, (jobject) strVal, (jobject) &(mOwner->GetWrapperFactory()->shareContext)); } rv = keyEvent->GetAltKey(&boolVal); if (NS_SUCCEEDED(rv)) { strVal = boolVal ? (jstring) TRUE_VALUE : (jstring) FALSE_VALUE; ::util_StoreIntoPropertiesObject(env, mProperties, ALT_KEY, (jobject) strVal, (jobject) &(mOwner->GetWrapperFactory()->shareContext)); } rv = keyEvent->GetCtrlKey(&boolVal); if (NS_SUCCEEDED(rv)) { strVal = boolVal ? (jstring) TRUE_VALUE : (jstring) FALSE_VALUE; ::util_StoreIntoPropertiesObject(env, mProperties, CTRL_KEY, (jobject) strVal, (jobject) &(mOwner->GetWrapperFactory()->shareContext)); } rv = keyEvent->GetShiftKey(&boolVal); if (NS_SUCCEEDED(rv)) { strVal = boolVal ? (jstring) TRUE_VALUE : (jstring) FALSE_VALUE; ::util_StoreIntoPropertiesObject(env, mProperties, SHIFT_KEY, (jobject) strVal, (jobject) &(mOwner->GetWrapperFactory()->shareContext)); } rv = keyEvent->GetMetaKey(&boolVal); if (NS_SUCCEEDED(rv)) { strVal = boolVal ? (jstring) TRUE_VALUE : (jstring) FALSE_VALUE; ::util_StoreIntoPropertiesObject(env, mProperties, META_KEY, (jobject) strVal, (jobject) &(mOwner->GetWrapperFactory()->shareContext)); } return rv; }
nsresult EmbedEventListener::addMouseEventDataToProperties(nsCOMPtr<nsIDOMMouseEvent> mouseEvent) { // if the initialization failed, don't modify the mProperties if (!mProperties || !util_StringConstantsAreInitialized()) { return NS_ERROR_INVALID_ARG; } nsresult rv; // Add modifiers, keys, mouse buttons, etc, to the mProperties table PRInt32 intVal; PRUint16 int16Val; PRBool boolVal; char buf[20]; jstring strVal; JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); // PENDING(edburns): perhaps use a macro to speed this up? rv = mouseEvent->GetScreenX(&intVal); if (NS_SUCCEEDED(rv)) { memset(buf, 0, 20); WC_ITOA(intVal, buf, 10); strVal = ::util_NewStringUTF(env, buf); ::util_StoreIntoPropertiesObject(env, mProperties, SCREEN_X_KEY, (jobject) strVal, (jobject) &(mOwner->GetWrapperFactory()->shareContext)); } rv = mouseEvent->GetScreenY(&intVal); if (NS_SUCCEEDED(rv)) { #if (defined(XP_MAC) || defined(XP_MACOSX)) && defined(MOZ_WIDGET_COCOA) intVal -=5; #endif memset(buf, 0, 20); WC_ITOA(intVal, buf, 10); strVal = ::util_NewStringUTF(env, buf); ::util_StoreIntoPropertiesObject(env, mProperties, SCREEN_Y_KEY, (jobject) strVal, (jobject) &(mOwner->GetWrapperFactory()->shareContext)); } rv = mouseEvent->GetClientX(&intVal); if (NS_SUCCEEDED(rv)) { memset(buf, 0, 20); WC_ITOA(intVal, buf, 10); strVal = ::util_NewStringUTF(env, buf); ::util_StoreIntoPropertiesObject(env, mProperties, CLIENT_X_KEY, (jobject) strVal, (jobject) &(mOwner->GetWrapperFactory()->shareContext)); } rv = mouseEvent->GetClientY(&intVal); if (NS_SUCCEEDED(rv)) { memset(buf, 0, 20); WC_ITOA(intVal, buf, 10); strVal = ::util_NewStringUTF(env, buf); ::util_StoreIntoPropertiesObject(env, mProperties, CLIENT_Y_KEY, (jobject) strVal, (jobject) &(mOwner->GetWrapperFactory()->shareContext)); } int16Val = 0; rv = mouseEvent->GetButton(&int16Val); if (NS_SUCCEEDED(rv)) { memset(buf, 0, 20); WC_ITOA(int16Val, buf, 10); strVal = ::util_NewStringUTF(env, buf); ::util_StoreIntoPropertiesObject(env, mProperties, BUTTON_KEY, (jobject) strVal, (jobject) &(mOwner->GetWrapperFactory()->shareContext)); } rv = mouseEvent->GetAltKey(&boolVal); if (NS_SUCCEEDED(rv)) { strVal = boolVal ? (jstring) TRUE_VALUE : (jstring) FALSE_VALUE; ::util_StoreIntoPropertiesObject(env, mProperties, ALT_KEY, (jobject) strVal, (jobject) &(mOwner->GetWrapperFactory()->shareContext)); } rv = mouseEvent->GetCtrlKey(&boolVal); if (NS_SUCCEEDED(rv)) { strVal = boolVal ? (jstring) TRUE_VALUE : (jstring) FALSE_VALUE; ::util_StoreIntoPropertiesObject(env, mProperties, CTRL_KEY, (jobject) strVal, (jobject) &(mOwner->GetWrapperFactory()->shareContext)); } rv = mouseEvent->GetShiftKey(&boolVal); if (NS_SUCCEEDED(rv)) { strVal = boolVal ? (jstring) TRUE_VALUE : (jstring) FALSE_VALUE; ::util_StoreIntoPropertiesObject(env, mProperties, SHIFT_KEY, (jobject) strVal, (jobject) &(mOwner->GetWrapperFactory()->shareContext)); } rv = mouseEvent->GetMetaKey(&boolVal); if (NS_SUCCEEDED(rv)) { strVal = boolVal ? (jstring) TRUE_VALUE : (jstring) FALSE_VALUE; ::util_StoreIntoPropertiesObject(env, mProperties, META_KEY, (jobject) strVal, (jobject) &(mOwner->GetWrapperFactory()->shareContext)); } return rv; }