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

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

Introduction

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

Prototype

@Override
    public int getOffsetLeft() 

Source Link

Usage

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/*w  w w.  j  a v a  2s  . 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();

    /*// w  w  w.j av a  2 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:ru.fly.client.ui.FElement.java

License:Apache License

public final int getRelativeLeft(Element relative) {
    int left = getOffsetLeft();
    Element parent = getOffsetParent().cast();
    while (parent != null && parent != relative) {
        left += parent.getOffsetLeft();
        parent = parent.getOffsetParent().cast();
    }//from w  ww . j a  va2s . c  om
    return left;
}