]> source.dussan.org Git - vaadin-framework.git/commitdiff
Added option to sink the same events on the overlay shadow to avoid flickering toolti...
authorLeif Åstrand <leif@vaadin.com>
Wed, 31 Aug 2011 10:50:22 +0000 (10:50 +0000)
committerLeif Åstrand <leif@vaadin.com>
Wed, 31 Aug 2011 10:50:22 +0000 (10:50 +0000)
svn changeset:20770/svn branch:6.7

src/com/vaadin/terminal/gwt/client/VTooltip.java
src/com/vaadin/terminal/gwt/client/ui/VOverlay.java

index 725c89a204fc8799876889a240f24c5e8cb3c37d..1f2ee809edad9c40dc1f30017fb44ca53011707c 100644 (file)
@@ -46,6 +46,7 @@ public class VTooltip extends VOverlay {
         layout.add(em);
         DOM.setElementProperty(description, "className", CLASSNAME + "-text");
         DOM.appendChild(layout.getElement(), description);
+        setSinkShadowEvents(true);
     }
 
     /**
index a277b4c42d2693fb8f8ffd8d813c4264edb60dc6..27b8840823ca7e11813a38b9cfab205e7a6a128c 100644 (file)
@@ -67,6 +67,8 @@ public class VOverlay extends PopupPanel implements CloseHandler<PopupPanel> {
      */
     private static final String SHADOW_HTML = "<div class=\"top-left\"></div><div class=\"top\"></div><div class=\"top-right\"></div><div class=\"left\"></div><div class=\"center\"></div><div class=\"right\"></div><div class=\"bottom-left\"></div><div class=\"bottom\"></div><div class=\"bottom-right\"></div>";
 
+    private boolean sinkShadowEvents = false;
+
     public VOverlay() {
         super();
         adjustZIndex();
@@ -116,11 +118,18 @@ public class VOverlay extends PopupPanel implements CloseHandler<PopupPanel> {
     }
 
     private void removeShadowIfPresent() {
-        if (isShadowEnabled() && shadow.getParentElement() != null) {
+        if (isShadowAttached()) {
             shadow.getParentElement().removeChild(shadow);
+
+            // Remove event listener from the shadow
+            unsinkShadowEvents();
         }
     }
 
+    private boolean isShadowAttached() {
+        return isShadowEnabled() && shadow.getParentElement() != null;
+    }
+
     private void adjustZIndex() {
         setZIndex(Z_INDEX);
     }
@@ -366,8 +375,9 @@ public class VOverlay extends PopupPanel implements CloseHandler<PopupPanel> {
         }
 
         // Attach to dom if not there already
-        if (shadow.getParentElement() == null) {
+        if (!isShadowAttached()) {
             RootPanel.get().getElement().insertBefore(shadow, getElement());
+            sinkShadowEvents();
         }
 
     }
@@ -382,4 +392,50 @@ public class VOverlay extends PopupPanel implements CloseHandler<PopupPanel> {
     public void onClose(CloseEvent<PopupPanel> event) {
         removeShadowIfPresent();
     }
+
+    @Override
+    public void sinkEvents(int eventBitsToAdd) {
+        super.sinkEvents(eventBitsToAdd);
+        // Also sink events on the shadow if present
+        sinkShadowEvents();
+    }
+
+    private void sinkShadowEvents() {
+        if (isSinkShadowEvents() && isShadowAttached()) {
+            // Sink the same events as the actual overlay has sunk
+            DOM.sinkEvents(shadow, DOM.getEventsSunk(getElement()));
+            // Send events to VOverlay.onBrowserEvent
+            DOM.setEventListener(shadow, this);
+        }
+    }
+
+    private void unsinkShadowEvents() {
+        if (isShadowAttached()) {
+            DOM.setEventListener(shadow, null);
+            DOM.sinkEvents(shadow, 0);
+        }
+    }
+
+    /**
+     * Enables or disables sinking the events of the shadow to the same
+     * onBrowserEvent as events to the actual overlay goes.
+     * 
+     * Please note, that if you enable this, you can't assume that e.g.
+     * event.getEventTarget returns an element inside the DOM structure of the
+     * overlay
+     * 
+     * @param sinkShadowEvents
+     */
+    protected void setSinkShadowEvents(boolean sinkShadowEvents) {
+        this.sinkShadowEvents = sinkShadowEvents;
+        if (sinkShadowEvents) {
+            sinkShadowEvents();
+        } else {
+            unsinkShadowEvents();
+        }
+    }
+
+    protected boolean isSinkShadowEvents() {
+        return sinkShadowEvents;
+    }
 }