*/
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();
}
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);
}
}
// Attach to dom if not there already
- if (shadow.getParentElement() == null) {
+ if (!isShadowAttached()) {
RootPanel.get().getElement().insertBefore(shadow, getElement());
+ sinkShadowEvents();
}
}
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;
+ }
}