Bug 1599061 - Don't reorder windows when clicking the Picture-in-picture window. r=mac-reviewers,spohl

Differential Revision: https://phabricator.services.mozilla.com/D143406
This commit is contained in:
Markus Stange 2022-04-12 18:23:48 +00:00
Родитель b2a42c4402
Коммит 04121e8a05
1 изменённых файлов: 18 добавлений и 8 удалений

Просмотреть файл

@ -2758,22 +2758,32 @@ NSEvent* gLastDragMouseDownEvent = nil; // [strong]
mUsingOMTCompositor = aUseOMTC; mUsingOMTCompositor = aUseOMTC;
} }
// Returning NO from this method only disallows ordering on mousedown - in order // By default, clicking on a window brings the clicked window to the foreground.
// to prevent it for mouseup too, we need to call [NSApp preventWindowOrdering] // This method is called before -[NSView mouseDown:] in order to influence that behavior.
// when handling the mousedown event.
- (BOOL)shouldDelayWindowOrderingForEvent:(NSEvent*)aEvent { - (BOOL)shouldDelayWindowOrderingForEvent:(NSEvent*)aEvent {
// Always using system-provided window ordering for normal windows. NSWindow* window = self.window;
if (![[self window] isKindOfClass:[PopupWindow class]]) return NO;
// Don't reorder when we don't have a parent window, like when we're a // Prevent reordering for clicks on context menus or tooltips. These are implemented
// context menu or a tooltip. // as PopupWindows without parent windows.
return ![[self window] parentWindow]; if ([window isKindOfClass:[PopupWindow class]] && !window.parentWindow) {
return YES;
}
// Prevent reordering for clicks on always-on-top video like the Picture-in-picture window.
if (window.level == NSFloatingWindowLevel) {
return YES;
}
return NO;
} }
- (void)mouseDown:(NSEvent*)theEvent { - (void)mouseDown:(NSEvent*)theEvent {
NS_OBJC_BEGIN_TRY_IGNORE_BLOCK; NS_OBJC_BEGIN_TRY_IGNORE_BLOCK;
if ([self shouldDelayWindowOrderingForEvent:theEvent]) { if ([self shouldDelayWindowOrderingForEvent:theEvent]) {
// By default, returning NO from shouldDelayWindowOrderingForEvent delays reordering
// so that it happens on the mouseup rather than on the mousedown. In order to prevent
// reordering entirely, we also need to call [NSApp preventWindowOrdering].
[NSApp preventWindowOrdering]; [NSApp preventWindowOrdering];
} }