Example usage for com.google.gwt.query.client GQuery scrollLeft

List of usage examples for com.google.gwt.query.client GQuery scrollLeft

Introduction

In this page you can find the example usage for com.google.gwt.query.client GQuery scrollLeft.

Prototype

public int scrollLeft() 

Source Link

Document

Gets the scroll left offset of the first matched element.

Usage

From source file:gwtquery.plugins.draggable.client.DraggableHandler.java

License:Apache License

/**
 * convert a relative position to a absolute position and vice versa.
 *
 * @param absolute  if true the position is convert to an absolute position, if
 *                  false it is convert in a relative position
 * @param aPosition position to convert//ww  w  . j a v a  2 s  .c o  m
 * @return
 */
public Offset convertPositionTo(boolean absolute, Offset aPosition) {
    int mod = absolute ? 1 : -1;
    GQuery scroll = getScrollParent();
    boolean scrollIsRootNode = isRootNode(scroll.get(0));

    int top = aPosition.top + relativeOffset.top * mod + parentOffset.top * mod
            - ("fixed".equals(helperCssPosition) ? -helperScrollParent.scrollTop()
                    : scrollIsRootNode ? 0 : scroll.scrollTop()) * mod;

    int left = aPosition.left + relativeOffset.left * mod + parentOffset.left * mod
            - ("fixed".equals(helperCssPosition) ? -helperScrollParent.scrollLeft()
                    : scrollIsRootNode ? 0 : scroll.scrollLeft()) * mod;

    return new Offset(left, top);

}

From source file:gwtquery.plugins.draggable.client.DraggableHandler.java

License:Apache License

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;
            }//w  w w . ja  v a 2s . c  o  m
            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);
}