You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by mi...@apache.org on 2016/03/22 14:58:32 UTC

[5/7] git commit: [flex-sdk] [refs/heads/develop] - FLEX-26808 CAUSE: DataGrid.grid_mouseDownHandler() committed the selection before checking whether the user was likely to begin a drag operation.

FLEX-26808
CAUSE: DataGrid.grid_mouseDownHandler() committed the selection before checking whether the user was likely to begin a drag operation.

SOLUTION: Following the pattern in the spark List component, we're committing the selection on MOUSE_DOWN only if the user has clicked on an item which isn't selected yet, or the grid is not dragEnabled, or we're not in row selection mode (i.e. either GridSelectionMode.SINGLE_ROW or  GridSelectionMode.MULTIPLE_ROWS). But when it looks like the user might start a dragOperation, we're deferring the selection adjustment to the MOUSE_UP event (caught either in DataGrid.grid_mouseUpHandler() or in DataGrid.sandbox_mouseUpHandler() ).

NOTES:
-also removed some duplication between DataGrid.grid_mouseDownHandler() and DataGrid.removeMouseHandlersForDragStart().
-also corrected some asdocs @see references.


Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/23f0bd47
Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/23f0bd47
Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/23f0bd47

Branch: refs/heads/develop
Commit: 23f0bd47c7b9e50d8da8f5a9f78b26ed8529c141
Parents: e0fbd86
Author: Mihai Chira <mi...@apache.org>
Authored: Tue Mar 22 14:08:11 2016 +0100
Committer: Mihai Chira <mi...@apache.org>
Committed: Tue Mar 22 14:08:11 2016 +0100

----------------------------------------------------------------------
 .../spark/src/spark/components/DataGrid.as      | 108 +++++++------------
 1 file changed, 40 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/23f0bd47/frameworks/projects/spark/src/spark/components/DataGrid.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/spark/src/spark/components/DataGrid.as b/frameworks/projects/spark/src/spark/components/DataGrid.as
index fb0676f..76cf418 100644
--- a/frameworks/projects/spark/src/spark/components/DataGrid.as
+++ b/frameworks/projects/spark/src/spark/components/DataGrid.as
@@ -5600,6 +5600,8 @@ public class DataGrid extends SkinnableContainerBase
             grid.hoverColumnIndex = event.columnIndex;
             updateHoverOnRollOver = true;
         }
+
+        removeMouseHandlersForDragStart(event);
     }
     
     /**
@@ -5620,40 +5622,15 @@ public class DataGrid extends SkinnableContainerBase
         if (rowIndex == -1 || isCellSelection && columnIndex == -1)
             return;
 
-
-        if (event.ctrlKey)
+        if (dragEnabled && isRowSelectionMode() && selectionContainsIndex(rowIndex))
         {
-            // ctrl-click toggles the selection and updates caret and anchor.
-            if (!toggleSelection(rowIndex, columnIndex))
-                return;
-            
-            grid.anchorRowIndex = rowIndex;
-            grid.anchorColumnIndex = columnIndex;
+            pendingSelectionOnMouseUp = true;
         }
         else
         {
-            if (event.shiftKey)
-            {
-                // shift-click extends the selection and updates the caret.
-                if  (grid.selectionMode == GridSelectionMode.MULTIPLE_ROWS || grid.selectionMode == GridSelectionMode.MULTIPLE_CELLS)
-                {    
-                    if (!extendSelection(rowIndex, columnIndex))
-                        return;
-                }
-            }
-            else
-            {
-                // click sets the selection and updates the caret and anchor positions.
-                setSelectionAnchorCaret(rowIndex, columnIndex);
-            }
+            adjustSelection(event, rowIndex, columnIndex);
         }
 
-
-        if (dragEnabled && isRowSelectionMode() && selectionContainsIndex(rowIndex))
-        {
-            pendingSelectionOnMouseUp = true;
-        }
-        
         // If selection is pending on mouse up then we have just moused down on
         // an item, part of an already commited selection.
         // However if we moused down on an item that's not currently selected,
@@ -5667,14 +5644,14 @@ public class DataGrid extends SkinnableContainerBase
         mouseDownRowIndex = rowIndex;
         mouseDownColumnIndex = columnIndex;
         
-        var listenForDrag:Boolean = (dragEnabled && 
+        var listenForDrag:Boolean = dragEnabled &&
             getStyle("interactionMode") == InteractionMode.MOUSE && selectedIndices && 
-            this.selectedIndices.indexOf(rowIndex) != -1);
+            this.selectedIndices.indexOf(rowIndex) != -1;
         // Handle any drag gestures that may have been started
         if (listenForDrag)
         {
             // Listen for GRID_MOUSE_DRAG.
-            // The user may have cliked on the item renderer close
+            // The user may have clicked on the item renderer close
             // to the edge of the list, and we still want to start a drag
             // operation if they move out of the list.
             grid.addEventListener(GridEvent.GRID_MOUSE_DRAG, grid_mouseDragHandler);
@@ -5698,6 +5675,30 @@ public class DataGrid extends SkinnableContainerBase
         
     }
     
+    private function adjustSelection(event:MouseEvent, rowIndex:int, columnIndex:int):void
+    {
+        if (event.ctrlKey)
+        {
+            // ctrl-click toggles the selection and updates caret and anchor.
+            if (!toggleSelection(rowIndex, columnIndex))
+                return;
+
+            grid.anchorRowIndex = rowIndex;
+            grid.anchorColumnIndex = columnIndex;
+        }
+        else if (event.shiftKey)
+        {
+            // shift-click extends the selection and updates the caret.
+            if  (grid.selectionMode == GridSelectionMode.MULTIPLE_ROWS || grid.selectionMode == GridSelectionMode.MULTIPLE_CELLS)
+                extendSelection(rowIndex, columnIndex);
+        }
+        else
+        {
+            // click sets the selection and updates the caret and anchor positions.
+            setSelectionAnchorCaret(rowIndex, columnIndex);
+        }
+    }
+
     /**
      *  @private
      *  Redispatch the grid's "caretChange" event.
@@ -6189,40 +6190,11 @@ public class DataGrid extends SkinnableContainerBase
         }
     }
     
-    private function removeMouseHandlersForDragStart(event:GridEvent):void
+    private function removeMouseHandlersForDragStart(event:MouseEvent):void
     {
         // If dragging failed, but we had a pending selection, commit it here
         if (pendingSelectionOnMouseUp && !DragManager.isDragging)
-        {
-            const rowIndex:int = mouseDownRowIndex;
-            const columnIndex:int = mouseDownColumnIndex;
-            
-            if (event.ctrlKey)
-            {
-                // ctrl-click toggles the selection and updates caret and anchor.
-                if (!toggleSelection(rowIndex, columnIndex))
-                    return;
-                
-                grid.anchorRowIndex = rowIndex;
-                grid.anchorColumnIndex = columnIndex;
-            }
-            else if (event.shiftKey)
-            {
-                // shift-click extends the selection and updates the caret.
-                if  (grid.selectionMode == GridSelectionMode.MULTIPLE_ROWS || 
-                    grid.selectionMode == GridSelectionMode.MULTIPLE_CELLS)
-                {    
-                    if (!extendSelection(rowIndex, columnIndex))
-                        return;
-                }
-            }
-            else
-            {
-                // click sets the selection and updates the caret and anchor 
-                // positions.
-                setSelectionAnchorCaret(rowIndex, columnIndex);
-            }           
-        }
+            adjustSelection(event, mouseDownRowIndex, mouseDownColumnIndex);
         
         // Always clean up the flag, even if currently dragging.
         pendingSelectionOnMouseUp = false;
@@ -6371,8 +6343,8 @@ public class DataGrid extends SkinnableContainerBase
      *
      *  @param event The DragEvent object.
      * 
-     *  @see spark.layouts.LayoutBase#showDropIndicator
-     *  @see spark.layouts.LayoutBase#hideDropIndicator
+     *  @see spark.layouts.supportClasses.LayoutBase#showDropIndicator
+     *  @see spark.layouts.supportClasses.LayoutBase#hideDropIndicator
      *  
      *  @langversion 3.0
      *  @playerversion Flash 11
@@ -6428,8 +6400,8 @@ public class DataGrid extends SkinnableContainerBase
      *
      *  @param event The DragEvent object.
      *  
-     *  @see spark.layouts.LayoutBase#showDropIndicator
-     *  @see spark.layouts.LayoutBase#hideDropIndicator
+     *  @see spark.layouts.supportClasses.LayoutBase#showDropIndicator
+     *  @see spark.layouts.supportClasses.LayoutBase#hideDropIndicator
      *  
      *  @langversion 3.0
      *  @playerversion Flash 11
@@ -6479,8 +6451,8 @@ public class DataGrid extends SkinnableContainerBase
      *
      *  @param event The DragEvent object.
      *  
-     *  @see spark.layouts.LayoutBase#showDropIndicator
-     *  @see spark.layouts.LayoutBase#hideDropIndicator
+     *  @see spark.layouts.supportClasses.LayoutBase#showDropIndicator
+     *  @see spark.layouts.supportClasses.LayoutBase#hideDropIndicator
      *  
      *  @langversion 3.0
      *  @playerversion Flash 11