diff options
author | Matti Tahvonen <matti.tahvonen@itmill.com> | 2011-11-21 13:38:31 +0000 |
---|---|---|
committer | Matti Tahvonen <matti.tahvonen@itmill.com> | 2011-11-21 13:38:31 +0000 |
commit | fdc8e9a3445612adb21e620ca9822455663e34ba (patch) | |
tree | 51e17ed9913d7cbf374788f5c5e8a651e527494c /tests | |
parent | e8f99a58c30d2813f0ddc60787fe7dc8774dac4e (diff) | |
download | vaadin-framework-fdc8e9a3445612adb21e620ca9822455663e34ba.tar.gz vaadin-framework-fdc8e9a3445612adb21e620ca9822455663e34ba.zip |
dragandropwrapper can now initiate html5 drags, fixes #7833
svn changeset:22081/svn branch:6.8
Diffstat (limited to 'tests')
-rw-r--r-- | tests/testbench/com/vaadin/tests/dd/StartHtml5Drag.java | 65 | ||||
-rw-r--r-- | tests/testbench/com/vaadin/tests/dd/html5drop.html | 51 |
2 files changed, 116 insertions, 0 deletions
diff --git a/tests/testbench/com/vaadin/tests/dd/StartHtml5Drag.java b/tests/testbench/com/vaadin/tests/dd/StartHtml5Drag.java new file mode 100644 index 0000000000..5a682de8ce --- /dev/null +++ b/tests/testbench/com/vaadin/tests/dd/StartHtml5Drag.java @@ -0,0 +1,65 @@ +package com.vaadin.tests.dd; + +import com.vaadin.event.dd.DragAndDropEvent; +import com.vaadin.event.dd.DropHandler; +import com.vaadin.event.dd.acceptcriteria.AcceptAll; +import com.vaadin.event.dd.acceptcriteria.AcceptCriterion; +import com.vaadin.terminal.ClassResource; +import com.vaadin.terminal.Sizeable; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.DragAndDropWrapper; +import com.vaadin.ui.DragAndDropWrapper.DragStartMode; +import com.vaadin.ui.DragAndDropWrapper.WrapperTransferable; +import com.vaadin.ui.Embedded; +import com.vaadin.ui.Label; + +public class StartHtml5Drag extends TestBase { + + @Override + protected void setup() { + DragAndDropWrapper dragStart = new DragAndDropWrapper(new Label( + "Drag me")); + dragStart.setDragStartMode(DragStartMode.HTML5); + dragStart.setHTML5DataFlavor("Text", "HTML5!"); + addComponent(dragStart); + + DragAndDropWrapper dropTarget = new DragAndDropWrapper(new Label( + "over here")); + dropTarget.setDropHandler(new DropHandler() { + + public AcceptCriterion getAcceptCriterion() { + return AcceptAll.get(); + } + + public void drop(DragAndDropEvent event) { + getWindows() + .iterator() + .next() + .showNotification( + ((WrapperTransferable) event.getTransferable()) + .getText()); + } + }); + addComponent(dropTarget); + + Embedded iframe = new Embedded("", new ClassResource("html5drop.html", + this)); + iframe.setType(Embedded.TYPE_BROWSER); + iframe.setWidth(400, Sizeable.UNITS_PIXELS); + iframe.setHeight(400, Sizeable.UNITS_PIXELS); + addComponent(iframe); + + } + + @Override + protected String getDescription() { + return "Should work. Try to e.g. drag the 'Hello Vaadin user' " + + "label to native text editor application. In text " + + "editor app 'HTML5!' text should appear."; + } + + @Override + protected Integer getTicketNumber() { + return 7833; + } +} diff --git a/tests/testbench/com/vaadin/tests/dd/html5drop.html b/tests/testbench/com/vaadin/tests/dd/html5drop.html new file mode 100644 index 0000000000..ed05fcedea --- /dev/null +++ b/tests/testbench/com/vaadin/tests/dd/html5drop.html @@ -0,0 +1,51 @@ +<!DOCTYPE html> +<html> +<head> +<meta charset="UTF-8"> +<title>Insert title here</title> +<script type="text/javascript"> + if (window.addEventListener) { + window.addEventListener('load', init, false); //W3C + } else { + window.attachEvent('onload', init); //IE + } + + function init(event) { + var el = document.getElementById("drop"); + if (el.addEventListener) { + el.addEventListener("dragover", dragover, false); + el.addEventListener("dragenter", dragenter, false); + el.addEventListener("drop", drop, false); + } else if (el.attachEvent) { + el.attachEvent('ondragover', dragover); + el.attachEvent('ondragenter', dragenter); + el.attachEvent('ondrop', drop); + } + } + + function dragover(event) { + event.dataTransfer.dropEffect = 'copy'; + return cancel(event); + } + + function drop(event) { + document.getElementById("drop").innerHTML = event.dataTransfer.getData('Text'); + return cancel(event); + } + + function dragenter(event) { + return cancel(event); + } + + function cancel(event) { + if (event.preventDefault) { + event.preventDefault(); + } + return false; + } +</script> +</head> +<body> + <div id="drop">or over here</div> +</body> +</html>
\ No newline at end of file |