Search in sources :

Example 1 with ClientRect

use of elemental.html.ClientRect in project che by eclipse.

the class PopupWidget method show.

/**
     * Show the widget at the given document position.
     * @param left the horizontal pixel position in the document
     * @param top the vertical pixel position in the document
     */
public void show(final float left, final float top) {
    if (!listElement.hasChildNodes()) {
        Element emptyElement = Elements.createLiElement(popupResources.popupStyle().item());
        emptyElement.setTextContent(getEmptyMessage());
        listElement.appendChild(emptyElement);
        return;
    }
    /* Reset popup dimensions and show. */
    popupElement.getStyle().setLeft(left, PX);
    popupElement.getStyle().setTop(top, PX);
    popupElement.getStyle().setWidth("" + MIN_WIDTH + "px");
    popupElement.getStyle().setHeight("" + MIN_HEIGHT + "px");
    popupElement.getStyle().setOpacity(0);
    Elements.getDocument().getBody().appendChild(popupElement);
    Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

        @Override
        public void execute() {
            popupElement.getStyle().setOpacity(1);
        }
    });
    Elements.getDocument().addEventListener(Event.MOUSEDOWN, popupListener, false);
    // does it fit inside the doc body?
    // This does exactly the same thing for height/top and width/left
    final Window window = Elements.getWindow();
    final int winX = window.getInnerWidth();
    final int winY = window.getInnerHeight();
    ClientRect widgetRect = this.popupElement.getBoundingClientRect();
    if (widgetRect.getBottom() > winY) {
        // it doesn't fit
        final float overflow = widgetRect.getBottom() - winY;
        if (widgetRect.getHeight() - overflow > MIN_HEIGHT) {
            // the widget can be shrunk to fit
            this.popupElement.getStyle().setHeight(widgetRect.getHeight() - overflow, PX);
        } else {
            // we need to shrink AND move the widget up
            this.popupElement.getStyle().setHeight(MIN_HEIGHT, PX);
            final int newTop = Math.max(winY - MIN_HEIGHT, MIN_HEIGHT);
            this.popupElement.getStyle().setTop(newTop, PX);
        }
    }
    // bounding rect has changed
    widgetRect = this.popupElement.getBoundingClientRect();
    if (widgetRect.getRight() > winX) {
        // it doesn't fit
        final float overflow = widgetRect.getRight() - winX;
        if (widgetRect.getWidth() - overflow > MIN_WIDTH) {
            // the widget can be shrunk to fit
            this.popupElement.getStyle().setWidth(widgetRect.getWidth() - overflow, PX);
        } else {
            // we need to shrink AND move the widget up
            this.popupElement.getStyle().setWidth(MIN_WIDTH, PX);
            final int newLeft = Math.max(winX - MIN_WIDTH, MIN_WIDTH);
            this.popupElement.getStyle().setLeft(newLeft - MIN_WIDTH, PX);
        }
    }
    if (needsFocus()) {
        // save previous focus and set focus in popup
        previousFocus = Elements.getDocument().getActiveElement();
        listElement.getFirstElementChild().focus();
    }
    // add key event listener on popup
    listElement.addEventListener(Event.KEYDOWN, keyboardListener, false);
}
Also used : Window(elemental.html.Window) Scheduler(com.google.gwt.core.client.Scheduler) Element(elemental.dom.Element) ClientRect(elemental.html.ClientRect)

Example 2 with ClientRect

use of elemental.html.ClientRect in project che by eclipse.

the class DomUtils method isFullyInScrollViewport.

/**
     * Checks whether the given {@code target} element is fully visible in
     * {@code scrollable}'s scrolled viewport.
     * <p/>
     * Note: This can trigger a synchronous layout.
     */
public static boolean isFullyInScrollViewport(Element scrollable, Element target) {
    ClientRect targetBounds = target.getBoundingClientRect();
    ClientRect scrollableBounds = scrollable.getBoundingClientRect();
    return targetBounds.getTop() >= scrollableBounds.getTop() && targetBounds.getBottom() <= scrollableBounds.getBottom();
}
Also used : ClientRect(elemental.html.ClientRect)

