Closed Bug 213144 Opened 21 years ago Closed 19 years ago

dispatchEvent for a key event stopped working since Mozilla 1.4

Categories

(Core :: DOM: Events, defect)

x86
Windows XP
defect
Not set
major

Tracking

()

RESOLVED FIXED
mozilla1.7alpha

People

(Reporter: orlink, Assigned: bryner)

References

Details

Attachments

(1 file)

User-Agent:       Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624

This code used to work with Mozilla 1.0, 1.1, 1.2, and I think under 1.3a.  It 
is not working anymore.
The event seems to get initialized properly, but after dispatchEvent nothing 
appears.  
var k=1050; // key code
e=document.createEvent("KeyEvents");
e.initKeyEvent("keypress",1,1,null,0,0,0,0,k,k);
elmnt.dispatchEvent(e);



Reproducible: Always

Steps to Reproduce:
1. Create a simple web page with a text box
2. Add a function to generate a keypress event like the code above
3. Call the function with setTimeout for example.

Actual Results:  
No character appears in the text box

Expected Results:  
A character should appear in the textbox.
Does it work if you also send keydown and keyup events?  Could you attach a
testcase?

It's not inconceivable that this is a security fix....
I am not sure about keyup and keydown.   The strange thing is that an event 
listener catches the dispatched event, but nothing appears. 
Here is a test page:
http://www.kredor.com/keyevent/keyevent.html
Clicking on the button 'Keypress' should put a character into the text field, 
but nothing appears.  The event listener attached to the text field catches 
the event though and its keyCode and charCode values are correct.

Thank you very much for the assistance.
Yeah, this this definitely feels like a security fix.
Hi Boris,

Can you explain why it seems to be a security fix?  Can it be restored to the 
way it was?  How?  How can I find out what the cause is for sure?
If I can set the value of a field via javascript why would sending keystrokes 
to it be a problem?
If it is a security fix, maybe the fix should be blocking non-printable 
characters only.  

I'm just basing that comment on remembering some vulnerabilities associated with
key events (eg key events bubbling up to the browser toolbar, etc).  It _may_ be
that one of those fixes changed the behavior here.
Hi Boris,

Are you familiar with mozilla processes?  What can I do to get this bug fixed?

Thanks.
Severity: normal → major
Well, the first step is to find out what changed... 

It looks like the behavior changed between the 2003-03-23-05 build and
2003-03-25-05 build.  The checkin that looks most suspicious in that period is
the one for bug 54035.

bryner, do events created via the DOM get dispatched to the system group?
Wow, thank you Boris!

That's significant progress!  I hope Brian can shed light on this.
Flags: blocking1.6?
getting assignment straighened out.  cc jst.  maybe byner, jst, or callion can
make some progress on this for 1.7
Assignee: saari → bryner
Flags: blocking1.6? → blocking1.6-
Depends on: 178134
Just wanted to comment that this bug is blocking development of a keymapping
extension that would allow users to easily define new key combinations for
browser commands.

In the SuperScroll extension for Mozilla Firebird, which allows for vi-style
directional scrolling that does not interfere with the Find As You Type search
feature, I am forced to emulate key commands (scroll / PageUp / PageDown / Home
/ End) instead of being able to simply create a new keypress event that can be
handled by the browser core or another event listener.
Flags: blocking1.7a?
byner has a patch coming
Flags: blocking1.7a? → blocking1.7a+
Attached patch patchSplinter Review
This patch sends synthetic events through the system event group the same way
as user events, by mirroring the logic in PresShell::HandleEventInternal(). 
This would have regressed when editor was changed to use the system event group
for typing characters.

(It would be nice to have this code shared between ESM and PresShell... I'd
like to centralize event dispatch sometime which would make that sharing easy
to do).
Attachment #141475 - Flags: superreview?(bzbarsky)
Attachment #141475 - Flags: review?(bzbarsky)
Comment on attachment 141475 [details] [diff] [review]
patch

r+sr=bzbarsky.	And yes, centralizing event dispatch would be great....
especially if it makes possible dispatch of events in documents with no
presshell (eg mutation events).
Attachment #141475 - Flags: superreview?(bzbarsky)
Attachment #141475 - Flags: superreview+
Attachment #141475 - Flags: review?(bzbarsky)
Attachment #141475 - Flags: review+
Attachment #141475 - Flags: approval1.7a?
Comment on attachment 141475 [details] [diff] [review]
patch

a=chofmann for 1.7a
Attachment #141475 - Flags: approval1.7a? → approval1.7a+
checked in.
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
(In reply to comment #16)
> checked in.

Great Job!  Thanks!
(In reply to comment #2)
> Here is a test page:
> http://www.kredor.com/keyevent/keyevent.html

[Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.8a1) Gecko/20040520] (release) (W98SE)

This works :-)

But, for the record,
{{
e.keyCode=90;
}}
generates
{{
Error: setting a property that has only a getter
Source File: http://www.kredor.com/keyevent/keyevent.html
Line: 17
}}
Target Milestone: --- → mozilla1.7alpha
(In reply to comment #17)
> (In reply to comment #16)
> > checked in.
> 
> Great Job!  Thanks!

The bug reappeared in Firefox 1.06!  It behaves exactly the same as the previous
time two years ago.  See the demo page in the second comment.

Thank you!
Orlin
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
The bug on regression is bug 303713.
Status: REOPENED → RESOLVED
Closed: 21 years ago19 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: