From 38a55c781303a59be28ea96d7c6bba2a8e885b21 Mon Sep 17 00:00:00 2001 From: Oleg Yadrov Date: Tue, 7 Mar 2017 16:47:29 -0800 Subject: [PATCH] QCocoaWindow: fix geometry issue when only minimumSize is set When only minimumSize was set and it matched to the size NSView was created with, viewDidChangeFrame() was not called for the window and it's internal geometry value was still (0, 0) what led to unpleasant side effects such as QML content was not displayed until something caused an update. Task-number: QTBUG-58963 Change-Id: Ib12d36d405969971e7ff62b79b50c3d78928a649 Reviewed-by: Timur Pocheptsov Reviewed-by: Qt CI Bot --- src/plugins/platforms/cocoa/qcocoawindow.mm | 7 +++++++ src/plugins/platforms/cocoa/qnsview.h | 1 + src/plugins/platforms/cocoa/qnsview.mm | 7 ++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 75c13d6bbc..cfe829905c 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -1636,6 +1636,13 @@ void QCocoaWindow::recreateWindowIfNeeded() [m_nsWindow setContentView:m_view]; [m_view release]; [m_view setPostsFrameChangedNotifications:YES]; + // QTBUG-58963 + // viewDidChangeFrame() should be called for each window automatically at this point because it is + // registered with Q_NOTIFICATION_HANDLER(NSViewFrameDidChangeNotification); + // The corner case when it's not called and we need to make a manual geometry update is when window's + // size is not specified explicitly but minimumSize is set and matches to the size NSView was created with. + if (QSizeF::fromCGSize(m_view.frame.size) == [QNSView defaultViewSize]) + viewDidChangeFrame(); } } diff --git a/src/plugins/platforms/cocoa/qnsview.h b/src/plugins/platforms/cocoa/qnsview.h index 75a508370f..a05bd66890 100644 --- a/src/plugins/platforms/cocoa/qnsview.h +++ b/src/plugins/platforms/cocoa/qnsview.h @@ -88,6 +88,7 @@ Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(QNSViewMouseMoveHelper)); QSet m_acceptedKeyDowns; } ++ (QSizeF)defaultViewSize; - (id)init; - (id)initWithCocoaWindow:(QCocoaWindow *)platformWindow; #ifndef QT_NO_OPENGL diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index 40efa092b3..967271be9c 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -140,7 +140,7 @@ static bool _q_dontOverrideCtrlLMB = false; - (id) init { - self = [super initWithFrame : NSMakeRect(0,0, 300,300)]; + self = [super initWithFrame : NSMakeRect(0, 0, [[self class] defaultViewSize].width(), [[self class] defaultViewSize].height())]; if (self) { m_backingStore = 0; m_maskImage = 0; @@ -189,6 +189,11 @@ static bool _q_dontOverrideCtrlLMB = false; [super dealloc]; } ++ (QSizeF)defaultViewSize +{ + return QSizeF(300.0, 300.0); +} + - (id)initWithCocoaWindow:(QCocoaWindow *)platformWindow { self = [self init];