]> source.dussan.org Git - vaadin-framework.git/commitdiff
fixes #4322
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 19 Mar 2010 10:12:10 +0000 (10:12 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 19 Mar 2010 10:12:10 +0000 (10:12 +0000)
svn changeset:11986/svn branch:6.3

src/com/vaadin/terminal/gwt/client/ui/VTree.java
src/com/vaadin/terminal/gwt/client/ui/dd/DDUtil.java

index c545e37c6371093b94ecaaff349ded02d612c7e2..3fc71c0047f2eb312dd9249a5a0aa7e9de0056cb 100644 (file)
@@ -163,10 +163,10 @@ public class VTree extends FlowPanel implements Paintable, VHasDropHandler {
         currentMouseOverKey = findCurrentMouseOverKey(drag.getElementOver());
 
         if (currentMouseOverKey != null) {
-            VerticalDropLocation detail = getDropDetail(drag
+            TreeNode treeNode = keyToNode.get(currentMouseOverKey);
+            VerticalDropLocation detail = treeNode.getDropDetail(drag
                     .getCurrentGwtEvent());
             Boolean overTreeNode = null;
-            TreeNode treeNode = keyToNode.get(currentMouseOverKey);
             if (treeNode != null && !treeNode.isLeaf()
                     && detail == VerticalDropLocation.MIDDLE) {
                 overTreeNode = true;
@@ -204,8 +204,8 @@ public class VTree extends FlowPanel implements Paintable, VHasDropHandler {
                             .getDropDetails().get("detail");
 
                     updateTreeRelatedDragData(currentDrag);
-                    final VerticalDropLocation detail = getDropDetail(currentDrag
-                            .getCurrentGwtEvent());
+                    final VerticalDropLocation detail = (VerticalDropLocation) currentDrag
+                            .getDropDetails().get("detail");
                     boolean nodeHasChanged = (currentMouseOverKey != null && currentMouseOverKey != oldIdOver)
                             || (currentMouseOverKey == null && oldIdOver != null);
                     boolean detailHasChanded = (detail != null && detail != oldDetail)
@@ -218,7 +218,7 @@ public class VTree extends FlowPanel implements Paintable, VHasDropHandler {
                         final String newKey = currentMouseOverKey;
                         TreeNode treeNode = keyToNode.get(oldIdOver);
                         if (treeNode != null) {
-                               // clear old styles
+                            // clear old styles
                             treeNode.emphasis(null);
                         }
                         validate(new VAcceptCallback() {
@@ -264,17 +264,6 @@ public class VTree extends FlowPanel implements Paintable, VHasDropHandler {
         dropHandler.updateAcceptRules(childUidl);
     }
 
-    public VerticalDropLocation getDropDetail(NativeEvent event) {
-        TreeNode treeNode = keyToNode.get(currentMouseOverKey);
-        if (treeNode == null) {
-            return null;
-        }
-        VerticalDropLocation verticalDropLocation = DDUtil
-                .getVerticalDropLocation(treeNode.nodeCaptionDiv, event
-                        .getClientY(), 0.2);
-        return verticalDropLocation;
-    }
-
     private void handleUpdate(UIDL uidl) {
         final TreeNode rootNode = keyToNode.get(uidl
                 .getStringAttribute("rootKey"));
@@ -345,12 +334,28 @@ public class VTree extends FlowPanel implements Paintable, VHasDropHandler {
 
         private Event mouseDownEvent;
 
+        private int cachedHeight = -1;
+
         public TreeNode() {
             constructDom();
             sinkEvents(Event.ONCLICK | Event.ONDBLCLICK | Event.MOUSEEVENTS
                     | Event.ONCONTEXTMENU);
         }
 
+        public VerticalDropLocation getDropDetail(NativeEvent currentGwtEvent) {
+            if (cachedHeight < 0) {
+                /*
+                 * Height is cached to avoid flickering (drop hints may change
+                 * the reported offsetheight -> would change the drop detail)
+                 */
+                cachedHeight = nodeCaptionDiv.getOffsetHeight();
+            }
+            VerticalDropLocation verticalDropLocation = DDUtil
+                    .getVerticalDropLocation(nodeCaptionDiv, cachedHeight,
+                            currentGwtEvent.getClientY(), 0.15);
+            return verticalDropLocation;
+        }
+
         protected void emphasis(VerticalDropLocation detail) {
             String base = "v-tree-node-drag-";
             UIObject.setStyleName(getElement(), base + "top",
index 60e81b36072b830bdd95412ae40cee16f43aee64..e544f1a4522a36ca6916d006e5d4c3653483239e 100644 (file)
@@ -6,9 +6,15 @@ public class DDUtil {
 
     public static VerticalDropLocation getVerticalDropLocation(Element element,
             int clientY, double topBottomRatio) {
+        int offsetHeight = element.getOffsetHeight();
+        return getVerticalDropLocation(element, offsetHeight, clientY,
+                topBottomRatio);
+    }
+
+    public static VerticalDropLocation getVerticalDropLocation(Element element,
+            int offsetHeight, int clientY, double topBottomRatio) {
 
         int absoluteTop = element.getAbsoluteTop();
-        int offsetHeight = element.getOffsetHeight();
         int fromTop = clientY - absoluteTop;
 
         float percentageFromTop = (fromTop / (float) offsetHeight);