Fix for missing JS KeyEvent

Koos Vriezen koos.vriezen at xs4all.nl
Sun Sep 29 20:44:31 BST 2002


On Sun, 29 Sep 2002, David Faure wrote:

> On Saturday 28 September 2002 12:24, Koos Vriezen wrote:
> > Hi,
> >
> > I noticed that the onkeydown event in JS, as in
> > 'document.onkeydown=myOnKeyDown;', gets an UIEvent and not a KeyEvent.
> > KHTML has support for it, but isn't available for JS. The attached patch
> > fills that gap. (I rather did it for onkeypress, but somehow
> > 'NodeImpl::handleLocalEvents' can't find the listener for it).

Should be 'textEvent'? Currently onkeypress is generated when autorepeat
is set in QKeyEvent. xml/dom2_eventsimpl.cpp:897

  if (key->type() == QEvent::KeyRelease && !key->isAutoRepeat())
      m_id = KHTML_KEYUP_EVENT;
  else if (key->isAutoRepeat())
      m_id = KHTML_KEYPRESS_EVENT;
  else if (key->type() == QEvent::KeyPress)
      m_id = KHTML_KEYDOWN_EVENT;

Which means you have to set
    document.onkeypress=myOnKeyDown;
    document.onkeydown=myOnKeyDown;
to get all the keys in JS. (Currently, KHTMLView only passes the keys when
document.onkeydown is given a value).

> Ah it's new-in-DOM3? Interesting.

http://www.w3.org/TR/2001/WD-DOM-Level-3-Events-20010410/DOM3-Events.html
Note, I only moved the documentation from xml/dom2_eventsimpl.h to
dom/dom2_events.h to match up with the other event declarations.

> The patch looks fine to me.

It's in CVS now. Maybe more should be moved from xml to dom?

It's now possible to write a wysiwyg HTML editor in JS (if only the
renderer would render 'mytextnode.nodeValue=newstr;' correcly ...).

Koos






More information about the kfm-devel mailing list