Re: [whatwg] focus change inside keypress event handler

On Thu, 29 Oct 2009 21:58:29 -0400, Michael A. Puls II  
<> wrote:

> I'll put together a new description with the changes to see if sounds  
> good.

O.K., this description might be better and sounds more like what Firefox  
does for compat with the net:

Fire 'keydown' first.

The default action for 'keydown' is to set the acceptKeypress flag to  
true. Using preventDefault() (either explicitly or implicitly through  
return false) prevents the default action and results in the  
acceptKeypress flag remaining false.

Changing the focus from one object to another inside the 'keydown' handler  
changes the current Context Object (what the action will be performed on)  
for the following 'keypress' handler.

After the 'keydown' handler runs, fire 'keypress'.

The default action for 'keypress' is to allow the keypress if the  
acceptKeypress flag is true.

If acceptKeypress is not true or if preventDefault() is called in the  
'keypress' handler (either explicitly or implicitly through return false),  
then the keypress is not allowed.

If the keypress is allowed then perform the action on the current Context  
Object. The action could be text insertion, text deletion, scrolling etc.

If the keypress is not allowed, then do not perform the action unless the  
UA does not allow preventing the action, which in that case, perform the  

Note that a focus change inside a 'keypress' handler does not change the  
current Context Object for the keypress.

If the a key is being held down and Repeat Processing is supported,  
process the above over and over. (e.g. keydown -> keyup -> keydown ->  

When the key is finally released, fire 'keyup'.

However, note that if alert(), confirm() or prompt() is used inside a  
'keydown' handler and or inside a 'keypress' handler, whether 'keyup'  
fires varies between implementations.

Also note that alert(), confirm(), prompt(), setTimeout and setInterval()  
inside the  'keydown' , 'keypress' and 'keyup' handlers may result in some  
code inside the handlers running in a different order than 'keydown' ->  
'keypress' -> 'keyup'.

That's how Firefox appears to work, in my words, from the outside looking  

Again though, even if that's not right, I still want the spec to go into  
details like that.


Received on Tuesday, 3 November 2009 08:26:38 UTC