Bug 699538 - Only register the event tap while our app is in the background and has a context menu open, because that's the only scenario we need it for. r=smichaud
authorBenoit Girard <b56girard@gmail.com>
Mon, 07 Nov 2011 11:43:10 -0500
changeset 165800 4eaaad2e06f20b53c5229ddfb4d7f3e3a8a52c66
parent 165799 075fc0110d9f2877cc9934b2598a50c79ab6bdaf
child 165801 a1d74808c32581a42de1d51bf9bafbffb4552c94
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmichaud
bugs699538
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 699538 - Only register the event tap while our app is in the background and has a context menu open, because that's the only scenario we need it for. r=smichaud
widget/cocoa/nsCocoaWindow.mm
widget/cocoa/nsToolkit.h
widget/cocoa/nsToolkit.mm
--- a/widget/cocoa/nsCocoaWindow.mm
+++ b/widget/cocoa/nsCocoaWindow.mm
@@ -1859,16 +1859,23 @@ nsMenuBarX* nsCocoaWindow::GetMenuBar()
 
 NS_IMETHODIMP nsCocoaWindow::CaptureRollupEvents(nsIRollupListener* aListener, bool aDoCapture)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
   gRollupListener = nullptr;
   
   if (aDoCapture) {
+    if (![NSApp isActive]) {
+      // We need to capture mouse event if we aren't
+      // the active application. We only set this up when needed
+      // because they cause spurious mouse event after crash
+      // and gdb sessions. See bug 699538.
+      nsToolkit::GetToolkit()->RegisterForAllProcessMouseEvents();
+    }
     gRollupListener = aListener;
 
     // Sometimes more than one popup window can be visible at the same time
     // (e.g. nested non-native context menus, or the test case (attachment
     // 276885) for bmo bug 392389, which displays a non-native combo-box in a
     // non-native popup window).  In these cases the "active" popup window should
     // be the topmost -- the (nested) context menu the mouse is currently over,
     // or the combo-box's drop-down list (when it's displayed).  But (among
@@ -1876,16 +1883,18 @@ NS_IMETHODIMP nsCocoaWindow::CaptureRoll
     // last received a mouse-down event, which may be incorrect (in the combo-
     // box case, it makes topmost the window containing the combo-box).  So
     // here we fiddle with a non-native popup window's level to make sure the
     // "active" one is always above any other non-native popup windows that
     // may be visible.
     if (mWindow && (mWindowType == eWindowType_popup))
       SetPopupWindowLevel();
   } else {
+    nsToolkit::GetToolkit()->UnregisterAllProcessMouseEventHandlers();
+
     // XXXndeakin this doesn't make sense.
     // Why is the new window assumed to be a modal panel?
     if (mWindow && (mWindowType == eWindowType_popup))
       [mWindow setLevel:NSModalPanelWindowLevel];
   }
   
   return NS_OK;
 
--- a/widget/cocoa/nsToolkit.h
+++ b/widget/cocoa/nsToolkit.h
@@ -27,24 +27,24 @@ public:
     gToolkit = nullptr;
   }
 
   static void        PostSleepWakeNotification(const char* aNotification);
 
   static nsresult    SwizzleMethods(Class aClass, SEL orgMethod, SEL posedMethod,
                                     bool classMethods = false);
 
+  void               RegisterForAllProcessMouseEvents();
+  void               UnregisterAllProcessMouseEventHandlers();
+
 protected:
 
   nsresult           RegisterForSleepWakeNotifcations();
   void               RemoveSleepWakeNotifcations();
 
-  void               RegisterForAllProcessMouseEvents();
-  void               UnregisterAllProcessMouseEventHandlers();
-
 protected:
 
   static nsToolkit*  gToolkit;
 
   CFRunLoopSourceRef mSleepWakeNotificationRLS;
   io_object_t        mPowerNotifier;
 
   CFMachPortRef      mEventTapPort;
--- a/widget/cocoa/nsToolkit.mm
+++ b/widget/cocoa/nsToolkit.mm
@@ -44,17 +44,16 @@ nsToolkit* nsToolkit::gToolkit = nullptr
 
 nsToolkit::nsToolkit()
 : mSleepWakeNotificationRLS(nullptr)
 , mEventTapPort(nullptr)
 , mEventTapRLS(nullptr)
 {
   MOZ_COUNT_CTOR(nsToolkit);
   RegisterForSleepWakeNotifcations();
-  RegisterForAllProcessMouseEvents();
 }
 
 nsToolkit::~nsToolkit()
 {
   MOZ_COUNT_DTOR(nsToolkit);
   RemoveSleepWakeNotifcations();
   UnregisterAllProcessMouseEventHandlers();
 }