]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixes exception when dragging on cells in Chrome (#13334)
authorHenrik Paul <henrik@vaadin.com>
Thu, 16 Oct 2014 12:54:56 +0000 (15:54 +0300)
committerHenrik Paul <henrik@vaadin.com>
Fri, 24 Oct 2014 10:09:16 +0000 (13:09 +0300)
Change-Id: I67b16e15884d9d44d99fcd1fa8063559babcb856

client/src/com/vaadin/client/ui/grid/Grid.java

index 38590507aa8a8c3001ce93a3025c182023fa59b5..dcb34fd8cc7973e488f1406ec772f67141974618 100644 (file)
@@ -770,6 +770,22 @@ public class Grid<T> extends ResizeComposite implements
 
     private boolean dataIsBeingFetched = false;
 
+    /**
+     * The cell a click event originated from
+     * <p>
+     * This is a workaround to make Chrome work like Firefox. In Chrome,
+     * normally if you start a drag on one cell and release on:
+     * <ul>
+     * <li>that same cell, the click event is that {@code <td>}.
+     * <li>a cell on that same row, the click event is the parent {@code <tr>}.
+     * <li>a cell on another row, the click event is the table section ancestor
+     * ({@code <thead>}, {@code <tbody>} or {@code <tfoot>}).
+     * </ul>
+     * 
+     * @see #onBrowserEvent(Event)
+     */
+    private Cell cellOnPrevMouseDown;
+
     /**
      * Enumeration for easy setting of selection mode.
      */
@@ -2282,15 +2298,32 @@ public class Grid<T> extends ResizeComposite implements
         RowContainer container = escalator.findRowContainer(e);
         Cell cell;
         boolean isGrid = Util.findWidget(e, null) == this;
+
         if (container == null) {
             // TODO: Add a check to catch mouse click outside of table but
             // inside of grid
             cell = activeCellHandler.getActiveCell();
             container = activeCellHandler.container;
-        } else {
+        }
+
+        else {
             cell = container.getCell(e);
+            if (event.getType().equals(BrowserEvents.MOUSEDOWN)) {
+                cellOnPrevMouseDown = cell;
+            } else if (cell == null
+                    && event.getType().equals(BrowserEvents.CLICK)) {
+                /*
+                 * Chrome has an interesting idea on click targets (see
+                 * cellOnPrevMouseDown javadoc). Firefox, on the other hand, has
+                 * the mousedown target as the click target.
+                 */
+                cell = cellOnPrevMouseDown;
+            }
         }
 
+        assert cell != null : "received " + event.getType()
+                + "-event with a null cell target";
+
         // Editor Row can steal focus from Grid and is still handled
         if (handleEditorRowEvent(event, container, cell)) {
             return;