OpenLayers OpenLayers

Ticket #827: drag.patch

File drag.patch, 8.9 kB (added by tschaub, 1 year ago)

prepare the drag handler for subclassing

  • lib/OpenLayers/Handler/Drag.js

    old new  
    7373    }, 
    7474     
    7575    /** 
     76     * Method: activate 
     77     * Activate the handler. 
     78     *  
     79     * Return: 
     80     * {Boolean} The handler was successfully activated. 
     81     */ 
     82    activate: function() { 
     83        var activated = false; 
     84        if(OpenLayers.Handler.prototype.activate.apply(this, arguments)) { 
     85            this.dragging = false; 
     86            activated = true; 
     87        } 
     88        return activated; 
     89    }, 
     90 
     91    /** 
     92     * Method: deactivate  
     93     * Deactivate the handler. 
     94     *  
     95     * Return: 
     96     * {Boolean} The handler was successfully deactivated. 
     97     */ 
     98    deactivate: function() { 
     99        var deactivated = false; 
     100        if(OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { 
     101            this.dragging = false; 
     102            deactivated = true; 
     103        } 
     104        return deactivated; 
     105    }, 
     106 
     107    /** 
     108     * The four methods below (down, move, up, and out) are used by subclasses 
     109     *     to do their own processing related to these mouse events, or to 
     110     *     modify the handling of these events before the drag handler gets to 
     111     *     them. In subclasses, these methods should typically return true. 
     112     */ 
     113     
     114    /** 
     115     * Method: down 
     116     * This method is called prior to handling the mouse down event.  Subclasses 
     117     *     can do their own processing here and return true to continue with the 
     118     *     normal drag handling, or they can return false to do their own 
     119     *     handling. Note that this method should only be used/overridden by 
     120     *     subclasses; controls that wrap handlers should deal with callbacks 
     121     *     instead. 
     122     * 
     123     * Parameters: 
     124     * evt - {Event} The mouse down event 
     125     * 
     126     * Return: 
     127     * {Boolean} Let the handler deal with the mouse down event.  This should 
     128     *     typically return true unless a subclass wants to modify event 
     129     *     handling. 
     130     */ 
     131    down: function(evt) { 
     132        return true; 
     133    }, 
     134     
     135    /** 
     136     * Method: move 
     137     * This method is called prior to handling the mouse move event.  Subclasses 
     138     *     can do their own processing here and return true to continue with the 
     139     *     normal drag handling, or they can return false to do their own 
     140     *     handling. Note that this method should only be used/overridden by 
     141     *     subclasses; controls that wrap handlers should deal with callbacks 
     142     *     instead. 
     143     * 
     144     * Parameters: 
     145     * evt - {Event} The mouse move event 
     146     * 
     147     * Return: 
     148     * {Boolean} Let the handler deal with the mouse move event.  This should 
     149     *     typically return true unless a subclass wants to modify event 
     150     *     handling. 
     151     */ 
     152    move: function(evt) { 
     153        return true; 
     154    }, 
     155 
     156    /** 
     157     * Method: up 
     158     * This method is called prior to handling the mouse up event.  Subclasses 
     159     *     can do their own processing here and return true to continue with the 
     160     *     normal drag handling, or they can return false to do their own 
     161     *     handling. Note that this method should only be used/overridden by 
     162     *     subclasses; controls that wrap handlers should deal with callbacks 
     163     *     instead. 
     164     * 
     165     * Parameters: 
     166     * evt - {Event} The mouse up event 
     167     * 
     168     * Return: 
     169     * {Boolean} Let the handler deal with the mouse up event.  This should 
     170     *     typically return true unless a subclass wants to modify event 
     171     *     handling. 
     172     */ 
     173    up: function(evt) { 
     174        return true; 
     175    }, 
     176 
     177    /** 
     178     * Method: out 
     179     * This method is called prior to handling the mouse out event.  Subclasses 
     180     *     can do their own processing here and return true to continue with the 
     181     *     normal drag handling, or they can return false to do their own 
     182     *     handling. Note that this method should only be used/overridden by 
     183     *     subclasses; controls that wrap handlers should deal with callbacks 
     184     *     instead. 
     185     * 
     186     * Parameters: 
     187     * evt - {Event} The mouse out event 
     188     * 
     189     * Return: 
     190     * {Boolean} Let the handler deal with the mouse out event.  This should 
     191     *     typically return true unless a subclass wants to modify event 
     192     *     handling. 
     193     */ 
     194    out: function(evt) { 
     195        return true; 
     196    }, 
     197 
     198    /** 
    76199     * The methods below are part of the magic of event handling.  Because 
    77200     *     they are named like browser events, they are registered as listeners 
    78201     *     for the events they represent. 
     
    89212     * {Boolean} Let the event propagate. 
    90213     */ 
    91214    mousedown: function (evt) { 
     215        var propagate = true; 
    92216        if (this.checkModifiers(evt) && OpenLayers.Event.isLeftClick(evt)) { 
    93             this.started = true; 
    94             this.dragging = false; 
    95             this.start = evt.xy.clone(); 
    96             // TBD replace with CSS classes 
    97             this.map.div.style.cursor = "move"; 
    98             this.callback("down", [evt.xy]); 
    99             OpenLayers.Event.stop(evt); 
    100             return false; 
     217            if(this.down(evt)) { 
     218                this.started = true; 
     219                this.dragging = false; 
     220                this.start = evt.xy.clone(); 
     221                // TBD replace with CSS classes 
     222                this.map.div.style.cursor = "move"; 
     223                this.callback("down", [evt.xy]); 
     224                OpenLayers.Event.stop(evt); 
     225                propagate = false; 
     226            } 
    101227        } 
    102         return true; 
     228        return propagate; 
    103229    }, 
    104230 
    105231    /** 
     
    114240     */ 
    115241    mousemove: function (evt) { 
    116242        if (this.started) { 
    117             this.dragging = true; 
    118             this.callback("move", [evt.xy]); 
    119             if(!this.oldOnselectstart) { 
    120                 this.oldOnselectstart = document.onselectstart; 
    121                 document.onselectstart = function() {return false;} 
     243            if(this.move(evt)) { 
     244                this.dragging = true; 
     245                this.callback("move", [evt.xy]); 
     246                if(!this.oldOnselectstart) { 
     247                    this.oldOnselectstart = document.onselectstart; 
     248                    document.onselectstart = function() {return false;} 
     249                } 
    122250            } 
    123251        } 
    124252        return true; 
     
    136264     */ 
    137265    mouseup: function (evt) { 
    138266        if (this.started) { 
    139             this.started = false; 
    140             // TBD replace with CSS classes 
    141             this.map.div.style.cursor = ""; 
    142             this.callback("up", [evt.xy]); 
    143             this.callback("done", [evt.xy]); 
    144             document.onselectstart = this.oldOnselectstart; 
     267            if(this.up(evt)) { 
     268                this.started = false; 
     269                // TBD replace with CSS classes 
     270                this.map.div.style.cursor = ""; 
     271                this.callback("up", [evt.xy]); 
     272                this.callback("done", [evt.xy]); 
     273                document.onselectstart = this.oldOnselectstart; 
     274            } 
    145275        } 
    146276        return true; 
    147277    }, 
     
    158288     */ 
    159289    mouseout: function (evt) { 
    160290        if (this.started && OpenLayers.Util.mouseLeft(evt, this.map.div)) { 
    161             this.started = false;  
    162             this.dragging = false; 
    163             // TBD replace with CSS classes 
    164             this.map.div.style.cursor = ""; 
    165             this.callback("out", []); 
    166             if(document.onselectstart) { 
    167                 document.onselectstart = this.oldOnselectstart; 
     291            if(this.out(evt)) { 
     292                this.started = false;  
     293                this.dragging = false; 
     294                // TBD replace with CSS classes 
     295                this.map.div.style.cursor = ""; 
     296                this.callback("out", []); 
     297                if(document.onselectstart) { 
     298                    document.onselectstart = this.oldOnselectstart; 
     299                } 
     300                this.callback("done", [evt.xy]) 
    168301            } 
    169             this.callback("done", [evt.xy]) 
    170302        } 
    171303        return true; 
    172304    }, 
     
    193325        return true; 
    194326    }, 
    195327 
    196     /** 
    197      * Method: activate 
    198      * Activate the handler. 
    199      *  
    200      * Return: 
    201      * {Boolean} The handler was successfully activated. 
    202      */ 
    203     activate: function() { 
    204         if(OpenLayers.Handler.prototype.activate.apply(this, arguments)) { 
    205             this.dragging = false; 
    206             return true; 
    207         } else { 
    208             return false; 
    209         } 
    210     }, 
    211  
    212     /** 
    213      * Method: deactivate  
    214      * Deactivate the handler. 
    215      *  
    216      * Return: 
    217      * {Boolean} The handler was successfully deactivated. 
    218      */ 
    219     deactivate: function() { 
    220         if(OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { 
    221             this.dragging = false; 
    222             return true; 
    223         } else { 
    224             return false; 
    225         } 
    226     }, 
    227  
    228328    /** @final @type String */ 
    229329    CLASS_NAME: "OpenLayers.Handler.Drag" 
    230330});