Fixes Issue #1309.
Adds method DOM.eventGetCurrentEvent() to provide classes using the old
listener style interface a means to access the currently active event.

Patch by: jlabanca
Review by: jgw, knorton



git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1280 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/DOM.java b/user/src/com/google/gwt/user/client/DOM.java
index b2a77cd..cba9244 100644
--- a/user/src/com/google/gwt/user/client/DOM.java
+++ b/user/src/com/google/gwt/user/client/DOM.java
@@ -29,6 +29,8 @@
  */
 public class DOM {
 
+  // The current event being fired
+  private static Event currentEvent = null;
   private static DOMImpl impl;
   private static Element sCaptureElem;
 
@@ -406,6 +408,18 @@
   public static boolean eventGetCtrlKey(Event evt) {
     return impl.eventGetCtrlKey(evt);
   }
+  
+  /**
+   * Gets the current event that is being fired.  The current event
+   * is only available within the lifetime of the onBrowserEvent function.
+   * Once the onBrowserEvent method returns, the current event is reset
+   * to null.
+   * 
+   * @return the current event
+   */
+  public static Event eventGetCurrentEvent() {
+    return currentEvent;
+  }
 
   /**
    * Gets the current target element of the given event. This is the element
@@ -1240,7 +1254,14 @@
       }
     }
 
-    // Pass the event to the listener.
-    listener.onBrowserEvent(evt);
+    // Preserve the current event in case we are in a reentrant event dispatch.
+    Event prevCurrentEvent = currentEvent;
+    currentEvent = evt;
+    try {
+      // Pass the event to the listener.
+      listener.onBrowserEvent(evt);
+    } finally {
+      currentEvent = prevCurrentEvent;
+    }
   }
 }