* Fixes to the Keyboard Handler to make it work better --

* drop keypress event (not used, registers as keydown in IE< which results
      in double events) 
    * return evt instead of evt.keyCode || evt.charCode, so apps can do
      whatever they like best
 * adjust ModifyFeature to new API
 * Adjust KeyboardDefaults to new API, and include a new set of keyCodes
    in switch statement to catch more cases
 * Include keyboard defaults test in list-tests.

Patch from tcoulter, work from Pedro Simonetti (See #1108), Paul Spencer,
myself. r=pagameba,me (Closes #1292)   


git-svn-id: http://svn.openlayers.org/trunk/openlayers@7644 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2008-07-31 17:45:16 +00:00
parent 3dcc30a24c
commit 09b4073636
6 changed files with 135 additions and 61 deletions

View File

@@ -47,18 +47,26 @@ OpenLayers.Control.KeyboardDefaults = OpenLayers.Class(OpenLayers.Control, {
*/
draw: function() {
this.handler = new OpenLayers.Handler.Keyboard( this, {
"keypress": this.defaultKeyPress });
"keydown": this.defaultKeyPress });
this.activate();
},
/**
* Method: defaultKeyPress
* When handling the key event, we only use evt.keyCode. This holds
* some drawbacks, though we get around them below. When interpretting
* the keycodes below (including the comments associated with them),
* consult the URL below. For instance, the Safari browser returns
* "IE keycodes", and so is supported by any keycode labeled "IE".
*
* Very informative URL:
* http://unixpapa.com/js/key.html
*
* Parameters:
* code - {Integer}
*/
defaultKeyPress: function (code) {
switch(code) {
defaultKeyPress: function (evt) {
switch(evt.keyCode) {
case OpenLayers.Event.KEY_LEFT:
this.map.pan(-this.slideFactor, 0);
break;
@@ -72,35 +80,35 @@ OpenLayers.Control.KeyboardDefaults = OpenLayers.Class(OpenLayers.Control, {
this.map.pan(0, this.slideFactor);
break;
case 33: // Page Up
case 33: // Page Up. Same in all browsers.
var size = this.map.getSize();
this.map.pan(0, -0.75*size.h);
break;
case 34: // Page Down
case 34: // Page Down. Same in all browsers.
var size = this.map.getSize();
this.map.pan(0, 0.75*size.h);
break;
case 35: // End
case 35: // End. Same in all browsers.
var size = this.map.getSize();
this.map.pan(0.75*size.w, 0);
break;
case 36: // Pos1
case 36: // Home. Same in all browsers.
var size = this.map.getSize();
this.map.pan(-0.75*size.w, 0);
break;
case 43: // +
case 43: // +/= (ASCII), keypad + (ASCII, Opera)
case 61: // +/= (Mozilla, Opera, some ASCII)
case 187: // +/= (IE)
case 107: // keypad + (IE, Mozilla)
this.map.zoomIn();
break;
case 45: // -
case 45: // -/_ (ASCII, Opera), keypad - (ASCII, Opera)
case 109: // -/_ (Mozilla), keypad - (Mozilla, IE)
case 189: // -/_ (IE)
case 95: // -/_ (some ASCII)
this.map.zoomOut();
break;
case 107: // + (IE only)
this.map.zoomIn();
break;
case 109: // - (IE only)
this.map.zoomOut();
break;
}
},