From 06902de06b23f808493cf17fb1001c788c43b86e Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Mon, 22 Jun 2020 09:15:05 -0700 Subject: [PATCH] fix: emit click events with tray context menu (#24236) Co-authored-by: Shelley Vohr --- shell/browser/ui/tray_icon_cocoa.mm | 39 ++++++++++++++++------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/shell/browser/ui/tray_icon_cocoa.mm b/shell/browser/ui/tray_icon_cocoa.mm index cdea63c7c4eab..8c58ecd2d7c2f 100644 --- a/shell/browser/ui/tray_icon_cocoa.mm +++ b/shell/browser/ui/tray_icon_cocoa.mm @@ -130,23 +130,7 @@ - (void)setMenuController:(ElectronMenuController*)menu { [statusItem_ setMenu:[menuController_ menu]]; } -- (void)mouseDown:(NSEvent*)event { - trayIcon_->NotifyMouseDown( - gfx::ScreenPointFromNSPoint([event locationInWindow]), - ui::EventFlagsFromModifiers([event modifierFlags])); - - // 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 { trayIcon_->NotifyMouseUp( gfx::ScreenPointFromNSPoint([event locationInWindow]), ui::EventFlagsFromModifiers([event modifierFlags])); @@ -170,6 +154,27 @@ - (void)mouseUp:(NSEvent*)event { ui::EventFlagsFromModifiers([event modifierFlags])); } +- (void)mouseDown:(NSEvent*)event { + trayIcon_->NotifyMouseDown( + gfx::ScreenPointFromNSPoint([event locationInWindow]), + ui::EventFlagsFromModifiers([event modifierFlags])); + + // 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;