summaryrefslogtreecommitdiffstats
path: root/ui/base
diff options
context:
space:
mode:
authortapted@chromium.org <tapted@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-21 04:37:35 +0000
committertapted@chromium.org <tapted@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-21 04:38:54 +0000
commitea7067ab788091fd79572955f2acff67f85dffff (patch)
tree20cd66bb3b49e186bd487a0aec6eb5f6fcb12251 /ui/base
parentec988d7d06f2fccac506cc1d9380d6d6d2cfe9f6 (diff)
downloadchromium_src-ea7067ab788091fd79572955f2acff67f85dffff.zip
chromium_src-ea7067ab788091fd79572955f2acff67f85dffff.tar.gz
chromium_src-ea7067ab788091fd79572955f2acff67f85dffff.tar.bz2
MacViews: Change ui_controls to send mouse events to the window under the cursor
On Mac, unless dragging, mouse events are sent to the window under the cursor. ui_controls_mac.mm currently sends them to the keyWindow, which results in an incorrect window reference being placed on the synthesized event, and incorrect coordinate transformations. This change is required for getting MenuItemView interactive tests passing. BUG=403679 TEST=interactive_ui_tests (On Mac, nothing should start failing) Review URL: https://codereview.chromium.org/481333002 Cr-Commit-Position: refs/heads/master@{#290999} git-svn-id: svn://svn.chromium.org/chrome/trunk/src@290999 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/base')
-rw-r--r--ui/base/test/ui_controls_mac.mm28
1 files changed, 21 insertions, 7 deletions
diff --git a/ui/base/test/ui_controls_mac.mm b/ui/base/test/ui_controls_mac.mm
index 5f58c41..f608f21 100644
--- a/ui/base/test/ui_controls_mac.mm
+++ b/ui/base/test/ui_controls_mac.mm
@@ -45,6 +45,12 @@
namespace {
+// Stores the current mouse location on the screen. So that we can use it
+// when firing keyboard and mouse click events.
+NSPoint g_mouse_location = { 0, 0 };
+
+bool g_ui_controls_enabled = false;
+
// From
// http://stackoverflow.com/questions/1597383/cgeventtimestamp-to-nsdate
// Which credits Apple sample code for this routine.
@@ -205,11 +211,17 @@ void EventQueueWatcher(const base::Closure& task) {
}
}
-// Stores the current mouse location on the screen. So that we can use it
-// when firing keyboard and mouse click events.
-NSPoint g_mouse_location = { 0, 0 };
-
-bool g_ui_controls_enabled = false;
+// Returns the NSWindow located at |g_mouse_location|. NULL if there is no
+// window there, or if the window located there is not owned by the application.
+// On Mac, unless dragging, mouse events are sent to the window under the
+// cursor. Note that the OS will ignore transparent windows and windows that
+// explicitly ignore mouse events.
+NSWindow* WindowAtCurrentMouseLocation() {
+ NSInteger window_number = [NSWindow windowNumberAtPoint:g_mouse_location
+ belowWindowWithWindowNumber:0];
+ return
+ [[NSApplication sharedApplication] windowWithWindowNumber:window_number];
+}
} // namespace
@@ -275,10 +287,12 @@ bool SendMouseMove(long x, long y) {
// platforms. E.g. (0,0) is upper-left.
bool SendMouseMoveNotifyWhenDone(long x, long y, const base::Closure& task) {
CHECK(g_ui_controls_enabled);
- NSWindow* window = [[NSApplication sharedApplication] keyWindow];
CGFloat screenHeight =
[[[NSScreen screens] objectAtIndex:0] frame].size.height;
g_mouse_location = NSMakePoint(x, screenHeight - y); // flip!
+
+ NSWindow* window = WindowAtCurrentMouseLocation();
+
NSPoint pointInWindow = g_mouse_location;
if (window)
pointInWindow = [window convertScreenToBase:pointInWindow];
@@ -340,7 +354,7 @@ bool SendMouseEventsNotifyWhenDone(MouseButton type, int state,
} else {
return false;
}
- NSWindow* window = [[NSApplication sharedApplication] keyWindow];
+ NSWindow* window = WindowAtCurrentMouseLocation();
NSPoint pointInWindow = g_mouse_location;
if (window)
pointInWindow = [window convertScreenToBase:pointInWindow];