fix multi byte input, rendering(Windows XP IE8, Firefox3.6, Chrome8)

This commit is contained in:
kyo_ago 2011-01-25 22:47:33 +09:00 committed by Fabian Jakobs
commit 84a2ceb28d

View file

@ -38,6 +38,7 @@
define(function(require, exports, module) {
var event = require("pilot/event");
var useragent = require("pilot/useragent");
var TextInput = function(parentNode, host) {
@ -77,6 +78,7 @@ var TextInput = function(parentNode, host) {
}
var onTextInput = function(e) {
if (useragent.isIE && text.value.charCodeAt(0) > 128) return;
setTimeout(function() {
if (!inCompostion)
sendText();
@ -85,20 +87,25 @@ var TextInput = function(parentNode, host) {
var onCompositionStart = function(e) {
inCompostion = true;
sendText();
text.value = "";
if (!useragent.isIE) {
sendText();
text.value = "";
};
host.onCompositionStart();
setTimeout(onCompositionUpdate, 0);
if (!useragent.isGecko) setTimeout(onCompositionUpdate, 0);
};
var onCompositionUpdate = function() {
if (!inCompostion) return;
host.onCompositionUpdate(text.value);
};
var onCompositionEnd = function() {
inCompostion = false;
host.onCompositionEnd();
onTextInput();
setTimeout(function () {
sendText();
}, 0);
};
var onCopy = function() {
@ -119,6 +126,16 @@ var TextInput = function(parentNode, host) {
event.addCommandKeyListener(text, host.onCommandKey.bind(host));
event.addListener(text, "keypress", onTextInput);
if (useragent.isIE) {
var keytable = { 13:1, 27:1 };
event.addListener(text, "keyup", function (e) {
if (inCompostion && (!text.value || keytable[e.keyCode])) setTimeout(onCompositionEnd, 0);
if ((text.value.charCodeAt(0)|0) < 129) {
return;
};
inCompostion ? onCompositionUpdate() : onCompositionStart();
});
};
event.addListener(text, "textInput", onTextInput);
event.addListener(text, "paste", function(e) {
// Some browsers support the event.clipboardData API. Use this to get
@ -133,13 +150,20 @@ var TextInput = function(parentNode, host) {
onTextInput();
}
});
event.addListener(text, "propertychange", onTextInput);
if (!useragent.isIE) {
event.addListener(text, "propertychange", onTextInput);
};
event.addListener(text, "copy", onCopy);
event.addListener(text, "cut", onCut);
event.addListener(text, "compositionstart", onCompositionStart);
event.addListener(text, "compositionupdate", onCompositionUpdate);
if (useragent.isGecko) {
event.addListener(text, "text", onCompositionUpdate);
};
if (useragent.isWebKit) {
event.addListener(text, "keyup", onCompositionUpdate);
};
event.addListener(text, "compositionend", onCompositionEnd);
event.addListener(text, "blur", function() {