return new Offset(0, 0);
}
private Offset generatePosition(GqEvent e, boolean initPosition) {
GQuery scroll = getScrollParent();
boolean scrollIsRootNode = isRootNode(scroll.get(0));
int pageX = e.pageX();
int pageY = e.pageY();
if (!initPosition) {
if (containment != null && containment.length == 4) {
if (e.pageX() - offsetClick.left < containment[0]) {
pageX = containment[0] + offsetClick.left;
}
if (e.pageY() - offsetClick.top < containment[1]) {
pageY = containment[1] + offsetClick.top;
}
if (e.pageX() - offsetClick.left > containment[2]) {
pageX = containment[2] + offsetClick.left;
}
if (e.pageY() - offsetClick.top > containment[3]) {
pageY = containment[3] + offsetClick.top;
}
}
if (options.getGrid() != null) {
int[] grid = options.getGrid();
int roundedTop = originalEventPageY
+ Math.round((pageY - originalEventPageY) / grid[1]) * grid[1];
int roundedLeft = originalEventPageX
+ Math.round((pageX - originalEventPageX) / grid[0]) * grid[0];
if (containment != null && containment.length == 4) {
boolean isOutOfContainment0 = roundedLeft - offsetClick.left < containment[0];
boolean isOutOfContainment1 = roundedTop - offsetClick.top < containment[1];
boolean isOutOfContainment2 = roundedLeft - offsetClick.left > containment[2];
boolean isOutOfContainment3 = roundedTop - offsetClick.top > containment[3];
pageY = !(isOutOfContainment1 || isOutOfContainment3) ? roundedTop
: (!isOutOfContainment1) ? roundedTop - grid[1] : roundedTop
+ grid[1];
pageX = !(isOutOfContainment0 || isOutOfContainment2) ? roundedLeft
: (!isOutOfContainment0) ? roundedLeft - grid[0] : roundedLeft
+ grid[0];
} else {
pageY = roundedTop;
pageX = roundedLeft;
}
}
}
int top = pageY
- offsetClick.top
- relativeOffset.top
- parentOffset.top
+ ("fixed".equals(helperCssPosition) ? -helperScrollParent.scrollTop()
: scrollIsRootNode ? 0 : scroll.scrollTop());
int left = pageX
- offsetClick.left
- relativeOffset.left
- parentOffset.left
+ ("fixed".equals(helperCssPosition) ? -helperScrollParent.scrollLeft()
: scrollIsRootNode ? 0 : scroll.scrollLeft());
return new Offset(left, top);
}