macOS: Handle NSViewFrameDidChangeNotification via QCocaWindow

There's no need to set postsFrameChangedNotifications = YES, it's
already the default.

Change-Id: I8c50dc119ba3779cdc6b3114d39c64f3cb236172
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
bb10
Tor Arne Vestbø 2016-10-18 16:02:05 +02:00
parent 7f507c1620
commit c1c99c3bfe
3 changed files with 25 additions and 10 deletions

View File

@ -197,6 +197,7 @@ public:
Q_NOTIFICATION_HANDLER(NSWindowWillMoveNotification) void windowWillMove();
Q_NOTIFICATION_HANDLER(NSWindowDidMoveNotification) void windowDidMove();
Q_NOTIFICATION_HANDLER(NSWindowDidResizeNotification) void windowDidResize();
Q_NOTIFICATION_HANDLER(NSViewFrameDidChangeNotification) void viewDidChangeFrame();
Q_NOTIFICATION_HANDLER(NSWindowDidEndLiveResizeNotification) void windowDidEndLiveResize();
Q_NOTIFICATION_HANDLER(NSWindowDidBecomeKeyNotification) void windowDidBecomeKey();
Q_NOTIFICATION_HANDLER(NSWindowDidResignKeyNotification) void windowDidResignKey();

View File

@ -362,15 +362,29 @@ static void qRegisterNotificationCallbacks()
[center addObserverForName:notificationName.toNSString() object:nil queue:nil
usingBlock:^(NSNotification *notification) {
NSWindow *window = notification.object;
NSView *view = nullptr;
if ([notification.object isKindOfClass:[NSWindow class]]) {
NSWindow *window = notification.object;
// Only top level NSWindows should notify their QNSViews
if (window.parentWindow)
return;
// Only top level NSWindows should notify their QNSViews
if (window.parentWindow)
if (!window.contentView)
return;
view = window.contentView;
} else if ([notification.object isKindOfClass:[NSView class]]) {
view = notification.object;
} else {
qCWarning(lcQpaCocoaWindow) << "Unhandled notifcation"
<< notification.name << "for" << notification.object;
return;
}
Q_ASSERT(view);
QCocoaWindow *cocoaWindow = nullptr;
if (QNSView *view = qnsview_cast(window.contentView))
cocoaWindow = view.platformWindow;
if (QNSView *qnsView = qnsview_cast(view))
cocoaWindow = qnsView.platformWindow;
// FIXME: Could be a foreign window, look up by iterating top level QWindows
@ -1251,6 +1265,11 @@ void QCocoaWindow::windowDidResize()
[qnsview_cast(m_view) updateGeometry];
}
void QCocoaWindow::viewDidChangeFrame()
{
[qnsview_cast(m_view) updateGeometry];
}
void QCocoaWindow::windowDidEndLiveResize()
{
if (m_synchedWindowState == Qt::WindowMaximized && ![m_nsWindow isZoomed]) {

View File

@ -217,11 +217,6 @@ static bool _q_dontOverrideCtrlLMB = false;
#endif
[self registerDragTypes];
[self setPostsFrameChangedNotifications : YES];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(updateGeometry)
name:NSViewFrameDidChangeNotification
object:self];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(textInputContextKeyboardSelectionDidChangeNotification:)