diff options
author | Markus Koivisto <markus@vaadin.com> | 2015-04-08 14:54:53 +0300 |
---|---|---|
committer | Markus Koivisto <markus@vaadin.com> | 2015-04-08 14:54:53 +0300 |
commit | db5fc67b3833e0424f5773c68dd98291282ebad1 (patch) | |
tree | fe2cc86ecefdf0fc9fc754e5cc14041df4fd8f2f /client | |
parent | 2478267d11fddfd798fee89227b5f258441e1331 (diff) | |
parent | 35d4a8fd0ec558b3a2a20bc6ffd0f1048ffc4c4d (diff) | |
download | vaadin-framework-db5fc67b3833e0424f5773c68dd98291282ebad1.tar.gz vaadin-framework-db5fc67b3833e0424f5773c68dd98291282ebad1.zip |
Merge branch 'grid-7.5' of ssh://dev.vaadin.com:29418/vaadin into grid-7.5
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/widgets/Escalator.java | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/client/src/com/vaadin/client/widgets/Escalator.java b/client/src/com/vaadin/client/widgets/Escalator.java index fe8ba4f67e..01567143dd 100644 --- a/client/src/com/vaadin/client/widgets/Escalator.java +++ b/client/src/com/vaadin/client/widgets/Escalator.java @@ -3720,19 +3720,32 @@ public class Escalator extends Widget implements RequiresResize, List<TableRowElement> orderedBodyRows = new ArrayList<TableRowElement>( visualRowOrder); - for (int i = 0; i < visualRowOrder.size(); i++) { - SpacerContainer.SpacerImpl spacer = body.spacerContainer - .getSpacer(getTopRowLogicalIndex() + i); + Map<Integer, SpacerContainer.SpacerImpl> spacers = body.spacerContainer + .getSpacers(); + + /* + * Start at -1 to include a spacer that is rendered above the + * viewport, but its parent row is still not shown + */ + for (int i = -1; i < visualRowOrder.size(); i++) { + SpacerContainer.SpacerImpl spacer = spacers.remove(Integer + .valueOf(getTopRowLogicalIndex() + i)); if (spacer != null) { orderedBodyRows.add(i + 1, spacer.getRootElement()); + spacer.show(); } } /* * At this point, invisible spacers aren't reordered, so their - * position in the DOM is undefined. + * position in the DOM will remain undefined. */ + // If a spacer was not reordered, it means that it's out of view. + for (SpacerContainer.SpacerImpl unmovedSpacer : spacers.values()) { + unmovedSpacer.hide(); + } + /* * If we have a focused row, start in the mode where we put * everything underneath that row. Otherwise, all rows are placed as @@ -4755,6 +4768,33 @@ public class Escalator extends Widget implements RequiresResize, root.setPropertyInt(SPACER_LOGICAL_ROW_PROPERTY, rowIndex); rowIndexToSpacer.put(this.rowIndex, this); } + + /** + * Updates the spacer's visibility parameters, based on whether it + * is being currently visible or not. + */ + public void updateVisibility() { + if (isInViewport()) { + show(); + } else { + hide(); + } + } + + private boolean isInViewport() { + int top = (int) Math.ceil(getTop()); + int height = (int) Math.floor(getHeight()); + Range location = Range.withLength(top, height); + return getViewportPixels().intersects(location); + } + + public void show() { + getRootElement().getStyle().clearDisplay(); + } + + public void hide() { + getRootElement().getStyle().setDisplay(Display.NONE); + } } private final TreeMap<Integer, SpacerImpl> rowIndexToSpacer = new TreeMap<Integer, SpacerImpl>(); @@ -4887,6 +4927,10 @@ public class Escalator extends Widget implements RequiresResize, } } + public Map<Integer, SpacerImpl> getSpacers() { + return new HashMap<Integer, SpacerImpl>(rowIndexToSpacer); + } + /** * Calculates the sum of all spacers. * @@ -5239,6 +5283,8 @@ public class Escalator extends Widget implements RequiresResize, spacerUpdater.init(spacer); assert getElement().isOrHasChild(spacer.getRootElement()) : "Spacer's root element somehow got detached from Escalator during attaching"; assert getElement().isOrHasChild(spacer.getElement()) : "Spacer element somehow got detached from Escalator during attaching"; + + spacer.updateVisibility(); } public String getSubPartName(Element subElement) { |