Ticket #827: drag.4.patch
| File drag.4.patch, 6.0 kB (added by tschaub, 1 year ago) |
|---|
-
tests/Handler/test_Drag.html
old new 248 248 249 249 } 250 250 251 function test_Handler_Drag_submethods(t) { 252 t.plan(4); 253 254 var map = new OpenLayers.Map('map', {controls: []}); 255 256 var control = new OpenLayers.Control(); 257 map.addControl(control); 258 259 260 var handler = new OpenLayers.Handler.Drag(control, {}); 261 // set test events 262 var events = ["down", "move", "up", "out"]; 263 var testEvents = {}; 264 var type, px; 265 for(var i=0; i<events.length; ++i) { 266 type = events[i]; 267 px = new OpenLayers.Pixel(Math.random(), Math.random()); 268 testEvents[type] = {xy: px}; 269 setMethod(type); 270 } 271 function setMethod(type) { 272 handler[type] = function(evt) { 273 t.ok(evt.xy.x == testEvents[type].xy.x && 274 evt.xy.y == testEvents[type].xy.y, 275 "handler." + type + " called with the right event"); 276 } 277 } 278 handler.activate(); 279 280 // test mousedown 281 handler.checkModifiers = function(evt) { 282 return true; 283 } 284 var oldIsLeftClick = OpenLayers.Event.isLeftClick; 285 OpenLayers.Event.isLeftClick = function(evt) { 286 return true; 287 } 288 map.events.triggerEvent("mousedown", testEvents.down); 289 OpenLayers.Event.isLeftClick = oldIsLeftClick; 290 291 // test mousemove 292 map.events.triggerEvent("mousemove", testEvents.move); 293 294 // test mouseup 295 map.events.triggerEvent("mouseup", testEvents.up); 296 297 // test mouseout 298 var oldMouseLeft = OpenLayers.Util.mouseLeft; 299 OpenLayers.Util.mouseLeft = function() { 300 return true; 301 }; 302 handler.started = true; 303 map.events.triggerEvent("mouseout", testEvents.out); 304 OpenLayers.Util.mouseLeft = oldMouseLeft; 305 306 } 307 251 308 function test_Handler_Drag_deactivate(t) { 252 309 t.plan(3); 253 310 var map = new OpenLayers.Map('map'); -
lib/OpenLayers/Handler/Drag.js
old new 77 77 }, 78 78 79 79 /** 80 * The four methods below (down, move, up, and out) are used by subclasses 81 * to do their own processing related to these mouse events. 82 */ 83 84 /** 85 * Method: down 86 * This method is called during the handling of the mouse down event. 87 * Subclasses can do their own processing here. 88 * 89 * Parameters: 90 * evt - {Event} The mouse down event 91 */ 92 down: function(evt) { 93 }, 94 95 /** 96 * Method: move 97 * This method is called during the handling of the mouse move event. 98 * Subclasses can do their own processing here. 99 * 100 * Parameters: 101 * evt - {Event} The mouse move event 102 * 103 */ 104 move: function(evt) { 105 }, 106 107 /** 108 * Method: up 109 * This method is called during the handling of the mouse up event. 110 * Subclasses can do their own processing here. 111 * 112 * Parameters: 113 * evt - {Event} The mouse up event 114 */ 115 up: function(evt) { 116 }, 117 118 /** 119 * Method: out 120 * This method is called during the handling of the mouse out event. 121 * Subclasses can do their own processing here. 122 * 123 * Parameters: 124 * evt - {Event} The mouse out event 125 */ 126 out: function(evt) { 127 }, 128 129 /** 80 130 * The methods below are part of the magic of event handling. Because 81 131 * they are named like browser events, they are registered as listeners 82 132 * for the events they represent. … … 100 150 this.last = evt.xy; 101 151 // TBD replace with CSS classes 102 152 this.map.div.style.cursor = "move"; 153 this.down(evt); 103 154 this.callback("down", [evt.xy]); 104 155 OpenLayers.Event.stop(evt); 105 156 return false; … … 121 172 if (this.started) { 122 173 if(evt.xy.x != this.last.x || evt.xy.y != this.last.y) { 123 174 this.dragging = true; 175 this.move(evt); 124 176 this.callback("move", [evt.xy]); 125 177 if(!this.oldOnselectstart) { 126 178 this.oldOnselectstart = document.onselectstart; … … 148 200 this.dragging = false; 149 201 // TBD replace with CSS classes 150 202 this.map.div.style.cursor = ""; 203 this.up(evt); 151 204 this.callback("up", [evt.xy]); 152 205 this.callback("done", [evt.xy]); 153 206 document.onselectstart = this.oldOnselectstart; … … 171 224 this.dragging = false; 172 225 // TBD replace with CSS classes 173 226 this.map.div.style.cursor = ""; 227 this.out(evt); 174 228 this.callback("out", []); 175 229 if(document.onselectstart) { 176 230 document.onselectstart = this.oldOnselectstart; … … 210 264 * {Boolean} The handler was successfully activated. 211 265 */ 212 266 activate: function() { 267 var activated = false; 213 268 if(OpenLayers.Handler.prototype.activate.apply(this, arguments)) { 214 269 this.dragging = false; 215 return true; 216 } else { 217 return false; 270 activated = true; 218 271 } 272 return activated; 219 273 }, 220 274 221 275 /** … … 226 280 * {Boolean} The handler was successfully deactivated. 227 281 */ 228 282 deactivate: function() { 283 var deactivated = false; 229 284 if(OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { 230 285 this.dragging = false; 231 return true; 232 } else { 233 return false; 286 deactivated = true; 234 287 } 288 return deactivated; 235 289 }, 236 290 237 291 CLASS_NAME: "OpenLayers.Handler.Drag"
