Example usage for com.google.gwt.dom.client Element getScrollTop

List of usage examples for com.google.gwt.dom.client Element getScrollTop

Introduction

In this page you can find the example usage for com.google.gwt.dom.client Element getScrollTop.

Prototype

@Override
    public int getScrollTop() 

Source Link

Usage

From source file:com.ait.lienzo.client.widget.LienzoHandlerManager.java

License:Open Source License

private final List<TouchPoint> getTouches(final TouchEvent<?> event) {
    final JsArray<Touch> jsarray = event.getTouches();

    final Element element = event.getRelativeElement();

    if ((null != jsarray) && (jsarray.length() > 0)) {
        final int size = jsarray.length();

        final ArrayList<TouchPoint> touches = new ArrayList<TouchPoint>(size);

        for (int i = 0; i < size; i++) {
            final Touch touch = jsarray.get(i);

            touches.add(new TouchPoint(touch.getRelativeX(element), touch.getRelativeY(element)));
        }//  w ww. j a v  a 2  s .  c om
        return touches;
    } else {
        int x = event.getNativeEvent().getClientX() - element.getAbsoluteLeft() + element.getScrollLeft()
                + element.getOwnerDocument().getScrollLeft();

        int y = event.getNativeEvent().getClientY() - element.getAbsoluteTop() + element.getScrollTop()
                + element.getOwnerDocument().getScrollTop();

        return Arrays.asList(new TouchPoint(x, y));
    }
}

From source file:com.alkacon.geranium.client.dnd.DNDHandler.java

License:Open Source License

/**
 * Execute on mouse wheel event.<p>
 * //from  w  w  w  . java  2s  .  c o m
 * @param event the native event
 */
protected void onMouseWheelScroll(Event event) {

    int scrollStep = event.getMouseWheelVelocityY() * 5;
    Element scrollTarget;
    if (getCurrentTarget() != null) {
        scrollTarget = getCurrentTarget().getElement();
    } else {
        scrollTarget = RootPanel.getBodyElement();
    }
    while ((scrollTarget.getScrollHeight() == scrollTarget.getClientHeight())
            && (scrollTarget != RootPanel.getBodyElement())) {
        scrollTarget = scrollTarget.getParentElement();
    }
    if (scrollTarget == RootPanel.getBodyElement()) {
        int top = Window.getScrollTop() + scrollStep;
        int left = Window.getScrollLeft();
        if (top < 0) {
            top = 0;
        }
        Window.scrollTo(left, top);
    } else {
        int top = scrollTarget.getScrollTop() + scrollStep;
        if (top < 0) {
            top = 0;
        }
        scrollTarget.setScrollTop(top);
    }
    onMove(event);
}

From source file:com.alkacon.geranium.client.util.DomUtil.java

License:Open Source License

/**
 * Ensures that the given element is visible.<p>
 * /*from ww  w. jav a  2  s  .c  o m*/
 * Assuming the scrollbars are on the container element, and that the element is a child of the container element.<p>
 * 
 * @param containerElement the container element, has to be parent of the element
 * @param element the element to be seen
 * @param animationTime the animation time for scrolling, use zero for no animation
 */
public static void ensureVisible(final Element containerElement, Element element, int animationTime) {

    Element item = element;
    int realOffset = 0;
    while ((item != null) && (item != containerElement)) {
        realOffset += element.getOffsetTop();
        item = item.getOffsetParent();
    }
    final int endScrollTop = realOffset - (containerElement.getOffsetHeight() / 2);

    if (animationTime <= 0) {
        // no animation
        containerElement.setScrollTop(endScrollTop);
        return;
    }
    final int startScrollTop = containerElement.getScrollTop();
    (new Animation() {

        /**
         * @see com.google.gwt.animation.client.Animation#onUpdate(double)
         */
        @Override
        protected void onUpdate(double progress) {

            containerElement.setScrollTop(startScrollTop + (int) ((endScrollTop - startScrollTop) * progress));
        }
    }).run(animationTime);
}

From source file:com.alkacon.geranium.client.util.DomUtil.java

License:Open Source License

/**
 * Gets the vertical position of the given y-coordinate relative to a given element.<p>
 * /*from w w  w .  ja v  a2s  . co m*/
 * @param y the coordinate to use 
 * @param target the element whose coordinate system is to be used
 * @param scrollParent the scroll parent of the target element
 * 
 * @return the relative vertical position
 * 
 * @see com.google.gwt.event.dom.client.MouseEvent#getRelativeY(com.google.gwt.dom.client.Element)
 */
public static int getRelativeY(int y, Element target, Element scrollParent) {

    return (y - target.getAbsoluteTop()) + (scrollParent != null ? scrollParent.getScrollTop() : 0)
            + target.getOwnerDocument().getScrollTop();
}

From source file:com.cgxlib.core.component.tooltip.TooltipBSViewHandler.java

License:Apache License

@Override
public SingleTooltip.Position getPosition(XQ $element) {
    $element = $element != null ? $element : root;

    Element el = $element.get(0);
    boolean isBody = el.getTagName().toUpperCase().equals("BODY");
    SingleTooltip.Position pos = new SingleTooltip.Position();

    JavaScriptObject rect = CGXHelper.clientRect(el);
    if (rect != null) {
        int bottom = (int) Math.round((Double) JsUtils.prop(rect, "bottom"));
        int top = (int) Math.round((Double) JsUtils.prop(rect, "top"));
        int left = (int) Math.round((Double) JsUtils.prop(rect, "left"));
        int right = (int) Math.round((Double) JsUtils.prop(rect, "right"));
        int width = (int) Math.round((Double) JsUtils.prop(rect, "width"));
        int height = (int) Math.round((Double) JsUtils.prop(rect, "height"));
        pos.bottom = bottom;//from   www  . jav  a2s . c o  m
        pos.top = top;
        pos.left = left;
        pos.right = right;
        pos.width = width;
        pos.height = height;
    }

    if (isBody) {
        Element documentEl = Document.get().getDocumentElement();
        XQ $window = $(XQ.window);
        pos.width = $window.width();
        pos.height = $window.height();

        pos.scroll = documentEl.getScrollTop();
        if (pos.scroll < 1) {
            pos.scroll = XQ.body.getScrollTop();
        }

        pos.top = 0;
        pos.left = 0;
    } else {
        pos.scroll = $element.scrollTop();
        XQ.Offset elOffset = $element.offset();
        if (elOffset != null) {
            pos.top = elOffset.top;
            pos.left = elOffset.left;
        }
    }

    return pos;
}

