зеркало из https://github.com/mozilla/pjs.git
r=akhil.arora@sun.com By Igor Nekrestyanov <nis@sparc.spb.su>
Minor changes to handle unicode strings properly
This commit is contained in:
Родитель
d3b0407c9b
Коммит
85556970cf
|
@ -1835,16 +1835,15 @@ void JavaDOMEventsGlobals::Destroy(JNIEnv *env)
|
|||
|
||||
//returns true if specified event "type" exists in the given list of types
|
||||
// NOTE: it is assumed that "types" list is enden with NULL
|
||||
static jboolean isEventOfType(char **types, char *type)
|
||||
static jboolean isEventOfType(char **types, nsString type)
|
||||
{
|
||||
int i=0;
|
||||
|
||||
if (type)
|
||||
while (types[i]) {
|
||||
if (strcmp(type, types[i]) == 0)
|
||||
return JNI_TRUE;
|
||||
i++;
|
||||
}
|
||||
while (types && types[i]) {
|
||||
if (type == types[i])
|
||||
return JNI_TRUE;
|
||||
i++;
|
||||
}
|
||||
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
@ -1884,22 +1883,29 @@ jobject JavaDOMEventsGlobals::CreateEventSubtype(JNIEnv *env,
|
|||
"Event.getType at JavaDOMEventsGlobals: failed");
|
||||
return NULL;
|
||||
}
|
||||
char *type = nsType.ToNewCString();
|
||||
|
||||
if (isEventOfType(mouseEventTypes, type) == JNI_TRUE) {
|
||||
if (isEventOfType(mouseEventTypes, nsType) == JNI_TRUE) {
|
||||
clazz = mouseEventClass;
|
||||
} else if (isEventOfType(keyEventTypes, type) == JNI_TRUE) {
|
||||
} else if (isEventOfType(keyEventTypes, nsType) == JNI_TRUE) {
|
||||
clazz = keyEventClass;
|
||||
} else if (isEventOfType(uiEventTypes, type) == JNI_TRUE) {
|
||||
} else if (isEventOfType(uiEventTypes, nsType) == JNI_TRUE) {
|
||||
clazz = uiEventClass;
|
||||
} else {
|
||||
/* Being paranoid here, make sure the (unicode) string is
|
||||
NULL-terminated before passing it to PR_LOG. Otherwise, we
|
||||
may cause a crash */
|
||||
|
||||
PRInt32 length = nsType.Length();
|
||||
char* buffer = new char[length+1];
|
||||
strncpy(buffer, nsType.GetBuffer(), length);
|
||||
buffer[length] = 0;
|
||||
|
||||
PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING,
|
||||
("Unknown type of UI event (%s)", type));
|
||||
("Unknown type of UI event (%s)", buffer));
|
||||
delete[] buffer;
|
||||
clazz = uiEventClass;
|
||||
}
|
||||
|
||||
delete [] type;
|
||||
|
||||
event->Release();
|
||||
event = (nsIDOMEvent *) target;
|
||||
}
|
||||
|
|
|
@ -151,16 +151,13 @@ JNIEXPORT jstring JNICALL Java_org_mozilla_dom_events_EventImpl_getType
|
|||
return NULL;
|
||||
}
|
||||
|
||||
char* cret = ret.ToNewCString();
|
||||
jstring jret = env->NewStringUTF(cret);
|
||||
jstring jret = env->NewString(ret.GetUnicode(), ret.Length());
|
||||
if (!jret) {
|
||||
JavaDOMGlobals::ThrowException(env,
|
||||
"Event.getType: NewStringUTF failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
delete[] cret;
|
||||
|
||||
return jret;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче