modify the drag handler so that it only modifies IE's document.onselectstart while dragging - add jsodc text - all browser event handlers now return a boolean - activate and deactivate respect the return of the parent class and return the same

git-svn-id: http://svn.openlayers.org/trunk/openlayers@2908 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2007-03-28 15:59:49 +00:00
parent 55440ab092
commit f570758676
+93 -26
View File
@@ -16,16 +16,22 @@ OpenLayers.Handler.Drag.prototype = OpenLayers.Class.inherit( OpenLayers.Handler
* When a mousedown event is received, we want to record it, but not set * When a mousedown event is received, we want to record it, but not set
* 'dragging' until the mouse moves after starting. * 'dragging' until the mouse moves after starting.
* *
* @type boolean * @type Boolean
**/ **/
started: false, started: false,
/** @type boolean **/ /** @type Boolean **/
dragging: null, dragging: false,
/** @type OpenLayers.Pixel **/ /** @type OpenLayers.Pixel **/
start: null, start: null,
/**
* @type Function
* @private
*/
oldOnselectstart: null,
/** /**
* @constructor * @constructor
* *
@@ -40,10 +46,16 @@ OpenLayers.Handler.Drag.prototype = OpenLayers.Class.inherit( OpenLayers.Handler
OpenLayers.Handler.prototype.initialize.apply(this, arguments); OpenLayers.Handler.prototype.initialize.apply(this, arguments);
}, },
/**
* Handle mousedown events
* @param {Event} evt
* @type Boolean
* @return Should the event propagate
*/
mousedown: function (evt) { mousedown: function (evt) {
if (this.checkModifiers(evt) && OpenLayers.Event.isLeftClick(evt)) { if (this.checkModifiers(evt) && OpenLayers.Event.isLeftClick(evt)) {
this.started = true; this.started = true;
this.dragging = null; this.dragging = false;
this.start = evt.xy.clone(); this.start = evt.xy.clone();
// TBD replace with CSS classes // TBD replace with CSS classes
this.map.div.style.cursor = "move"; this.map.div.style.cursor = "move";
@@ -51,58 +63,113 @@ OpenLayers.Handler.Drag.prototype = OpenLayers.Class.inherit( OpenLayers.Handler
OpenLayers.Event.stop(evt); OpenLayers.Event.stop(evt);
return false; return false;
} }
return true;
}, },
/**
* Handle mousemove events
* @param {Event} evt
* @type Boolean
* @return Should the event propagate
*/
mousemove: function (evt) { mousemove: function (evt) {
if (this.started) { if (this.started) {
this.dragging = true; this.dragging = true;
this.callback("move", [evt.xy]); this.callback("move", [evt.xy]);
if(document.onselectstart) {
if(!this.oldOnselectstart) {
this.oldOnselectstart = document.onselectstart;
document.onselectstart = function() {return false;}
}
}
} }
return true;
}, },
/**
* Handle mouseup events
* @param {Event} evt
* @type Boolean
* @return Should the event propagate
*/
mouseup: function (evt) { mouseup: function (evt) {
if (this.started) { if (this.started) {
this.started = false; this.started = false;
this.dragging = false;
// TBD replace with CSS classes // TBD replace with CSS classes
this.map.div.style.cursor = "default"; this.map.div.style.cursor = "default";
this.callback("up", [evt.xy]); this.callback("up", [evt.xy]);
if(document.onselectstart) {
document.onselectstart = this.oldOnselectstart;
}
} }
return true;
}, },
/**
* Handle mouseout events
* @param {Event} evt
* @type Boolean
* @return Should the event propagate
*/
mouseout: function (evt) { mouseout: function (evt) {
if (this.started && OpenLayers.Util.mouseLeft(evt, this.map.div)) { if (this.started && OpenLayers.Util.mouseLeft(evt, this.map.div)) {
this.started = false; this.started = false;
this.dragging = null; this.dragging = false;
// TBD replace with CSS classes // TBD replace with CSS classes
this.map.div.style.cursor = "default"; this.map.div.style.cursor = "default";
this.callback("out", []); this.callback("out", []);
if(document.onselectstart) {
document.onselectstart = this.oldOnselectstart;
}
}
return true;
},
/**
* The drag handler captures the click event. If something else registers
* for clicks on the same element, its listener will not be called after a
* drag.
* @param {Event} evt
* @type Boolean
* @return Should the event propagate
*/
click: function (evt) {
// throw away the first left click event that happens after a mouse up
if (OpenLayers.Event.isLeftClick(evt) && this.dragging) {
this.dragging = true;
return false;
}
this.started = false;
return true;
},
/**
* Activate the handler.
* @type Boolean
* @return Was activation successful. Returns false if already active.
*/
activate: function() {
if(OpenLayers.Handler.prototype.activate.apply(this, arguments)) {
this.dragging = false;
return true;
} else {
return false;
} }
}, },
/** /**
* @param {Event} evt * Deactivate the handler.
*
* @type Boolean * @type Boolean
* @return Was deactivation successful. Returns false if not already active.
*/ */
click: function (evt) { deactivate: function() {
// throw away the first left click event that happens after a mouse up if(OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) {
if (OpenLayers.Event.isLeftClick(evt) && this.dragging != null) { this.dragging = false;
this.dragging = null; return true;
return false; } else {
return false;
} }
this.started = false;
},
activate: function (evt) {
OpenLayers.Handler.prototype.activate.apply(this, arguments);
document.onselectstart = function() { return false; };
this.dragging = null;
},
deactivate: function (evt) {
OpenLayers.Handler.prototype.deactivate.apply(this, arguments);
document.onselectstart = null;
this.dragging = null;
}, },
/** @final @type String */ /** @final @type String */