You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VerticalDropLocation.java 749B

123456789101112131415161718192021222324252627
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal.gwt.client.ui.dd;
  5. import com.google.gwt.user.client.Element;
  6. public enum VerticalDropLocation {
  7. TOP, BOTTOM, MIDDLE;
  8. public static VerticalDropLocation get(Element element, int clientY,
  9. double topBottomRatio) {
  10. int absoluteTop = element.getAbsoluteTop();
  11. int offsetHeight = element.getOffsetHeight();
  12. int fromTop = clientY - absoluteTop;
  13. float percentageFromTop = (fromTop / (float) offsetHeight);
  14. if (percentageFromTop < topBottomRatio) {
  15. return TOP;
  16. } else if (percentageFromTop > 1 - topBottomRatio) {
  17. return BOTTOM;
  18. } else {
  19. return MIDDLE;
  20. }
  21. }
  22. }