Fix IME on Firefox.

Hello, this pull request implements the IME part of #1946, in a hopefully proper way.

> Firefox prevents keystrokes from being detected while inputting with
an IME. That is, keystrokes produced from the start and the end of an
IME composition and its ending are blocked. As a result, pressing the
enter key to commit a composition does not filter the results and
select the previously highlighted result right away, preventing Firefox
users from ever changing the seleted item.

> To work around this problem, we differenciate “pressing enter to commit
a composition” from “pressing enter to select the highlighted result in
Chosen” by checking if the keydown event preceded the keyup one.

> Chrome and IE are not affected by this problem because they [do not
block key events during composition](https://bugzilla.mozilla.org/show_bug.cgi?id=354358#c40). If Firefox happen to switch to
Chrome and IE’s beheaviour, this commit should be reverted.