Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: emit click events with tray context menu #24236

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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