diff options
author | Artur Signell <artur@vaadin.com> | 2013-11-11 16:26:51 +0200 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2013-11-11 16:26:51 +0200 |
commit | dc5183c62552135a1f2aa5a94ef6796ffebfcf15 (patch) | |
tree | 96e87de11748d81b41dd09d9603bde377c641e01 /client | |
parent | 2f9bcc0c210dafecfdc2943b8603fa4f41a9f16f (diff) | |
parent | 13858578966dad8cf5a6f10448b42961817beafc (diff) | |
download | vaadin-framework-dc5183c62552135a1f2aa5a94ef6796ffebfcf15.tar.gz vaadin-framework-dc5183c62552135a1f2aa5a94ef6796ffebfcf15.zip |
Merge changes from origin/7.1
0d3c35b Forces redraw in IE 8 when table does post layout. (#12687)
533ddcd Fixed lost scrollLeft when row count changed in Table (#12652).
c351b64 Revert "Make Panel scroll the correct div (#12736)" Revert "Reverted change in how hack works (#12727, #12736)" Revert "Fixes the handling of the scroll position of a Window (#12736)" Revert "Recovering scroll position after regression problems. (#12727)" Revert "Ticket #12727 - Panels get unnecessary scroll bars in WebKit when content is 100% wide."
2e3e877 Fix scroll position handling in Window Webkit hack (#12736)
6b38173 Adds JBoss EAP 6 server to integration test suit (#12908)
e933562 Minimal fix for error handling with streaming (#12578)
1385857 Do not apply fix on mobile devices or devices without scrollbars (#12736)
Change-Id: I1e620342c936ea23eacd2082a0a92b15e453b924
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/BrowserInfo.java | 16 | ||||
-rw-r--r-- | client/src/com/vaadin/client/Util.java | 88 | ||||
-rw-r--r-- | client/src/com/vaadin/client/ui/VPanel.java | 2 | ||||
-rw-r--r-- | client/src/com/vaadin/client/ui/VScrollTable.java | 47 | ||||
-rw-r--r-- | client/src/com/vaadin/client/ui/VWindow.java | 46 | ||||
-rw-r--r-- | client/src/com/vaadin/client/ui/table/TableConnector.java | 3 |
6 files changed, 143 insertions, 59 deletions
diff --git a/client/src/com/vaadin/client/BrowserInfo.java b/client/src/com/vaadin/client/BrowserInfo.java index 273964c889..78c5c1f59f 100644 --- a/client/src/com/vaadin/client/BrowserInfo.java +++ b/client/src/com/vaadin/client/BrowserInfo.java @@ -347,6 +347,22 @@ public class BrowserInfo { } /** + * Indicates whether the browser might require juggling to properly update + * sizes inside elements with overflow: auto when adjusting absolutely + * positioned elements. + * <p> + * See https://bugs.webkit.org/show_bug.cgi?id=123958 and + * http://code.google.com/p/chromium/issues/detail?id=316549 + * + * @since 7.1.8 + * @return <code>true</code> if the browser requires the workaround, + * otherwise <code>false</code> + */ + public boolean requiresPositionAbsoluteOverflowAutoFix() { + return (getWebkitVersion() > 0) && Util.getNativeScrollbarSize() > 0; + } + + /** * Checks if the browser is run on iOS * * @return true if the browser is run on iOS, false otherwise diff --git a/client/src/com/vaadin/client/Util.java b/client/src/com/vaadin/client/Util.java index 9cdfa954c6..7c7978be09 100644 --- a/client/src/com/vaadin/client/Util.java +++ b/client/src/com/vaadin/client/Util.java @@ -32,7 +32,6 @@ import com.google.gwt.dom.client.Node; import com.google.gwt.dom.client.NodeList; import com.google.gwt.dom.client.Style; import com.google.gwt.dom.client.Style.Display; -import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.dom.client.Touch; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; @@ -449,6 +448,35 @@ public class Util { } /** + * Calculates maximum horizontal scrolling value for the given element. + * + * @since 7.1.9 + * @param element + * which scrollLeft should be calculated + * @return maximum value for scrollLeft of the given element + */ + public static int getMaxScrollLeft(final Element element) { + int scrollWidth = element.getScrollWidth(); + int clientWidth = element.getClientWidth(); + return scrollWidth - clientWidth; + } + + /** + * Checks if scrollLeft of the element is at its maximum value. Returns + * false if the element can't be scrolled horizontally. + * + * @since 7.1.9 + * @param element + * which scrollLeft should be checked + * @return true, if scrollLeft is at maximum (false if element can't be + * scrolled horizontally) + */ + public static boolean isScrollLeftAtMax(final Element element) { + int scrollLeft = element.getScrollLeft(); + return scrollLeft != 0 && scrollLeft == getMaxScrollLeft(element); + } + + /** * Run workaround for webkits overflow auto issue. * * See: our bug #2138 and https://bugs.webkit.org/show_bug.cgi?id=21462 @@ -469,6 +497,8 @@ public class Util { // check the scrolltop value before hiding the element final int scrolltop = elem.getScrollTop(); final int scrollleft = elem.getScrollLeft(); + final boolean scrollLeftAtMax = isScrollLeftAtMax(elem); + elem.getStyle().setProperty("overflow", "hidden"); Scheduler.get().scheduleDeferred(new Command() { @@ -492,6 +522,12 @@ public class Util { elem.setScrollTop(scrollvalue); } + // keep horizontal scroll at max if it was before vertical + // scroll bar was added/removed + if (scrollLeftAtMax) { + elem.setScrollLeft(getMaxScrollLeft(elem)); + } + // fix for #6940 : Table horizontal scroll sometimes not // updated when collapsing/expanding columns // Also appeared in Safari 5.1 with webkit 534 (#7667) @@ -519,56 +555,6 @@ public class Util { } /** - * Prevents some browsers from adding scroll bars to a component (such as a - * Window) whose contents fit in the component. - * <p> - * See: bugs #11994 and #12736. - * - * @param contentNode - * an element that is scrollable - * - * @since 7.1.8 - */ - public static void removeUnneededScrollbars(final Element scrollable) { - if (BrowserInfo.get().isWebkit()) { - - /* - * Shake up the DOM a bit to make the window shed unnecessary - * scrollbars and resize correctly afterwards. This resulting code - * took over a week to summon forth, and involved some pretty hairy - * black magic. Don't touch it unless you know what you're doing! - * Fixes ticket #11994. Later modified to fix ticket #12736. - */ - Scheduler.get().scheduleFinally(new ScheduledCommand() { - - @Override - public void execute() { - // Adjusting the width or height may change the scroll - // position, so store the current position - int horizontalScrollPosition = scrollable.getScrollLeft(); - int verticalScrollPosition = scrollable.getScrollTop(); - - final String oldWidth = scrollable.getStyle().getWidth(); - final String oldHeight = scrollable.getStyle().getHeight(); - - scrollable.getStyle().setWidth(110, Unit.PCT); - scrollable.getOffsetWidth(); - scrollable.getStyle().setProperty("width", oldWidth); - scrollable.getStyle().setHeight(110, Unit.PCT); - scrollable.getOffsetHeight(); - scrollable.getStyle().setProperty("height", oldHeight); - - // Restore the scroll position - scrollable.setScrollLeft(horizontalScrollPosition); - scrollable.setScrollTop(verticalScrollPosition); - - } - }); - - } - } - - /** * Parses shared state and fetches the relative size of the component. If a * dimension is not specified as relative it will return -1. If the shared * state does not contain width or height specifications this will return diff --git a/client/src/com/vaadin/client/ui/VPanel.java b/client/src/com/vaadin/client/ui/VPanel.java index 307a2e4a91..6b02f079d1 100644 --- a/client/src/com/vaadin/client/ui/VPanel.java +++ b/client/src/com/vaadin/client/ui/VPanel.java @@ -24,7 +24,6 @@ import com.google.gwt.user.client.Event; import com.google.gwt.user.client.ui.SimplePanel; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.Focusable; -import com.vaadin.client.Util; import com.vaadin.client.ui.ShortcutActionHandler.ShortcutActionHandlerOwner; import com.vaadin.client.ui.TouchScrollDelegate.TouchScrollHandler; @@ -207,6 +206,5 @@ public class VPanel extends SimplePanel implements ShortcutActionHandlerOwner, touchScrollHandler = TouchScrollDelegate.enableTouchScrolling(this); } touchScrollHandler.addElement(contentNode); - Util.removeUnneededScrollbars(contentNode); } } diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java index 02ae01d844..0e64c71005 100644 --- a/client/src/com/vaadin/client/ui/VScrollTable.java +++ b/client/src/com/vaadin/client/ui/VScrollTable.java @@ -276,6 +276,10 @@ public class VScrollTable extends FlowPanel implements HasWidgets, */ private int detachedScrollPosition = 0; + // fields used in fixing erroneously lost scrollLeft + int lastScrollBodyHeight = 0; + boolean lastScrollLeftWasAtMax = false; + /** * Represents a select range of rows */ @@ -1005,6 +1009,15 @@ public class VScrollTable extends FlowPanel implements HasWidgets, initialContentReceived = true; sizeNeedsInit = true; scrollBody.restoreRowVisibility(); + + // At least FireFox requires that scrollLeft is restored deferred after + // scrollBody is recreated + Scheduler.get().scheduleFinally(new ScheduledCommand() { + @Override + public void execute() { + restoreScrollLeft(); + } + }); } /** For internal use only. May be removed or replaced in the future. */ @@ -6878,12 +6891,44 @@ public class VScrollTable extends FlowPanel implements HasWidgets, } /** + * Tries to restore horizontal scroll position if it was lost due to change + * in the height of scrollBody (#12652). + */ + private void restoreScrollLeft() { + int upcomingScrollLeft = scrollLeft; + + if (lastScrollLeftWasAtMax) { + upcomingScrollLeft = Util.getMaxScrollLeft(scrollBodyPanel + .getElement()); + } + scrollBodyPanel.getElement().setScrollLeft(upcomingScrollLeft); + } + + /** + * Checks if restore of scrollLeft is needed by checking if height of the + * scrollBody has changed. + * + * @return true, if restore is required + */ + private boolean isScrollLeftRestoreRequired() { + return (scrollBody.getElement().getClientHeight() != lastScrollBodyHeight); + } + + /** * This method has logic which rows needs to be requested from server when * user scrolls */ - @Override public void onScroll(ScrollEvent event) { + // restore in initializeRows() doesn't work right with Chrome + if (isScrollLeftRestoreRequired()) { + restoreScrollLeft(); + } + + lastScrollBodyHeight = scrollBody.getElement().getClientHeight(); + lastScrollLeftWasAtMax = Util.isScrollLeftAtMax(scrollBodyPanel + .getElement()); + scrollLeft = scrollBodyPanel.getElement().getScrollLeft(); scrollTop = scrollBodyPanel.getScrollPosition(); /* diff --git a/client/src/com/vaadin/client/ui/VWindow.java b/client/src/com/vaadin/client/ui/VWindow.java index 19e217129a..c4b2af76e7 100644 --- a/client/src/com/vaadin/client/ui/VWindow.java +++ b/client/src/com/vaadin/client/ui/VWindow.java @@ -538,11 +538,47 @@ public class VWindow extends VWindowOverlay implements if (!visibilityChangesDisabled) { super.setVisible(visible); } - if (visible && BrowserInfo.get().isWebkit()) { - Util.removeUnneededScrollbars((Element) contents - .getFirstChildElement()); - updateContentsSize(); - positionOrSizeUpdated(); + + if (visible + && BrowserInfo.get().requiresPositionAbsoluteOverflowAutoFix()) { + + /* + * Shake up the DOM a bit to make the window shed unnecessary + * scrollbars and resize correctly afterwards. This resulting code + * took over a week to summon forth, and involved some pretty hairy + * black magic. Don't touch it unless you know what you're doing! + * Fixes ticket #11994 + */ + Scheduler.get().scheduleFinally(new ScheduledCommand() { + @Override + public void execute() { + final com.google.gwt.dom.client.Element scrollable = contents + .getFirstChildElement(); + + // Adjusting the width or height may change the scroll + // position, so store the current position + int horizontalScrollPosition = scrollable.getScrollLeft(); + int verticalScrollPosition = scrollable.getScrollTop(); + + final String oldWidth = scrollable.getStyle().getWidth(); + final String oldHeight = scrollable.getStyle().getHeight(); + + scrollable.getStyle().setWidth(110, Unit.PCT); + scrollable.getOffsetWidth(); + scrollable.getStyle().setProperty("width", oldWidth); + + scrollable.getStyle().setHeight(110, Unit.PCT); + scrollable.getOffsetHeight(); + scrollable.getStyle().setProperty("height", oldHeight); + + // Restore the scroll position + scrollable.setScrollLeft(horizontalScrollPosition); + scrollable.setScrollTop(verticalScrollPosition); + + updateContentsSize(); + positionOrSizeUpdated(); + } + }); } } diff --git a/client/src/com/vaadin/client/ui/table/TableConnector.java b/client/src/com/vaadin/client/ui/table/TableConnector.java index f1710351bf..eacd5bc77a 100644 --- a/client/src/com/vaadin/client/ui/table/TableConnector.java +++ b/client/src/com/vaadin/client/ui/table/TableConnector.java @@ -343,6 +343,9 @@ public class TableConnector extends AbstractHasComponentsConnector implements Scheduler.get().scheduleFinally(new ScheduledCommand() { @Override public void execute() { + // IE8 needs some hacks to measure sizes correctly + Util.forceIE8Redraw(getWidget().getElement()); + getLayoutManager().setNeedsMeasure(TableConnector.this); ServerConnector parent = getParent(); if (parent instanceof ComponentConnector) { |