Bug 9933

Summary: DOM3 keyboard events are not working like real ones
Product: WebKit Reporter: David Carson <dacarson>
Component: DOMAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: ap, darin, ggaren, syoichi
Priority: P2    
Version: 420+   
Hardware: Mac   
OS: OS X 10.4   
URL: http://www.w3.org/TR/DOM-Level-3-Events/events.html#Events-KeyboardEvents-Interfaces

Description David Carson 2006-07-15 09:53:05 PDT
DOM3 KeyboardEvents created with Javascript do not construct a PlatformKeyboardEvent, see http://bugzilla.opendarwin.org/show_bug.cgi?id=9743#c6
What should happen is KeyboardEvent is used through out the code. Presently PlatformKeyboardEvent is being used. PlatformKeyboardEvent should only be used to parse the platform event and setup the KeyboardEvent properly.
Comment 1 Geoffrey Garen 2006-07-15 09:55:26 PDT
One benefit of fixing this bug is that editing will start to work with key events dispatched by JavaScript. See this comment in FrameMac.mm:

    // FIXME: We might eventually need to make sure key bindings for editing work even with
    // events created with the DOM API. Those don't have a PlatformKeyboardEvent.
Comment 2 Darin Adler 2006-07-17 10:45:56 PDT
(In reply to comment #1)
> One benefit of fixing this bug is that editing will start to work with key
> events dispatched by JavaScript. See this comment in FrameMac.mm:
> 
>     // FIXME: We might eventually need to make sure key bindings for editing
> work even with
>     // events created with the DOM API. Those don't have a
> PlatformKeyboardEvent.

There are really two separate issues.

One is that within WebCore itself we'd like to use the DOM keyboard event objects. That may turn out to be straightforward, but it also may turn out that there's information in the platform events that the DOM events don't contain. So we might need to extend the DOM.

The key bindings issue is a separate one. That mechanism, part of OS X, is based on NSEvent objects. So a PlatformKeyboardEvent is not good enough -- we actually need an NSEvent. To fix that we'll need to create NSEvent objects for events created by the DOM.

While similar, there are different types of fixes needed for each of these two issues.
Comment 3 David Carson 2006-08-07 16:49:54 PDT
When this defect is corrected, hasFeature("keyboardevent", "3.0") should return true

Comment 4 David Carson 2006-08-07 16:51:23 PDT
(In reply to comment #3)
> When this defect is corrected, hasFeature("keyboardevent", "3.0") should return
> true
> 

Also see http://bugzilla.opendarwin.org/show_bug.cgi?id=10297 
hasFeature() is implemented in DOMImplementation.cpp
Comment 5 David Carson 2006-08-08 17:28:48 PDT
Current IDL represents the DOM3 KeyboardEvent IDL as of 31st march 2003. The IDL for keyboardevent was updated on 11th Nov 2003 to what it is today. What changed was the boolean for each of the modifier keys to a DOMString whitespace separated string list.
Comment 6 Alexey Proskuryakov 2008-01-12 14:04:46 PST
See also: http://bugs.webkit.org/show_bug.cgi?id=16735
Comment 7 Alexey Proskuryakov 2011-01-27 14:33:58 PST
The most tricky part here is probably to assess security implications. What exactly should DOM be allowed to do by dispatching synthetic events? Should it be able to dispatch Cmd+Q to quit the application, for example?
Comment 8 Darin Adler 2011-01-27 14:35:32 PST
(In reply to comment #7)
> The most tricky part here is probably to assess security implications.

OK.

> What exactly should DOM be allowed to do by dispatching synthetic events?

Generally speaking, commands that have effects within the webpage.

> Should it be able to dispatch Cmd+Q to quit the application, for example?

No.