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.

HorizontalDropLocation.java 753B

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 HorizontalDropLocation {
  7. LEFT, RIGHT, CENTER;
  8. public static HorizontalDropLocation get(Element element, int clientX,
  9. double leftRightRatio) {
  10. int absoluteLeft = element.getAbsoluteLeft();
  11. int offsetWidth = element.getOffsetWidth();
  12. int fromTop = clientX - absoluteLeft;
  13. float percentageFromTop = (fromTop / (float) offsetWidth);
  14. if (percentageFromTop < leftRightRatio) {
  15. return LEFT;
  16. } else if (percentageFromTop > 1 - leftRightRatio) {
  17. return RIGHT;
  18. } else {
  19. return CENTER;
  20. }
  21. }
  22. }