summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorMika Murtojarvi <mika@vaadin.com>2015-06-25 13:07:23 +0300
committerHenri Sara <hesara@vaadin.com>2015-07-04 14:33:02 +0300
commit861581c1b87a0b3ef42b55544372497bc829d60c (patch)
tree0c61ccbabf82edf07c5d92807c05bfda793bc9d7 /client
parent337e4a7fe7836286aa96898b23db34eafb55ade9 (diff)
downloadvaadin-framework-861581c1b87a0b3ef42b55544372497bc829d60c.tar.gz
vaadin-framework-861581c1b87a0b3ef42b55544372497bc829d60c.zip
Change focused Grid cell when scrolling with the keyboard (#18356).
- The focused cell is now updated when scrolling with pageup/down, home or end key. - The scroll amount is slightly reduced to ensure that no cells are skipped over with pgup/down scroll. Change-Id: I8a7dccf46350761f86714715183b24ec29d79f4e
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/widgets/Grid.java89
1 files changed, 35 insertions, 54 deletions
diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java
index f6772ba1f6..b3edca9140 100644
--- a/client/src/com/vaadin/client/widgets/Grid.java
+++ b/client/src/com/vaadin/client/widgets/Grid.java
@@ -2146,6 +2146,41 @@ public class Grid<T> extends ResizeComposite implements
return;
}
break;
+ case KeyCodes.KEY_HOME:
+ if (newContainer.getRowCount() > 0) {
+ newRow = 0;
+ }
+ break;
+ case KeyCodes.KEY_END:
+ if (newContainer.getRowCount() > 0) {
+ newRow = newContainer.getRowCount() - 1;
+ }
+ break;
+ case KeyCodes.KEY_PAGEDOWN:
+ case KeyCodes.KEY_PAGEUP:
+ if (newContainer.getRowCount() > 0) {
+ boolean down = event.getKeyCode() == KeyCodes.KEY_PAGEDOWN;
+ // If there is a visible focused cell, scroll by one
+ // page from its position. Otherwise, use the first or
+ // the last visible row as the scroll start position.
+ // This avoids jumping when using both keyboard and the
+ // scroll bar for scrolling.
+ int firstVisible = getFirstVisibleRowIndex();
+ int lastVisible = getLastVisibleRowIndex();
+ if (newRow < firstVisible || newRow > lastVisible) {
+ newRow = down ? lastVisible : firstVisible;
+ }
+ // Scroll by a little less than the visible area to
+ // account for the possibility that the top and the
+ // bottom row are only partially visible.
+ int moveFocusBy = Math.max(1, lastVisible
+ - firstVisible - 1);
+ moveFocusBy *= down ? 1 : -1;
+ newRow += moveFocusBy;
+ newRow = Math.max(0, Math.min(
+ newContainer.getRowCount() - 1, newRow));
+ }
+ break;
default:
return;
}
@@ -6376,10 +6411,6 @@ public class Grid<T> extends ResizeComposite implements
return;
}
- if (handleNavigationEvent(event, container)) {
- return;
- }
-
if (handleCellFocusEvent(event, container)) {
return;
}
@@ -6518,56 +6549,6 @@ public class Grid<T> extends ResizeComposite implements
return false;
}
- private boolean handleNavigationEvent(Event event, RowContainer unused) {
- if (!event.getType().equals(BrowserEvents.KEYDOWN)) {
- // Only handle key downs
- return false;
- }
-
- 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 false;
- }
-
- scrollToRow(newRow);
-
- return true;
- }
-
private boolean handleHeaderCellDragStartEvent(Event event,
RowContainer container) {
if (!isColumnReorderingAllowed()) {