Java Code Examples for com.google.gwt.dom.client.Element#getAbsoluteTop()

The following examples show how to use com.google.gwt.dom.client.Element#getAbsoluteTop() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VDragDropUtil.java    From cuba with Apache License 2.0 6 votes vote down vote up
/**
 * Get the vertical drop location in a ordered layout
 * 
 * @param element
 *            The target element or cell
 * @param offsetHeight
 *            The height of the cell
 * @param clientY
 *            The width of the cell
 * @param topBottomRatio
 *            The ratio of the cell
 * @return The location of the drop
 */
public static VerticalDropLocation getVerticalDropLocation(Element element,
        int offsetHeight, int clientY, double topBottomRatio) {

    int absoluteTop = element.getAbsoluteTop();
    int fromTop = clientY - absoluteTop;

    float percentageFromTop = (fromTop / (float) offsetHeight);
    if (percentageFromTop < topBottomRatio) {
        return VerticalDropLocation.TOP;
    } else if (percentageFromTop > 1 - topBottomRatio) {
        return VerticalDropLocation.BOTTOM;
    } else {
        return VerticalDropLocation.MIDDLE;
    }
}
 
Example 2
Source File: CellContainerToDomMapper.java    From jetpad-projectional-open-source with Apache License 2.0 6 votes vote down vote up
private void refreshLineHighlight() {
  if (myLineHighlightUpToDate || !isAttached()) return;
  Cell current = getSource().focusedCell.get();
  for (Element e : Arrays.asList(myLineHighlight1, myLineHighlight2)) {
    Style style = e.getStyle();
    if (current == null || !Cells.isLeaf(current)) {
      style.setVisibility(Style.Visibility.HIDDEN);
    } else {
      int deltaTop = myContent.getAbsoluteTop() - getTarget().getAbsoluteTop();
      style.setVisibility(Style.Visibility.VISIBLE);
      int rootTop = myContent.getAbsoluteTop();
      final Element currentElement = getElement(current);
      int currentTop = currentElement.getAbsoluteTop();
      style.setTop(currentTop - rootTop + deltaTop, Style.Unit.PX);
      style.setHeight(currentElement.getClientHeight(), Style.Unit.PX);
      if (e == myLineHighlight2) {
        style.setWidth(0, Style.Unit.PX);
        style.setWidth(getTarget().getScrollWidth(), Style.Unit.PX);
      }
    }
  }
  myLineHighlightUpToDate = true;
}
 
Example 3
Source File: TDialog.java    From openchemlib-js with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public DialogResult doModalAt(final double x, final double y) {
  final Element element = getElementFromPoint((int) x, (int) y);
  if (element != null) {
    final int left = element.getAbsoluteLeft();
    final int top = element.getAbsoluteTop();

    onInitialUpdate();
    setPopupPositionAndShow(new PositionCallback() {

      @Override
      public void setPosition(int offsetWidth, int offsetHeight) {
        setPopupPosition(left + (element.getOffsetWidth() - offsetWidth) / 2,
            Math.max(top, top + (element.getOffsetHeight() - offsetHeight) / 2));

      }
    });
    setStyles();
    return DialogResult.IDOK;
  }
  return DialogResult.IDABORT;
}
 
Example 4
Source File: Scrolling.java    From jetpad-projectional-open-source with Apache License 2.0 6 votes vote down vote up
public static void scrollTo(Rectangle rect, Element element) {
  rect = rect.intersect(new Rectangle(0, 0, element.getScrollWidth(), element.getScrollHeight()));

  adjustScrollers(rect, element);
  Rectangle visibleArea = new Rectangle(getScrollX(), getScrollY(), getScrollWidth(), getScrollHeight());
  Rectangle elementBounds = getBounds(element);
  Rectangle bounds = new Rectangle(elementBounds.origin.add(rect.origin), rect.dimension);
  if (!visibleArea.contains(bounds)) {    // are we sure about this?
    int top = element.getAbsoluteTop() + rect.origin.y;
    int left = element.getAbsoluteLeft() + rect.origin.x;
    int width = rect.dimension.x;
    int height = rect.dimension.y;

    int winTop = getScrollY();
    int winLeft = getScrollX();
    int winWidth = getScrollWidth();
    int winHeigh = getScrollHeight();

    int deltaX = getScrollAdjustment(new Interval(winLeft, winLeft + winWidth), new Interval(left, left + width), winLeft);
    int deltaY = getScrollAdjustment(new Interval(winTop, winTop + winHeigh), new Interval(top, top + height), winTop);

    if (deltaX != 0 || deltaY != 0) {
      Window.scrollTo(winLeft + deltaX, winTop + deltaY);
    }
  }
}
 
