From: Henrik Paul Date: Thu, 16 Oct 2014 12:54:56 +0000 (+0300) Subject: Fixes exception when dragging on cells in Chrome (#13334) X-Git-Tag: 7.4.0.beta1~9^2~130 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c430aa77c2fee0742cfd8c5e6df5397933dba9b8;p=vaadin-framework.git Fixes exception when dragging on cells in Chrome (#13334) Change-Id: I67b16e15884d9d44d99fcd1fa8063559babcb856 --- diff --git a/client/src/com/vaadin/client/ui/grid/Grid.java b/client/src/com/vaadin/client/ui/grid/Grid.java index 38590507aa..dcb34fd8cc 100644 --- a/client/src/com/vaadin/client/ui/grid/Grid.java +++ b/client/src/com/vaadin/client/ui/grid/Grid.java @@ -770,6 +770,22 @@ public class Grid extends ResizeComposite implements private boolean dataIsBeingFetched = false; + /** + * The cell a click event originated from + *

+ * This is a workaround to make Chrome work like Firefox. In Chrome, + * normally if you start a drag on one cell and release on: + *

+ * + * @see #onBrowserEvent(Event) + */ + private Cell cellOnPrevMouseDown; + /** * Enumeration for easy setting of selection mode. */ @@ -2282,15 +2298,32 @@ public class Grid 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;