summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2018-11-16 18:41:11 +0100
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2018-11-23 00:51:54 +0000
commit1931aedcf827f837ce81a58a8f8f0e55d8212df6 (patch)
treeb798bcd6fad0c8de546f9c22a8af00ed19d856b7 /src/plugins
parent5f49788e3348406f1399e4e911a765f850f5788f (diff)
macOS: Track changes to our NSView's superview and window properties
As a start, we just log the changes, but going forward we can use this to report parent changes to QPA or get rid of old QNSWindows. Change-Id: Id3625fb0b7608d85240f58bdecc70a5892075da3 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/platforms/cocoa/qnsview.mm73
1 files changed, 67 insertions, 6 deletions
diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm
index 03c5001270..7f826942f3 100644
--- a/src/plugins/platforms/cocoa/qnsview.mm
+++ b/src/plugins/platforms/cocoa/qnsview.mm
@@ -68,6 +68,8 @@
// Private interface
@interface QT_MANGLE_NAMESPACE(QNSView) ()
- (BOOL)isTransparentForUserInput;
+@property (assign) NSView* previousSuperview;
+@property (assign) NSWindow* previousWindow;
@end
@interface QT_MANGLE_NAMESPACE(QNSView) (Drawing) <CALayerDelegate>
@@ -153,6 +155,9 @@
self.focusRingType = NSFocusRingTypeNone;
self.cursor = nil;
+ self.previousSuperview = nil;
+ self.previousWindow = nil;
+
[self initDrawing];
[self registerDragTypes];
@@ -195,8 +200,40 @@
return description;
}
+// ----------------------------- Re-parenting ---------------------------------
+
+- (void)removeFromSuperview
+{
+ QMacAutoReleasePool pool;
+ [super removeFromSuperview];
+}
+
+- (void)viewWillMoveToSuperview:(NSView *)newSuperview
+{
+ Q_ASSERT(!self.previousSuperview);
+ self.previousSuperview = self.superview;
+
+ if (newSuperview == self.superview)
+ qCDebug(lcQpaWindow) << "Re-ordering" << self << "inside" << self.superview;
+ else
+ qCDebug(lcQpaWindow) << "Re-parenting" << self << "from" << self.superview << "to" << newSuperview;
+}
+
- (void)viewDidMoveToSuperview
{
+ auto cleanup = qScopeGuard([&] { self.previousSuperview = nil; });
+
+ if (self.superview == self.previousSuperview) {
+ qCDebug(lcQpaWindow) << "Done re-ordering" << self << "new index:"
+ << [self.superview.subviews indexOfObject:self];
+ return;
+ }
+
+ qCDebug(lcQpaWindow) << "Done re-parenting" << self << "into" << self.superview;
+
+ // Note: at this point the view's window property hasn't been updated to match the window
+ // of the new superview. We have to wait for viewDidMoveToWindow for that to be reflected.
+
if (!m_platformWindow)
return;
@@ -210,6 +247,36 @@
}
}
+- (void)viewWillMoveToWindow:(NSWindow *)newWindow
+{
+ Q_ASSERT(!self.previousWindow);
+ self.previousWindow = self.window;
+
+ // This callback is documented to be called also when a view is just moved between
+ // subviews in the same NSWindow, so we're not necessarily moving between NSWindows.
+ if (newWindow == self.window)
+ return;
+
+ qCDebug(lcQpaWindow) << "Moving" << self << "from" << self.window << "to" << newWindow;
+
+ // Note: at this point the superview has already been updated, so we know which view inside
+ // the new window the view will be a child of.
+}
+
+- (void)viewDidMoveToWindow
+{
+ auto cleanup = qScopeGuard([&] { self.previousWindow = nil; });
+
+ // This callback is documented to be called also when a view is just moved between
+ // subviews in the same NSWindow, so we're not necessarily moving between NSWindows.
+ if (self.window == self.previousWindow)
+ return;
+
+ qCDebug(lcQpaWindow) << "Done moving" << self << "to" << self.window;
+}
+
+// ----------------------------------------------------------------------------
+
- (QWindow *)topLevelWindow
{
if (!m_platformWindow)
@@ -239,12 +306,6 @@
// viewDidUnhide so no reason to override it here.
}
-- (void)removeFromSuperview
-{
- QMacAutoReleasePool pool;
- [super removeFromSuperview];
-}
-
- (BOOL)isTransparentForUserInput
{
return m_platformWindow->window() &&