From: handa Date: Fri, 12 Mar 2010 10:44:24 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: ALPHA~17 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7c26a3518b1bf90717a59b165edb254a8c9f31d2;p=m17n%2Fm17n-lib-js.git *** empty log message *** --- diff --git a/xex.js b/xex.js index b342683..9f2dc42 100644 --- a/xex.js +++ b/xex.js @@ -3129,65 +3129,64 @@ MIM.update = function (target, ic) }; (function () { - function capitalize(prop){ - return prop.replace(/-(.)/g, function(m, m1){ return m1.toUpperCase() }) - } - - function imitateElement(elmOriginal, elmClone){ - var styleOriginal = getComputedStyle(elmOriginal,''); - var styleClone = getComputedStyle(elmClone,''); + var style_props = { + width: 'width', + height: 'height', + padingLeft: 'padding-left', + paddingRight: 'padding-right', + paddingTop: 'padding-top', + paddintBottom: 'padding-bottom', + borderLeftStyle: 'border-left-style', + borderRightStyle: 'border-right-style', + borderTopStyle: 'border-top-style', + borderBottomStyle: 'border-bottom-style', + borderLeftWidth: 'border-left-width', + borderRightWidth: 'border-right-width', + borderTopWidth: 'border-top-width', + borderBottomWidth: 'border-bottom-width', + fontFamily: 'font-family', + fontSize: 'font-size', + lineHeight: 'line-height', + letterSpacing: 'letter-spacing', + wordSpacing: 'word-spacing' }; + + function copy_style (from, to) + { + var from_style = getComputedStyle(from,''); - elmClone.style.left = elmOriginal.offsetLeft + 'px'; - elmClone.style.top = elmOriginal.offsetTop + 'px'; - - var copyProps = [ - 'width', 'height', - 'padding-left', 'padding-right', 'padding-top', 'padding-bottom', - 'border-left-style', 'border-right-style','border-top-style','border-bottom-style', - 'border-left-width', 'border-right-width','border-top-width','border-bottom-width', - 'font-family', 'font-size', 'line-height', 'letter-spacing', 'word-spacing']; - for(var i in copyProps){ - elmClone.style[capitalize(copyProps[i])] = - styleOriginal.getPropertyValue(copyProps[i]); - } + for(var name in style_props) + to.style[name] = from_style.getPropertyValue (style_props[name]); - elmClone.style.width = elmOriginal.offsetWidth; - elmClone.style.height = elmOriginal.offsetHeight; - elmClone.style.visibility="hidden"; // Äɲà - elmClone.style.position = "absolute"; //Äɲà - //elmClone.style =elmOriginal.style; - - elmClone.scrollLeft = elmOriginal.scrollLeft; - elmClone.scrollTop = elmOriginal.scrollTop; + to.style.left = from.offsetLeft + 'px'; + to.style.top = from.offsetTop + 'px'; + to.style.width = from.offsetWidth; + to.style.height = from.offsetHeight; + to.scrollLeft = from.scrollLeft; + to.scrollTop = from.scrollTop; } - var elm; - - MIM.caret_pos = function (target) + MIM.show = function (target, ic) { - if (! elm) + if (! ic.can_node) { - elm = document.createElement ('div'); - document.getElementsByTagName ('body')[0].appendChild (elm); - } + var elm = document.createTextNode (''); - imitateElement(target, elm); - var selectionEnd = target.selectionEnd; - var value = target.value; - - var elmCursor = document.createElement('span'); - elmCursor.innerHTML = '|'; - - //elm = document.createElement ('pre'); - elm.innerHTML = ''; - var elmChild = document.createTextNode(value.substr(0,selectionEnd)); - elm.appendChild(elmChild); - elm.appendChild(elmCursor); + ic.can_node = document.createElement ('div'); + ic.can_node.style.visibility="hidden"; + ic.can_node.style.position = "absolute"; + ic.can_node.appendChild (elm) + elm = document.createElement('span'); + elm.innerHTML = '.'; + ic.can_node.appendChild (elm) + document.getElementsByTagName ('body')[0].appendChild (ic.can_node); + } - var x = target.offsetLeft + elmCursor.offsetLeft +2; - var y = target.offsetTop + elmCursor.offsetTop -2; + copy_style (target, ic.can_node); + ic.can_node.firstChild.value = target.value.substr (0, ic.range[0]); + var x = target.offsetLeft + ic.can_node.lastChild.offsetLeft +2; + var y = target.offsetTop + ic.can_node.lastChild.offsetTop -2; - Xex.Log ("x:" + x + "px y:" + y + "px w:" + elm.offsetWidth); + Xex.Log ("x:" + x + "px y:" + y + "px"); } }) (); @@ -3232,8 +3231,6 @@ MIM.keydown = function (event) if (! (target.type == "text" || target.type == "textarea")) return; - MIM.caret_pos (target); - var ic = target.mim_ic; if (! ic || ic.im != MIM.current) { @@ -3252,6 +3249,7 @@ MIM.keydown = function (event) if (! MIM.get_range (target, ic)) ic.reset (); } + MIM.show (target, ic); MIM.debug_print (event, ic); ic.key = MIM.decode_key_event (event); if (ic.key)