Example 5
Source File: SimpleDropdown.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void open() {
	StyleUtils.addStyle(this, SimpleDropdown.STYLE_OPEN);
	Element menuElt = this.menuContainer.getElement();
	int topMenu = menuElt.getAbsoluteTop() - Window.getScrollTop();
	int menuHeight = menuElt.getOffsetHeight();
	int anchorHeight = this.anchor.getOffsetHeight();
	int clientHeight = Window.getClientHeight();
	if (topMenu + menuHeight > clientHeight && topMenu >= anchorHeight + menuHeight) {
		StyleUtils.addStyle(this, SimpleDropdown.STYLE_OPEN_UP);
	}
	int leftMenu = menuElt.getAbsoluteLeft() - Window.getScrollLeft();
	int menuWidth = menuElt.getOffsetWidth();
	int anchorWidth = this.anchor.getOffsetWidth();
	int clientWidth = Window.getClientWidth();
	if (leftMenu + menuWidth > clientWidth && leftMenu >= anchorWidth + menuWidth) {
		StyleUtils.addStyle(this, SimpleDropdown.STYLE_OPEN_LEFT);
	}
	this.open = true;
	this.updateHandlers();
}
 
Example 6
Source File: SelectionCoordinatesHelperW3C.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
private IntRange getBounds(Node node, int offset) {
  if (node == null || node.getParentElement() == null) {
    // Return null if cannot get selection, or selection is inside an
    // "unattached" node.
    return null;
  }

  if (DomHelper.isTextNode(node)) {
    Element parentElement = node.getParentElement();
    return new IntRange(parentElement.getAbsoluteTop(), parentElement.getAbsoluteBottom());
  } else {
    Element e = node.<Element>cast();
    return new IntRange(e.getAbsoluteTop(), e.getAbsoluteBottom());
  }
}
 
Example 7
Source File: VLayoutDragDropMouseHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
private boolean isEventOnScrollBar(NativeEvent event) {
    Element element = Element.as(event.getEventTarget());
    ;

    if (WidgetUtil.mayHaveScrollBars(element)) {

        final int nativeScrollbarSize = WidgetUtil.getNativeScrollbarSize();

        int x = WidgetUtil.getTouchOrMouseClientX(event)
                - element.getAbsoluteLeft();
        int y = WidgetUtil.getTouchOrMouseClientY(event)
                - element.getAbsoluteTop();

        // Hopefully we have horizontal scroll.
        final int scrollWidth = element.getScrollWidth();
        final int clientWidth = element.getClientWidth();
        if (scrollWidth > clientWidth
                && clientWidth - nativeScrollbarSize < x) {
            return true;
        }

        // Hopefully we have vertical scroll.
        final int scrollHeight = element.getScrollHeight();
        final int clientHeight = element.getClientHeight();
        if (scrollHeight > clientHeight
                && clientHeight - nativeScrollbarSize < y) {
            return true;
        }

    }

    return false;
}
 
Example 8
Source File: OffsetPosition.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the position of target relative to a specified element.
 * @param target
 * @param relative
 */
public static OffsetPosition getRelativePosition(OffsetPosition target, Element relative) {
  int parentLeft = 0;
  int parentTop = 0;
  if (target.offsetParent != null) {
    parentLeft = target.offsetParent.getAbsoluteLeft();
    parentTop = target.offsetParent.getAbsoluteTop();
  }
  int left = parentLeft + target.left - relative.getAbsoluteLeft();
  int top =  parentTop + target.top - relative.getAbsoluteTop();
  return new OffsetPosition(left, top, relative);
}
 
Example 9
Source File: GanttWidget.java    From gantt with Apache License 2.0 5 votes vote down vote up
protected void onTouchOrMouseDown(NativeEvent event) {
    if (targetBarElement != null && isMoveOrResizingInProgress()) {
        // discard previous 'operation'.
        resetBarPosition(targetBarElement);
        stopDrag(event);
        return;
    }
    Element bar = getBar(event);
    if (bar == null) {
        return;
    }

    targetBarElement = bar;
    capturePoint = new Point(getTouchOrMouseClientX(event), getTouchOrMouseClientY(event));
    movePoint = new Point(getTouchOrMouseClientX(event), getTouchOrMouseClientY(event));

    capturePointLeftPercentage = bar.getStyle().getProperty("left");
    capturePointWidthPercentage = bar.getStyle().getProperty("width");
    capturePointLeftPx = bar.getOffsetLeft();
    capturePointTopPx = bar.getOffsetTop();
    capturePointAbsTopPx = bar.getAbsoluteTop();
    capturePointWidthPx = bar.getClientWidth();
    capturePointBgColor = bar.getStyle().getBackgroundColor();

    if (detectResizing(bar)) {
        resizing = true;
        resizingFromLeft = isResizingLeft(bar);
    } else {
        resizing = false;
    }

    disallowClickTimer.schedule(CLICK_INTERVAL);
    insideDoubleClickDetectionInterval = true;
    doubleClickDetectionMaxTimer.schedule(DOUBLECLICK_DETECTION_INTERVAL);

    event.stopPropagation();
}
 
Example 10
Source File: Scrolling.java    From jetpad-projectional-open-source with Apache License 2.0 5 votes vote down vote up
private static Rectangle getBounds(Element element) {
  int x = element.getAbsoluteLeft();
  int y = element.getAbsoluteTop();
  int width = element.getScrollWidth();
  int height = element.getScrollHeight();
  return new Rectangle(x, y, width, height);
}
 
Example 11
Source File: InputDatePicker.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void popup(Widget container, Widget relativeTo) {
	this.setVisible(true);
	StyleUtils.addStyle(this, InputDatePicker.STYLE_POPUP);
	RootPanel.get().add(this);

	Element positioningElement = this.getElement();
	Element relativeElement = relativeTo.getElement();

	int targetHeight = relativeElement.getOffsetHeight();
	int targetTop = relativeElement.getAbsoluteTop();

	int positioningWidth = positioningElement.getOffsetWidth();
	int targetRight = relativeElement.getAbsoluteRight();

	Style elementStyle = positioningElement.getStyle();
	elementStyle.setPosition(Position.ABSOLUTE);
	elementStyle.setLeft(targetRight - positioningWidth, Unit.PX);
	elementStyle.setTop(targetTop + targetHeight, Unit.PX);

	StyleUtils.addStyle(this, InputDatePicker.STYLE_FADE);
	StyleUtils.addStyle(this, InputDatePicker.STYLE_SHOW);

	this.setFocus(true);

	if (this.popupBlurHandler == null) {
		this.popupBlurHandler = this.addBlurHandler(new BlurHandler() {

			@Override
			public void onBlur(BlurEvent event) {
				InputDatePicker.this.hide();
			}
		});
	}
}
 
Example 12
Source File: Scrolling.java    From jetpad-projectional-open-source with Apache License 2.0 5 votes vote down vote up
private static void adjustScrollers(Rectangle rect, Element element) {
  int left = element.getAbsoluteLeft() + rect.origin.x;
  int top = element.getAbsoluteTop() + rect.origin.y;
  int width = rect.dimension.x;
  int height = rect.dimension.y;

  while (element.getParentElement() != null) {
    Element parent = element.getParentElement();

    String overflow = $(parent).css("overflow");
    if ("scroll".equals(overflow) || "auto".equals(overflow)) {
      int scrollTop = parent.getScrollTop();
      int parentTop = parent.getAbsoluteTop();
      int parentHeight = parent.getClientHeight();
      int scrollLeft = parent.getScrollLeft();
      int parentLeft = parent.getAbsoluteLeft();
      int parentWidth = parent.getClientWidth();

      int deltaX = getScrollAdjustment(new Interval(parentLeft, parentLeft + parentWidth), new Interval(left, left + width), scrollLeft);
      if (deltaX != 0) {
        parent.setScrollLeft(scrollLeft + deltaX);
        left -= deltaX;
      }
      int deltaY = getDelta(new Interval(parentTop, parentTop + parentHeight), new Interval(top, top + height));
      if (deltaY != 0) {
        parent.setScrollTop(scrollTop + deltaY);
        top -= deltaY;
      }
    }

    element = parent;
  }
}
 
Example 13
Source File: SelectionCoordinatesHelperW3C.java    From swellrt with Apache License 2.0 5 votes vote down vote up
private IntRange getBounds(Node node, int offset) {
  if (node == null || node.getParentElement() == null) {
    // Return null if cannot get selection, or selection is inside an
    // "unattached" node.
    return null;
  }

  if (DomHelper.isTextNode(node)) {
    Element parentElement = node.getParentElement();
    return new IntRange(parentElement.getAbsoluteTop(), parentElement.getAbsoluteBottom());
  } else {
    Element e = node.<Element>cast();
    return new IntRange(e.getAbsoluteTop(), e.getAbsoluteBottom());
  }
}
 
Example 14
Source File: OffsetPosition.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the position of target relative to a specified element.
 * @param target
 * @param relative
 */
public static OffsetPosition getRelativePosition(OffsetPosition target, Element relative) {
  int parentLeft = 0;
  int parentTop = 0;
  if (target.offsetParent != null) {
    parentLeft = target.offsetParent.getAbsoluteLeft();
    parentTop = target.offsetParent.getAbsoluteTop();
  }
  int left = parentLeft + target.left - relative.getAbsoluteLeft();
  int top =  parentTop + target.top - relative.getAbsoluteTop();
  return new OffsetPosition(left, top, relative);
}
 
Example 15
Source File: VSliderPanel.java    From vaadin-sliderpanel with MIT License 5 votes vote down vote up
/**
 * checks whether the event come's from a elements that lays visually within the slider<br>
 * it doesn't lay directly in the dom tree - for example dropdown popups
 * 
 * @param event NativeEvent
 * @return true when events comes from within
 */
private boolean eventTargetsInnerElementsPopover(NativeEvent event) {
    EventTarget target = event.getEventTarget();
    if (Element.is(target)) {
        Element targetElement = Element.as(target);

        int absoluteLeft = targetElement.getAbsoluteLeft();
        int absoluteTop = targetElement.getAbsoluteTop();
        
        return contentNode.getAbsoluteLeft() <= absoluteLeft && contentNode.getAbsoluteRight() >= absoluteLeft && contentNode.getAbsoluteTop() <= absoluteTop
                && contentNode.getAbsoluteBottom() >= absoluteTop;
    }
    return false;
}
 
Example 16
Source File: Geometry.java    From gwt-traction with Apache License 2.0 4 votes vote down vote up
public static final int getY(Element e) {
    return e.getAbsoluteTop();
}
 
Example 17
Source File: NavSpy.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 4 votes vote down vote up
private int getElementTop(Element heading) {
	if (this.isBodyScrollWidget()) {
		return heading.getAbsoluteTop();
	}
	return heading.getOffsetTop() - this.scrollWidget.getElement().getOffsetTop();
}
 
Example 18
Source File: MeasurerInstance.java    From swellrt with Apache License 2.0 4 votes vote down vote up
@Override
public double bottom(Element base, Element e) {
  return e.getAbsoluteBottom() - (base != null ? base.getAbsoluteTop() : 0);
}
 
Example 19
Source File: MeasurerInstance.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
@Override
public double bottom(Element base, Element e) {
  return e.getAbsoluteBottom() - (base != null ? base.getAbsoluteTop() : 0);
}
 
Example 20
Source File: VDragDropUtil.java    From cuba with Apache License 2.0 2 votes vote down vote up
/**
 * Measures the top margin of an element
 * 
 * @param element
 *            The element to measure
 * @return Top margin in pixels
 */
public static int measureMarginTop(Element element) {
    return element.getAbsoluteTop()
            - element.getParentElement().getAbsoluteTop();
}