private Point getTargetXY(int targetCounter) {
if (toolTipConfig.getAnchor() != null) {
targetCounter++;
int[] offsets = getOffsets();
Point xy = (toolTipConfig.isAnchorToTarget() && !toolTipConfig.isTrackMouse()) ? el().getAlignToXY(
target.el().dom, getAnchorAlign(), null) : targetXY;
int dw = XDOM.getViewWidth(false) - 5;
int dh = XDOM.getViewHeight(false) - 5;
int scrollX = XDOM.getBodyScrollLeft() + 5;
int scrollY = XDOM.getBodyScrollTop() + 5;
int[] axy = new int[] {xy.x + offsets[0], xy.y + offsets[1]};
Size sz = getSize();
Region r = target.el().getRegion();
anchorEl.removeStyleName(anchorStyle);
// if we are not inside valid ranges we try to switch the anchor
if (!((toolTipConfig.getAnchor().equals("top") && (sz.height + offsets[1] + scrollY < dh - r.bottom))
|| (toolTipConfig.getAnchor().equals("right") && (sz.width + offsets[0] + scrollX < r.left))
|| (toolTipConfig.getAnchor().equals("bottom") && (sz.height + offsets[1] + scrollY < r.top)) || (toolTipConfig.getAnchor().equals(
"left") && (sz.width + offsets[0] + scrollX < dw - r.right)))
&& targetCounter < 4) {
if (sz.width + offsets[0] + scrollX < dw - r.right) {
toolTipConfig.setAnchor("left");
return getTargetXY(targetCounter);
}
if (sz.width + offsets[0] + scrollX < r.left) {
toolTipConfig.setAnchor("right");
return getTargetXY(targetCounter);
}
if (sz.height + offsets[1] + scrollY < dh - r.bottom) {
toolTipConfig.setAnchor("top");
return getTargetXY(targetCounter);
}
if (sz.height + offsets[1] + scrollY < r.top) {
toolTipConfig.setAnchor("bottom");
return getTargetXY(targetCounter);
}
}
anchorStyle = "x-tip-anchor-" + toolTipConfig.getAnchor();
anchorEl.addStyleName(anchorStyle);
targetCounter = 0;
return new Point(axy[0], axy[1]);
} else {
int x = targetXY.x;
int y = targetXY.y;
int[] mouseOffset = toolTipConfig.getMouseOffset();
if (mouseOffset != null) {
x += mouseOffset[0];
y += mouseOffset[1];
}
return new Point(x, y);
}
}