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;
.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)
final String newKey = currentMouseOverKey;
TreeNode treeNode = keyToNode.get(oldIdOver);
if (treeNode != null) {
- // clear old styles
+ // clear old styles
treeNode.emphasis(null);
}
validate(new VAcceptCallback() {
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"));
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",
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);