Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

VDragAndDropWrapper.java 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client.ui;
  17. import java.util.ArrayList;
  18. import java.util.List;
  19. import java.util.Map;
  20. import com.google.gwt.core.client.GWT;
  21. import com.google.gwt.core.client.JsArrayString;
  22. import com.google.gwt.core.client.Scheduler;
  23. import com.google.gwt.dom.client.Element;
  24. import com.google.gwt.dom.client.NativeEvent;
  25. import com.google.gwt.event.dom.client.MouseDownEvent;
  26. import com.google.gwt.event.dom.client.MouseDownHandler;
  27. import com.google.gwt.event.dom.client.MouseUpEvent;
  28. import com.google.gwt.event.dom.client.MouseUpHandler;
  29. import com.google.gwt.event.dom.client.TouchStartEvent;
  30. import com.google.gwt.event.dom.client.TouchStartHandler;
  31. import com.google.gwt.user.client.Command;
  32. import com.google.gwt.user.client.DOM;
  33. import com.google.gwt.user.client.Event;
  34. import com.google.gwt.user.client.Timer;
  35. import com.google.gwt.user.client.ui.Widget;
  36. import com.google.gwt.xhr.client.ReadyStateChangeHandler;
  37. import com.google.gwt.xhr.client.XMLHttpRequest;
  38. import com.vaadin.client.ApplicationConnection;
  39. import com.vaadin.client.ComponentConnector;
  40. import com.vaadin.client.ConnectorMap;
  41. import com.vaadin.client.LayoutManager;
  42. import com.vaadin.client.MouseEventDetailsBuilder;
  43. import com.vaadin.client.Util;
  44. import com.vaadin.client.VConsole;
  45. import com.vaadin.client.ValueMap;
  46. import com.vaadin.client.WidgetUtil;
  47. import com.vaadin.client.ui.dd.DDUtil;
  48. import com.vaadin.client.ui.dd.VAbstractDropHandler;
  49. import com.vaadin.client.ui.dd.VAcceptCallback;
  50. import com.vaadin.client.ui.dd.VDragAndDropManager;
  51. import com.vaadin.client.ui.dd.VDragEvent;
  52. import com.vaadin.client.ui.dd.VDropHandler;
  53. import com.vaadin.client.ui.dd.VHasDropHandler;
  54. import com.vaadin.client.ui.dd.VHtml5DragEvent;
  55. import com.vaadin.client.ui.dd.VHtml5File;
  56. import com.vaadin.client.ui.dd.VTransferable;
  57. import com.vaadin.shared.ui.dd.HorizontalDropLocation;
  58. import com.vaadin.shared.ui.dd.VerticalDropLocation;
  59. /**
  60. * A wrapper for Drag and Drop. Must have features pending:
  61. *
  62. * drop details: locations + sizes in document hierarchy up to wrapper
  63. *
  64. */
  65. public class VDragAndDropWrapper extends VCustomComponent
  66. implements VHasDropHandler {
  67. /**
  68. * Minimum pixel delta is used to detect click from drag. #12838
  69. */
  70. private static final int MIN_PX_DELTA = 4;
  71. private static final String CLASSNAME = "v-ddwrapper";
  72. protected static final String DRAGGABLE = "draggable";
  73. /** For internal use only. May be removed or replaced in the future. */
  74. public boolean hasTooltip = false;
  75. private int startX = 0;
  76. private int startY = 0;
  77. public VDragAndDropWrapper() {
  78. super();
  79. hookHtml5Events(getElement());
  80. setStyleName(CLASSNAME);
  81. addDomHandler(new MouseDownHandler() {
  82. @Override
  83. public void onMouseDown(final MouseDownEvent event) {
  84. if (getConnector().isEnabled()
  85. && event.getNativeEvent()
  86. .getButton() == Event.BUTTON_LEFT
  87. && startDrag(event.getNativeEvent())) {
  88. event.preventDefault(); // prevent text selection
  89. startX = event.getClientX();
  90. startY = event.getClientY();
  91. }
  92. }
  93. }, MouseDownEvent.getType());
  94. addDomHandler(new MouseUpHandler() {
  95. @Override
  96. public void onMouseUp(final MouseUpEvent event) {
  97. final int deltaX = Math.abs(event.getClientX() - startX);
  98. final int deltaY = Math.abs(event.getClientY() - startY);
  99. if ((deltaX + deltaY) < MIN_PX_DELTA) {
  100. Element clickedElement = WidgetUtil.getElementFromPoint(
  101. event.getClientX(), event.getClientY());
  102. clickedElement.focus();
  103. }
  104. }
  105. }, MouseUpEvent.getType());
  106. addDomHandler(new TouchStartHandler() {
  107. @Override
  108. public void onTouchStart(TouchStartEvent event) {
  109. if (getConnector().isEnabled()
  110. && startDrag(event.getNativeEvent())) {
  111. /*
  112. * Dont let eg. panel start scrolling.
  113. */
  114. event.stopPropagation();
  115. }
  116. }
  117. }, TouchStartEvent.getType());
  118. sinkEvents(Event.TOUCHEVENTS);
  119. }
  120. /**
  121. * Starts a drag and drop operation from mousedown or touchstart event if
  122. * required conditions are met.
  123. *
  124. * @param event
  125. * @return true if the event was handled as a drag start event
  126. */
  127. private boolean startDrag(NativeEvent event) {
  128. if (dragStartMode == WRAPPER || dragStartMode == COMPONENT
  129. || dragStartMode == COMPONENT_OTHER) {
  130. VTransferable transferable = new VTransferable();
  131. transferable.setDragSource(getConnector());
  132. ComponentConnector paintable = Util.findPaintable(client,
  133. Element.as(event.getEventTarget()));
  134. Widget widget = paintable.getWidget();
  135. transferable.setData("component", paintable);
  136. VDragEvent dragEvent = VDragAndDropManager.get()
  137. .startDrag(transferable, event, true);
  138. transferable.setData("mouseDown", MouseEventDetailsBuilder
  139. .buildMouseEventDetails(event).serialize());
  140. if (dragStartMode == WRAPPER) {
  141. dragEvent.createDragImage(getElement(), true);
  142. } else if (dragStartMode == COMPONENT_OTHER
  143. && getDragImageWidget() != null) {
  144. dragEvent.createDragImage(getDragImageWidget().getElement(),
  145. true);
  146. } else {
  147. dragEvent.createDragImage(widget.getElement(), true);
  148. }
  149. return true;
  150. }
  151. return false;
  152. }
  153. protected static final int NONE = 0;
  154. protected static final int COMPONENT = 1;
  155. protected static final int WRAPPER = 2;
  156. protected static final int HTML5 = 3;
  157. protected static final int COMPONENT_OTHER = 4;
  158. /** For internal use only. May be removed or replaced in the future. */
  159. public int dragStartMode;
  160. /** For internal use only. May be removed or replaced in the future. */
  161. public ApplicationConnection client;
  162. /** For internal use only. May be removed or replaced in the future. */
  163. public VAbstractDropHandler dropHandler;
  164. /** For internal use only. May be removed or replaced in the future. */
  165. public UploadHandler uploadHandler;
  166. private VDragEvent vaadinDragEvent;
  167. int filecounter = 0;
  168. /** For internal use only. May be removed or replaced in the future. */
  169. public Map<String, String> fileIdToReceiver;
  170. /** For internal use only. May be removed or replaced in the future. */
  171. public ValueMap html5DataFlavors;
  172. private Element dragStartElement;
  173. /** For internal use only. May be removed or replaced in the future. */
  174. public void initDragStartMode() {
  175. Element div = getElement();
  176. if (dragStartMode == HTML5) {
  177. if (dragStartElement == null) {
  178. dragStartElement = getDragStartElement();
  179. dragStartElement.setPropertyBoolean(DRAGGABLE, true);
  180. VConsole.log("draggable = "
  181. + dragStartElement.getPropertyBoolean(DRAGGABLE));
  182. hookHtml5DragStart(dragStartElement);
  183. VConsole.log("drag start listeners hooked.");
  184. }
  185. } else {
  186. dragStartElement = null;
  187. if (div.hasAttribute(DRAGGABLE)) {
  188. div.removeAttribute(DRAGGABLE);
  189. }
  190. }
  191. }
  192. protected com.google.gwt.user.client.Element getDragStartElement() {
  193. return getElement();
  194. }
  195. private boolean uploading;
  196. private final ReadyStateChangeHandler readyStateChangeHandler = new ReadyStateChangeHandler() {
  197. @Override
  198. public void onReadyStateChange(XMLHttpRequest xhr) {
  199. if (xhr.getReadyState() == XMLHttpRequest.DONE) {
  200. // #19616 Notify the upload handler that the request is complete
  201. // and let it poll the server for changes.
  202. uploadHandler.uploadDone();
  203. uploading = false;
  204. startNextUpload();
  205. xhr.clearOnReadyStateChange();
  206. }
  207. }
  208. };
  209. private Timer dragleavetimer;
  210. /** For internal use only. May be removed or replaced in the future. */
  211. public void startNextUpload() {
  212. Scheduler.get().scheduleDeferred(new Command() {
  213. @Override
  214. public void execute() {
  215. if (!uploading) {
  216. if (!fileIds.isEmpty()) {
  217. uploading = true;
  218. final Integer fileId = fileIds.remove(0);
  219. VHtml5File file = files.remove(0);
  220. final String receiverUrl = client.translateVaadinUri(
  221. fileIdToReceiver.remove(fileId.toString()));
  222. ExtendedXHR extendedXHR = (ExtendedXHR) ExtendedXHR
  223. .create();
  224. extendedXHR
  225. .setOnReadyStateChange(readyStateChangeHandler);
  226. extendedXHR.open("POST", receiverUrl);
  227. extendedXHR.postFile(file);
  228. }
  229. }
  230. }
  231. });
  232. }
  233. public boolean html5DragStart(VHtml5DragEvent event) {
  234. if (dragStartMode == HTML5) {
  235. /*
  236. * Populate html5 payload with dataflavors from the serverside
  237. */
  238. JsArrayString flavors = html5DataFlavors.getKeyArray();
  239. for (int i = 0; i < flavors.length(); i++) {
  240. String flavor = flavors.get(i);
  241. event.setHtml5DataFlavor(flavor,
  242. html5DataFlavors.getString(flavor));
  243. }
  244. event.setEffectAllowed("copy");
  245. return true;
  246. }
  247. return false;
  248. }
  249. public boolean html5DragEnter(VHtml5DragEvent event) {
  250. if (dropHandler == null) {
  251. return true;
  252. }
  253. try {
  254. if (dragleavetimer != null) {
  255. // returned quickly back to wrapper
  256. dragleavetimer.cancel();
  257. dragleavetimer = null;
  258. }
  259. if (VDragAndDropManager.get()
  260. .getCurrentDropHandler() != getDropHandler()) {
  261. VTransferable transferable = new VTransferable();
  262. transferable.setDragSource(getConnector());
  263. vaadinDragEvent = VDragAndDropManager.get()
  264. .startDrag(transferable, event, false);
  265. VDragAndDropManager.get()
  266. .setCurrentDropHandler(getDropHandler());
  267. }
  268. try {
  269. event.preventDefault();
  270. event.stopPropagation();
  271. } catch (Exception e) {
  272. // VConsole.log("IE9 fails");
  273. }
  274. return false;
  275. } catch (Exception e) {
  276. GWT.getUncaughtExceptionHandler().onUncaughtException(e);
  277. return true;
  278. }
  279. }
  280. public boolean html5DragLeave(VHtml5DragEvent event) {
  281. if (dropHandler == null) {
  282. return true;
  283. }
  284. try {
  285. dragleavetimer = new Timer() {
  286. @Override
  287. public void run() {
  288. // Yes, dragleave happens before drop. Makes no sense to me.
  289. // IMO shouldn't fire leave at all if drop happens (I guess
  290. // this
  291. // is what IE does).
  292. // In Vaadin we fire it only if drop did not happen.
  293. if (vaadinDragEvent != null && VDragAndDropManager.get()
  294. .getCurrentDropHandler() == getDropHandler()) {
  295. VDragAndDropManager.get().interruptDrag();
  296. }
  297. }
  298. };
  299. dragleavetimer.schedule(350);
  300. try {
  301. event.preventDefault();
  302. event.stopPropagation();
  303. } catch (Exception e) {
  304. // VConsole.log("IE9 fails");
  305. }
  306. return false;
  307. } catch (Exception e) {
  308. GWT.getUncaughtExceptionHandler().onUncaughtException(e);
  309. return true;
  310. }
  311. }
  312. public boolean html5DragOver(VHtml5DragEvent event) {
  313. if (dropHandler == null) {
  314. return true;
  315. }
  316. if (dragleavetimer != null) {
  317. // returned quickly back to wrapper
  318. dragleavetimer.cancel();
  319. dragleavetimer = null;
  320. }
  321. vaadinDragEvent.setCurrentGwtEvent(event);
  322. getDropHandler().dragOver(vaadinDragEvent);
  323. try {
  324. String s = event.getEffectAllowed();
  325. if ("all".equals(s) || s.contains("opy")) {
  326. event.setDropEffect("copy");
  327. } else {
  328. event.setDropEffect(s);
  329. }
  330. } catch (Exception e) {
  331. // IE10 throws exception here in getEffectAllowed, ignore it, let
  332. // drop effect be whatever it is
  333. }
  334. try {
  335. event.preventDefault();
  336. event.stopPropagation();
  337. } catch (Exception e) {
  338. // VConsole.log("IE9 fails");
  339. }
  340. return false;
  341. }
  342. public boolean html5DragDrop(VHtml5DragEvent event) {
  343. if (dropHandler == null || !currentlyValid) {
  344. VDragAndDropManager.get().interruptDrag();
  345. return true;
  346. }
  347. try {
  348. VTransferable transferable = vaadinDragEvent.getTransferable();
  349. JsArrayString types = event.getTypes();
  350. for (int i = 0; i < types.length(); i++) {
  351. String type = types.get(i);
  352. if (isAcceptedType(type)) {
  353. String data = event.getDataAsText(type);
  354. if (data != null) {
  355. transferable.setData(type, data);
  356. }
  357. }
  358. }
  359. final int eventFileCount = event.getFileCount();
  360. int fileIndex = 0;
  361. for (int i = 0; i < eventFileCount; i++) {
  362. // Transfer only files and not folders
  363. if (event.isFile(i)) {
  364. final int fileId = filecounter++;
  365. final VHtml5File file = event.getFile(i);
  366. VConsole.log("Preparing to upload file " + file.getName()
  367. + " with id " + fileId + ", size="
  368. + file.getSize());
  369. transferable.setData("fi" + fileIndex, "" + fileId);
  370. transferable.setData("fn" + fileIndex, file.getName());
  371. transferable.setData("ft" + fileIndex, file.getType());
  372. transferable.setData("fs" + fileIndex, file.getSize());
  373. queueFilePost(fileId, file);
  374. fileIndex++;
  375. }
  376. }
  377. if (fileIndex > 0) {
  378. transferable.setData("filecount", fileIndex);
  379. }
  380. VDragAndDropManager.get().endDrag();
  381. vaadinDragEvent = null;
  382. try {
  383. event.preventDefault();
  384. event.stopPropagation();
  385. } catch (Exception e) {
  386. // VConsole.log("IE9 fails");
  387. }
  388. return false;
  389. } catch (Exception e) {
  390. GWT.getUncaughtExceptionHandler().onUncaughtException(e);
  391. return true;
  392. }
  393. }
  394. protected String[] acceptedTypes = { "Text", "Url", "text/html",
  395. "text/plain", "text/rtf" };
  396. private boolean isAcceptedType(String type) {
  397. for (String t : acceptedTypes) {
  398. if (t.equals(type)) {
  399. return true;
  400. }
  401. }
  402. return false;
  403. }
  404. static class ExtendedXHR extends XMLHttpRequest {
  405. protected ExtendedXHR() {
  406. }
  407. public final native void postFile(VHtml5File file)
  408. /*-{
  409. this.setRequestHeader('Content-Type', 'multipart/form-data');
  410. // Seems like IE10 will loose the file if we don't keep a reference to it...
  411. this.fileBeingUploaded = file;
  412. this.send(file);
  413. }-*/;
  414. }
  415. /** For internal use only. May be removed or replaced in the future. */
  416. public List<Integer> fileIds = new ArrayList<>();
  417. /** For internal use only. May be removed or replaced in the future. */
  418. public List<VHtml5File> files = new ArrayList<>();
  419. private void queueFilePost(final int fileId, final VHtml5File file) {
  420. fileIds.add(fileId);
  421. files.add(file);
  422. }
  423. @Override
  424. public VDropHandler getDropHandler() {
  425. return dropHandler;
  426. }
  427. protected VerticalDropLocation verticalDropLocation;
  428. protected HorizontalDropLocation horizontalDropLocation;
  429. private VerticalDropLocation emphasizedVDrop;
  430. private HorizontalDropLocation emphasizedHDrop;
  431. /**
  432. * Flag used by html5 dd
  433. */
  434. private boolean currentlyValid;
  435. private Widget dragImageWidget;
  436. private static final String OVER_STYLE = "v-ddwrapper-over";
  437. public class CustomDropHandler extends VAbstractDropHandler {
  438. @Override
  439. public void dragEnter(VDragEvent drag) {
  440. if (!getConnector().isEnabled()) {
  441. return;
  442. }
  443. updateDropDetails(drag);
  444. currentlyValid = false;
  445. super.dragEnter(drag);
  446. }
  447. @Override
  448. public void dragLeave(VDragEvent drag) {
  449. deEmphasis(true);
  450. dragleavetimer = null;
  451. }
  452. @Override
  453. public void dragOver(final VDragEvent drag) {
  454. if (!getConnector().isEnabled()) {
  455. return;
  456. }
  457. boolean detailsChanged = updateDropDetails(drag);
  458. if (detailsChanged) {
  459. currentlyValid = false;
  460. validate(new VAcceptCallback() {
  461. @Override
  462. public void accepted(VDragEvent event) {
  463. dragAccepted(drag);
  464. }
  465. }, drag);
  466. }
  467. }
  468. @Override
  469. public boolean drop(VDragEvent drag) {
  470. if (!getConnector().isEnabled()) {
  471. return false;
  472. }
  473. deEmphasis(true);
  474. Map<String, Object> dd = drag.getDropDetails();
  475. // this is absolute layout based, and we may want to set
  476. // component
  477. // relatively to where the drag ended.
  478. // need to add current location of the drop area
  479. int absoluteLeft = getAbsoluteLeft();
  480. int absoluteTop = getAbsoluteTop();
  481. dd.put("absoluteLeft", absoluteLeft);
  482. dd.put("absoluteTop", absoluteTop);
  483. if (verticalDropLocation != null) {
  484. dd.put("verticalLocation", verticalDropLocation.toString());
  485. dd.put("horizontalLocation", horizontalDropLocation.toString());
  486. }
  487. return super.drop(drag);
  488. }
  489. @Override
  490. protected void dragAccepted(VDragEvent drag) {
  491. if (!getConnector().isEnabled()) {
  492. return;
  493. }
  494. currentlyValid = true;
  495. emphasis(drag);
  496. }
  497. @Override
  498. public ComponentConnector getConnector() {
  499. return VDragAndDropWrapper.this.getConnector();
  500. }
  501. @Override
  502. public ApplicationConnection getApplicationConnection() {
  503. return client;
  504. }
  505. }
  506. public ComponentConnector getConnector() {
  507. return ConnectorMap.get(client).getConnector(this);
  508. }
  509. /**
  510. * @deprecated As of 7.2, call or override
  511. * {@link #hookHtml5DragStart(Element)} instead
  512. */
  513. @Deprecated
  514. protected native void hookHtml5DragStart(
  515. com.google.gwt.user.client.Element el)
  516. /*-{
  517. var me = this;
  518. el.addEventListener("dragstart", $entry(function(ev) {
  519. return me.@com.vaadin.client.ui.VDragAndDropWrapper::html5DragStart(Lcom/vaadin/client/ui/dd/VHtml5DragEvent;)(ev);
  520. }), false);
  521. }-*/;
  522. /**
  523. * @since 7.2
  524. */
  525. protected void hookHtml5DragStart(Element el) {
  526. hookHtml5DragStart(DOM.asOld(el));
  527. }
  528. /**
  529. * Prototype code, memory leak risk.
  530. *
  531. * @param el
  532. * @deprecated As of 7.2, call or override {@link #hookHtml5Events(Element)}
  533. * instead
  534. */
  535. @Deprecated
  536. protected native void hookHtml5Events(com.google.gwt.user.client.Element el)
  537. /*-{
  538. var me = this;
  539. el.addEventListener("dragenter", $entry(function(ev) {
  540. return me.@com.vaadin.client.ui.VDragAndDropWrapper::html5DragEnter(Lcom/vaadin/client/ui/dd/VHtml5DragEvent;)(ev);
  541. }), false);
  542. el.addEventListener("dragleave", $entry(function(ev) {
  543. return me.@com.vaadin.client.ui.VDragAndDropWrapper::html5DragLeave(Lcom/vaadin/client/ui/dd/VHtml5DragEvent;)(ev);
  544. }), false);
  545. el.addEventListener("dragover", $entry(function(ev) {
  546. return me.@com.vaadin.client.ui.VDragAndDropWrapper::html5DragOver(Lcom/vaadin/client/ui/dd/VHtml5DragEvent;)(ev);
  547. }), false);
  548. el.addEventListener("drop", $entry(function(ev) {
  549. return me.@com.vaadin.client.ui.VDragAndDropWrapper::html5DragDrop(Lcom/vaadin/client/ui/dd/VHtml5DragEvent;)(ev);
  550. }), false);
  551. }-*/;
  552. /**
  553. * Prototype code, memory leak risk.
  554. *
  555. * @param el
  556. *
  557. * @since 7.2
  558. */
  559. protected void hookHtml5Events(Element el) {
  560. hookHtml5Events(DOM.asOld(el));
  561. }
  562. public boolean updateDropDetails(VDragEvent drag) {
  563. VerticalDropLocation oldVL = verticalDropLocation;
  564. verticalDropLocation = DDUtil.getVerticalDropLocation(getElement(),
  565. drag.getCurrentGwtEvent(), 0.2);
  566. drag.getDropDetails().put("verticalLocation",
  567. verticalDropLocation.toString());
  568. HorizontalDropLocation oldHL = horizontalDropLocation;
  569. horizontalDropLocation = DDUtil.getHorizontalDropLocation(getElement(),
  570. drag.getCurrentGwtEvent(), 0.2);
  571. drag.getDropDetails().put("horizontalLocation",
  572. horizontalDropLocation.toString());
  573. return oldHL != horizontalDropLocation || oldVL != verticalDropLocation;
  574. }
  575. protected void deEmphasis(boolean doLayout) {
  576. if (emphasizedVDrop != null) {
  577. VDragAndDropWrapper.setStyleName(getElement(), OVER_STYLE, false);
  578. VDragAndDropWrapper.setStyleName(getElement(),
  579. OVER_STYLE + "-" + emphasizedVDrop.toString().toLowerCase(),
  580. false);
  581. VDragAndDropWrapper.setStyleName(getElement(),
  582. OVER_STYLE + "-" + emphasizedHDrop.toString().toLowerCase(),
  583. false);
  584. }
  585. if (doLayout) {
  586. notifySizePotentiallyChanged();
  587. }
  588. }
  589. private void notifySizePotentiallyChanged() {
  590. LayoutManager.get(client).setNeedsMeasure(getConnector());
  591. }
  592. protected void emphasis(VDragEvent drag) {
  593. deEmphasis(false);
  594. VDragAndDropWrapper.setStyleName(getElement(), OVER_STYLE, true);
  595. VDragAndDropWrapper.setStyleName(getElement(), OVER_STYLE + "-"
  596. + verticalDropLocation.toString().toLowerCase(), true);
  597. VDragAndDropWrapper.setStyleName(getElement(),
  598. OVER_STYLE + "-"
  599. + horizontalDropLocation.toString().toLowerCase(),
  600. true);
  601. emphasizedVDrop = verticalDropLocation;
  602. emphasizedHDrop = horizontalDropLocation;
  603. // TODO build (to be an example) an emphasis mode where drag image
  604. // is fitted before or after the content
  605. notifySizePotentiallyChanged();
  606. }
  607. /**
  608. * Set the widget that will be used as the drag image when using
  609. * DragStartMode {@link COMPONENT_OTHER} .
  610. *
  611. * @param widget
  612. */
  613. public void setDragAndDropWidget(Widget widget) {
  614. dragImageWidget = widget;
  615. }
  616. /**
  617. * @return the widget used as drag image. Returns <code>null</code> if no
  618. * widget is set.
  619. */
  620. public Widget getDragImageWidget() {
  621. return dragImageWidget;
  622. }
  623. /**
  624. * Internal client side interface used by the connector and the widget for
  625. * the drag and drop wrapper to signal the completion of an HTML5 file
  626. * upload.
  627. *
  628. * @since 7.6.4
  629. */
  630. public interface UploadHandler {
  631. public void uploadDone();
  632. }
  633. }