summaryrefslogtreecommitdiffstats
path: root/tests/manual/cocoa/qt_on_cocoa
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2017-08-30 19:48:26 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2017-09-01 10:04:52 +0000
commit362dcb4759112a79462d7019e42fbe711eed58a8 (patch)
tree29d009e239f13d3a53d106fa28396de5640a3f7a /tests/manual/cocoa/qt_on_cocoa
parentca14d84197a8489dff87a414dfdab6eccd4cb2f5 (diff)
macOS: Respect responder chain when setting cursor
There's no need for us to walk our own ancestor chain to figure out which cursor to set. AppKit will automatically call cursorUpdate: on the view that would be the hitTest target of the current mouse position, and by falling back to super when no cursor is set for the current view, we automatically get the behavior that effectiveWindowCursor tried to solve. In addition, it solves the case of applyEffectiveWindowCursor applying the arrowCursor when no cursor was set, which would mean that if any native parent view of our view _did_ have a cursor set, we would not fall back to the native view's cursor, but instead override it with the arrow cursor. Following the responder chain gives the correct behavior in this case. Unfortunately, due to rdar://34183708, if a subview of one of our views uses the legacy cursorRect approach to cursor management, the cursor will not be reset back to our cursor via cursorUpdate: when leaving the child and entering the parent view (our view). Moving our implementation over to the legacy API would solve this problem, but just propagate it to native parent views of our views, which could potentially use NSTrackingAreas, and would not have _their_ cursors re-set. Change-Id: Id20cc03136f0b1d4b9120750fe63ddc455363aaf Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'tests/manual/cocoa/qt_on_cocoa')
-rw-r--r--tests/manual/cocoa/qt_on_cocoa/main.mm18
-rw-r--r--tests/manual/cocoa/qt_on_cocoa/rasterwindow.cpp1
2 files changed, 18 insertions, 1 deletions
diff --git a/tests/manual/cocoa/qt_on_cocoa/main.mm b/tests/manual/cocoa/qt_on_cocoa/main.mm
index f99406f619..5e3b8fcd39 100644
--- a/tests/manual/cocoa/qt_on_cocoa/main.mm
+++ b/tests/manual/cocoa/qt_on_cocoa/main.mm
@@ -42,6 +42,12 @@
[[NSColor whiteColor] setFill];
NSRectFill(dirtyRect);
}
+
+- (void)cursorUpdate:(NSEvent *)theEvent
+{
+ Q_UNUSED(theEvent);
+ [[NSCursor pointingHandCursor] set];
+}
@end
@interface AppDelegate : NSObject <NSApplicationDelegate> {
@@ -76,18 +82,28 @@
[window setTitle:title];
[window setBackgroundColor:[NSColor blueColor]];
- window.contentView = [[[ContentView alloc] initWithFrame:frame] autorelease];
+ NSView *contentView = [[[ContentView alloc] initWithFrame:frame] autorelease];
+ [contentView addTrackingArea:[[NSTrackingArea alloc] initWithRect:[contentView frame]
+ options:NSTrackingActiveInActiveApp | NSTrackingInVisibleRect | NSTrackingCursorUpdate
+ owner:contentView userInfo:nil]];
+
+ window.contentView = contentView;
// Create the QWindow, add its NSView to the content view
m_window = new RasterWindow;
m_window->setObjectName("RasterWindow");
+ m_window->setCursor(Qt::CrossCursor);
m_window->setGeometry(QRect(0, 0, 300, 300));
QWindow *childWindow = new RasterWindow;
childWindow->setObjectName("RasterWindowChild");
childWindow->setParent(m_window);
+ childWindow->setCursor(Qt::BusyCursor);
childWindow->setGeometry(50, 50, 100, 100);
+ NSTextField *textField = [[NSTextField alloc] initWithFrame:NSMakeRect(10, 10, 80, 25)];
+ [(NSView*)childWindow->winId() addSubview:textField];
+
[window.contentView addSubview:reinterpret_cast<NSView *>(m_window->winId())];
// Show the NSWindow
diff --git a/tests/manual/cocoa/qt_on_cocoa/rasterwindow.cpp b/tests/manual/cocoa/qt_on_cocoa/rasterwindow.cpp
index 8a451d5f7c..dca39839dd 100644
--- a/tests/manual/cocoa/qt_on_cocoa/rasterwindow.cpp
+++ b/tests/manual/cocoa/qt_on_cocoa/rasterwindow.cpp
@@ -64,6 +64,7 @@ void RasterWindow::initialize()
void RasterWindow::mousePressEvent(QMouseEvent *event)
{
m_lastPos = event->pos();
+ unsetCursor();
}
void RasterWindow::mouseMoveEvent(QMouseEvent *event)