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

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

Introduction

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

Prototype

@Override
    public Element getOffsetParent() 

Source Link

Usage

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

License:Open Source License

/**
 * Ensures that the given element is visible.<p>
 * /*  w w w  . j  a va  2s  . 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.allen_sauer.gwt.dnd.client.util.WidgetArea.java

License:Apache License

public WidgetArea(Widget widget, Widget reference) {
    setLeft(widget.getAbsoluteLeft());/*w  w  w  .  j av  a2 s  .co  m*/
    setTop(widget.getAbsoluteTop());

    if (reference != null) {
        setLeft(getLeft() - reference.getAbsoluteLeft() - DOMUtil.getBorderLeft(reference.getElement()));
        setTop(getTop() - reference.getAbsoluteTop() - DOMUtil.getBorderTop(reference.getElement()));
    }
    setRight(getLeft() + widget.getOffsetWidth());
    setBottom(getTop() + widget.getOffsetHeight());

    Element elem = widget.getElement().getOffsetParent();
    Element p;

    while (elem != null && (p = elem.getOffsetParent()) != null) {
        if (!"visible".equals(DOMUtil.getEffectiveStyle(elem, "overflow"))) {
            int left = elem.getAbsoluteLeft();

            if (getLeft() < left) {
                setLeft(left);
            }

            int top = elem.getAbsoluteTop();
            if (getTop() < top) {
                setTop(top);
            }

            int bottom = top + elem.getOffsetHeight();
            if (getBottom() > bottom) {
                setBottom(Math.max(getTop(), bottom));
            }

            int right = left + elem.getOffsetWidth();
            if (getRight() > right) {
                setRight(Math.max(getLeft(), right));
            }
        }

        elem = p;
    }
}

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

License:sencha.com license

/**
 * Ensured the current row and column is visible.
 * //w ww  .j a v  a  2 s  .  c  o  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.google.speedtracer.client.visualizations.view.EventWaterfallRowDetails.java

License:Apache License

private Tree createEventTrace(Container parent, final int pieChartHeight) {
    Widget header = new Widget(parent.getDocument().createHElement(2), parent) {
    };//  w w w .ja  va 2  s  . c  o m
    header.setStyleName(getCss().eventBreakdownHeader());
    header.getElement().setInnerText("Event Trace");

    final LazyEventTree tree = new LazyEventTree(parent, eventWaterfall.getPresenter(),
            getParentRow().getEvent(), getParentRow().getEventBreakdown(), resources);

    // Hook listeners to tree list to monitor selection changes and
    // expansion changes.
    tree.addSelectionChangeListener(new SelectionChangeListener() {
        Element offsetParent = getParentRow().getElement();

        public void onSelectionChange(ArrayList<Item> selected) {
            // Wipe the old table
            detailsTable.destroy();

            // Sort the nodes by start time.
            Collections.sort(selected, new Comparator<Item>() {

                public int compare(Item node1, Item node2) {
                    UiEvent e1 = (UiEvent) node1.getItemTarget();
                    UiEvent e2 = (UiEvent) node2.getItemTarget();

                    return Double.compare(e1.getTime(), e2.getTime());
                }
            });

            Item newSelection = selected.get(selected.size() - 1);
            // Find how far to move table down to current selection.
            // We have to recursively walk up to compute the correct offset top.
            // We will encounter the UI padding two extra times along the way
            // crossing the tree boundary and crossing the details div boundary,
            // totally 3 encounters with padding we have to account for.
            int minTableOffset = Math.max(pieChartHeight,
                    recursiveGetOffsetTop(newSelection.getElement()) - (3 * getCss().uiPadding()));

            if (selected.size() == 1) {
                // We have a single selection. Simply display the details for the
                // single node.
                detailsTable = createDetailsTable(detailsTableContainer, minTableOffset,
                        (UiEvent) newSelection.getItemTarget());

            } else {
                // Display aggregate information over the range of nodes.
                detailsTable = createMultiNodeDetailsTable(detailsTableContainer, minTableOffset, selected);
            }

            fixHeightOfParentRow();
        }

        private int recursiveGetOffsetTop(Element node) {
            if (node == null || node.getOffsetParent() == null || node.equals(offsetParent)) {
                return 0;
            } else {
                return node.getOffsetTop() + recursiveGetOffsetTop(node.getOffsetParent());
            }
        }

    });

    tree.addExpansionChangeListener(new ExpansionChangeListener() {

        public void onExpansionChange(Item changedItem) {
            fixHeightOfParentRow();
        }

    });

    // We make sure to have the tree cleaned up when we clean up ourselves.
    manageEventListener(tree.getRemover());

    return tree;
}

From source file:jetbrains.jetpad.projectional.domUtil.DomUtil.java

License:Apache License

public static Rectangle visiblePart(Element ctx, Rectangle rect) {
    while (true) {
        if (ctx.getOffsetParent() == null) {
            Rectangle visibleArea = new Rectangle(Window.getScrollLeft(), Window.getScrollTop(),
                    Window.getClientWidth(), Window.getClientHeight());
            return visibleArea.intersect(rect);
        } else {/*from www  . ja  va2 s .c om*/
            Rectangle visible;
            if (hasScroller(ctx)) {
                visible = new Rectangle(0, 0, ctx.getClientWidth(), ctx.getClientHeight());
                Vector scroll = new Vector(ctx.getScrollLeft(), ctx.getScrollTop());
                rect = rect.sub(scroll);
            } else {
                visible = new Rectangle(0, 0, ctx.getScrollWidth(), ctx.getScrollHeight());
            }

            Rectangle newRect = visible.intersect(rect);
            Vector offset = new Vector(ctx.getOffsetLeft(), ctx.getOffsetTop());

            ctx = ctx.getOffsetParent();
            rect = newRect.add(offset);
        }
    }
}

