Revert async context menu events from bug 389542 now that 392652 is fixed. b=396186 r=smichaud sr=roc a=schrep
authorjoshmoz@gmail.com
Wed, 16 Jan 2008 20:59:43 -0800
changeset 10345 2e17cf0a15584b96dafde0be6e36e9eb4376721f
parent 10344 921ecce7bfbb5f7e30223291cdaee2068128ff3e
child 10346 cfa43c9eeeef687390712b58ab5d5cdc34fddd80
push idunknown
push userunknown
push dateunknown
reviewerssmichaud, roc, schrep
bugs389542, 392652, 396186
milestone1.9b3pre
Revert async context menu events from bug 389542 now that 392652 is fixed. b=396186 r=smichaud sr=roc a=schrep
widget/src/cocoa/nsChildView.mm
--- a/widget/src/cocoa/nsChildView.mm
+++ b/widget/src/cocoa/nsChildView.mm
@@ -44,19 +44,16 @@
  
 #include "nsChildView.h"
 #include "nsCocoaWindow.h"
 
 #include "nsCOMPtr.h"
 #include "nsToolkit.h"
 #include "nsCRT.h"
 #include "nsplugindefs.h"
-#include "nsThreadUtils.h"
-#include "nsIPrefService.h"
-#include "nsIPrefBranch.h"
 
 #include "nsIFontMetrics.h"
 #include "nsIDeviceContext.h"
 #include "nsIRegion.h"
 #include "nsIRollupListener.h"
 #include "nsIScrollableView.h"
 #include "nsIViewManager.h"
 #include "nsIInterfaceRequestor.h"
@@ -153,18 +150,16 @@ nsIWidget         * gRollupWidget   = ns
 - (BOOL)isRectObscuredBySubview:(NSRect)inRect;
 
 - (void)processPendingRedraws;
 
 - (BOOL)ensureCorrectMouseEventTarget:(NSEvent *)anEvent;
 
 - (void)maybeInitContextMenuTracking;
 
-- (nsChildView *)getGeckoChild;
-
 #if USE_CLICK_HOLD_CONTEXTMENU
  // called on a timer two seconds after a mouse down to see if we should display
  // a context menu (click-hold)
 - (void)clickHoldCallback:(id)inEvent;
 #endif
 
 #ifdef ACCESSIBILITY
 - (id<mozAccessible>)accessible;
@@ -2430,68 +2425,16 @@ NSEvent* gLastDragEvent = nil;
 
   [[NSDistributedNotificationCenter defaultCenter]
     postNotificationName:@"com.apple.HIToolbox.beginMenuTrackingNotification"
                   object:@"org.mozilla.gecko.PopupWindow"];
   [(PopupWindow*)popupWindow setIsContextMenu:YES];
 }
 
 
-- (nsChildView *)getGeckoChild
-{
-  return mGeckoChild;
-}
-
-
-// Browsers that use non-native context menus (e.g. Cocoa widgets Firefox as
-// opposed to Camino) need to postpone generating a context menu until after
-// the previous one (if one exists) has had a chance to close.  The reason why
-// is that, as of the fix for bmo bug 279703, non-native context menus are
-// hidden asynchronously (after a call to gRollupListener->Rollup()), using an
-// nsXULPopupHidingEvent.  If we don't asynchronously generate non-native
-// context menus, only the first control-click or right-click in a window will
-// display a context menu.  This change resolves bmo bug 389542.
-class nsNonNativeContextMenuEvent : public nsRunnable {
-  public:
-    nsNonNativeContextMenuEvent(ChildView *baseView, NSEvent *triggerEvent) {
-      mBaseView = [baseView retain];
-      mTriggerEvent = [triggerEvent retain];
-    }
-
-    virtual ~nsNonNativeContextMenuEvent() {
-      [mBaseView release];
-      [mTriggerEvent release];
-    }
-
-    NS_IMETHOD Run() {
-      if (!mBaseView || !mTriggerEvent)
-        return NS_ERROR_FAILURE;
-      nsChildView *geckoChild = [mBaseView getGeckoChild];
-      if (!geckoChild)
-        return NS_ERROR_FAILURE;
-      nsMouseEvent geckoEvent(PR_TRUE, NS_CONTEXTMENU, nsnull, nsMouseEvent::eReal);
-      [mBaseView convertCocoaMouseEvent:mTriggerEvent toGeckoEvent:&geckoEvent];
-      geckoEvent.button = nsMouseEvent::eRightButton;
-      geckoChild->DispatchMouseEvent(geckoEvent);
-      // Even though we're not going to use the geckoChild variable any more here,
-      // we don't want to bother sending maybeInitContextMenuTracking if the widget
-      // got destroyed by the context menu event we just sent.
-      geckoChild = [mBaseView getGeckoChild];
-      if (!geckoChild)
-        return NS_ERROR_FAILURE;
-      [mBaseView maybeInitContextMenuTracking];
-      return NS_OK;
-    }
-
-  private:
-    ChildView *mBaseView;   // [STRONG]
-    NSEvent *mTriggerEvent; // [STRONG]
-};
-
-
 - (BOOL)maybeRollup:(NSEvent*)theEvent
 {
   if (mLastMenuForEventEvent == theEvent)
     return PR_FALSE;
 
   PRBool retVal = PR_FALSE;
   if (gRollupWidget && gRollupListener) {
     NSWindow* currentPopup = static_cast<NSWindow*>(gRollupWidget->GetNativeData(NS_NATIVE_WINDOW));
@@ -3053,38 +2996,24 @@ static nsEventStatus SendGeckoMouseEnter
   nsAutoRetainView kungFuDeathGrip(self);
 
   [self maybeRollup:theEvent];
   if (!mGeckoChild)
     return nil;
 
   [mLastMenuForEventEvent release];
   mLastMenuForEventEvent = [theEvent retain];
-  
-  // If we're running in a browser that (like Camino) uses native context
-  // menus, fire a context menu event into Gecko here.  Otherwise (if we're
-  // using non-native context menus) we need to open the context menu
-  // asynchronously.
-  nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
-  if (prefs) {
-    PRBool useNativeContextMenus;
-    nsresult rv = prefs->GetBoolPref("ui.use_native_popup_windows", &useNativeContextMenus);
-    if (NS_SUCCEEDED(rv) && useNativeContextMenus) {
-      nsMouseEvent geckoEvent(PR_TRUE, NS_CONTEXTMENU, nsnull, nsMouseEvent::eReal);
-      [self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
-      geckoEvent.button = nsMouseEvent::eRightButton;
-      mGeckoChild->DispatchMouseEvent(geckoEvent);
-      if (!mGeckoChild)
-        return nil;
-    } else {
-      nsIRunnable *contextMenuEvent = new nsNonNativeContextMenuEvent(self, theEvent);
-      NS_DispatchToCurrentThread(contextMenuEvent);
-    }
-  }
-  
+
+  nsMouseEvent geckoEvent(PR_TRUE, NS_CONTEXTMENU, nsnull, nsMouseEvent::eReal);
+  [self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
+  geckoEvent.button = nsMouseEvent::eRightButton;
+  mGeckoChild->DispatchMouseEvent(geckoEvent);
+  if (!mGeckoChild)
+    return nil;
+
   // Go up our view chain to fetch the correct menu to return.
   return [self contextMenu];
 }
 
 
 - (NSMenu*)contextMenu
 {
   NSView* superView = [self superview];