Improve mouseup/mousedown behaviour when dragging:
authorRichard Fairhurst <richard@systemeD.net>
Tue, 27 Dec 2011 16:17:10 +0000 (16:17 +0000)
committerRichard Fairhurst <richard@systemeD.net>
Tue, 27 Dec 2011 16:17:10 +0000 (16:17 +0000)
1. if browser doesn't send mouseup when the mouse is outside the window (as per Safari), allow a simple click to stop the drag
2. don't drag-and-drop POIs when dragging the map

net/systemeD/halcyon/Map.as
net/systemeD/potlatch2/TagViewer.mxml
net/systemeD/potlatch2/controller/NoSelection.as

index 3902f36..3d3e949 100644 (file)
@@ -64,6 +64,7 @@ package net.systemeD.halcyon {
                public const NOT_DRAGGING:uint=0;                               //  |
                public const NOT_MOVED:uint=1;                                  //  |
                public const DRAGGING:uint=2;                                   //  |
+               public const SWALLOW_MOUSEUP:uint=3;                    //  |
                /** How far the map can be dragged without actually triggering a pan. */
                public const TOLERANCE:uint=7;                                  //  |
                
@@ -389,7 +390,8 @@ package net.systemeD.halcyon {
                /** Prepare for being dragged by recording start time and location of mouse. */
                public function mouseDownHandler(event:MouseEvent):void {
                        if (!_draggable) { return; }
-                       dragstate=NOT_MOVED;
+                       if (dragstate==DRAGGING) { moveMap(x,y); dragstate=SWALLOW_MOUSEUP; }   // cancel drag if mouse-up occurred outside the window (thanks, Safari)
+                       else { dragstate=NOT_MOVED; }
                        lastxmouse=stage.mouseX; downX=stage.mouseX;
                        lastymouse=stage.mouseY; downY=stage.mouseY;
                        downTime=new Date().getTime();
index 9c8ae32..0359372 100644 (file)
@@ -32,6 +32,8 @@
                                                        import mx.core.DragSource;
 
                                                        private function dragPOI(event:MouseEvent, tags:Array):void {
+                                                               if (outerDocument.controller.map.dragstate==outerDocument.controller.map.DRAGGING) return;
+
                                                                // Get the drag initiator component from the event object.
                                                                var dragInitiator:Image = event.currentTarget as Image;
                                                                var dragSource:DragSource = new DragSource();
index b780bd2..873ddb8 100644 (file)
@@ -23,7 +23,7 @@ package net.systemeD.potlatch2.controller {
                        var paint:MapPaint = getMapPaint(DisplayObject(event.target));
                        var focus:Entity = getTopLevelFocusEntity(entity);
 
-                       if (event.type==MouseEvent.MOUSE_UP && (focus==null || (paint && paint.isBackground)) && map.dragstate!=map.DRAGGING) {
+                       if (event.type==MouseEvent.MOUSE_UP && (focus==null || (paint && paint.isBackground)) && map.dragstate!=map.DRAGGING && map.dragstate!=map.SWALLOW_MOUSEUP) {
                                map.dragstate=map.NOT_DRAGGING;
                                // ** FIXME: BeginWayAction ought to be a discrete class
                                var undo:CompositeUndoableAction = new BeginWayAction();