lewisje / svgweb

Automatically exported from code.google.com/p/svgweb
Other
0 stars 0 forks source link

Keyboard events are not supported properly #511

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Run samples/javascript-samples/helloworld.html?svg.render.forceflash=true

Paste this into the browser url:
javascript:(function()
{document.onkeydown = function(evt){alert('hi')};})();

Click on the different svg images on the left and the white space on the right 
and then hit a keystroke, one by one.

What is the expected output? What do you see instead?
Flash is eating the document level keyboard events for inline svg script form 
and native support does not eat it. Both are eating keyboard events for objects 
that have focus so I suppose we are doing the right thing there, no doubt by 
accident.

Also this behavior should be tested and implemented:
Browsers SVG capable support key events as in X/HTML
documents, for instance you can add a key listener to a SVG text
element. To receive key events you
must click on the text (this element gets the focus) and then press
some keys (don't move the mouse).

Original issue reported on code.google.com by grick23@gmail.com on 13 Jun 2010 at 8:50

GoogleCodeExporter commented 8 years ago
Raising priority to reflect the fact that keyboard based applications are 
essentially broken when using SVG Web inline images and there is no workaround 
yet. 

My current plan is to try supporting key events on the svg root element. The 
idea is that you would register that listener as well as one on document. This 
would require extra code to register that key listener for SVG Web, so that is 
not optimal. Another solution is to try to bubble key events to the document or 
window listeners, but that is harder because we have to intercept 
addEventListener. However, that would not require any special code to work with 
SVG Web.

Original comment by grick23@gmail.com on 26 Jun 2010 at 3:33

GoogleCodeExporter commented 8 years ago
As of r1226 document.addEventListener('keydown', listener, useCapture) should 
work.

The form onkeydown=function(evt) {} is not supported.
Adding keyboard listeners to the window is not supported.

Note that firefox and chrome behave strangely with respect to keyboard events. 
If the flash control has attribute wmode='transparent' then keyboard events 
captured while flash has the focus are also dispatched to any top level 
document listeners. When wmode is not set, then the keyboard events flash 
captures are not also dispatched to the document listeners. Note that wmode is 
always set to transparent unless the svg image has 'background-color' set.

So, if the flash control is rendering and inline svg image and has the focus, 
we relay the keyboard event to any registered keyboard listeners on the 
document UNLESS it is firefox or chrome and wmode is 'transparent', in which 
case the document will get the event anyway so we do not bother.

There still remains some conditions where the keyboard events do not work 
exactly the same as the browser. If you add keyboard listeners to an object 
embedded svg image and you do not set background-color, then any keyboard 
events captured by flash will be relayed to document listeners, and those 
listeners will ALSO get the native keyboard event directly. If this corner case 
is a problem for you, either set background-color on the svg root, or look at 
evt.target and filter out the extra event coming from the embed.

Issue 433 remains open for support of document.onkeydown = function(evt) {}

Original comment by grick23@gmail.com on 8 Aug 2010 at 4:43

GoogleCodeExporter commented 8 years ago
Test files for keyboard issues

Original comment by grick23@gmail.com on 8 Aug 2010 at 4:40

Attachments:

GoogleCodeExporter commented 8 years ago
The condition I mentioned in the last part of comment #2 has been fixed now in 
r1245. The extra event is no longer bubbled.

Original comment by grick23@gmail.com on 20 Nov 2010 at 11:56

GoogleCodeExporter commented 8 years ago
Fixed problem with IE7 in r1246.

Original comment by grick23@gmail.com on 21 Nov 2010 at 7:58

GoogleCodeExporter commented 8 years ago
Supported keyup event in r1247.

Original comment by grick23@gmail.com on 21 Nov 2010 at 8:17