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

The following examples show how to use com.google.gwt.dom.client.Element#getScrollTop() . 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: CubaScrollBoxLayoutWidget.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
    super.onBrowserEvent(event);

    if (DOM.eventGetType(event) == Event.ONSCROLL) {
        Element element = getElement();

        int scrollTop = element.getScrollTop();
        int scrollLeft = element.getScrollLeft();

        if (this.scrollTop != scrollTop || this.scrollLeft != scrollLeft) {

            this.scrollTop = scrollTop;
            this.scrollLeft = scrollLeft;

            if (CubaScrollBoxLayoutState.DEFERRED_MODE.equals(scrollChangeMode)) {
                updateScrollState();
            } else {
                scrollBoxStateTrigger.cancel();
                scrollBoxStateTrigger.schedule(TIMEOUT);
            }
        }
    }
}
 
Example 2
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 3
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 4
Source File: AutoSizingTextArea.java    From gwt-traction with Apache License 2.0 5 votes vote down vote up
/**
    * Returns the size of the shadow element
    */
   @Override
   public int getShadowSize() {
Element shadowElement = shadow.getElement();
shadowElement.setScrollTop(10000);
return shadowElement.getScrollTop();
   }
 
Example 5
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;
  }
}