Skip to content

Commit

Permalink
fix: emit click events with tray context menu (#24236)
Browse files Browse the repository at this point in the history
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
  • Loading branch information
trop[bot] and codebytere committed Jun 22, 2020
1 parent f92b42e commit 06902de
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions shell/browser/ui/tray_icon_cocoa.mm
Expand Up @@ -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]));
Expand All @@ -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;
Expand Down

0 comments on commit 06902de

Please sign in to comment.