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

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

Introduction

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

Prototype

@Override
    public int getScrollTop() 

Source Link

Usage

From source file:com.googlecode.kanbanik.client.components.WindowBox.java

License:Apache License

/**
 *
 * @param resize/*from w  w  w .  ja  v a 2  s . c o  m*/
 * @param clientY
 * @return
 */
private int getRelY(com.google.gwt.dom.client.Element resize, int clientY) {
    return clientY - resize.getAbsoluteTop() + resize.getScrollTop() + resize.getOwnerDocument().getScrollTop();
}

From source file:com.haulmont.cuba.web.toolkit.ui.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) {
            if (onScrollHandler != null) {
                onScrollHandler.accept(scrollTop, scrollLeft);
            }/*  w w  w .  j  av a 2  s  .  c  o  m*/

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

From source file:com.vaadin.terminal.gwt.client.Util.java

License:Open Source License

/**
 * Run workaround for webkits overflow auto issue.
 * /*  w  w  w. j a  v  a 2  s.  c  o m*/
 * See: our bug #2138 and https://bugs.webkit.org/show_bug.cgi?id=21462
 * 
 * @param elem
 *            with overflow auto
 */
public static void runWebkitOverflowAutoFix(final Element elem) {
    // Add max version if fix lands sometime to Webkit
    // Starting from Opera 11.00, also a problem in Opera
    if ((BrowserInfo.get().getWebkitVersion() > 0 || BrowserInfo.get().getOperaVersion() >= 11)
            && getNativeScrollbarSize() > 0) {
        final String originalOverflow = elem.getStyle().getProperty("overflow");
        if ("hidden".equals(originalOverflow)) {
            return;
        }

        // check the scrolltop value before hiding the element
        final int scrolltop = elem.getScrollTop();
        final int scrollleft = elem.getScrollLeft();
        elem.getStyle().setProperty("overflow", "hidden");

        Scheduler.get().scheduleDeferred(new Command() {
            public void execute() {
                // Dough, Safari scroll auto means actually just a moped
                elem.getStyle().setProperty("overflow", originalOverflow);

                if (scrolltop > 0 || elem.getScrollTop() > 0) {
                    int scrollvalue = scrolltop;
                    if (scrollvalue == 0) {
                        // mysterious are the ways of webkits scrollbar
                        // handling. In some cases webkit reports bad (0)
                        // scrolltop before hiding the element temporary,
                        // sometimes after.
                        scrollvalue = elem.getScrollTop();
                    }
                    // fix another bug where scrollbar remains in wrong
                    // position
                    elem.setScrollTop(scrollvalue - 1);
                    elem.setScrollTop(scrollvalue);
                }

                // fix for #6940 : Table horizontal scroll sometimes not
                // updated when collapsing/expanding columns
                // Also appeared in Safari 5.1 with webkit 534 (#7667)
                if ((BrowserInfo.get().isChrome()
                        || (BrowserInfo.get().isSafari() && BrowserInfo.get().getWebkitVersion() >= 534))
                        && (scrollleft > 0 || elem.getScrollLeft() > 0)) {
                    int scrollvalue = scrollleft;

                    if (scrollvalue == 0) {
                        // mysterious are the ways of webkits scrollbar
                        // handling. In some cases webkit may report a bad
                        // (0) scrollleft before hiding the element
                        // temporary, sometimes after.
                        scrollvalue = elem.getScrollLeft();
                    }
                    // fix another bug where scrollbar remains in wrong
                    // position
                    elem.setScrollLeft(scrollvalue - 1);
                    elem.setScrollLeft(scrollvalue);
                }
            }
        });
    }

}

From source file:com.zipsoft.widgets.client.lazylayout.VLazyLayout.java

License:Apache License

/**
 * Proveravam u DOM-u koji se widgeti trenutno vide
 * @param mainWidget To je u stvari ova komponenta
 * @param child/*from www  . ja  va2  s.c  om*/
 * @param proximity
 * @return
 */
private static boolean isBeingShown(final Widget mainWidget, final Widget child, final int proximity) {

    final Element element = child.getElement();

    /*
     * track the original element's position as we iterate through the DOM
     * tree
     */
    int originalTopAdjusted = 0;
    final int originalHeight = element.getOffsetHeight();
    int originalLeftAdjusted = 0;
    final int originalWidth = element.getOffsetWidth();

    com.google.gwt.dom.client.Element childElement = element;
    com.google.gwt.dom.client.Element parentElement = element.getParentElement();

    // What part of its canvas the parent shows, relative to its own
    // coordinates (0,0 is the top left corner)
    //            final int parentTop = parentElement.getScrollTop();            
    //VEROVATNO MORA DA SE UZME I SKROL POZICIJA ELEMENTA KOJI SKROLUJE
    final int parentTop = mainWidget.getElement().getScrollTop();

    //OVO JE VISINA CELOG KONTEJNERA - ONE JE MAKSIMALNA - MOZDA TREBA MERITI SAMO VISINU KOJA SE VIDI 
    //            final int parentBottom = parentTop + parentElement.getClientHeight();
    final int parentBottom = parentTop + mainWidget.getElement().getClientHeight();

    //        debug("Box: top: " + parentTop+ "px, btm: " + parentBottom + "px");

    final int parentLeft = parentElement.getScrollLeft();
    final int parentRight = parentLeft + parentElement.getClientWidth();

    /*
     * renderbox is the target box that is checked for visibility. If
     * the renderbox and parent's viewport don't overlap, it should not
     * be rendered. The renderbox is the child's position with an
     * adjusted margin.
     */
    final int renderBoxTop = childElement.getOffsetTop() - proximity;
    final int renderBoxBottom = childElement.getOffsetTop() + childElement.getOffsetHeight() + proximity;
    final int renderBoxLeft = childElement.getOffsetLeft() - proximity;
    final int renderBoxRight = childElement.getOffsetLeft() + childElement.getOffsetWidth() + proximity;

    if (!colliding2D(parentTop, parentRight, parentBottom, parentLeft, renderBoxTop, renderBoxRight,
            renderBoxBottom, renderBoxLeft)) {
        return false;
    }

    /*
     * see if the original component is visible from the parent. Move
     * the object around to correspond the relative changes in position.
     * The offset is always relative to the parent - not the canvas.
     */
    originalTopAdjusted += childElement.getOffsetTop() - childElement.getScrollTop();
    originalLeftAdjusted += childElement.getOffsetLeft() - childElement.getScrollLeft();
    if (!colliding2D(parentTop, parentRight, parentBottom, parentLeft, originalTopAdjusted - proximity,
            originalLeftAdjusted + originalWidth + proximity, originalTopAdjusted + originalHeight + proximity,
            originalLeftAdjusted - proximity)) {
        return false;
    }

    return true;
}

From source file:com.zipsoft.widgets.client.lazylayout.VLazyLayout.java

License:Apache License

@Deprecated
private static boolean isBeingShown(final Widget child, final int proximity) {

    final Element element = child.getElement();

    /*//from   ww w.ja v a2 s  .c o  m
     * track the original element's position as we iterate through the DOM
     * tree
     */
    int originalTopAdjusted = 0;
    final int originalHeight = element.getOffsetHeight();
    int originalLeftAdjusted = 0;
    final int originalWidth = element.getOffsetWidth();

    com.google.gwt.dom.client.Element childElement = element;
    com.google.gwt.dom.client.Element parentElement = element.getParentElement();

    //        while (parentElement != null) {

    // clientheight == the height as seen in browser
    // offsetheight == the DOM element's native height

    // What part of its canvas the parent shows, relative to its own
    // coordinates (0,0 is the top left corner)
    final int parentTop = parentElement.getScrollTop();

    //OVO JE VISINA CELOG KONTEJNERA - ONE JE MAKSIMALNA - MOZDA TREBA MERITI SAMO VISINU KOJA SE VIDI 
    //            final int parentBottom = parentTop + parentElement.getClientHeight();
    final int parentBottom = parentTop + parentElement.getClientHeight();

    final int parentLeft = parentElement.getScrollLeft();
    final int parentRight = parentLeft + parentElement.getClientWidth();

    /*
     * renderbox is the target box that is checked for visibility. If
     * the renderbox and parent's viewport don't overlap, it should not
     * be rendered. The renderbox is the child's position with an
     * adjusted margin.
     */
    final int renderBoxTop = childElement.getOffsetTop() - proximity;
    final int renderBoxBottom = childElement.getOffsetTop() + childElement.getOffsetHeight() + proximity;
    final int renderBoxLeft = childElement.getOffsetLeft() - proximity;
    final int renderBoxRight = childElement.getOffsetLeft() + childElement.getOffsetWidth() + proximity;

    if (!colliding2D(parentTop, parentRight, parentBottom, parentLeft, renderBoxTop, renderBoxRight,
            renderBoxBottom, renderBoxLeft)) {
        return false;
    }

    /*
     * see if the original component is visible from the parent. Move
     * the object around to correspond the relative changes in position.
     * The offset is always relative to the parent - not the canvas.
     */
    originalTopAdjusted += childElement.getOffsetTop() - childElement.getScrollTop();
    originalLeftAdjusted += childElement.getOffsetLeft() - childElement.getScrollLeft();
    if (!colliding2D(parentTop, parentRight, parentBottom, parentLeft, originalTopAdjusted - proximity,
            originalLeftAdjusted + originalWidth + proximity, originalTopAdjusted + originalHeight + proximity,
            originalLeftAdjusted - proximity)) {
        return false;
    }

    //            debug("Menjam Parent element - OVO NE BI TREBALO DA SE DOGODI!!!");
    //            childElement = parentElement;
    //            parentElement = childElement.getOffsetParent();
    //        }

    //TODO MISLIM DA OVO NE TREBA VISE
    // lastly, check the browser itself.
    //        final int parentTop = Window.getScrollTop();
    //        final int parentBottom = parentTop + Window.getClientHeight();
    //        final int parentLeft = Window.getScrollLeft();
    //        final int parentRight = parentLeft + Window.getClientWidth();
    //
    //        final int renderBoxTop = childElement.getOffsetTop() - proximity;
    //        final int renderBoxBottom = childElement.getOffsetTop() + childElement.getClientHeight() + proximity;
    //
    //        final int renderBoxLeft = childElement.getOffsetLeft() - proximity;
    //        final int renderBoxRight = childElement.getOffsetLeft() + childElement.getClientWidth() + proximity;
    //
    //        if (!colliding2D(parentTop, parentRight, parentBottom, parentLeft,
    //                renderBoxTop, renderBoxRight, renderBoxBottom, renderBoxLeft)) {
    //            return false;
    //        }
    //
    //        originalTopAdjusted += childElement.getOffsetTop();
    //        originalLeftAdjusted += childElement.getOffsetLeft();
    //        if (!colliding2D(parentTop, parentRight, parentBottom, parentLeft,
    //                originalTopAdjusted - proximity, originalLeftAdjusted
    //                        + originalWidth + proximity, originalTopAdjusted
    //                        + originalHeight + proximity, originalLeftAdjusted
    //                        - proximity)) {
    //            return false;
    //        }

    return true;
}

From source file:com.zipsoft.widgets.client.lazylayout.VLazyLayout.java

License:Apache License

private void setScrollTop(final int topPx) {
    com.google.gwt.dom.client.Element parent = getElement();
    while (parent != null && parent.getScrollTop() <= 0) {
        parent = parent.getOffsetParent();
    }/*from   ww  w  .  ja  v  a2 s.co m*/
    if (parent != null) {
        parent.setScrollTop(topPx);
        debug("setting scrolltop to " + topPx);
    } else {
        final int currentScrollLeft = Window.getScrollLeft();
        Window.scrollTo(currentScrollLeft, topPx);
        debug("setting scrolltop for window to " + topPx);
    }
    scrollingWasProgrammaticallyAdjusted = true;
}

From source file:com.zipsoft.widgets.client.lazylayout.VLazyLayout.java

License:Apache License

/**
 * Trenutna scroll pozicija//www  .jav  a  2s .  c o m
 * 
 * TODO Izbaciti ovo merenje PROZORA - WINDOW
 * 
 * @return
 */
private int getCurrentScrollPos() {
    final com.google.gwt.dom.client.Element parent = getFirstScrolledElement();

    if (parent != null) {
        return parent.getScrollTop();
    } else {
        return Window.getScrollTop();
    }
}

From source file:com.zipsoft.widgets.client.lazylayout.VLazyLayout.java

License:Apache License

/**
 * Ponalazi Prvi skroll element - OVO BI TREBALO DA BUDE ELEMENT WIDGETA
 * @return//from  www.  j a  va2s.  co m
 */
private com.google.gwt.dom.client.Element getFirstScrolledElement() {

    //TODO Debagovati ovo
    //       com.google.gwt.dom.client.Element parent = getElement().getOffsetParent();
    com.google.gwt.dom.client.Element parent = getElement();
    while (parent != null && parent.getScrollTop() <= 0) {
        parent = parent.getOffsetParent();
    }
    return parent;
}

From source file:edu.caltech.ipac.firefly.ui.imageGrid.BasicImageGrid.java

private void saveScrollPosition() {
    Element body = getElement();
    int scrollX = body.getScrollLeft();
    int scrollY = body.getScrollTop();
    int viewWidth = DOM.getElementPropertyInt(body, "clientWidth");
    int viewHeight = DOM.getElementPropertyInt(body, "clientHeight");

    if (currentViewHeight != viewHeight) {
        currentViewHeight = viewHeight;/*from  w  w w . j  a  v a2  s  .  co  m*/
    }

    if (currentViewWidth != viewWidth) {
        currentViewWidth = viewWidth;
    }

    if (currentScrollX != scrollX) {
        currentScrollX = scrollX;
    }

    if (currentScrollY != scrollY) {
        currentScrollY = scrollY;
    }

    if (lockrelated != null && mpwList.size() > 0) {
        lockrelated = mpwList.get(0).getGroup().getLockRelated();
    }
}

From source file:edu.caltech.ipac.firefly.ui.imageGrid.BasicImageGrid.java

private void restoreScrollPositions() {
    Element body = getElement();
    int scrollX = body.getScrollLeft();
    int scrollY = body.getScrollTop();
    int viewWidth = DOM.getElementPropertyInt(body, "clientWidth");
    int viewHeight = DOM.getElementPropertyInt(body, "clientHeight");
    if (currentViewHeight == viewHeight && currentViewWidth == viewWidth) {
        if (currentScrollX != scrollX) {
            setHorizontalScrollPosition(currentScrollX);
        }//from  w  w  w.  j a  v  a  2s.  c o m

        if (currentScrollY != scrollY) {
            setScrollPosition(currentScrollY);
        }
    }
}