fix: macOS tray button selection with VoiceOver (#39352)
This commit is contained in:
parent
1eb6e45a36
commit
dc707ee938
1 changed files with 25 additions and 1 deletions
|
@ -54,7 +54,12 @@
|
||||||
NSStatusItem* item = [[NSStatusBar systemStatusBar]
|
NSStatusItem* item = [[NSStatusBar systemStatusBar]
|
||||||
statusItemWithLength:NSVariableStatusItemLength];
|
statusItemWithLength:NSVariableStatusItemLength];
|
||||||
statusItem_ = item;
|
statusItem_ = item;
|
||||||
[[statusItem_ button] addSubview:self]; // inject custom view
|
[[statusItem_ button] addSubview:self];
|
||||||
|
|
||||||
|
// We need to set the target and action on the button, otherwise
|
||||||
|
// VoiceOver doesn't know where to send the select action.
|
||||||
|
[[statusItem_ button] setTarget:self];
|
||||||
|
[[statusItem_ button] setAction:@selector(mouseDown:)];
|
||||||
[self updateDimensions];
|
[self updateDimensions];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
|
@ -190,6 +195,25 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)mouseDown:(NSEvent*)event {
|
- (void)mouseDown:(NSEvent*)event {
|
||||||
|
// If |event| does not respond to locationInWindow, we've
|
||||||
|
// arrived here from VoiceOver, which does not pass an event.
|
||||||
|
// Create a synthetic event to pass to the click handler.
|
||||||
|
if (![event respondsToSelector:@selector(locationInWindow)]) {
|
||||||
|
event = [NSEvent mouseEventWithType:NSEventTypeRightMouseDown
|
||||||
|
location:NSMakePoint(0, 0)
|
||||||
|
modifierFlags:0
|
||||||
|
timestamp:NSApp.currentEvent.timestamp
|
||||||
|
windowNumber:0
|
||||||
|
context:nil
|
||||||
|
eventNumber:0
|
||||||
|
clickCount:1
|
||||||
|
pressure:1.0];
|
||||||
|
|
||||||
|
// We also need to explicitly call the click handler here, since
|
||||||
|
// VoiceOver won't trigger mouseUp.
|
||||||
|
[self handleClickNotifications:event];
|
||||||
|
}
|
||||||
|
|
||||||
trayIcon_->NotifyMouseDown(
|
trayIcon_->NotifyMouseDown(
|
||||||
gfx::ScreenPointFromNSPoint([event locationInWindow]),
|
gfx::ScreenPointFromNSPoint([event locationInWindow]),
|
||||||
ui::EventFlagsFromModifiers([event modifierFlags]));
|
ui::EventFlagsFromModifiers([event modifierFlags]));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue