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

The following examples show how to use com.google.gwt.dom.client.Element#getOffsetLeft() . 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: ArrowPositionData.java    From gantt with Apache License 2.0 6 votes vote down vote up
public ArrowPositionData(Element from, Element to) {
    this.from = from;
    this.to = to;

    predecessorHeightCenter = from.getOffsetHeight() / 2;
    predecessorTop = from.getOffsetTop();
    predecesorBottom = from.getOffsetTop() + from.getOffsetHeight();
    predecessorRight = from.getOffsetLeft() + from.getOffsetWidth();
    predecessorLeft = from.getOffsetLeft();
    thisBottom = to.getOffsetTop() + to.getOffsetHeight();
    thisCenter = to.getOffsetHeight() / 2;

    top = Math.min(predecessorTop, to.getOffsetTop());
    bottom = Math.max(predecesorBottom, thisBottom);
    height = bottom - top;

    left = Math.min(predecessorRight, to.getOffsetLeft());
    right = Math.max(predecessorRight, to.getOffsetLeft());
    width = right - left;

    fromTop = predecessorTop <= to.getOffsetTop();
    fromLeft = predecessorRight <= to.getOffsetLeft();
    halfWidth = (int) width / 2;
}
 
Example 2
Source File: DomUtil.java    From jetpad-projectional-open-source with Apache License 2.0 6 votes vote down vote up
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 {
      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);
    }
  }
}
 
Example 3
Source File: TextLayer.java    From djvu-html5 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onScroll(ScrollEvent event) {
	int scrollTop = getElement().getScrollTop();
	int page = currentPage;
	Element pageElement = pages.get(page).getElement();
	while (page > 0 && pageElement.getOffsetTop() > scrollTop) {
		pageElement = pages.get(--page).getElement();
	}
	while (page + 1 < pages.size() && pageElement.getOffsetTop() + pageElement.getOffsetHeight() < scrollTop) {
		pageElement = pages.get(++page).getElement();
	}
	int left = pageElement.getOffsetLeft() - getElement().getScrollLeft();
	int top = pageElement.getOffsetTop() - scrollTop;
	app.getPageLayout().externalScroll(page, left, top);
}
 
Example 4
Source File: SelectionCoordinatesHelperW3C.java    From swellrt with Apache License 2.0 5 votes vote down vote up
private OffsetPosition getNearestElementPosition(Node focusNode, int focusOffset) {
  Node startContainer;
  if (focusNode == null) {
    return null;
  }

  Element e =
    DomHelper.isTextNode(focusNode) ? focusNode.getParentElement() : focusNode.<Element>cast();
  return e == null ? null
      : new OffsetPosition(e.getOffsetLeft(), e.getOffsetTop(), e.getOffsetParent());
}
 
Example 5
Source File: SelectionCoordinatesHelperW3C.java    From swellrt with Apache License 2.0 5 votes vote down vote up
private OffsetPosition getPosition(Node focusNode, int focusOffset) {
  if (focusNode == null || focusNode.getParentElement() == null) {
    // Return null if cannot get selection, or selection is inside an
    // "unattached" node.
    return null;
  }

  if (DomHelper.isTextNode(focusNode)) {
    // We don't want to split the existing child text node, so we just add
    // duplicate the string up to the offset.
    Node txt =
        Document.get().createTextNode(
            focusNode.getNodeValue().substring(0, focusOffset));
    try {
      mutationListener.startTransientMutations();
      focusNode.getParentNode().insertBefore(txt, focusNode);
      txt.getParentNode().insertAfter(SPAN, txt);
      OffsetPosition ret =
          new OffsetPosition(SPAN.getOffsetLeft(), SPAN.getOffsetTop(), SPAN.getOffsetParent());

      return ret;
    } finally {
      SPAN.removeFromParent();
      txt.removeFromParent();
      mutationListener.endTransientMutations();
    }
  } else {
    Element e = focusNode.cast();
    return new OffsetPosition(e.getOffsetLeft(), e.getOffsetTop(), e.getOffsetParent());
  }
}
 
Example 6
Source File: AbstractHover.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void resetPosition(Element toPositionedElement, Widget relativeTo, Placement placement) {
	Element relativeElement = relativeTo.getElement();

	com.google.gwt.dom.client.Style elementStyle = toPositionedElement.getStyle();
	int tooltipWidth = toPositionedElement.getOffsetWidth();
	int tooltipHeight = toPositionedElement.getOffsetHeight();

	int targetWidth = relativeElement.getOffsetWidth();
	int targetHeight = relativeElement.getOffsetHeight();
	int targetTop = relativeElement.getOffsetTop();
	int targetLeft = relativeElement.getOffsetLeft();

	elementStyle.setPosition(Position.ABSOLUTE);
	switch (placement) {
		case TOP:
			elementStyle.setLeft(targetLeft + targetWidth / 2 - tooltipWidth / 2, Unit.PX);
			elementStyle.setTop(targetTop - tooltipHeight, Unit.PX);
			break;
		case BOTTOM:
			elementStyle.setLeft(targetLeft + targetWidth / 2 - tooltipWidth / 2, Unit.PX);
			elementStyle.setTop(targetTop + targetHeight, Unit.PX);
			break;
		case LEFT:
			elementStyle.setLeft(targetLeft - tooltipWidth, Unit.PX);
			elementStyle.setTop(targetTop + targetHeight / 2 - tooltipHeight / 2, Unit.PX);
			break;
		case RIGHT:
			elementStyle.setLeft(targetLeft + targetWidth, Unit.PX);
			elementStyle.setTop(targetTop + targetHeight / 2 - tooltipHeight / 2, Unit.PX);
			break;
		default:
			break;
	}
}
 
Example 7
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 8
Source File: SelectionCoordinatesHelperW3C.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
private OffsetPosition getNearestElementPosition(Node focusNode, int focusOffset) {
  Node startContainer;
  if (focusNode == null) {
    return null;
  }

  Element e =
    DomHelper.isTextNode(focusNode) ? focusNode.getParentElement() : focusNode.<Element>cast();
  return e == null ? null
      : new OffsetPosition(e.getOffsetLeft(), e.getOffsetTop(), e.getOffsetParent());
}
 
Example 9
Source File: SelectionCoordinatesHelperW3C.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
private OffsetPosition getPosition(Node focusNode, int focusOffset) {
  if (focusNode == null || focusNode.getParentElement() == null) {
    // Return null if cannot get selection, or selection is inside an
    // "unattached" node.
    return null;
  }

  if (DomHelper.isTextNode(focusNode)) {
    // We don't want to split the existing child text node, so we just add
    // duplicate the string up to the offset.
    Node txt =
        Document.get().createTextNode(
            focusNode.getNodeValue().substring(0, focusOffset));
    try {
      mutationListener.startTransientMutations();
      focusNode.getParentNode().insertBefore(txt, focusNode);
      txt.getParentNode().insertAfter(SPAN, txt);
      OffsetPosition ret =
          new OffsetPosition(SPAN.getOffsetLeft(), SPAN.getOffsetTop(), SPAN.getOffsetParent());

      return ret;
    } finally {
      SPAN.removeFromParent();
      txt.removeFromParent();
      mutationListener.endTransientMutations();
    }
  } else {
    Element e = focusNode.cast();
    return new OffsetPosition(e.getOffsetLeft(), e.getOffsetTop(), e.getOffsetParent());
  }
}