From source file:com.emitrom.lienzo.client.widget.LienzoHandlerManager.java

License:Open Source License

private final ArrayList<TouchPoint> getTouches(TouchEvent<?> event) {
    ArrayList<TouchPoint> touches = new ArrayList<TouchPoint>();

    JsArray<Touch> jsarray = event.getTouches();

    Element element = event.getRelativeElement();

    if ((null != jsarray) && (jsarray.length() > 0)) {
        int size = jsarray.length();

        for (int i = 0; i < size; i++) {
            Touch touch = jsarray.get(i);

            touches.add(new TouchPoint(touch.getRelativeX(element), touch.getRelativeY(element)));
        }//from www  .  j a  va  2s  . c  o m
    } else {
        int x = event.getNativeEvent().getClientX() - element.getAbsoluteLeft() + element.getScrollLeft()
                + element.getOwnerDocument().getScrollLeft();

        int y = event.getNativeEvent().getClientY() - element.getAbsoluteTop() + element.getScrollTop()
                + element.getOwnerDocument().getScrollTop();

        touches.add(new TouchPoint(x, y));
    }
    return touches;
}

From source file:com.extjs.gxt.ui.client.widget.grid.GridView.java

License:sencha.com license

/**
 * Ensured the current row and column is visible.
 * /*from w  w  w . j  a va2s.  co m*/
 * @param row the row index
 * @param col the column index
 * @param hscroll true to scroll horizontally if needed
 * @return the calculated point
 */
public Point ensureVisible(int row, int col, boolean hscroll) {
    if (grid == null || !grid.isViewReady() || row < 0 || row > ds.getCount()) {
        return null;
    }

    if (col == -1) {
        col = 0;
    }

    Element rowEl = getRow(row);
    Element cellEl = null;
    if (!(!hscroll && col == 0)) {
        while (cm.isHidden(col)) {
            col++;
        }
        cellEl = getCell(row, col);

    }

    if (rowEl == null) {
        return null;
    }

    Element c = scroller.dom;

    int ctop = 0;
    Element p = rowEl, stope = el.dom;
    while (p != null && p != stope) {
        ctop += p.getOffsetTop();
        p = p.getOffsetParent().cast();
    }
    ctop -= mainHd.dom.getOffsetHeight();

    int cbot = ctop + rowEl.getOffsetHeight();

    int ch = c.getOffsetHeight();
    int stop = c.getScrollTop();
    int sbot = stop + ch;

    if (ctop < stop) {
        c.setScrollTop(ctop);
    } else if (cbot > sbot) {
        if (hscroll && (cm.getTotalWidth() > scroller.getWidth() - scrollOffset)) {
            cbot += scrollOffset;
        }
        c.setScrollTop(cbot -= ch);
    }

    if (hscroll && cellEl != null) {
        int cleft = cellEl.getOffsetLeft();
        int cright = cleft + cellEl.getOffsetWidth();
        int sleft = c.getScrollLeft();
        int sright = sleft + c.getOffsetWidth();
        if (cleft < sleft) {
            c.setScrollLeft(cleft);
        } else if (cright > sright) {
            c.setScrollLeft(cright - scroller.getStyleWidth());
        }
    }

    return cellEl != null ? fly(cellEl).getXY() : new Point(c.getScrollLeft(), fly(rowEl).getY());
}

From source file:com.github.ligangty.common.highconvert.events.MouseEvent.java

License:Apache License

/**
 * Gets the mouse y-position relative to a given element.
 *
 * @param target the element whose coordinate system is to be used
 * @return the relative y-position/*from w w  w. j  av  a 2s . c o  m*/
 */
public int getRelativeY(Element target) {
    return getClientY() - target.getAbsoluteTop() + target.getScrollTop()
            + target.getOwnerDocument().getScrollTop();
}

From source file:com.haulmont.cuba.web.widgets.client.scrollboxlayout.CubaScrollBoxLayoutWidget.java

License:Apache License

@Override
public void onBrowserEvent(Event event) {
    super.onBrowserEvent(event);

    if (DOM.eventGetType(event) == Event.ONSCROLL) {
        Element element = getElement();

        int scrollTop = element.getScrollTop();
        int scrollLeft = element.getScrollLeft();

        if (this.scrollTop != scrollTop || this.scrollLeft != scrollLeft) {

            this.scrollTop = scrollTop;
            this.scrollLeft = scrollLeft;

            if (CubaScrollBoxLayoutState.DEFERRED_MODE.equals(scrollChangeMode)) {
                updateScrollState();// w ww. j  a va2 s .co  m
            } else {
                scrollBoxStateTrigger.cancel();
                scrollBoxStateTrigger.schedule(TIMEOUT);
            }
        }
    }
}

From source file:com.nubotech.client.ui.event.Touch.java

License:Open Source License

public final int getRelativeY(Element target) {
    return getClientY() - target.getAbsoluteTop() + target.getScrollTop()
            + target.getOwnerDocument().getScrollTop();
}