From: handa Date: Mon, 8 Mar 2010 13:19:17 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: ALPHA~26 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=143b2123cb939cd2aef1ba8754b1efe20c6f1abd;p=m17n%2Fm17n-lib-js.git *** empty log message *** --- diff --git a/xex.js b/xex.js index ffcfc70..ef1bea0 100644 --- a/xex.js +++ b/xex.js @@ -1407,6 +1407,10 @@ var MIM = { } MIM.Key.prototype.toString = function () { return this.key; }; + + MIM.Key.FocusIn = new MIM.Key (new Xex.StrTerm ('input-focus-in')); + MIM.Key.FocusOut = new MIM.Key (new Xex.StrTerm ('input-focus-out')); + MIM.Key.FocusMove = new MIM.Key (new Xex.StrTerm ('input-focus-move')); }) (); (function () { @@ -2119,9 +2123,9 @@ MIM.im_domain.DefType (MIM.State.prototype); var ic = domain.context; var n = args.length == 0 ? -2 : args[0].val; if (n < 0) - ic.keys.val.splice (ic.keys.length + n, -n); + ic.keys.val.splice (ic.keys.val.length + n, -n); else - ic.keys.val.splice (n, ic.keys.length); + ic.keys.val.splice (n, ic.keys.val.length); ic.reset (); return Xex.nil; } @@ -2287,8 +2291,11 @@ MIM.im_domain.DefType (MIM.State.prototype); alert ('inclusion fail'); continue; } - for (var mapname in im.map_list) - this.map_list[mapname] = im.map_list[mapname]; + for (var mname in im.map_list) + { + this.map_list[mname] = im.map_list[mname]; + Xex.Log ('include map ' + mname); + } } else { @@ -2302,7 +2309,21 @@ MIM.im_domain.DefType (MIM.State.prototype); this.domain.map_list = this.map_list; for (node = node.firstElement (); node; node = node.nextElement ()) { - if (node.nodeName == 'state') + if (node.nodeName == 'xi:include') + { + var im = include (node); + if (! im) + alert ('inclusion fail'); + for (var sname in im.state_list) + { + state = im.state_list[sname]; + if (! this.initial_state) + this.initial_state = state; + this.state_list[sname] = state; + Xex.Log ('include state ' + sname); + } + } + else if (node.nodeName == 'state') { var state = Xex.Term.Parse (this.domain, node); if (! state.title) @@ -2533,7 +2554,7 @@ MIM.im_domain.DefType (MIM.State.prototype); proto = { reset: function () { - Xex.Log ('reseting ' + this.im.lang); + Xex.Log ('reseting ' + this.im.lang + '-' + this.im.name); this.cursor_pos = 0; this.candidate_show = false; this.prev_state = null; @@ -2543,7 +2564,6 @@ MIM.im_domain.DefType (MIM.State.prototype); this.state_var_values = {}; this.state_pos = 0; this.key_head = 0; - this.keys.val.length = 0; this.key_unhandled = false; this.unhandled_key = null; this.changed = MIM.ChangedStatus.None; @@ -3069,6 +3089,8 @@ MIM.set_caret = function (target, ic) } }; +MIM.ignore_focus = false; + MIM.update = function (target, ic) { var text = target.value; @@ -3081,15 +3103,55 @@ MIM.update = function (target, ic) MIM.set_caret (target, ic); }; -MIM.reset_ic = function (event) +MIM.focus_in = function (event) +{ + var target = event.target; + var ic = target.mim_ic; + if (ic) + { + if (target.mim_ignore_focus_in) + { + // Ignore this event which happened in setSelectionRange (). + target.mim_ignore_focus_in = false; + event.preventDefault (); + } + else + { + try { + ic.Filter (MIM.Key.FocusIn); + MIM.update (target, ic); + // Ignore further focus-in caused by setSelectionRange (). + target.mim_ignore_focus_in = true; + } + catch (e) { Xex.Log ('Error:' + e); throw (e); } + } + } +} + +MIM.focus_out = function (event) { - if (event.target.mim_ic) + var target = event.target; + var ic = target.mim_ic; + if (ic) { - var target = event.target; - var ic = target.mim_ic; - if (ic.preedit.length > 0) - event.target.setSelectionRange (ic.range[1], ic.range[1]); - ic.reset (); + if (target.mim_ignore_focus_out) + { + // Ignore this event which caused by setSelectionRange (). + target.mim_ignore_focus_out = false; + event.preventDefault (); + } + else + { + try { + if (! MIM.get_range (target, ic)) + ic.reset (); + ic.Filter (MIM.Key.FocusOut); + MIM.update (target, ic); + // Ignore further focus-out caused by setSelectionRange (). + target.mim_ignore_focus_out = true; + } + catch (e) { Xex.Log ('Error:' + e); throw (e); } + } } }; @@ -3100,6 +3162,7 @@ MIM.keydown = function (event) return; if (! (target.type == "text" || target.type == "textarea")) return; + document.akey = event; var ic = target.mim_ic; if (! ic || ic.im != MIM.current) @@ -3110,7 +3173,8 @@ MIM.keydown = function (event) if (ic.im.load_status != MIM.LoadStatus.Loaded) return; target.mim_ic = ic; - MIM.add_event_listener (target, 'blur', MIM.reset_ic); + MIM.add_event_listener (target, 'focus', MIM.focus_in); + MIM.add_event_listener (target, 'blur', MIM.focus_out); MIM.get_range (target, ic) } else @@ -3126,7 +3190,7 @@ MIM.keydown = function (event) try { var result = ic.Filter (ic.key); } catch (e) { - Xex.Log ('Error;' + e); + Xex.Log ('Error' + e); throw (e); } MIM.update (target, ic);