Browse Source

fix: emit click events with tray context menu (#24239)

Shelley Vohr 4 years ago
parent
commit
8c4c4fb4f0
1 changed files with 18 additions and 13 deletions
  1. 18 13
      shell/browser/ui/tray_icon_cocoa.mm

+ 18 - 13
shell/browser/ui/tray_icon_cocoa.mm

@@ -130,19 +130,7 @@
   [statusItem_ setMenu:[menuController_ menu]];
 }
 
-- (void)mouseDown:(NSEvent*)event {
-  // Pass click to superclass to show menu. Custom mouseUp handler won't be
-  // invoked.
-  if (menuController_) {
-    [super mouseDown:event];
-  } else {
-    [[statusItem_ button] highlight:YES];
-  }
-}
-
-- (void)mouseUp:(NSEvent*)event {
-  [[statusItem_ button] highlight:NO];
-
+- (void)handleClickNotifications:(NSEvent*)event {
   // If we are ignoring double click events, we should ignore the `clickCount`
   // value and immediately emit a click event.
   BOOL shouldBeHandledAsASingleClick =
@@ -162,6 +150,23 @@
         ui::EventFlagsFromModifiers([event modifierFlags]));
 }
 
+- (void)mouseDown:(NSEvent*)event {
+  // Pass click to superclass to show menu. Custom mouseUp handler won't be
+  // invoked.
+  if (menuController_) {
+    [self handleClickNotifications:event];
+    [super mouseDown:event];
+  } else {
+    [[statusItem_ button] highlight:YES];
+  }
+}
+
+- (void)mouseUp:(NSEvent*)event {
+  [[statusItem_ button] highlight:NO];
+
+  [self handleClickNotifications:event];
+}
+
 - (void)popUpContextMenu:(electron::ElectronMenuModel*)menu_model {
   // Make sure events can be pumped while the menu is up.
   base::MessageLoopCurrent::ScopedNestableTaskAllower allow;