diff options
author | Automerge <automerge@vaadin.com> | 2012-05-15 17:11:36 +0000 |
---|---|---|
committer | Automerge <automerge@vaadin.com> | 2012-05-15 17:11:36 +0000 |
commit | 41f5328ef5600ce61bb323814f605cc6e77cbca2 (patch) | |
tree | f49871777765c16219ef820a599ec26ede016ae8 /src/com | |
parent | 531e592760c2f2fe065ff203b120cba3f6950da3 (diff) | |
download | vaadin-framework-41f5328ef5600ce61bb323814f605cc6e77cbca2.tar.gz vaadin-framework-41f5328ef5600ce61bb323814f605cc6e77cbca2.zip |
[merge from 6.7] Take viewport scrolling into account when calculating drop position (#6021)
svn changeset:23749/svn branch:6.8
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/dd/DDUtil.java | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/DDUtil.java b/src/com/vaadin/terminal/gwt/client/ui/dd/DDUtil.java index 02c1fe5061..225770b62b 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/dd/DDUtil.java +++ b/src/com/vaadin/terminal/gwt/client/ui/dd/DDUtil.java @@ -5,6 +5,7 @@ package com.vaadin.terminal.gwt.client.ui.dd; import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.user.client.Element; +import com.google.gwt.user.client.Window; import com.vaadin.terminal.gwt.client.Util; public class DDUtil { @@ -43,8 +44,11 @@ public class DDUtil { public static VerticalDropLocation getVerticalDropLocation(Element element, int offsetHeight, int clientY, double topBottomRatio) { - int absoluteTop = element.getAbsoluteTop(); - int fromTop = clientY - absoluteTop; + // Event coordinates are relative to the viewport, element absolute + // position is relative to the document. Make element position relative + // to viewport by adjusting for viewport scrolling. See #6021 + int elementTop = element.getAbsoluteTop() - Window.getScrollTop(); + int fromTop = clientY - elementTop; float percentageFromTop = (fromTop / (float) offsetHeight); if (percentageFromTop < topBottomRatio) { @@ -74,11 +78,14 @@ public class DDUtil { public static HorizontalDropLocation getHorizontalDropLocation( Element element, int clientX, double leftRightRatio) { - int absoluteLeft = element.getAbsoluteLeft(); + // Event coordinates are relative to the viewport, element absolute + // position is relative to the document. Make element position relative + // to viewport by adjusting for viewport scrolling. See #6021 + int elementLeft = element.getAbsoluteLeft() - Window.getScrollLeft(); int offsetWidth = element.getOffsetWidth(); - int fromTop = clientX - absoluteLeft; + int fromLeft = clientX - elementLeft; - float percentageFromTop = (fromTop / (float) offsetWidth); + float percentageFromTop = (fromLeft / (float) offsetWidth); if (percentageFromTop < leftRightRatio) { return HorizontalDropLocation.LEFT; } else if (percentageFromTop > 1 - leftRightRatio) { |