зеркало из 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,13 +1835,12 @@ void JavaDOMEventsGlobals::Destroy(JNIEnv *env)
|
||||||
|
|
||||||
//returns true if specified event "type" exists in the given list of types
|
//returns true if specified event "type" exists in the given list of types
|
||||||
// NOTE: it is assumed that "types" list is enden with NULL
|
// 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;
|
int i=0;
|
||||||
|
|
||||||
if (type)
|
while (types && types[i]) {
|
||||||
while (types[i]) {
|
if (type == types[i])
|
||||||
if (strcmp(type, types[i]) == 0)
|
|
||||||
return JNI_TRUE;
|
return JNI_TRUE;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
@ -1884,22 +1883,29 @@ jobject JavaDOMEventsGlobals::CreateEventSubtype(JNIEnv *env,
|
||||||
"Event.getType at JavaDOMEventsGlobals: failed");
|
"Event.getType at JavaDOMEventsGlobals: failed");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
char *type = nsType.ToNewCString();
|
|
||||||
|
|
||||||
if (isEventOfType(mouseEventTypes, type) == JNI_TRUE) {
|
if (isEventOfType(mouseEventTypes, nsType) == JNI_TRUE) {
|
||||||
clazz = mouseEventClass;
|
clazz = mouseEventClass;
|
||||||
} else if (isEventOfType(keyEventTypes, type) == JNI_TRUE) {
|
} else if (isEventOfType(keyEventTypes, nsType) == JNI_TRUE) {
|
||||||
clazz = keyEventClass;
|
clazz = keyEventClass;
|
||||||
} else if (isEventOfType(uiEventTypes, type) == JNI_TRUE) {
|
} else if (isEventOfType(uiEventTypes, nsType) == JNI_TRUE) {
|
||||||
clazz = uiEventClass;
|
clazz = uiEventClass;
|
||||||
} else {
|
} 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,
|
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;
|
clazz = uiEventClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete [] type;
|
|
||||||
|
|
||||||
event->Release();
|
event->Release();
|
||||||
event = (nsIDOMEvent *) target;
|
event = (nsIDOMEvent *) target;
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,16 +151,13 @@ JNIEXPORT jstring JNICALL Java_org_mozilla_dom_events_EventImpl_getType
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* cret = ret.ToNewCString();
|
jstring jret = env->NewString(ret.GetUnicode(), ret.Length());
|
||||||
jstring jret = env->NewStringUTF(cret);
|
|
||||||
if (!jret) {
|
if (!jret) {
|
||||||
JavaDOMGlobals::ThrowException(env,
|
JavaDOMGlobals::ThrowException(env,
|
||||||
"Event.getType: NewStringUTF failed");
|
"Event.getType: NewStringUTF failed");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] cret;
|
|
||||||
|
|
||||||
return jret;
|
return jret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче