Package elemental.html

Examples of elemental.html.ClientRect


   * {@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()) {
View Full Code Here


   * @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);
  }
View Full Code Here

   * Ensures that an element is not display: none and is just visibility hidden so we can get an
   * accurate client rect.
   */
  private static ClientRect ensureVisibleAndGetRect(Element element) {
    // Try to get rect and see if it isn't all 0's
    ClientRect rect = element.getBoundingClientRect();
    double rectSum = rect.getBottom() + rect.getTop() + rect.getLeft() + rect.getRight()
        + rect.getHeight() + rect.getWidth();
    if (rectSum != 0) {
      return rect;
    }

    // We make an attempt to get an accurate measurement of the element
View Full Code Here

    }

    @Override
    double getTop(ClientRect elementRect, int offsetY) {
      Element gwt = Elements.getElementById(AppContext.GWT_ROOT);
      ClientRect anchorRect = RelativeClientRect.relativeToRect(
          gwt.getBoundingClientRect(), anchor.getBoundingClientRect());

      switch (getVerticalAlignment()) {
        case TOP:
          return anchorRect.getTop() - elementRect.getHeight() - offsetY;
        case MIDDLE:
          double anchory = anchorRect.getTop() + anchorRect.getHeight() / 2;
          return anchory - elementRect.getHeight() / 2 - offsetY;
        case BOTTOM:
          return anchorRect.getBottom() + offsetY;
        default:
          return 0;
      }
    }
View Full Code Here

    }

    @Override
    double getLeft(ClientRect elementRect, int offsetX) {
      Element gwt = Elements.getElementById(AppContext.GWT_ROOT);
      ClientRect anchorRect = RelativeClientRect.relativeToRect(
          gwt.getBoundingClientRect(), anchor.getBoundingClientRect());

      switch (getHorizontalAlignment()) {
        case LEFT:
          if (getPosition() == Position.OVERLAP) {
            return anchorRect.getLeft() + offsetX;
          } else {
            return anchorRect.getLeft() - elementRect.getWidth() - offsetX;
          }
        case MIDDLE:
          double anchorx = anchorRect.getLeft() + anchorRect.getWidth() / 2;
          return anchorx - elementRect.getWidth() / 2 - offsetX;
        case RIGHT:
          if (getPosition() == Position.OVERLAP) {
            return anchorRect.getRight() - elementRect.getWidth() - offsetX;
          } else {
            return anchorRect.getRight() + offsetX;
          }
        default:
          return 0;
      }
    }
View Full Code Here

    @Override
    double getTop(ClientRect elementRect, int offsetY) {
      // This rect is to only be used for width and height since the coordinates are relative to the
      // viewport and we are relative to an offsetParent.
      ClientRect anchorRect = anchor.getBoundingClientRect();

      ensureOffsetCalculated();
      switch (getVerticalAlignment()) {
        case TOP:
          return anchorOffsetTop - elementRect.getHeight() - offsetY;
        case MIDDLE:
          double anchory = anchorOffsetTop + anchorRect.getHeight() / 2;
          return anchory - elementRect.getHeight() / 2 - offsetY;
        case BOTTOM:
          double anchorBottom = anchorOffsetTop + anchorRect.getHeight();
          return anchorBottom + offsetY;
        default:
          return 0;
      }
    }
View Full Code Here

    @Override
    double getLeft(ClientRect elementRect, int offsetX) {
      // This rect is to only be used for width and height since the coordinates are relative to the
      // viewport and we are relative to an offsetParent.
      ClientRect anchorRect = anchor.getBoundingClientRect();

      ensureOffsetCalculated();
      switch (getHorizontalAlignment()) {
        case LEFT:
          if (getPosition() == Position.OVERLAP) {
            return anchorOffsetLeft + offsetX;
          } else {
            return anchorOffsetLeft - elementRect.getWidth() - offsetX;
          }
        case MIDDLE:
          double anchorx = anchorOffsetLeft + anchorRect.getWidth() / 2;
          return anchorx - elementRect.getWidth() / 2 - offsetX;
        case RIGHT:
          double anchorRight = anchorOffsetLeft + anchorRect.getWidth();
          if (getPosition() == Position.OVERLAP) {
            return anchorRight - elementRect.getWidth() - offsetX;
          } else {
            return anchorRight + offsetX;
          }
View Full Code Here

   * {@code target} is visible.
   *
   * 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);
View Full Code Here

   * {@code scrollable}'s scrolled viewport.
   *
   * 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();
  }
View Full Code Here

  }

  private void ensureRootElementWillBeOnScreen(boolean showingFromHidden) {
    // Remove any max-heights so we can get its desired height
    container.getStyle().removeProperty("max-height");
    ClientRect bounds = box.getBoundingClientRect();
    int height = (int) bounds.getHeight();
    int delta = height - (int) container.getBoundingClientRect().getHeight();

    ClientRect bufferBounds = editor.getBuffer().getBoundingClientRect();
    int lineHeight = editor.getBuffer().getEditorLineHeight();
    int lineTop = (int) bounds.getTop() - CssUtils.parsePixels(box.getStyle().getMarginTop());

    int spaceAbove =  lineTop - (int) bufferBounds.getTop();
    int spaceBelow = (int) bufferBounds.getBottom() - lineTop - lineHeight;

    if (showingFromHidden) {
      // If it was already showing, we don't adjust the positioning.
      positionAbove = spaceAbove >= css.maxHeight() && spaceBelow < css.maxHeight();
    }
View Full Code Here

TOP

Related Classes of elemental.html.ClientRect

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.