From 46a0731a5bd6a51d0e7b80c2d596df29bc271710 Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Wed, 18 Nov 2015 11:46:23 +0100 Subject: Prevent text selection while DnD resizing columns (#16838) This patch uses a JavaScript workaround to prevent text selection in IE8 and IE9 and Safari. The selection is prevented everywhere in the DOM while a column is resizing. Change-Id: I1e7b9cdc675c83a9666493d8545337d601e40077 --- client/src/com/vaadin/client/WidgetUtil.java | 23 +++++++++++++++++++++++ client/src/com/vaadin/client/widgets/Grid.java | 9 +++++++++ 2 files changed, 32 insertions(+) (limited to 'client') diff --git a/client/src/com/vaadin/client/WidgetUtil.java b/client/src/com/vaadin/client/WidgetUtil.java index e9ec163612..b0e0030769 100644 --- a/client/src/com/vaadin/client/WidgetUtil.java +++ b/client/src/com/vaadin/client/WidgetUtil.java @@ -1306,6 +1306,29 @@ public class WidgetUtil { } }-*/; + /** + * JavaScript hack to prevent text selection in various browsers. + * + * @since + * @param e + * element for enabling or disabling text selection + * @param enable + * true if selection is enabled; false + * if not + */ + public native static void setTextSelectionEnabled(Element e, boolean enable) + /*-{ + if (!enable) { + e.ondrag = function () { return false; }; + e.onselectstart = function () { return false; }; + e.style.webkitUserSelect = "none"; + } else { + e.ondrag = null; + e.onselectstart = null; + e.style.webkitUserSelect = "text"; + } + }-*/; + /** * The allowed value inaccuracy when comparing two double-typed pixel * values. diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index a5a93c19ef..33672517fe 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -36,6 +36,7 @@ import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.core.shared.GWT; import com.google.gwt.dom.client.BrowserEvents; import com.google.gwt.dom.client.DivElement; +import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.EventTarget; import com.google.gwt.dom.client.NativeEvent; @@ -5580,16 +5581,24 @@ public class Grid extends ResizeComposite implements c)); } } + WidgetUtil.setTextSelectionEnabled(Document + .get().getBody(), false); } @Override public void onComplete() { fireEvent(new ColumnResizeEvent(col)); + + WidgetUtil.setTextSelectionEnabled(Document + .get().getBody(), true); } @Override public void onCancel() { col.setWidth(initialWidth); + + WidgetUtil.setTextSelectionEnabled(Document + .get().getBody(), true); } }); dragger.addTo(td); -- cgit v1.2.3