summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorJohannes Dahlström <johannes.dahlstrom@vaadin.com>2012-05-14 09:57:39 +0000
committerJohannes Dahlström <johannes.dahlstrom@vaadin.com>2012-05-14 09:57:39 +0000
commit22652ba707768ab4955f1632d0d98d1f35fe6256 (patch)
treed40ccea8d1a3d1dde8d65625379bb76b8b649179 /src/com
parent9ae6ce60f0965a17886b532d52de6ecdc42a173e (diff)
downloadvaadin-framework-22652ba707768ab4955f1632d0d98d1f35fe6256.tar.gz
vaadin-framework-22652ba707768ab4955f1632d0d98d1f35fe6256.zip
#8763 Removed debug messages, added Javadoc to TouchScrollHandler
svn changeset:23731/svn branch:6.8
Diffstat (limited to 'src/com')
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/TouchScrollDelegate.java61
1 files changed, 45 insertions, 16 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/TouchScrollDelegate.java b/src/com/vaadin/terminal/gwt/client/ui/TouchScrollDelegate.java
index 171ec2838d..4e19f66b14 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/TouchScrollDelegate.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/TouchScrollDelegate.java
@@ -90,28 +90,34 @@ public class TouchScrollDelegate implements NativePreviewHandler {
private static final boolean androidWithBrokenScrollTop = BrowserInfo.get()
.isAndroidWithBrokenScrollTop();
+ /**
+ * A helper class for making a widget scrollable. Uses native scrolling if
+ * supported by the browser, otherwise registers a touch start handler
+ * delegating to a TouchScrollDelegate instance.
+ */
public static class TouchScrollHandler implements TouchStartHandler {
+ private static final String SCROLLABLE_CLASSNAME = "v-scrollable";
+
private final TouchScrollDelegate delegate;
private final boolean requiresDelegate = BrowserInfo.get()
.requiresTouchScrollDelegate();
+ /**
+ * Constructs a scroll handler for the given widget.
+ *
+ * @param widget
+ * The widget that contains scrollable elements
+ * @param scrollables
+ * The elements of the widget that should be scrollable.
+ */
public TouchScrollHandler(Widget widget, Element... scrollables) {
if (requiresDelegate) {
- VConsole.log("REQUIRES DELEGATE");
delegate = new TouchScrollDelegate();
widget.addDomHandler(this, TouchStartEvent.getType());
} else {
- VConsole.log("DOES NOT REQUIRE DELEGATE");
delegate = null;
}
- VConsole.log(BrowserInfo.getBrowserString());
- BrowserInfo bi = BrowserInfo.get();
- VConsole.log("Is Android: " + bi.isAndroid());
- VConsole.log("Is Android with broken scrolltop: "
- + bi.isAndroidWithBrokenScrollTop());
- VConsole.log("Is IOS: " + bi.isIOS());
- VConsole.log("Is Webkit: " + bi.isWebkit());
for (Element scrollable : scrollables) {
addElement(scrollable);
}
@@ -128,27 +134,40 @@ public class TouchScrollDelegate implements NativePreviewHandler {
+ e.getStyle().getProperty("WebkitOverflowScrolling"));
}
+ /**
+ * Registers the given element as scrollable.
+ */
public void addElement(Element scrollable) {
- scrollable.addClassName("v-scrollable");
- scrollable.getStyle().setProperty("WebkitOverflowScrolling",
- "touch");
- scrollable.getStyle().setProperty("overflowY", "auto");
- scrollable.getStyle().setProperty("overflowX", "auto");
+ scrollable.addClassName(SCROLLABLE_CLASSNAME);
if (requiresDelegate) {
delegate.scrollableElements.add(scrollable);
}
- VConsole.log("Added scrollable: " + scrollable.getClassName());
}
+ /**
+ * Unregisters the given element as scrollable. Should be called when a
+ * previously-registered element is removed from the DOM to prevent
+ * memory leaks.
+ */
public void removeElement(Element scrollable) {
- scrollable.removeClassName("v-scrollable");
+ scrollable.removeClassName(SCROLLABLE_CLASSNAME);
if (requiresDelegate) {
delegate.scrollableElements.remove(scrollable);
}
}
+ /**
+ * Registers the given elements as scrollable, removing previously
+ * registered scrollables from this handler.
+ *
+ * @param scrollables
+ * The elements that should be scrollable
+ */
public void setElements(Element... scrollables) {
if (requiresDelegate) {
+ for (Element e : delegate.scrollableElements) {
+ e.removeClassName(SCROLLABLE_CLASSNAME);
+ }
delegate.scrollableElements.clear();
}
for (Element e : scrollables) {
@@ -157,6 +176,16 @@ public class TouchScrollDelegate implements NativePreviewHandler {
}
}
+ /**
+ * Makes the given elements scrollable, either natively or by using a
+ * TouchScrollDelegate, depending on platform capabilities.
+ *
+ * @param widget
+ * The widget that contains scrollable elements
+ * @param scrollables
+ * The elements inside the widget that should be scrollable
+ * @return A scroll handler for the given widget.
+ */
public static TouchScrollHandler enableTouchScrolling(Widget widget,
Element... scrollables) {
return new TouchScrollHandler(widget, scrollables);