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: macOS tray button selection with VoiceOver #39352

Merged
merged 1 commit into from
Aug 7, 2023
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
26 changes: 25 additions & 1 deletion shell/browser/ui/tray_icon_cocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,16 @@
NSPasteboardTypeString,
]];

// Create the status item.
NSStatusItem* item = [[NSStatusBar systemStatusBar]

Check failure on line 54 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon_cocoa.mm#L53-L54

Patch Conflict
Raw output
++<<<<<<< HEAD
 +    statusItem_.reset([item retain]);
 +    [[statusItem_ button] addSubview:self];  // inject custom view
++=======
+     statusItem_ = item;
+     [[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:)];
++>>>>>>> fix: macOS tray button selection with VoiceOver

Check failure on line 54 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon_cocoa.mm#L53-L54

Patch Conflict
Raw output
++<<<<<<< HEAD
 +    statusItem_.reset([item retain]);
 +    [[statusItem_ button] addSubview:self];  // inject custom view
++=======
+     statusItem_ = item;
+     [[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:)];
++>>>>>>> fix: macOS tray button selection with VoiceOver

Check failure on line 54 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon_cocoa.mm#L53-L54

Patch Conflict
Raw output
++<<<<<<< HEAD
 +    statusItem_.reset([item retain]);
 +    [[statusItem_ button] addSubview:self];  // inject custom view
++=======
+     statusItem_ = item;
+     [[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:)];
++>>>>>>> fix: macOS tray button selection with VoiceOver

Check failure on line 54 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon_cocoa.mm#L53-L54

Patch Conflict
Raw output
++<<<<<<< HEAD
 +    statusItem_.reset([item retain]);
 +    [[statusItem_ button] addSubview:self];  // inject custom view
++=======
+     statusItem_ = item;
+     [[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:)];
++>>>>>>> fix: macOS tray button selection with VoiceOver

Check failure on line 54 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon_cocoa.mm#L53-L54

Patch Conflict
Raw output
++<<<<<<< HEAD
 +    statusItem_.reset([item retain]);
 +    [[statusItem_ button] addSubview:self];  // inject custom view
++=======
+     statusItem_ = item;
+     [[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:)];
++>>>>>>> fix: macOS tray button selection with VoiceOver
statusItemWithLength:NSVariableStatusItemLength];

Check failure on line 55 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 26-x-y

shell/browser/ui/tray_icon_cocoa.mm#L54-L55

Patch Conflict
Raw output
++<<<<<<< HEAD
 +    statusItem_.reset([item retain]);
 +    [[statusItem_ button] addSubview:self];  // inject custom view
++=======
+     statusItem_ = item;
+     [[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:)];
++>>>>>>> fix: macOS tray button selection with VoiceOver

Check failure on line 55 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 26-x-y

shell/browser/ui/tray_icon_cocoa.mm#L54-L55

Patch Conflict
Raw output
++<<<<<<< HEAD
 +    statusItem_.reset([item retain]);
 +    [[statusItem_ button] addSubview:self];  // inject custom view
++=======
+     statusItem_ = item;
+     [[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:)];
++>>>>>>> fix: macOS tray button selection with VoiceOver

Check failure on line 55 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 26-x-y

shell/browser/ui/tray_icon_cocoa.mm#L54-L55

Patch Conflict
Raw output
++<<<<<<< HEAD
 +    statusItem_.reset([item retain]);
 +    [[statusItem_ button] addSubview:self];  // inject custom view
++=======
+     statusItem_ = item;
+     [[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:)];
++>>>>>>> fix: macOS tray button selection with VoiceOver
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];
}
return self;
Expand Down Expand Up @@ -190,6 +195,25 @@
}

- (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(
gfx::ScreenPointFromNSPoint([event locationInWindow]),
ui::EventFlagsFromModifiers([event modifierFlags]));
Expand Down