}
- private int getLastVisibleRowIndex() {
- int lastRowIndex = escalator.getVisibleRowRange().getEnd();
- int footerTop = escalator.getFooter().getElement().getAbsoluteTop();
- Element lastRow;
-
- do {
- lastRow = escalator.getBody().getRowElement(--lastRowIndex);
- } while (lastRow.getAbsoluteBottom() > footerTop);
-
- return lastRowIndex;
- }
-
- private int getFirstVisibleRowIndex() {
- int firstRowIndex = escalator.getVisibleRowRange().getStart();
- int headerBottom = escalator.getHeader().getElement()
- .getAbsoluteBottom();
- Element firstRow = escalator.getBody().getRowElement(firstRowIndex);
-
- while (firstRow.getAbsoluteTop() < headerBottom) {
- firstRow = escalator.getBody().getRowElement(++firstRowIndex);
- }
-
- return firstRowIndex;
- }
-
private RowContainer getPreviousContainer(RowContainer current) {
if (current == escalator.getFooter()) {
current = escalator.getBody();
&& (Util.getFocusedElement() == getElement() || cell != null)) {
activeCellHandler.handleNavigationEvent(event, cell);
}
+
+ handleGridNavigation(event, cell);
}
}
+ private void handleGridNavigation(Event event, Cell cell) {
+ if (!event.getType().equals(BrowserEvents.KEYDOWN)) {
+ // Only handle key downs
+ return;
+ }
+
+ int newRow = -1;
+ RowContainer container = escalator.getBody();
+ switch (event.getKeyCode()) {
+ case KeyCodes.KEY_HOME:
+ if (container.getRowCount() > 0) {
+ newRow = 0;
+ }
+ break;
+ case KeyCodes.KEY_END:
+ if (container.getRowCount() > 0) {
+ newRow = container.getRowCount() - 1;
+ }
+ break;
+ case KeyCodes.KEY_PAGEUP: {
+ Range range = escalator.getVisibleRowRange();
+ if (!range.isEmpty()) {
+ int firstIndex = getFirstVisibleRowIndex();
+ newRow = firstIndex - range.length();
+ if (newRow < 0) {
+ newRow = 0;
+ }
+ }
+ break;
+ }
+ case KeyCodes.KEY_PAGEDOWN: {
+ Range range = escalator.getVisibleRowRange();
+ if (!range.isEmpty()) {
+ int lastIndex = getLastVisibleRowIndex();
+ newRow = lastIndex + range.length();
+ if (newRow >= container.getRowCount()) {
+ newRow = container.getRowCount() - 1;
+ }
+ }
+ break;
+ }
+ default:
+ return;
+ }
+
+ scrollToRow(newRow);
+ }
+
private Point rowEventTouchStartingPoint;
private boolean handleDefaultRowEvent(final Cell cell, NativeEvent event) {
fireEvent(new SortEvent<T>(this,
Collections.unmodifiableList(sortOrder), originator));
}
+
+ private int getLastVisibleRowIndex() {
+ int lastRowIndex = escalator.getVisibleRowRange().getEnd();
+ int footerTop = escalator.getFooter().getElement().getAbsoluteTop();
+ Element lastRow;
+
+ do {
+ lastRow = escalator.getBody().getRowElement(--lastRowIndex);
+ } while (lastRow.getAbsoluteBottom() > footerTop);
+
+ return lastRowIndex;
+ }
+
+ private int getFirstVisibleRowIndex() {
+ int firstRowIndex = escalator.getVisibleRowRange().getStart();
+ int headerBottom = escalator.getHeader().getElement()
+ .getAbsoluteBottom();
+ Element firstRow = escalator.getBody().getRowElement(firstRowIndex);
+
+ while (firstRow.getAbsoluteTop() < headerBottom) {
+ firstRow = escalator.getBody().getRowElement(++firstRowIndex);
+ }
+
+ return firstRowIndex;
+ }
}
import org.openqa.selenium.interactions.Actions;
import com.vaadin.tests.components.grid.GridElement;
-import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
+import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures;
import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
public class GridKeyboardNavigationTest extends GridBasicFeaturesTest {
assertTrue("Footer cell 0, 2 is not active", grid.getFooterCell(0, 2)
.isActive());
}
+
+ @Test
+ public void testHomeEnd() throws Exception {
+ openTestURL();
+
+ getGridElement().getCell(100, 2).click();
+
+ new Actions(getDriver()).sendKeys(Keys.HOME).perform();
+ assertTrue("First row is not visible", getGridElement().getCell(0, 2)
+ .isDisplayed());
+
+ new Actions(getDriver()).sendKeys(Keys.END).perform();
+ assertTrue("Last row cell not visible",
+ getGridElement().getCell(GridBasicFeatures.ROWS - 1, 2)
+ .isDisplayed());
+ }
+
+ @Test
+ public void testPageUpPageDown() throws Exception {
+ openTestURL();
+
+ selectMenuPath("Component", "Size", "HeightMode Row");
+
+ getGridElement().getCell(5, 2).click();
+
+ new Actions(getDriver()).sendKeys(Keys.PAGE_DOWN).perform();
+ assertTrue("Row 5 did not remain active", getGridElement()
+ .getCell(5, 2).isActive());
+ assertTrue("Row 20 did not become visible",
+ getGridElement().getCell(20, 2).isDisplayed());
+
+ new Actions(getDriver()).sendKeys(Keys.PAGE_DOWN).perform();
+ assertTrue("Row 5 did not remain active", getGridElement()
+ .getCell(5, 2).isActive());
+ assertTrue("Row 40 did not become visible",
+ getGridElement().getCell(40, 2).isDisplayed());
+
+ getGridElement().getCell(50, 2).click();
+
+ new Actions(getDriver()).sendKeys(Keys.PAGE_UP).perform();
+ assertTrue("Row 50 did not remain active",
+ getGridElement().getCell(50, 2).isActive());
+ assertTrue("Row 20 did not become visible",
+ getGridElement().getCell(20, 2).isDisplayed());
+
+ new Actions(getDriver()).sendKeys(Keys.PAGE_UP).perform();
+ assertTrue("Row 50 did not remain active",
+ getGridElement().getCell(50, 2).isActive());
+ assertTrue("Row 0 did not become visible",
+ getGridElement().getCell(0, 2).isDisplayed());
+
+ }
+
}