From 0a931b7fc43769a8b7cc6ef58e0cfa531e0903af Mon Sep 17 00:00:00 2001 From: Ismo Haataja Date: Wed, 8 Oct 2014 15:28:01 +0300 Subject: Fix for scrolling the active row visible in diff page When using keyboard navigation keys in the diff page, the active row was not automatically scrolled into view in Chrome and IE. Firefox did not have the same problem, though. The 'scrollIntoView' function from 'com.google.gwt.client.Element' class just doesn't work correctly in those two browsers. Problem fixed by implementing an own version for scrolling the window to correct position. Task-number: QTQAINFRA-903 Change-Id: I170fa0e4d2f45fcab95e2af08ed9530b71c1ee15 Reviewed-by: Oswald Buddenhagen Reviewed-by: Ismo Haataja --- .../java/com/google/gerrit/client/ui/NavigationTable.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/NavigationTable.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/NavigationTable.java index 7e1add3914..7c41a43225 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/NavigationTable.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/NavigationTable.java @@ -20,6 +20,7 @@ import com.google.gwt.dom.client.Document; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Event; +import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.HTMLTable.CellFormatter; import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.ScrollPanel; @@ -267,7 +268,18 @@ public abstract class NavigationTable extends FancyFlexTable { } }); } else { - tr.scrollIntoView(); + // tr.scrollIntoView(); works just for Firefox, not for Chrome and IE + // so replacing it with following which works for all three browsers + final int sTop = Window.getScrollTop(); + final int sEnd = sTop + Window.getClientHeight(); + final int eTop = tr.getAbsoluteTop(); + final int eEnd = eTop + tr.getClientHeight(); + // Element below view area + if (eEnd > sEnd) { + Window.scrollTo(Window.getScrollLeft(), eEnd - Window.getClientHeight()); + } else if (eTop < sTop) { // Element above view area + Window.scrollTo(Window.getScrollLeft(), eTop); + } } } -- cgit v1.2.3