From b0b9cc3389e2ae9e570fb698605bf923f042f222 Mon Sep 17 00:00:00 2001 From: Juho Nurminen Date: Thu, 14 Aug 2014 17:54:24 +0300 Subject: Update VBrowserDetails to handle the new IE11 UA on WP 8.1 Update (#14376) Change-Id: I7fdd091a3b2994270e9928eb4f118ab5ca59ef30 --- shared/src/com/vaadin/shared/VBrowserDetails.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'shared/src') diff --git a/shared/src/com/vaadin/shared/VBrowserDetails.java b/shared/src/com/vaadin/shared/VBrowserDetails.java index 3680e4168e..81a39cdedc 100644 --- a/shared/src/com/vaadin/shared/VBrowserDetails.java +++ b/shared/src/com/vaadin/shared/VBrowserDetails.java @@ -68,19 +68,19 @@ public class VBrowserDetails implements Serializable { isGecko = userAgent.indexOf("gecko") != -1 && userAgent.indexOf("webkit") == -1 && userAgent.indexOf("trident/") == -1; - isWebKit = userAgent.indexOf("applewebkit") != -1; isPresto = userAgent.indexOf(" presto/") != -1; isTrident = userAgent.indexOf("trident/") != -1; + isWebKit = !isTrident && userAgent.indexOf("applewebkit") != -1; // browser name isChrome = userAgent.indexOf(" chrome/") != -1; - isSafari = !isChrome && userAgent.indexOf("safari") != -1; isOpera = userAgent.indexOf("opera") != -1; isIE = userAgent.indexOf("msie") != -1 && !isOpera && (userAgent.indexOf("webtv") == -1); // IE 11 no longer contains MSIE in the user agent isIE = isIE || isTrident; + isSafari = !isChrome && !isIE && userAgent.indexOf("safari") != -1; isFirefox = userAgent.indexOf(" firefox/") != -1; // chromeframe -- cgit v1.2.3 From 1020faa337eddeb07f141cb7ef12fbb20bd2ded2 Mon Sep 17 00:00:00 2001 From: Sebastian Nyholm Date: Tue, 27 May 2014 14:46:47 +0300 Subject: Fixes DragAndDropWrapper does not support choosing a custom component as the drag image (#13836) Amend : Fixes the comments for the last commit. Amend 2: Fixes a nullpointer found in a certain test scenario Change-Id: I72327f5f8ab9e46d88e1ebed8f1db3a7da39d7d8 --- .../com/vaadin/client/ui/VDragAndDropWrapper.java | 27 +++++++++++++- .../DragAndDropWrapperConnector.java | 26 ++++++++++++++ server/src/com/vaadin/ui/DragAndDropWrapper.java | 41 ++++++++++++++++++++++ .../DragAndDropWrapperConstants.java | 2 ++ .../draganddropwrapper/DragStartModes.java | 31 ++++++++++++++-- .../draganddropwrapper/DragStartModesTest.java | 1 + 6 files changed, 125 insertions(+), 3 deletions(-) (limited to 'shared/src') diff --git a/client/src/com/vaadin/client/ui/VDragAndDropWrapper.java b/client/src/com/vaadin/client/ui/VDragAndDropWrapper.java index 4010ffd542..7bf341a387 100644 --- a/client/src/com/vaadin/client/ui/VDragAndDropWrapper.java +++ b/client/src/com/vaadin/client/ui/VDragAndDropWrapper.java @@ -114,7 +114,8 @@ public class VDragAndDropWrapper extends VCustomComponent implements * @return true if the event was handled as a drag start event */ private boolean startDrag(NativeEvent event) { - if (dragStartMode == WRAPPER || dragStartMode == COMPONENT) { + if (dragStartMode == WRAPPER || dragStartMode == COMPONENT + || dragStartMode == COMPONENT_OTHER) { VTransferable transferable = new VTransferable(); transferable.setDragSource(getConnector()); @@ -130,6 +131,10 @@ public class VDragAndDropWrapper extends VCustomComponent implements if (dragStartMode == WRAPPER) { dragEvent.createDragImage(getElement(), true); + } else if (dragStartMode == COMPONENT_OTHER + && getDragImageWidget() != null) { + dragEvent.createDragImage(getDragImageWidget().getElement(), + true); } else { dragEvent.createDragImage(widget.getElement(), true); } @@ -142,6 +147,7 @@ public class VDragAndDropWrapper extends VCustomComponent implements protected final static int COMPONENT = 1; protected final static int WRAPPER = 2; protected final static int HTML5 = 3; + protected final static int COMPONENT_OTHER = 4; /** For internal use only. May be removed or replaced in the future. */ public int dragStartMode; @@ -458,6 +464,7 @@ public class VDragAndDropWrapper extends VCustomComponent implements * Flag used by html5 dd */ private boolean currentlyValid; + private Widget dragImageWidget; private static final String OVER_STYLE = "v-ddwrapper-over"; @@ -661,4 +668,22 @@ public class VDragAndDropWrapper extends VCustomComponent implements notifySizePotentiallyChanged(); } + /** + * Set the widget that will be used as the drag image when using + * DragStartMode {@link COMPONENT_OTHER} . + * + * @param widget + */ + public void setDragAndDropWidget(Widget widget) { + dragImageWidget = widget; + } + + /** + * @return the widget used as drag image. Returns null if no + * widget is set. + */ + public Widget getDragImageWidget() { + return dragImageWidget; + } + } diff --git a/client/src/com/vaadin/client/ui/draganddropwrapper/DragAndDropWrapperConnector.java b/client/src/com/vaadin/client/ui/draganddropwrapper/DragAndDropWrapperConnector.java index afb521b141..f222721e24 100644 --- a/client/src/com/vaadin/client/ui/draganddropwrapper/DragAndDropWrapperConnector.java +++ b/client/src/com/vaadin/client/ui/draganddropwrapper/DragAndDropWrapperConnector.java @@ -17,8 +17,12 @@ package com.vaadin.client.ui.draganddropwrapper; import java.util.HashMap; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; import com.vaadin.client.ApplicationConnection; +import com.vaadin.client.ComponentConnector; +import com.vaadin.client.ConnectorMap; import com.vaadin.client.Paintable; import com.vaadin.client.UIDL; import com.vaadin.client.VConsole; @@ -81,6 +85,25 @@ public class DragAndDropWrapperConnector extends CustomComponentConnector getWidget().dragStartMode = uidl .getIntAttribute(DragAndDropWrapperConstants.DRAG_START_MODE); + + String dragImageComponentConnectorId = uidl + .getStringAttribute(DragAndDropWrapperConstants.DRAG_START_COMPONENT_ATTRIBUTE); + + ComponentConnector connector = null; + if (dragImageComponentConnectorId != null) { + connector = (ComponentConnector) ConnectorMap.get(client) + .getConnector(dragImageComponentConnectorId); + + if (connector == null) { + getLogger().log( + Level.WARNING, + "DragAndDropWrapper drag image component" + + " connector now found. Make sure the" + + " component is attached."); + } else { + getWidget().setDragAndDropWidget(connector.getWidget()); + } + } getWidget().initDragStartMode(); getWidget().html5DataFlavors = uidl .getMapAttribute(DragAndDropWrapperConstants.HTML5_DATA_FLAVORS); @@ -95,4 +118,7 @@ public class DragAndDropWrapperConnector extends CustomComponentConnector return (VDragAndDropWrapper) super.getWidget(); } + private static Logger getLogger() { + return Logger.getLogger(DragAndDropWrapperConnector.class.getName()); + } } diff --git a/server/src/com/vaadin/ui/DragAndDropWrapper.java b/server/src/com/vaadin/ui/DragAndDropWrapper.java index 3d3356b338..0e2e8f6d2f 100644 --- a/server/src/com/vaadin/ui/DragAndDropWrapper.java +++ b/server/src/com/vaadin/ui/DragAndDropWrapper.java @@ -180,10 +180,17 @@ public class DragAndDropWrapper extends CustomComponent implements DropTarget, * the wrapper will no longer work. */ HTML5, + + /** + * Uses the component defined in + * {@link #setDragImageComponent(Component)} as the drag image. + */ + COMPONENT_OTHER, } private final Map html5DataFlavors = new LinkedHashMap(); private DragStartMode dragStartMode = DragStartMode.NONE; + private Component dragImageComponent = null; private Set sentIds = new HashSet(); @@ -227,6 +234,19 @@ public class DragAndDropWrapper extends CustomComponent implements DropTarget, public void paintContent(PaintTarget target) throws PaintException { target.addAttribute(DragAndDropWrapperConstants.DRAG_START_MODE, dragStartMode.ordinal()); + + if (dragStartMode.equals(DragStartMode.COMPONENT_OTHER)) { + if (dragImageComponent != null) { + target.addAttribute( + DragAndDropWrapperConstants.DRAG_START_COMPONENT_ATTRIBUTE, + dragImageComponent.getConnectorId()); + } else { + throw new IllegalArgumentException( + "DragStartMode.COMPONENT_OTHER set but no component " + + "was defined. Please set a component using DragAnd" + + "DropWrapper.setDragStartComponent(Component)."); + } + } if (getDropHandler() != null) { getDropHandler().getAcceptCriterion().paint(target); } @@ -300,6 +320,27 @@ public class DragAndDropWrapper extends CustomComponent implements DropTarget, return dragStartMode; } + /** + * Sets the component that will be used as the drag image. Only used when + * wrapper is set to {@link DragStartMode#COMPONENT_OTHER} + * + * @param dragImageComponent + */ + public void setDragImageComponent(Component dragImageComponent) { + this.dragImageComponent = dragImageComponent; + markAsDirty(); + } + + /** + * Gets the component that will be used as the drag image. Only used when + * wrapper is set to {@link DragStartMode#COMPONENT_OTHER} + * + * @return null if no component is set. + */ + public Component getDragImageComponent() { + return dragImageComponent; + } + final class ProxyReceiver implements StreamVariable { private String id; diff --git a/shared/src/com/vaadin/shared/ui/draganddropwrapper/DragAndDropWrapperConstants.java b/shared/src/com/vaadin/shared/ui/draganddropwrapper/DragAndDropWrapperConstants.java index 8dd8ef513e..9dda86ad73 100644 --- a/shared/src/com/vaadin/shared/ui/draganddropwrapper/DragAndDropWrapperConstants.java +++ b/shared/src/com/vaadin/shared/ui/draganddropwrapper/DragAndDropWrapperConstants.java @@ -25,4 +25,6 @@ public class DragAndDropWrapperConstants implements Serializable { @Deprecated public static final String DRAG_START_MODE = "dragStartMode"; + public static final String DRAG_START_COMPONENT_ATTRIBUTE = "dragStartComponent"; + } diff --git a/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragStartModes.java b/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragStartModes.java index b143ddf2dc..8539f70b17 100644 --- a/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragStartModes.java +++ b/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragStartModes.java @@ -3,26 +3,53 @@ package com.vaadin.tests.components.draganddropwrapper; import com.vaadin.tests.components.TestBase; import com.vaadin.tests.util.TestUtils; import com.vaadin.ui.Component; +import com.vaadin.ui.CssLayout; import com.vaadin.ui.DragAndDropWrapper; import com.vaadin.ui.DragAndDropWrapper.DragStartMode; import com.vaadin.ui.Label; +import com.vaadin.ui.VerticalLayout; public class DragStartModes extends TestBase { @Override protected void setup() { - TestUtils.injectCSS(getMainWindow(), - ".v-ddwrapper { background: #ACF; }"); + TestUtils + .injectCSS(getMainWindow(), + ".v-ddwrapper { background: #ACF; } .extra{ background: #FFA500; }"); addComponent(makeWrapper(DragStartMode.NONE)); addComponent(makeWrapper(DragStartMode.COMPONENT)); addComponent(makeWrapper(DragStartMode.WRAPPER)); addComponent(makeWrapper(DragStartMode.HTML5)); + addComponent(makeOtherComponentWrapper(DragStartMode.COMPONENT_OTHER)); addComponent(new Label("Drop here")); } + private Component makeOtherComponentWrapper(DragStartMode componentOther) { + VerticalLayout parent = new VerticalLayout(); + parent.setWidth("200px"); + parent.setSpacing(true); + + CssLayout header = new CssLayout(); + header.addComponent(new Label("Drag start mode : COMPONENT_OTHER")); + header.setSizeUndefined(); + + DragAndDropWrapper wrapper = new DragAndDropWrapper(header); + wrapper.setDragStartMode(DragStartMode.COMPONENT_OTHER); + wrapper.setDragImageComponent(parent); + wrapper.setId("label" + "COMPONENT_OTHER"); + parent.addComponent(wrapper); + + Label extra = new Label( + "Extra label that is not part of the wrapper. This should be dragged along with COMPONENT_OTHER."); + extra.addStyleName("extra"); + parent.addComponent(extra); + + return parent; + } + private Component makeWrapper(DragStartMode mode) { Label label = new Label("Drag start mode: " + mode); label.setId("label" + mode); diff --git a/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragStartModesTest.java b/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragStartModesTest.java index 25aef1b815..ba27ee293e 100644 --- a/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragStartModesTest.java +++ b/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragStartModesTest.java @@ -31,6 +31,7 @@ public class DragStartModesTest extends MultiBrowserTest { WebElement dropTarget = vaadinElement("/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[0]"); dragToTarget("COMPONENT", dropTarget); dragToTarget("WRAPPER", dropTarget); + dragToTarget("COMPONENT_OTHER", dropTarget); } private void dragToTarget(String dragMode, WebElement dropTarget) -- cgit v1.2.3