Example 3 with ClientRect

use of elemental.html.ClientRect in project che by eclipse.

the class DomUtils method ensureScrolledTo.

/**
     * Ensures that the {@code scrollable} element is scrolled such that
     * {@code target} is visible.
     * <p/>
     * Note: This can trigger a synchronous layout.
     */
public static boolean ensureScrolledTo(Element scrollable, Element target) {
    ClientRect targetBounds = target.getBoundingClientRect();
    ClientRect scrollableBounds = scrollable.getBoundingClientRect();
    int deltaBottoms = (int) (targetBounds.getBottom() - scrollableBounds.getBottom());
    int deltaTops = (int) (targetBounds.getTop() - scrollableBounds.getTop());
    if (deltaTops >= 0 && deltaBottoms <= 0) {
        // In bounds
        return false;
    }
    if (targetBounds.getHeight() > scrollableBounds.getHeight() || deltaTops < 0) {
        /*
          * Selected is taller than viewport height or selected is scrolled above
          * viewport, so set to top
          */
        scrollable.setScrollTop(scrollable.getScrollTop() + deltaTops);
    } else {
        // Selected is scrolled below viewport
        scrollable.setScrollTop(scrollable.getScrollTop() + deltaBottoms);
    }
    return true;
}
Also used : ClientRect(elemental.html.ClientRect)

Example 4 with ClientRect

use of elemental.html.ClientRect in project che by eclipse.

the class PositionController method checkPositionValidAndMaybeUpdatePositioner.

/**
     * Checks if the element is completely visible on the screen, if not it will temporarily flip our
     * {@link #elementPositioner} with updated alignment values which might work to fix the problem.
     */
private boolean checkPositionValidAndMaybeUpdatePositioner() {
    // recalculate the element's dimensions and check to see if any of the edges
    // of the element are outside the window
    ClientRect elementRect = ensureVisibleAndGetRect(element);
    VerticalAlign updatedVerticalAlign = elementPositioner.getVerticalAlignment();
    HorizontalAlign updatedHorizontalAlign = elementPositioner.getHorizontalAlignment();
    if (elementRect.getBottom() > Window.getClientHeight()) {
        updatedVerticalAlign = VerticalAlign.TOP;
    } else if (elementRect.getTop() < 0) {
        updatedVerticalAlign = VerticalAlign.BOTTOM;
    }
    if (elementRect.getRight() > Window.getClientWidth()) {
        updatedHorizontalAlign = HorizontalAlign.RIGHT;
    } else if (elementRect.getLeft() < 0) {
        updatedHorizontalAlign = HorizontalAlign.LEFT;
    }
    if (updatedVerticalAlign != elementPositioner.getVerticalAlignment() || updatedHorizontalAlign != elementPositioner.getHorizontalAlignment()) {
        elementPositioner.flip(updatedVerticalAlign, updatedHorizontalAlign);
        return false;
    }
    return true;
}
Also used : ClientRect(elemental.html.ClientRect) RelativeClientRect(org.eclipse.che.ide.util.RelativeClientRect)

Example 5 with ClientRect

use of elemental.html.ClientRect in project che by eclipse.

the class PositionController method place.

/**
     * Place the element based on the given information.
     *
     * @param x
     *         the offset or location depending on the underlying positioner.
     * @param y
     *         the offset or location depending on the underlying positioner.
     */
private void place(int x, int y) {
    resetElementPosition();
    ClientRect elementRect = ensureVisibleAndGetRect(element);
    double left = elementPositioner.getLeft(elementRect, x);
    double top = elementPositioner.getTop(elementRect, y);
    setElementLeftAndTop(left, top);
}
Also used : ClientRect(elemental.html.ClientRect) RelativeClientRect(org.eclipse.che.ide.util.RelativeClientRect)

Aggregations

ClientRect (elemental.html.ClientRect)7 RelativeClientRect (org.eclipse.che.ide.util.RelativeClientRect)3 Scheduler (com.google.gwt.core.client.Scheduler)1 CSSStyleDeclaration (elemental.css.CSSStyleDeclaration)1 Element (elemental.dom.Element)1 Window (elemental.html.Window)1