Skip to content
Snippets Groups Projects

macosx: Fix incorrect mouse entry and exit tracking behaviour of VLCTrackingView around scrolling

Merged Claudio Cambra requested to merge claucambra/vlc:work/fix-tracking-views into master
1 file
+ 29
2
Compare changes
  • Side-by-side
  • Inline
@@ -25,13 +25,16 @@
@interface VLCTrackingView ()
{
NSTrackingArea *_trackingArea;
BOOL _mouseIn;
}
@end
@implementation VLCTrackingView
- (void)mouseExited:(NSEvent *)event
- (void)handleMouseExit
{
_mouseIn = NO;
if (self.animatesTransition) {
[self.viewToHide setAlphaValue:1.0];
[self.viewToShow setAlphaValue:.0];
@@ -53,8 +56,10 @@
}
}
- (void)mouseEntered:(NSEvent *)event
- (void)handleMouseEnter
{
_mouseIn = YES;
if (self.animatesTransition) {
[self.viewToHide setAlphaValue:.0];
[self.viewToHide setHidden:NO];
@@ -75,6 +80,16 @@
}
}
- (void)mouseExited:(NSEvent *)event
{
[self handleMouseExit];
}
- (void)mouseEntered:(NSEvent *)event
{
[self handleMouseEnter];
}
- (void)updateTrackingAreas
{
[super updateTrackingAreas];
@@ -88,6 +103,18 @@
owner:self
userInfo:nil];
[self addTrackingArea:_trackingArea];
// Once tracking area updated, check if the cursor is still inside the tracking view.
// This prevents situations where the mouseEntered/mouseExited is not called because the view
// itself has moved but the cursor has not (e.g. when this view is inside a scrollview and the
// user scrolls)
const NSPoint mouseLocation = [self convertPoint:self.window.mouseLocationOutsideOfEventStream fromView:self.window.contentView];
const BOOL mouseInsideView = [self mouse:mouseLocation inRect:self.frame];
if (mouseInsideView && !_mouseIn) {
[self handleMouseEnter];
} else if (!mouseInsideView && _mouseIn) {
[self handleMouseExit];
}
}
@end
Loading