From 833e6e3bd98ff04a35b428c35afe16c874893780 Mon Sep 17 00:00:00 2001 From: Artur Date: Tue, 7 Mar 2017 12:44:01 +0200 Subject: Always calculate Escalator max row count the same way (#8740) * Rename getMaxEscalatorRowCapacity to describe what it does * Always calculate Escalator max row count the same way This changes Escalator to not take a horizontal scrollbar into account when trying to determine "maximum visible rows". This will add another row, compared to previous versions, when there is a horizontal scrollbar. In reality, it would likely make sense to always add 10 more rows to have some buffer above and below the visible area. Fixes #8661 --- .../com/vaadin/v7/client/widgets/Escalator.java | 32 +++++++++++++--------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'compatibility-client') diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/widgets/Escalator.java b/compatibility-client/src/main/java/com/vaadin/v7/client/widgets/Escalator.java index 04fcdbe766..f022d691b7 100644 --- a/compatibility-client/src/main/java/com/vaadin/v7/client/widgets/Escalator.java +++ b/compatibility-client/src/main/java/com/vaadin/v7/client/widgets/Escalator.java @@ -2982,7 +2982,7 @@ public class Escalator extends Widget private List fillAndPopulateEscalatorRowsIfNeeded( final int index, final int numberOfRows) { - final int escalatorRowsStillFit = getMaxEscalatorRowCapacity() + final int escalatorRowsStillFit = getMaxVisibleRowCount() - getDomRowCount(); final int escalatorRowsNeeded = Math.min(numberOfRows, escalatorRowsStillFit); @@ -3015,16 +3015,22 @@ public class Escalator extends Widget } } - private int getMaxEscalatorRowCapacity() { - final int maxEscalatorRowCapacity = (int) Math - .ceil(getHeightOfSection() / getDefaultRowHeight()) + 1; + private int getMaxVisibleRowCount() { + double heightOfSection = getHeightOfSection(); + // By including the possibly shown scrollbar height, we get a + // consistent count and do not add/remove rows whenever a scrollbar + // is shown + heightOfSection += horizontalScrollbarDeco.getOffsetHeight(); + double defaultRowHeight = getDefaultRowHeight(); + final int maxVisibleRowCount = (int) Math + .ceil(heightOfSection / defaultRowHeight) + 1; /* - * maxEscalatorRowCapacity can become negative if the headers and - * footers start to overlap. This is a crazy situation, but Vaadin - * blinks the components a lot, so it's feasible. + * maxVisibleRowCount can become negative if the headers and footers + * start to overlap. This is a crazy situation, but Vaadin blinks + * the components a lot, so it's feasible. */ - return Math.max(0, maxEscalatorRowCapacity); + return Math.max(0, maxVisibleRowCount); } @Override @@ -3507,12 +3513,12 @@ public class Escalator extends Widget * TODO [[spacer]]: these assumptions will be totally broken with * spacers. */ - final int maxEscalatorRows = getMaxEscalatorRowCapacity(); + final int maxVisibleRowCount = getMaxVisibleRowCount(); final int currentTopRowIndex = getLogicalRowIndex( visualRowOrder.getFirst()); final Range[] partitions = logicalRange.partitionWith( - Range.withLength(currentTopRowIndex, maxEscalatorRows)); + Range.withLength(currentTopRowIndex, maxVisibleRowCount)); final Range insideRange = partitions[1]; return insideRange.offsetBy(-currentTopRowIndex); } @@ -3624,8 +3630,8 @@ public class Escalator extends Widget return; } - final int maxEscalatorRows = getMaxEscalatorRowCapacity(); - final int neededEscalatorRows = Math.min(maxEscalatorRows, + final int maxVisibleRowCount = getMaxVisibleRowCount(); + final int neededEscalatorRows = Math.min(maxVisibleRowCount, body.getRowCount()); final int neededEscalatorRowsDiff = neededEscalatorRows - visualRowOrder.size(); @@ -6673,7 +6679,7 @@ public class Escalator extends Widget * @return the maximum capacity */ public int getMaxVisibleRowCount() { - return body.getMaxEscalatorRowCapacity(); + return body.getMaxVisibleRowCount(); } /** -- cgit v1.2.3