code: public static int getScrollIntoView (Widget target)
      {
          int top = Window.getScrollTop(), height = Window.getClientHeight();
          int ttop = target.getAbsoluteTop(), theight = target.getOffsetHeight();
          // if the target widget is taller than the browser window, or is above the current scroll
          // position of the browser window, scroll the top of the widget to the top of the window
          if (theight > height || ttop < top) {
              return ttop;
          // otherwise scroll the bottom of the widget to the bottom of the window
          } else if (ttop + theight > top + height) {
              return ttop - (height - theight);
          } else {
              return top; // no scrolling needed
          }
      }
docs: Returns the vertical scroll position needed to place the specified target widget in view,
  while trying to minimize scrolling.