Handling IME composition events

# Joone Hur (6 years ago)

Hello all,

I’m working on a Hangul(Korean alphabet) composition issue in WebKit. bugs.webkit.org/show_bug.cgi?id=40518 By the way, I noticed that WebKit based browsers are inconsistent with IME composition events.

According to the W3C DOM Level 3 events(bit.ly/bM7YVQ), 1) A browser should fire compositionstart, compositionupdate, and compositionend event during a composition. 2) The textEvent event should be dispatched after a compositionend event if the composition has not been canceled. 3) While a composition session is active, keyboard events should not be dispatched to the DOM (i.e., the text composition system "swallows" the keyboard events), and only compositionupdate events may be dispatched to indicate the composition process.

However, all ports of WebKit handle composition events in inconsistent ways. Even keyboard events are still dispatched to the DOM during a composition.

Therefore, it is necessary to fix those problems as follows: 1) IME Composition events should be handled consistently in all ports of WebKit. 2) The textInput event should be dispatched after a compositionend event. 3) Keyboard events should not be dispatched during a composition.

The following link shows an example of testing composition events with the major WebKit based browsers. bug-43020-attachments.webkit.org/attachment.cgi?id=62647 I was wondering what is a good example of handling composition events. In my opinion, the composition events should be dispatched as follows if we follow the W3C DOM Level3 events.

For example, when we type ‘rksk’ for inputting ‘가나' using Korean IME,

Type ‘r(ㄱ)’

  1. compositionstart
  2. input

Type ‘k(ㅏ)

  1. compositionupdate
  2. input

Type ‘s(ㄴ)’

  1. compositionupdate
  2. input

Type ‘k(ㅏ)’

  1. compositionend (for 가)
  2. textInput
  3. input
  4. compositionstart
  5. input

mouse press

  1. compositionend (for 나)
  2. textInput
  3. input

Currently, Firefox, Chrome, and Safari don’t handle composition events like this because they seem not to follow the W3C specification on IME composition events yet. So I filed a bug for this issue. bugs.webkit.org/show_bug.cgi?id=43020

I would be grateful if you could give me your opinion on this issue.

Thanks,

Joone

Contact us to advertise here
# Oliver Hunt (6 years ago)

On Jul 28, 2010, at 8:45 AM, Joone Hur wrote:

Hello all,

I’m working on a Hangul(Korean alphabet) composition issue in WebKit. bugs.webkit.org/show_bug.cgi?id=40518 By the way, I noticed that WebKit based browsers are inconsistent with IME composition events.

According to the W3C DOM Level 3 events(bit.ly/bM7YVQ), 1) A browser should fire compositionstart, compositionupdate, and compositionend event during a composition. 2) The textEvent event should be dispatched after a compositionend event if the composition has not been canceled. 3) While a composition session is active, keyboard events should not be dispatched to the DOM (i.e., the text composition system "swallows" the keyboard events), and only compositionupdate events may be dispatched to indicate the composition process.

The DOM Level 3 event model for input composition does not match the requirements of actual web content. This is unfortunate, but will hopefully be fixed in future.

However, all ports of WebKit handle composition events in inconsistent ways. Even keyboard events are still dispatched to the DOM during a composition.

Therefore, it is necessary to fix those problems as follows: 1) IME Composition events should be handled consistently in all ports of WebKit.

I'm not sure this can be achieved as it depends (to an extent) on the platform IME system, and the active IME -- different IMEs have completely different behaviours making consistent behaviour across multiple platforms is an exercise in futility.

However if you're seeing different behaviour with the same IME on a single platform that's a bug.

2) The textInput event should be dispatched after a compositionend event.

Unsure of the specifics of this.

3) Keyboard events should not be dispatched during a composition.

Key events must be sent while an IME is active otherwise sites break. IIRC you get keydown and keyup events, but not keypress. The keydown event when an IME is active has charCode 229 in order to be compatible with IE.

# Ojan Vafai (6 years ago)

On Wed, Jul 28, 2010 at 11:13 AM, Oliver Hunt <oliver at apple.com> wrote:

On Jul 28, 2010, at 8:45 AM, Joone Hur wrote:

2) The textInput event should be dispatched after a compositionend event. Unsure of the specifics of this.

There's a discussion on www-dom at w3.org about changing the spec here. See lists.w3.org/Archives/Public/www-dom/2010AprJun/0048.html.

# Joone Hur (6 years ago)

On Thu, Jul 29, 2010 at 3:13 AM, Oliver Hunt <oliver at apple.com> wrote: >

On Jul 28, 2010, at 8:45 AM, Joone Hur wrote:

3) Keyboard events should not be dispatched during a composition. Key events must be sent while an IME is active otherwise sites break. IIRC you get keydown and keyup events, but not keypress. The keydown event when an IME is active has charCode 229 in order to be compatible with IE.

In case of Firefox, it doesn't fire any keyboard events during a composition. Therefore, a Mozilla developer mentioned on a bug about "no keyboard events during a Hangul composition" as follows, "I still think that we shouldn't fire any key events during composing. The compositionupdate event is enough for this issue." bugzilla.mozilla.org/show_bug.cgi?id=354358#c24

Firefox4.0b1 also doesn't fire any keyboard events after compositionstart event. => You can find a test result from bit.ly/99tkd0

Of course, there has been a compatibility issue of detecting composition states in case of Firefox compared to IE. However, I think that composition events seem enough without keyboard events during a IME composition. Because many Korean web developers have known this issue so they have used a workaround to avoid it.

We need a consensus on this issue between WebKit and Mozilla developers.

Thanks for your feedback.

Joone

# Ojan Vafai (6 years ago)

On Thu, Jul 29, 2010 at 9:18 AM, Joone Hur <joone at kldp.org> wrote:

On Thu, Jul 29, 2010 at 3:13 AM, Oliver Hunt <oliver at apple.com> wrote:

On Jul 28, 2010, at 8:45 AM, Joone Hur wrote:

3) Keyboard events should not be dispatched during a composition. Key events must be sent while an IME is active otherwise sites break. IIRC you get keydown and keyup events, but not keypress. The keydown event when an IME is active has charCode 229 in order to be compatible with IE.

However, I think that composition events seem enough without keyboard events during a IME composition.

If were were designing these APIs from scratch, that might be the case. But WebKit only recently added composition events. We have been firing key events for a long time. If we stopped firing them, a lot of sites would break in WebKit browsers. So, not firing them is not an option.

We need a consensus on this issue between WebKit and Mozilla developers.

I don't think we could reasonably stop firing key events. Too many sites would break.

Ojan

Want more features?

Request early access to our private beta of readable email premium.