From source file:org.openremote.app.client.assets.browser.AssetBrowserImpl.java

License:Open Source License

@Override
public void showAndSelectNode(String[] path, BrowserTreeNode treeNode, boolean scrollIntoView) {
    List<BrowserTreeNode> selectedPath = new AssetTree.AssetIdSearch().resolvePath(Arrays.asList(path),
            assetTree.getRootTreeNode());

    if (selectedPath.size() > 0) {
        BrowserTreeNode selectedNode = selectedPath.get(selectedPath.size() - 1);
        assetTree.getTreeViewModel().getSelectionModel().setSelected(selectedNode, true);

        if (!scrollIntoView)
            return;

        // We place the selected asset in the middle of the tree container
        elemental.dom.Element treeElement = (elemental.dom.Element) assetTree.getElement();
        elemental.dom.Element assetElement = treeElement
                .querySelector(AssetTreeCell.CELL_ID_SELECTOR(treeNode));
        int offsetTop = 0;
        if (assetElement != null && assetElement.getOffsetParent() != null) {
            elemental.dom.Element el = assetElement.getOffsetParent();
            do {//from  ww  w .j a  v a 2s .c  om
                offsetTop += el.getOffsetTop();
            } while ((el = el.getOffsetParent()) != null);
            Element treeContainerElement = assetTreeContainer.getElement();
            treeContainerElement.setAttribute("tabindex", "1");
            int middleOffset = offsetTop - treeContainerElement.getClientHeight() / 2
                    - treeContainerElement.getOffsetTop();
            treeContainerElement.setScrollTop(middleOffset);
        }
    }
}

From source file:org.openremote.manager.client.assets.browser.AssetBrowserImpl.java

License:Open Source License

@Override
public void showAndSelectAsset(String[] path, String selectedAssetId, boolean scrollIntoView) {
    List<AssetInfo> selectedPath = new AssetTree.IdSearch().resolvePath(Arrays.asList(path),
            assetTree.getRootTreeNode());

    if (selectedPath.size() > 0) {
        AssetInfo selectedAsset = selectedPath.get(selectedPath.size() - 1);
        assetTree.getTreeViewModel().getSelectionModel().setSelected(selectedAsset, true);

        if (!scrollIntoView)
            return;

        // We place the selected asset in the middle of the tree container
        elemental.dom.Element treeElement = (elemental.dom.Element) assetTree.getElement();
        String selector = "#asset-" + selectedAssetId.replaceAll(":", "\\\\:");
        elemental.dom.Element assetElement = treeElement.querySelector(selector);
        int offsetTop = 0;
        if (assetElement != null && assetElement.getOffsetParent() != null) {
            elemental.dom.Element el = assetElement.getOffsetParent();
            do {/*from w w w  .j  a v  a  2 s  . c o m*/
                offsetTop += el.getOffsetTop();
            } while ((el = el.getOffsetParent()) != null);
            Element treeContainerElement = assetTreeContainer.getElement();
            int middleOffset = offsetTop - treeContainerElement.getClientHeight() / 2
                    - treeContainerElement.getOffsetTop();
            treeContainerElement.setScrollTop(middleOffset);
        }
    }
}

From source file:org.rstudio.core.client.dom.DomUtils.java

License:Open Source License

public static Point getRelativePosition(Element container, Element child) {
    int left = 0, top = 0;
    while (child != null && child != container) {
        left += child.getOffsetLeft();/*  w  ww  .j a v a2 s  .  c  o m*/
        top += child.getOffsetTop();
        child = child.getOffsetParent();
    }

    return new Point(left, top);
}

From source file:org.rstudio.core.client.dom.DomUtils.java

License:Open Source License

public static int topRelativeTo(Element parent, Element child) {
    int top = 0;/*ww w  . j ava2 s .c  o m*/
    Element el = child;
    while (el != null && el != parent) {
        top += el.getOffsetTop();
        el = el.getOffsetParent();
    }
    return top;
}

From source file:org.rstudio.core.client.dom.DomUtils.java

License:Open Source License

public static int leftRelativeTo(Element parent, Element child) {
    int left = 0;
    Element el = child;
    while (el != null && el != parent) {
        left += el.getOffsetLeft();//from   w  ww . j av  a  2 s  .co  m
        el = el.getOffsetParent();
    }
    return left;
}