Ticket #1292: keyboard.3.patch
| File keyboard.3.patch, 14.9 kB (added by pagameba, 5 months ago) |
|---|
-
tests/Control/KeyboardDefaults.html
old new 23 23 "new OpenLayers.Map creates map" ); 24 24 map.addControl(control); 25 25 t.ok( control.map === map, "Control.map is set to the map object" ); 26 t.ok( map.controls[3] === control, "map.controls contains control" );26 t.ok( OpenLayers.Util.indexOf(map.controls, control), "map.controls contains control" ); 27 27 } 28 28 29 /* When interpretting 30 * the keycodes below (including the comments associated with them), 31 * consult the URL below. For instance, the Safari browser returns 32 * "IE keycodes", and so is supported by any keycode labeled "IE". 33 * 34 * Very informative URL: 35 * http://unixpapa.com/js/key.html 36 */ 29 37 function test_Control_KeyboardDefaults_KeyDownEvent (t) { 30 t.plan( 1 0);38 t.plan( 16 ); 31 39 32 40 var evt = {which: 1}; 33 41 map = new OpenLayers.Map('map'); … … 38 46 control = new OpenLayers.Control.KeyboardDefaults(); 39 47 map.addControl(control); 40 48 49 var STARTING_ZOOM_LEVEL = 4; 50 41 51 var centerLL = new OpenLayers.LonLat(0,0); 42 map.setCenter(centerLL, 4);52 map.setCenter(centerLL, STARTING_ZOOM_LEVEL); 43 53 44 54 console.log(map.getCenter()); 55 // Start new test. 45 56 evt.keyCode = OpenLayers.Event.KEY_LEFT; 46 control.defaultKey Down(evt);57 control.defaultKeyPress(evt); 47 58 t.delay_call( 48 1, function() {59 2, function() { 49 60 t.ok( map.getCenter().lon < centerLL.lon, "key left works correctly" ); 61 62 // Start new test. 50 63 evt.keyCode = OpenLayers.Event.KEY_RIGHT; 51 control.defaultKey Down(evt);64 control.defaultKeyPress(evt); 52 65 }, 53 1, function() { 54 t.ok( map.getCenter().lon == centerLL.lon, "key right works correctly" ); 66 2, function() { 67 t.eq( map.getCenter().lon, centerLL.lon, "key right works correctly" ); 68 69 // Start new test. 55 70 evt.keyCode = OpenLayers.Event.KEY_UP; 56 control.defaultKey Down(evt);71 control.defaultKeyPress(evt); 57 72 }, 58 1, function() {73 2, function() { 59 74 t.ok( map.getCenter().lat > centerLL.lat, "key up works correctly" ); 75 76 // Start new test. 60 77 evt.keyCode = OpenLayers.Event.KEY_DOWN; 61 control.defaultKey Down(evt);78 control.defaultKeyPress(evt); 62 79 }, 63 1, function() {80 2, function() { 64 81 t.ok( map.getCenter().lat == centerLL.lat, "key down works correctly" ); 82 83 // Start new test. 65 84 evt.keyCode = 33; //page up 66 control.defaultKey Down(evt);85 control.defaultKeyPress(evt); 67 86 }, 68 1, function() {87 2, function() { 69 88 t.ok( map.getCenter().lat > centerLL.lat, "key page up works correctly" ); 89 90 // Start new test. 70 91 evt.keyCode = 34; //page down 71 control.defaultKey Down(evt);92 control.defaultKeyPress(evt); 72 93 }, 73 1, function() {94 2, function() { 74 95 t.ok( map.getCenter().lat == centerLL.lat, "key page down works correctly" ); 96 97 // Start new test. 75 98 evt.keyCode = 35; //end 76 control.defaultKey Down(evt);99 control.defaultKeyPress(evt); 77 100 }, 78 1, function() {101 2, function() { 79 102 t.ok( map.getCenter().lon > centerLL.lon, "key end works correctly" ); 80 evt.keyCode = 36; //pos1 81 control.defaultKeyDown(evt); 103 104 // Start new test. 105 evt.keyCode = 36; //home 106 control.defaultKeyPress(evt); 82 107 }, 83 1, function() { 84 t.ok( map.getCenter().lon == centerLL.lon, "key pos1 works correctly" ); 85 evt.charCode = 43; //+ 86 control.defaultKeyDown(evt); 87 }, 88 1, function() { 89 t.eq( map.getZoom(), 5, "key + works correctly" ); 108 2, function() { 109 t.ok( map.getCenter().lon == centerLL.lon, "key home works correctly"); 110 111 // Start new test. 112 evt.keyCode = 43; //+ 113 control.defaultKeyPress(evt); 114 t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 1, "key code 43 works correctly: +/= key (ASCII), keypad + (ASCII, Opera)" ); 115 116 // Start new test. 117 evt.keyCode = 61; 118 control.defaultKeyPress(evt); 119 t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 2, "key code 61 works correctly: +/= key (Mozilla, Opera, some ASCII)"); 120 121 // Start new test. 122 evt.keyCode = 187; 123 control.defaultKeyPress(evt); 124 t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 3, "key code 187 works correctly: +/= key (IE)"); 125 126 // Start new test. 127 evt.keyCode = 107; 128 control.defaultKeyPress(evt); 129 t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 4, "key code 107 works correctly: keypad + (IE, Mozilla)"); 130 131 // Start new test. 90 132 // set zoomanimation flag manually, 91 133 // reason: loadend event in layers.js will not achieved in unittests 92 134 map.zoomanimationActive = false; 93 evt.charCode = 45; //- 94 control.defaultKeyDown(evt); 95 }, 96 1, function() { 97 t.eq( map.getZoom(), 4, "key - works correctly" ); 135 evt.keyCode = 45; 136 control.defaultKeyPress(evt); 137 t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 3, "key code 45 works correctly: -/_ key (ASCII, Opera), keypad - (ASCII, Opera)"); 138 139 // Start new test. 140 // set zoomanimation flag manually, 141 // reason: loadend event in layers.js will not achieved in unittests 142 map.zoomanimationActive = false; 143 evt.keyCode = 109; 144 control.defaultKeyPress(evt); 145 t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 2, "key code 109 works correctly: -/_ key (Mozilla), keypad - (Mozilla, IE)"); 146 147 // Start new test. 148 // set zoomanimation flag manually, 149 // reason: loadend event in layers.js will not achieved in unittests 150 map.zoomanimationActive = false; 151 evt.keyCode = 189; 152 control.defaultKeyPress(evt); 153 t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 1, "key code 189 works correctly: -/_ key (IE)"); 154 155 // Start new test. 156 // set zoomanimation flag manually, 157 // reason: loadend event in layers.js will not achieved in unittests 158 map.zoomanimationActive = false; 159 evt.keyCode = 95; 160 control.defaultKeyPress(evt); 161 t.eq( map.getZoom(), STARTING_ZOOM_LEVEL, "key code 95 works correctly: -/_ key (some ASCII)"); 98 162 } 99 163 ); 100 164 } -
tests/Control/ModifyFeature.html
old new 67 67 t.eq(control.deleteCodes[0], 46, "Delete code properly turned into an array."); 68 68 var control = new OpenLayers.Control.ModifyFeature(layer); 69 69 t.eq(control.deleteCodes[0], 46, "Default deleteCodes include delete"); 70 t.eq(control.deleteCodes[1], 100, "Default deleteCodes include 'd'");70 t.eq(control.deleteCodes[1], 68, "Default deleteCodes include 'd'"); 71 71 72 72 control.destroy(); 73 73 layer.destroy(); … … 123 123 "vertex deletion: onModification called with the proper feature"); 124 124 }; 125 125 // run the above four tests twice 126 control.handleKeypress( delKey);127 control.handleKeypress( dKey);126 control.handleKeypress({keyCode:delKey}); 127 control.handleKeypress({keyCode:dKey}); 128 128 129 129 // now make sure nothing happens if the vertex is mid-drag 130 130 control.dragControl.handlers.drag.dragging = true; 131 control.handleKeypress( delKey);131 control.handleKeypress({keyCode:delKey}); 132 132 133 133 // clean up 134 134 control.destroy(); … … 428 428 }; 429 429 point.geometry.parent = poly.geometry; 430 430 control.dragControl.feature = point; 431 control.handleKeypress( 46);431 control.handleKeypress({keyCode:46}); 432 432 layer.drawFeature = oldDraw; 433 433 434 434 map.destroy(); -
tests/list-tests.html
old new 91 91 <li>Control/DragFeature.html</li> 92 92 <li>Control/DragPan.html</li> 93 93 <li>Control/DrawFeature.html</li> 94 <li>Control/KeyboardDefaults.html</li> 94 95 <li>Control/LayerSwitcher.html</li> 95 96 <li>Control/ModifyFeature.html</li> 96 97 <li>Control/MousePosition.html</li> -
lib/OpenLayers/Control/KeyboardDefaults.js
old new 47 47 */ 48 48 draw: function() { 49 49 this.handler = new OpenLayers.Handler.Keyboard( this, { 50 "key press": this.defaultKeyPress });50 "keydown": this.defaultKeyPress }); 51 51 this.activate(); 52 52 }, 53 53 54 54 /** 55 55 * Method: defaultKeyPress 56 * When handling the key event, we only use evt.keyCode. This holds 57 * some drawbacks, though we get around them below. When interpretting 58 * the keycodes below (including the comments associated with them), 59 * consult the URL below. For instance, the Safari browser returns 60 * "IE keycodes", and so is supported by any keycode labeled "IE". 61 * 62 * Very informative URL: 63 * http://unixpapa.com/js/key.html 56 64 * 57 65 * Parameters: 58 66 * code - {Integer} 59 67 */ 60 defaultKeyPress: function ( code) {61 switch( code) {68 defaultKeyPress: function (evt) { 69 switch(evt.keyCode) { 62 70 case OpenLayers.Event.KEY_LEFT: 63 71 this.map.pan(-this.slideFactor, 0); 64 72 break; … … 72 80 this.map.pan(0, this.slideFactor); 73 81 break; 74 82 75 case 33: // Page Up 83 case 33: // Page Up. Same in all browsers. 76 84 var size = this.map.getSize(); 77 85 this.map.pan(0, -0.75*size.h); 78 86 break; 79 case 34: // Page Down 87 case 34: // Page Down. Same in all browsers. 80 88 var size = this.map.getSize(); 81 89 this.map.pan(0, 0.75*size.h); 82 90 break; 83 case 35: // End 91 case 35: // End. Same in all browsers. 84 92 var size = this.map.getSize(); 85 93 this.map.pan(0.75*size.w, 0); 86 94 break; 87 case 36: // Pos195 case 36: // Home. Same in all browsers. 88 96 var size = this.map.getSize(); 89 97 this.map.pan(-0.75*size.w, 0); 90 98 break; 91 99 92 case 43: // + 100 case 43: // +/= (ASCII), keypad + (ASCII, Opera) 101 case 61: // +/= (Mozilla, Opera, some ASCII) 102 case 187: // +/= (IE) 103 case 107: // keypad + (IE, Mozilla) 93 104 this.map.zoomIn(); 94 105 break; 95 case 45: // - 106 case 45: // -/_ (ASCII, Opera), keypad - (ASCII, Opera) 107 case 109: // -/_ (Mozilla), keypad - (Mozilla, IE) 108 case 189: // -/_ (IE) 109 case 95: // -/_ (some ASCII) 96 110 this.map.zoomOut(); 97 111 break; 98 case 107: // + (IE only)99 this.map.zoomIn();100 break;101 case 109: // - (IE only)102 this.map.zoomOut();103 break;104 112 } 105 113 }, 106 114 -
lib/OpenLayers/Control/ModifyFeature.js
old new 93 93 * {Array(Integer)} Keycodes for deleting verticies. Set to null to disable 94 94 * vertex deltion by keypress. If non-null, keypresses with codes 95 95 * in this array will delete vertices under the mouse. Default 96 * is 46 and 100, the 'delete' and lowercase 'd' keys.96 * is 46 and 68, the 'delete' and lowercase 'd' keys. 97 97 */ 98 98 deleteCodes: null, 99 99 … … 183 183 this.layer.style || this.layer.styleMap.createSymbolizer()); 184 184 this.virtualStyle.fillOpacity = 0.3; 185 185 this.virtualStyle.strokeOpacity = 0.3; 186 this.deleteCodes = [46, 100];186 this.deleteCodes = [46, 68]; 187 187 this.mode = OpenLayers.Control.ModifyFeature.RESHAPE; 188 188 OpenLayers.Control.prototype.initialize.apply(this, [options]); 189 189 if(!(this.deleteCodes instanceof Array)) { … … 227 227 228 228 // configure the keyboard handler 229 229 var keyboardOptions = { 230 key press: this.handleKeypress230 keydown: this.handleKeypress 231 231 }; 232 232 this.handlers = { 233 233 keyboard: new OpenLayers.Handler.Keyboard(this, keyboardOptions) … … 517 517 * Parameters: 518 518 * {Integer} Key code corresponding to the keypress event. 519 519 */ 520 handleKeypress: function(code) { 520 handleKeypress: function(evt) { 521 var code = evt.keyCode; 522 521 523 // check for delete key 522 524 if(this.feature && 523 525 OpenLayers.Util.indexOf(this.deleteCodes, code) != -1) { -
lib/OpenLayers/Handler/Keyboard.js
old new 100 100 */ 101 101 handleKeyEvent: function (evt) { 102 102 if (this.checkModifiers(evt)) { 103 this.callback(evt.type, [evt .charCode || evt.keyCode]);103 this.callback(evt.type, [evt]); 104 104 } 105 105 },
