Example usage for com.google.gwt.dom.client Document setScrollTop

List of usage examples for com.google.gwt.dom.client Document setScrollTop

Introduction

In this page you can find the example usage for com.google.gwt.dom.client Document setScrollTop.

Prototype

public void setScrollTop(int top) 

Source Link

Usage

From source file:org.rstudio.core.client.ScrollUtil.java

License:Open Source License

public static void setScrollPositionOnLoad(final RStudioFrame frame, final int scrollPosition) {
    Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
        @Override/*from  ww w  . j  a  v  a 2  s  .  c  o  m*/
        public boolean execute() {
            // don't wait indefinitely for the document to load
            retries_++;
            if (retries_ > MAX_SCROLL_RETRIES)
                return false;

            // wait for a document to become available in the frame
            if (frame.getIFrame() == null)
                return true;

            if (frame.getIFrame().getContentDocument() == null)
                return true;

            // wait for the document to finish loading
            Document doc = frame.getIFrame().getContentDocument();
            String readyState = getDocumentReadyState(doc);
            if (readyState == null)
                return true;

            if (!readyState.equals("complete"))
                return true;

            // wait for a real document to load (about:blank may be intermediate)
            if (doc.getScrollTop() > 0)
                return true;

            if (doc.getURL().equals(ViewerPane.ABOUT_BLANK))
                return true;

            // restore scroll position
            if (scrollPosition > 0)
                doc.setScrollTop(scrollPosition);

            return false;
        }

        private int retries_ = 0;
    }, SCROLL_RETRY_MS);
}