OS X: Do not re-create tracking areas over and over again

NSTrackingInVisibleRect already makes sure that the tracking area
updates itself, so we only need to add our tracking area if it is
missing.

For some reason this also fixes that Qt mouse tracking was broken after
showing e.g. an embedded native WebView.

Task-number: QTBUG-21944
Change-Id: I8013517f474f18e44b1ddd411defe1b6e60f05bf
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>
This commit is contained in:
Eike Ziller 2015-03-27 12:28:40 +01:00
parent 1ae657344c
commit 5e8e04a29f
2 changed files with 13 additions and 18 deletions

View File

@ -59,6 +59,7 @@ Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(QNSViewMouseMoveHelper));
bool m_shouldInvalidateWindowShadow;
QWindow *m_window;
QCocoaWindow *m_platformWindow;
NSTrackingArea *m_trackingArea;
Qt::MouseButtons m_buttons;
Qt::MouseButtons m_frameStrutButtons;
QString m_composingText;

View File

@ -167,6 +167,7 @@ static NSString *_q_NSWindowDidChangeOcclusionStateNotification = nil;
- (void)dealloc
{
CGImageRelease(m_maskImage);
[m_trackingArea release];
m_maskImage = 0;
m_window = 0;
m_subscribesForGlobalFrameNotifications = false;
@ -188,6 +189,7 @@ static NSString *_q_NSWindowDidChangeOcclusionStateNotification = nil;
m_window = window;
m_platformWindow = platformWindow;
m_sendKeyEvent = false;
m_trackingArea = nil;
#ifdef QT_COCOA_ENABLE_ACCESSIBILITY_INSPECTOR
// prevent rift in space-time continuum, disable
@ -841,19 +843,11 @@ QT_WARNING_POP
{
[super updateTrackingAreas];
// [NSView addTrackingArea] is slow, so bail out early if we can:
if (NSIsEmptyRect([self visibleRect]))
return;
// Remove current trakcing areas:
QCocoaAutoReleasePool pool;
if (NSArray *trackingArray = [self trackingAreas]) {
NSUInteger size = [trackingArray count];
for (NSUInteger i = 0; i < size; ++i) {
NSTrackingArea *t = [trackingArray objectAtIndex:i];
[self removeTrackingArea:t];
}
}
// NSTrackingInVisibleRect keeps care of updating once the tracking is set up, so bail out early
if (m_trackingArea && [[self trackingAreas] containsObject:m_trackingArea])
return;
// Ideally, we shouldn't have NSTrackingMouseMoved events included below, it should
// only be turned on if mouseTracking, hover is on or a tool tip is set.
@ -863,12 +857,12 @@ QT_WARNING_POP
// is a performance hit). So it goes.
NSUInteger trackingOptions = NSTrackingMouseEnteredAndExited | NSTrackingActiveInActiveApp
| NSTrackingInVisibleRect | NSTrackingMouseMoved | NSTrackingCursorUpdate;
NSTrackingArea *ta = [[[NSTrackingArea alloc] initWithRect:[self frame]
options:trackingOptions
owner:m_mouseMoveHelper
userInfo:nil]
autorelease];
[self addTrackingArea:ta];
[m_trackingArea release];
m_trackingArea = [[NSTrackingArea alloc] initWithRect:[self frame]
options:trackingOptions
owner:m_mouseMoveHelper
userInfo:nil];
[self addTrackingArea:m_trackingArea];
}
-(void)cursorUpdateImpl:(NSEvent *)theEvent