When creating a custom widget, I want to be able to scroll something (for example InlineLabel in a FlowPanel in a ScrollPanel).
First try to understand various coordinations I can obtain from a click event
"event" below is com.google.gwt.event.dom.client.ClickEvent received by a ClickHandler.
Method 1: ScrollPanel.ensureVisible(UIObject item) - Ensures that the specified item is visible, by adjusting the panel's scroll position.
Method 2: element.scrollIntoView - crawl up DOM tree and scroll every scrollable element to show this element
Method 3: calculate and scroll. use absolute position of both scroll panel left-top corner and the object, calculate how much to further scroll, then calculate scroll position with current scroll position, and not to exceed min / max scroll position.
// sp is the ScrollPanel
// calculate scroll, try to scroll element to mid point
int scrollPanelMidVertical = sp.getAbsoluteTop()+sp.getOffsetHeight()/2;
int newScrollVerticalPos = sp.getVerticalScrollPosition()+(e.getAbsoluteTop()-scrollPanelMidVertical);
if (newScrollVerticalPos < sp.getMinimumVerticalScrollPosition())
newScrollVerticalPos = sp.getMinimumVerticalScrollPosition();
if (newScrollVerticalPos > sp.getMaximumVerticalScrollPosition())
newScrollVerticalPos = sp.getMaximumVerticalScrollPosition();
sp.setVerticalScrollPosition(newScrollVerticalPos);