From ba10d13395e8b6a60eff9e0816f01c05d8e81604 Mon Sep 17 00:00:00 2001 From: John Alhroos Date: Fri, 6 Aug 2010 15:09:07 +0000 Subject: [PATCH] Fix for #5385 svn changeset:14429/svn branch:6.4 --- .../terminal/gwt/client/ui/VScrollTable.java | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java index eb7e872921..957e56f2cc 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java @@ -4864,7 +4864,12 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, // Set new focused row focusedRow = row; - row.getElement().scrollIntoView(); + /* + * We can't use row.getElement.scrollIntoView() here. It will scroll + * the row right if the table has horizontal scrollbars. Using + * homegrown method instead. #5385 + */ + ensureRowIsVisible(row); return true; } @@ -4872,6 +4877,37 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, return false; } + /** + * Ensures that the row is visible + * + * @param row + * The row to ensure is visible + */ + private void ensureRowIsVisible(VScrollTableRow row) { + boolean hasHorizontalScrollbars = scrollBody.getOffsetHeight() > scrollBodyPanel + .getOffsetHeight(); + int rowTop = row.getElement().getOffsetTop(); + int rowBottom = rowTop + row.getElement().getOffsetHeight(); + int bodyTop = scrollBodyPanel.getScrollPosition(); + int bodyBottom = bodyTop + getElement().getScrollHeight() + - tHead.getOffsetHeight(); + + // Take into account horizontal scrollbars + bodyBottom -= hasHorizontalScrollbars ? row.getOffsetHeight() : 0; + + // Scrolling above body + if (rowTop < bodyTop) { + int diff = bodyTop - rowTop; + scrollBodyPanel.setScrollPosition(bodyTop - diff); + } + + // Scrolling below body + if (rowBottom > bodyBottom) { + int diff = rowBottom - bodyBottom; + scrollBodyPanel.setScrollPosition(bodyTop + diff); + } + } + /** * Handles the keyboard events handled by the table * -- 2.39.5