+// 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",
}
};
-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)
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;
}
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;
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)
}
else
{
- Xex.Log (' without submap', false, true);
+ Xex.Log (' without submap', -1);
this.keymap = sub;
var current_state = this.state;
var map = this.keymap;
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);
return true;
}
- proto = {
+ MIM.IC.prototype = {
reset: function (clear_keys)
{
this.cursor_pos = 0;
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;
}
}
- 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')
(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;
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-';
{
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
};
(function () {
- var temp;
-
var style_props = {
width: 'width',
height: 'height',
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',
{
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)
}
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
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';
}
// 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.
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)
{
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);
}
}
},
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;
},
{
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;
},
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)
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);
}
return new Xex.ErrTerm (ename, message, false);
}
- proto.Equals = function (obj)
+ proto.equals = function (obj)
{
return (obj.IsError
&& obj.ename == ename && obj.message == message
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;
}
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;
}