From 873b494ec1f4c7d4b4697871b105fa10e18a2231 Mon Sep 17 00:00:00 2001 From: handa Date: Mon, 22 Mar 2010 23:38:29 +0000 Subject: [PATCH] *** empty log message *** --- index.html | 30 ++++---------- mim.js | 135 +++++++++++++++++++++++++++++++++++++++--------------------- xex.js | 70 ++++++++++++++++--------------- 3 files changed, 132 insertions(+), 103 deletions(-) diff --git a/index.html b/index.html index ab298ae..3455399 100644 --- a/index.html +++ b/index.html @@ -61,28 +61,12 @@ MIM.debug_nodes.range1.innerHTML = '' } }; - - MIM.toggle_log = function () + function toggle_debug (event) { - if (Xex.LogNode) - { - Xex.LogNode.parentNode.removeChild (Xex.LogNode); - Xex.LogNode = false; - } - else - { - Xex.LogNode = document.createElement ('div'); - Xex.LogNode.style.border = '1px solid black'; - Xex.LogNode.style.font = 'normal normal normal small monospace'; - Xex.LogNode.style.width = '100%'; - Xex.LogNode.style.minHeight = '300px'; - Xex.LogNode.style.maxHeight = '300px'; - Xex.LogNode.style.overflow = 'auto'; - Xex.Log (null); - document.getElementsByTagName ('body')[0].appendChild (Xex.LogNode); - } - } - + Xex.LogToggle (); + event.preventDefault (); + return false; + } @@ -93,7 +77,7 @@ Click an input area by Control-Mouse-1 to select any other input method.
textarea
text
-
debug Info
+
debug Info
@@ -107,5 +91,5 @@ to the bookmark. Then, you can activate the MIM input method on any page when you access the bookmarked link.
--> + onmousedown="toggle_debug ()"> diff --git a/mim.js b/mim.js index 26c978f..733d5d1 100644 --- a/mim.js +++ b/mim.js @@ -1,3 +1,28 @@ +// mim.js -- M17N Input Method driver +// Copyright (C) 2010 +// National Institute of Advanced Industrial Science and Technology (AIST) +// Registration Number H15PRO112 + +// This file is part of the m17n database; a sub-part of the m17n +// library. + +// The m17n library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation; either version 2.1 of +// the License, or (at your option) any later version. + +// The m17n library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. + +// You should have received a copy of the GNU Lesser General Public +// License along with the m17n library; if not, write to the Free +// Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301, USA. + +// Please note that the code is not yet matured. + var MIM = { // URL of the input method server. server: "http://www.m17n.org/common/mim-js", @@ -51,17 +76,17 @@ var MIM = { } }; -if (window.location == 'http://localhost/mim/index.html') +if (window.location.hostname == 'localhost') MIM.server = 'http://localhost/mim'; (function () { var keysyms = new Array (); - keysyms["bs"] = "backspace"; - keysyms["lf"] = "linefeed"; - keysyms["cr"] = keysyms["enter"] = "return"; - keysyms["esc"] = "escape"; + keysyms["bs"] = "BackSpace"; + keysyms["lf"] = "Linefeed"; + keysyms["cr"] = keysyms["enter"] = "Return"; + keysyms["esc"] = "Escape"; keysyms["spc"] = "space"; - keysyms["del"] = "delete"; + keysyms["del"] = "Delete"; function decode_keysym (str) { if (str.length == 1) @@ -441,7 +466,8 @@ MIM.Keymap = function () keymap = sub; keymap.name = name; } - keymap.map_actions = rule.actions; + if (rule.actions) + keymap.map_actions = rule.actions; if (branch_actions) keymap.branch_actions = branch_actions; } @@ -505,9 +531,9 @@ MIM.State = function (name) state.keymap.Add (map_list[node.attributes['mname'].nodeValue], branch_actions); else if (node.nodeName == 'state-hook') - state.enter_actions = branch_actions; + state.keymap.map_actions = branch_actions; else if (node.nodeName == 'catch-all-branch') - state.fallback_actions = branch_actions; + state.keymap.branch_actions = branch_actions; } } return state; @@ -1261,7 +1287,7 @@ MIM.im_domain.DefType (MIM.State.prototype); if (out.index > this.key_head) { this.key_head = out.index; - Xex.Log (' with submap', false, true); + Xex.Log (' with submap', -1); restore_state.call (this); this.keymap = sub; if (sub.map_actions) @@ -1294,7 +1320,7 @@ MIM.im_domain.DefType (MIM.State.prototype); } else { - Xex.Log (' without submap', false, true); + Xex.Log (' without submap', -1); this.keymap = sub; var current_state = this.state; var map = this.keymap; @@ -1315,7 +1341,7 @@ MIM.im_domain.DefType (MIM.State.prototype); Xex.Log ('unhandled'); return false; } - if (this.keymap != current_state.keymap) + if (map != current_state.keymap) this.shift (current_state); else if (this.keymap.actions == null) this.shift (this.initial_state); @@ -1324,7 +1350,7 @@ MIM.im_domain.DefType (MIM.State.prototype); return true; } - proto = { + MIM.IC.prototype = { reset: function (clear_keys) { this.cursor_pos = 0; @@ -1586,8 +1612,8 @@ MIM.im_domain.DefType (MIM.State.prototype); if (state != this.state) this.prev_state = this.state; } - if (state != this.state && state.enter_actions) - this.take_actions (state.enter_actions); + if (state != this.state && state.keymap.map_actions) + this.take_actions (state.keymap.map_actions); if (! this.state || this.state.title != state.title) this.changed |= MIM.ChangedStatus.StateTitle; this.state = state; @@ -1662,8 +1688,7 @@ MIM.im_domain.DefType (MIM.State.prototype); } } - MIM.IC.prototype = proto; - + // Load the list of input methods. var node = Xex.Load (MIM.server, "imlist.xml"); for (node = node.firstChild; node; node = node.nextSibling) if (node.nodeName == 'input-method') @@ -1706,33 +1731,35 @@ MIM.im_domain.DefType (MIM.State.prototype); (function () { var keys = new Array (); - keys[0x09] = 'tab'; - keys[0x08] = 'backspace'; - keys[0x0D] = 'return'; - keys[0x1B] = 'escape'; + keys[0x09] = 'Tab'; + keys[0x08] = 'BackSpace'; + keys[0x0D] = 'Return'; + keys[0x1B] = 'Escape'; keys[0x20] = 'space'; - keys[0x21] = 'pageup'; - keys[0x22] = 'pagedown'; - keys[0x23] = 'end'; - keys[0x24] = 'home'; - keys[0x25] = 'left'; - keys[0x26] = 'up'; - keys[0x27] = 'right'; - keys[0x28] = 'down'; - keys[0x2D] = 'insert'; - keys[0x2E] = 'delete'; + keys[0x21] = 'Page_Up'; + keys[0x22] = 'Page_Down'; + keys[0x23] = 'End'; + keys[0x24] = 'Home'; + keys[0x25] = 'Left'; + keys[0x26] = 'Up'; + keys[0x27] = 'Right'; + keys[0x28] = 'Down'; + keys[0x2D] = 'Insert'; + keys[0x2E] = 'Delete'; for (var i = 1; i <= 12; i++) keys[111 + i] = "f" + i; - keys[0x90] = "numlock"; - keys[0xF0] = "capslock"; + keys[0x90] = "Num_Lock"; + keys[0xF0] = "Caps_Lock"; var keyids = {}; - keyids['U+0008'] = 'Backspace'; + keyids['U+0008'] = 'BackSpace'; keyids['U+0009'] = 'Tab'; keyids['U+0018'] = 'Cancel'; keyids['U+001B'] = 'Escape'; - keyids['U+0020'] = 'Space'; + keyids['U+0020'] = 'space'; keyids['U+007F'] = 'Delete'; + keyids['PageUp'] = 'Page_Up'; + keyids['PageDown'] = 'Page_Down'; var modifiers = {} modifiers.Shift = 1; @@ -1750,6 +1777,7 @@ MIM.im_domain.DefType (MIM.State.prototype); if (modifiers[key]) return false; var mod = ''; + var shifted = event.shiftKey; if (event.ctrlKey) mod += 'C-'; if (event.metaKey) mod += 'M-'; if (event.altKey) mod += 'A-'; @@ -1760,11 +1788,17 @@ MIM.im_domain.DefType (MIM.State.prototype); { if (mod.length == 0) return false; - key = String.fromCharCode (parseInt (RegExp.$1, 16)); + var c = parseInt (RegExp.$1, 16); + // Chrome sets, for instance, "U+0x00C1" when the key 'A' + // is typed with control or alt/meta key. + if (c >= 0x80) + c -= 0x80; + if (c >= 0x41 && c <= 0x5A && ! event.shiftKey) + c += 0x20; + key = String.fromCharCode (c); + shifted = false; } - //else - //key = key.toLowerCase (); - if (event.shiftKey) mod += 'S-'; + if (shifted) mod += 'S-'; return new MIM.Key (mod + key); } else @@ -1839,8 +1873,6 @@ MIM.get_range = function (target, ic) }; (function () { - var temp; - var style_props = { width: 'width', height: 'height', @@ -1848,6 +1880,8 @@ MIM.get_range = function (target, ic) paddingRight: 'padding-right', paddingTop: 'padding-top', paddintBottom: 'padding-bottom', + marginRight: 'margin-right', + marginTop: 'margin-top', borderLeftStyle: 'border-left-style', borderRightStyle: 'border-right-style', borderTopStyle: 'border-top-style', @@ -1866,13 +1900,16 @@ MIM.get_range = function (target, ic) { var from_style = getComputedStyle(from,''); for(var name in style_props) - to.style[name] = from_style.getPropertyValue (style_props[name]); + to.style[name] = from_style[style_props[name]]; to.style.left = from.offsetLeft + 'px'; to.style.top = from.offsetTop + 'px'; to.style.width = from.offsetWidth; to.style.height = from.offsetHeight; + return from_style; } + var temp; // Temporary 'div' element + MIM.get_preedit_pos = function (target, ic) { if (! temp) @@ -1886,15 +1923,19 @@ MIM.get_range = function (target, ic) } if (temp.ic != ic) { - temp.ic = ic; - copy_style (target, temp); - ic.abs_top = 0; - ic.abs_left = 0; + var styles = copy_style (target, temp); + ic.abs_top = (parseInt (styles.marginTop) + + parseInt (styles.borderTopWidth) + + parseInt (styles.paddingTop)); + ic.abs_left = (parseInt (styles.marginLeft) + + parseInt (styles.borderLeftWidth) + + parseInt (styles.paddingLeft)); for (var elm = target.offsetParent; elm; elm = elm.offsetParent) { ic.abs_top += elm.offsetTop; ic.abs_left += elm.offsetLeft; } + temp.ic = ic; } temp.firstChild.innerText = target.value.substring (0, ic.range[0]); temp.lastChild.innerText @@ -1921,7 +1962,7 @@ MIM.update_bar = function (target, ic) document.getElementsByTagName ('body')[0].appendChild (ic.bar); } ic.bar.style.display = 'block' - ic.bar.style.top = (ic.abs_y + 1) + 'px'; + ic.bar.style.top = ic.abs_y + 'px'; ic.bar.style.left = ic.abs_x0 + 'px'; ic.bar.style.minWidth = ic.bar.style.maxWidth = (ic.abs_x1 - ic.abs_x0) + 'px'; } diff --git a/xex.js b/xex.js index 705a99b..81353b2 100644 --- a/xex.js +++ b/xex.js @@ -21,9 +21,11 @@ // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, // Boston, MA 02110-1301, USA. +// Please note that the code is not yet matured. + var Xex = {}; -(function () { // Tracing +(function () { // Logging // The logging node containing tracing information. var log = null; // Number of lines. @@ -122,32 +124,34 @@ Xex.Error = { UncaughtThrow: "uncaught-throw" }; -Xex.Variable = function (domain, name, desc, val, range) +Xex.Variable = function (name, desc, val, range) { - this.domain = domain; - this.name = name; - this.desc = desc; + if (name) + this.name = name; + if (desc) + this.desc = desc; this.val = val; - this.range = range; + if (range) + this.range = range; } -Xex.Variable.prototype.clone = function () -{ - return new Xex.Variable (this.domain, this.name, this.desc, - this.val, this.range); -} - -Xex.Variable.prototype.Equals = function (obj) -{ - return ((obj instanceof Xex.Variable) - && obj.name == this.name); -} +Xex.Variable.prototype = { + clone: function () + { + return new Xex.Variable (this.name, this.desc, this.val, this.range); + }, + equals: function (obj) + { + return ((obj instanceof Xex.Variable) + && obj.name == this.name); + }, + SetValue: function (term) + { + this.val = term; + return term; + } +} -Xex.Variable.prototype.SetValue = function (term) -{ - this.val = term; - return term; -} Xex.Function = function (name, with_var, min_args, max_args) { @@ -318,7 +322,7 @@ Xex.Domain = function (name, parent, context) for (elt in parent.variables) { var vari = parent.variables[elt]; - this.variables[elt] = new Xex.Variable (this, vari.name, vari.desc, + this.variables[elt] = new Xex.Variable (vari.name, vari.desc, vari.val, vari.range); } } @@ -440,7 +444,7 @@ Xex.Domain.prototype = { }, Defvar: function (name, desc, val, range) { - var vari = new Xex.Variable (this, name, desc, val, range); + var vari = new Xex.Variable (name, desc, val, range); this.variables[name] = vari; return vari; }, @@ -467,7 +471,7 @@ Xex.Domain.prototype = { { var vari = this.variables[name]; if (! vari) - vari = this.variables[name] = new Xex.Variable (this, name, null, + vari = this.variables[name] = new Xex.Variable (name, null, Xex.Zero, null); return vari; }, @@ -495,13 +499,13 @@ Xex.Term.prototype = { IsTrue: function () { return true; }, Eval: function (domain) { return this.Clone (); }, Clone: function (domain) { return this; }, - Equals: function (obj) + equals: function (obj) { return (this.type == obj.type && this.val != undefined && obj.val == this.val); }, - Matches: function (obj) { return this.Equals (obj); }, + Matches: function (obj) { return this.equals (obj); }, toString: function () { if (this.val != undefined) @@ -771,11 +775,11 @@ Xex.Funcall = function (func, vname, args) return new Xex.Funcall (this.func, this.vari, this.args); } - proto.Equals = function (obj) + proto.equals = function (obj) { return (obj.type == 'funcall' && obj.func == this.func - && obj.vari.Equals (this.vari) + && obj.vari.equals (this.vari) && obj.args.length == this.func.length); } @@ -827,7 +831,7 @@ Xex.ErrTerm = function (ename, message, stack) return new Xex.ErrTerm (ename, message, false); } - proto.Equals = function (obj) + proto.equals = function (obj) { return (obj.IsError && obj.ename == ename && obj.message == message @@ -900,13 +904,13 @@ Xex.LstTerm = function (list) { this.val = list; }; proto.IsTrue = function () { return this.val.length > 0; } proto.Clone = function () { return new Xex.LstTerm (this.val.slice (0)); } - proto.Equals = function (obj) + proto.equals = function (obj) { if (obj.type != 'list' || obj.val.length != this.val.length) return false; var i, len = this.val.length; for (i = 0; i < len; i++) - if (! this.val[i].Equals (obj.val[i])) + if (! this.val[i].equals (obj.val[i])) return false; return true; } @@ -1089,7 +1093,7 @@ Xex.LstTerm = function (list) { this.val = list; }; function Feq (domain, vari, args) { for (var i = 1; i < args.length; i++) - if (! args[i - 1].Equals (args[i])) + if (! args[i - 1].equals (args[i])) return Xex.Zero; return Xex.One; } -- 1.7.10.4
keystatuskeycodekeymappreeditrange
down0