diff options
author | Matti Tahvonen <matti.tahvonen@itmill.com> | 2010-03-19 10:12:10 +0000 |
---|---|---|
committer | Matti Tahvonen <matti.tahvonen@itmill.com> | 2010-03-19 10:12:10 +0000 |
commit | 512497c13ff50b8cb1609fa5daa6c24afd729070 (patch) | |
tree | a56a3733dc7ac0eef3e6df8e1bd5e77a6d7fe6ec /src | |
parent | 2a6b6defde5be1bae5ea57c802ac781d0794cc4e (diff) | |
download | vaadin-framework-512497c13ff50b8cb1609fa5daa6c24afd729070.tar.gz vaadin-framework-512497c13ff50b8cb1609fa5daa6c24afd729070.zip |
fixes #4322
svn changeset:11986/svn branch:6.3
Diffstat (limited to 'src')
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/VTree.java | 37 | ||||
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/dd/DDUtil.java | 8 |
2 files changed, 28 insertions, 17 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTree.java b/src/com/vaadin/terminal/gwt/client/ui/VTree.java index c545e37c63..3fc71c0047 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTree.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTree.java @@ -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", 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 60e81b3607..e544f1a452 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/dd/DDUtil.java +++ b/src/com/vaadin/terminal/gwt/client/ui/dd/DDUtil.java @@ -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); |