Reviewers: jgw,

Description:
Firing MenuItem commands using a finally command instead of a deferred
command so that the command executes within the event loop.  If the
command is not executed in the event loop, popup blockers will prevent
the code from opening popups.  It seems like it could be possible that
somebody expects the command to fire deferred, but I can't think of any
way that it would cause a problem.


Please review this at http://gwt-code-reviews.appspot.com/543804/show

Affected files:
  M /user/src/com/google/gwt/user/client/ui/MenuBar.java


Index: /user/src/com/google/gwt/user/client/ui/MenuBar.java
===================================================================
--- /user/src/com/google/gwt/user/client/ui/MenuBar.java        (revision 8200)
+++ /user/src/com/google/gwt/user/client/ui/MenuBar.java        (working copy)
@@ -16,6 +16,7 @@
 package com.google.gwt.user.client.ui;

 import com.google.gwt.core.client.GWT;
+import com.google.gwt.core.client.Scheduler;
 import com.google.gwt.dom.client.EventTarget;
 import com.google.gwt.event.dom.client.BlurEvent;
 import com.google.gwt.event.dom.client.BlurHandler;
@@ -30,7 +31,6 @@
 import com.google.gwt.resources.client.ImageResource.ImageOptions;
 import com.google.gwt.user.client.Command;
 import com.google.gwt.user.client.DOM;
-import com.google.gwt.user.client.DeferredCommand;
 import com.google.gwt.user.client.Element;
 import com.google.gwt.user.client.Event;
 import com.google.gwt.user.client.Event.NativePreviewEvent;
@@ -834,9 +834,14 @@
         // Close this menu and all of its parents.
         closeAllParents();

-        // Fire the item's command.
-        Command cmd = item.getCommand();
-        DeferredCommand.addCommand(cmd);
+ // Fire the item's command. The command must be fired in the same event
+        // loop or popup blockers will prevent popups from opening.
+        final Command cmd = item.getCommand();
+        Scheduler.get().scheduleFinally(new Scheduler.ScheduledCommand() {
+          public void execute() {
+            cmd.execute();
+          }
+        });

         // hide any open submenus of this item
         if (shownChildMenu != null) {


--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to