This change list improves IME support on Linux. Many corner cases that were not
handled in original code are addressed, for example the input method in password
box case.

The most important change in this CL is the change to key event processing flow.
 In old code, a key event will first be sent to webkit then dispatched to IME
for filtering. With this CL, a key event will first be dispatched to IME for
filtering, then how to send the event to webkit is decided by the filtering
result.

This CL tries to emulate the keyboard input behavior on Windows as much as
possible. For example, if a keydown event is filtered by IME, then its virtual
key code will be changed to VK_PROCESSKEY(0xE5) to prevent webkit from
processing it again. This behavior can workaround bug 16281.

To test this CL, you may cut and save following html code into a file and open
it in chrome.
------------------8<----cut here----->8---------------------
<html><head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">

<script>
function keyEventHandler(event) {
  var props = [ "type", "charCode", "keyCode", "altKey",
    "ctrlKey", "shiftKey", "metaKey" ];
  var info = document.getElementById('info');
  var s = '';
  for (var i in props) {
    s += props[i] + ':' + event[props[i]] + ' ';
  }
  info.value += s + '\n';
}

function textEventHandler(event) {
  info.value += "type:" + event['type'] + " data:" + event['data'] + '\n';
}

function passwordChangeEventHandler(event) {
  var input2 = document.getElementById('input2');
  info.value += "password:" + input2.value + '\n';
}

function onLoad() {
  var input = document.getElementById('input');
  input.addEventListener('keydown', keyEventHandler, false);
  input.addEventListener('keyup', keyEventHandler, false);
  input.addEventListener('keypress', keyEventHandler, false);
  input.addEventListener('textInput', textEventHandler, false);
  var input2 = document.getElementById('input2');
  input2.addEventListener('change', passwordChangeEventHandler, false);
}
</script>
</head><body onload="onLoad()">
<input id="input" size="20">
<input id="input2" type="password" size="20">
<p>
<textarea id="info" rows="40" cols="150"></textarea>
</p></body></html>
------------------8<----cut here----->8---------------------

This CL was confirmed to fix following issues:
BUG=16281 "arrow keys and backspace/delete keys move/delete two characters at a
time when xim immodule is used"
BUG=16282 "Disable IMEs in a password input"
BUG=16596 "fcitx (chinese input method) not working in ubuntu 9.04"
BUG=16659 "Crash near RenderWidgetHostViewGtk::IMEUpdateStatus"
BUG=16699 "Can't move cursor to omnibox and use input method if cursor is
currently in a text input box in web page."
BUG=16796 "Input method issue: When inputting text in a text box, if there is a
composition string then pressing Backspace or Delete will cause the composition
string be cleared and the text box refuses to accept any further input.

All tests assume above html code is used.
TEST=Start scim with "scim -d" and start chrome with GTK_IM_MODULE=xim and
XMODIFIERS=@im=SCIM. Type something in input box, eg. "hello", then press
backspace, to see if only one character is deleted.
TEST=Move cursor to password input box, press ctrl-space to see if input method
is not activated. Switch keyboard layout to Canadian-French then type a'[{' key
and an 'a' key, then press enter, to see if a Latin character "U+00E2" is
inputted in password box.
TEST=Install fcitx with "sudo apt-get install fcitx" (assume you are using
Ubuntu/Debian). Open a terminal, export XMODIFIERS=@im=fcitx and
GTK_IM_MODULE=xim then run fcitx, then start chrome. Move cursor into an input
box, press ctrl-space and input something, eg. "nihao" then press space. Check
if some Chinese characters are inputted.
TEST=Start chrome with GTK_IM_MODULE=scim. Move cursor into a text input box
then move into a password box, chrome should not crash.
TEST=Move cursor into a text input box, then click omnibox, and see if the text
input box has lost focus. Press ctrl-space to activate input method, then type
something, and see of the input goes into omnibox.
TEST=Move cursor into a text input box and enable a Chinese Pinyin input method,
then type something, eg. "dajiahao", make sure a composition string is displayed
in the text input box, then press backspace and see if there is still a
composition string and backspace is handled by input method.

patch by James Su <james.su [at] gmail>
original review URL: <http://codereview.chromium.org/149755>


Review URL: http://codereview.chromium.org/155869

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21203 0039d316-1c4b-4281-b951-d872f2087c98
3 files changed