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

The following examples show how to use com.google.gwt.dom.client.Element#getOffsetTop() . 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: 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 2
Source File: Lookup.java    From unitime with Apache License 2.0 6 votes vote down vote up
private void scrollToSelectedRow() {
	int row = iTable.getSelectedRow();
	if (row < 0) return;
	
	Element scroll = iScroll.getElement();
	
	Element item = iTable.getRowFormatter().getElement(iTable.getSelectedRow());
	if (item==null) return;
	
	int realOffset = 0;
	while (item !=null && !item.equals(scroll)) {
		realOffset += item.getOffsetTop();
		item = item.getOffsetParent();
	}
	
	scroll.setScrollTop(realOffset - scroll.getOffsetHeight() / 2);
}
 
Example 3
Source File: TextLayer.java    From djvu-html5 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param left position of page's left edge on the canvas
 * @param top position of page's top edge on the canvas
 */
public void setViewPosition(int pageNum, int left, int top, double zoom) {
	boolean pageChanged = currentPage != pageNum;
	TextPage page = getPage(pageNum);
	if (pageChanged) {
		getPage(currentPage).removeStyleName(PAGE_STYLE_VISIBLE);
		page.addStyleName(PAGE_STYLE_VISIBLE);
	}
	page.resize(zoom, pageChanged);
	currentPage = pageNum;

	Element layerElement = getElement();
	Element pageElement = page.getElement();
	pageElement.getStyle().setMarginLeft(Math.max(left, 0) + EXTRA_PAGE_MARGIN, Unit.PX);

	int targetScrollLeft = Math.max(-left, 0) + EXTRA_PAGE_MARGIN;
	if (layerElement.getScrollLeft() != targetScrollLeft)
		layerElement.setScrollLeft(targetScrollLeft);

	int targetScrollTop = pageElement.getOffsetTop() - top;
	if (layerElement.getScrollTop() != targetScrollTop)
		layerElement.setScrollTop(targetScrollTop);
}
 
Example 4
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 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: 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());
  }
}
 
Example 7
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 8
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 9
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 10
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 11
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 12
Source File: TeachingRequestDetailPage.java    From unitime with Apache License 2.0 5 votes vote down vote up
protected void scrollToRow(Integer row) {
	if (row != null) {
		Element scroll = iScroll.getElement();
		Element item = iForm.getRowFormatter().getElement(row);
		int realOffset = 0;
		while (item !=null && !item.equals(scroll)) {
			realOffset += item.getOffsetTop();
			item = item.getOffsetParent();
		}
		scroll.setScrollTop(realOffset - scroll.getOffsetHeight() / 2);
	}
}
 
Example 13
Source File: MaterialCutOut.java    From gwt-material-addins with Apache License 2.0 5 votes vote down vote up
/**
 * Setups the cut out position when the screen changes size or is scrolled.
 */
protected void setupCutOutPosition(Element cutOut, Element relativeTo, int padding, boolean circle) {
    float top = relativeTo.getOffsetTop() - (Math.max($("html").scrollTop(), $("body").scrollTop()));
    float left = relativeTo.getAbsoluteLeft();

    float width = relativeTo.getOffsetWidth();
    float height = relativeTo.getOffsetHeight();

    if (circle) {
        if (width != height) {
            float dif = width - height;
            if (width > height) {
                height += dif;
                top -= dif / 2;
            } else {
                dif = -dif;
                width += dif;
                left -= dif / 2;
            }
        }
    }

    top -= padding;
    left -= padding;
    width += padding * 2;
    height += padding * 2;

    $(cutOut).css("top", top + "px");
    $(cutOut).css("left", left + "px");
    $(cutOut).css("width", width + "px");
    $(cutOut).css("height", height + "px");
}
 
Example 14
Source File: DateCell.java    From calendar-component with Apache License 2.0 4 votes vote down vote up
private void handleEventRange(final MouseEvent event) {

        if (event.getNativeButton() != NativeEvent.BUTTON_LEFT) {
            return;
        }

        if (eventRangeStart >= 0) {

            int newY = event.getY();
            int fromY, toY;

            if (newY < eventRangeStart) {
                fromY = newY;
                toY = eventRangeStart;
            } else {
                fromY = eventRangeStart;
                toY = newY;
            }

            eventRangeStop = newY;

            Element main = getElement();
            NodeList<Node> nodes = main.getChildNodes();
            for (int i = 0; i < nodes.getLength(); i++) {

                Element c = (Element) nodes.getItem(i);

                if (Arrays.stream(slotElements).anyMatch(e -> e == c)) {

                    int elemStart = c.getOffsetTop();
                    int elemStop = elemStart + getSlotHeight();
                    if (elemStart >= fromY && elemStart <= toY) {
                        c.addClassName("v-daterange");
                    } else if (elemStop >= fromY && elemStop <= toY) {
                        c.addClassName("v-daterange");
                    } else if (elemStop >= fromY && elemStart <= toY) {
                        c.addClassName("v-daterange");
                    } else {
                        c.removeClassName("v-daterange");
                    }
                }
            }
        }

        event.preventDefault();
    }
 
Example 15
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 16
Source File: MeasurerInstance.java    From swellrt with Apache License 2.0 4 votes vote down vote up
@Override
public double offsetBottom(Element e) {
  return e.getOffsetTop() + e.getOffsetHeight();
}
 
Example 17
Source File: MeasurerInstance.java    From swellrt with Apache License 2.0 4 votes vote down vote up
@Override
public double offsetTop(Element e) {
  return e.getOffsetTop();
}
 
Example 18
Source File: MeasurerInstance.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
@Override
public double offsetTop(Element e) {
  return e.getOffsetTop();
}
 
Example 19
Source File: MeasurerInstance.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
@Override
public double offsetBottom(Element e) {
  return e.getOffsetTop() + e.getOffsetHeight();
}