| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/base/test/ui_controls.h" | 5 #include "ui/base/test/ui_controls.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 13 #include "ui/events/keycodes/keyboard_code_conversion_mac.h" | 14 #include "ui/events/keycodes/keyboard_code_conversion_mac.h" |
| 14 #import "ui/events/test/cocoa_test_event_utils.h" | 15 #import "ui/events/test/cocoa_test_event_utils.h" |
| 15 | 16 |
| 16 // Implementation details: We use [NSApplication sendEvent:] instead | 17 // Implementation details: We use [NSApplication sendEvent:] instead |
| 17 // of [NSApplication postEvent:atStart:] so that the event gets sent | 18 // of [NSApplication postEvent:atStart:] so that the event gets sent |
| 18 // immediately. This lets us run the post-event task right | 19 // immediately. This lets us run the post-event task right |
| 19 // immediately as well. Unfortunately I cannot subclass NSEvent (it's | 20 // immediately as well. Unfortunately I cannot subclass NSEvent (it's |
| 20 // probably a class cluster) to allow other easy answers. For | 21 // probably a class cluster) to allow other easy answers. For |
| 21 // example, if I could subclass NSEvent, I could run the Task in it's | 22 // example, if I could subclass NSEvent, I could run the Task in it's |
| 22 // dealloc routine (which necessarily happens after the event is | 23 // dealloc routine (which necessarily happens after the event is |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 bool SendMouseMoveNotifyWhenDone(long x, long y, const base::Closure& task) { | 236 bool SendMouseMoveNotifyWhenDone(long x, long y, const base::Closure& task) { |
| 236 CHECK(g_ui_controls_enabled); | 237 CHECK(g_ui_controls_enabled); |
| 237 CGFloat screenHeight = | 238 CGFloat screenHeight = |
| 238 [[[NSScreen screens] firstObject] frame].size.height; | 239 [[[NSScreen screens] firstObject] frame].size.height; |
| 239 g_mouse_location = NSMakePoint(x, screenHeight - y); // flip! | 240 g_mouse_location = NSMakePoint(x, screenHeight - y); // flip! |
| 240 | 241 |
| 241 NSWindow* window = WindowAtCurrentMouseLocation(); | 242 NSWindow* window = WindowAtCurrentMouseLocation(); |
| 242 | 243 |
| 243 NSPoint pointInWindow = g_mouse_location; | 244 NSPoint pointInWindow = g_mouse_location; |
| 244 if (window) | 245 if (window) |
| 245 pointInWindow = [window convertScreenToBase:pointInWindow]; | 246 pointInWindow = ui::ConvertPointFromScreenToWindow(window, pointInWindow); |
| 246 NSTimeInterval timestamp = TimeIntervalSinceSystemStartup(); | 247 NSTimeInterval timestamp = TimeIntervalSinceSystemStartup(); |
| 247 | 248 |
| 248 NSEvent* event = | 249 NSEvent* event = |
| 249 [NSEvent mouseEventWithType:NSMouseMoved | 250 [NSEvent mouseEventWithType:NSMouseMoved |
| 250 location:pointInWindow | 251 location:pointInWindow |
| 251 modifierFlags:0 | 252 modifierFlags:0 |
| 252 timestamp:timestamp | 253 timestamp:timestamp |
| 253 windowNumber:[window windowNumber] | 254 windowNumber:[window windowNumber] |
| 254 context:nil | 255 context:nil |
| 255 eventNumber:0 | 256 eventNumber:0 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 etype = NSRightMouseUp; | 298 etype = NSRightMouseUp; |
| 298 } else { | 299 } else { |
| 299 etype = NSRightMouseDown; | 300 etype = NSRightMouseDown; |
| 300 } | 301 } |
| 301 } else { | 302 } else { |
| 302 return false; | 303 return false; |
| 303 } | 304 } |
| 304 NSWindow* window = WindowAtCurrentMouseLocation(); | 305 NSWindow* window = WindowAtCurrentMouseLocation(); |
| 305 NSPoint pointInWindow = g_mouse_location; | 306 NSPoint pointInWindow = g_mouse_location; |
| 306 if (window) | 307 if (window) |
| 307 pointInWindow = [window convertScreenToBase:pointInWindow]; | 308 pointInWindow = ui::ConvertPointFromScreenToWindow(window, pointInWindow); |
| 308 | 309 |
| 309 NSEvent* event = | 310 NSEvent* event = |
| 310 [NSEvent mouseEventWithType:etype | 311 [NSEvent mouseEventWithType:etype |
| 311 location:pointInWindow | 312 location:pointInWindow |
| 312 modifierFlags:0 | 313 modifierFlags:0 |
| 313 timestamp:TimeIntervalSinceSystemStartup() | 314 timestamp:TimeIntervalSinceSystemStartup() |
| 314 windowNumber:[window windowNumber] | 315 windowNumber:[window windowNumber] |
| 315 context:nil | 316 context:nil |
| 316 eventNumber:0 | 317 eventNumber:0 |
| 317 clickCount:1 | 318 clickCount:1 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 334 void RunClosureAfterAllPendingUIEvents(const base::Closure& closure) { | 335 void RunClosureAfterAllPendingUIEvents(const base::Closure& closure) { |
| 335 base::MessageLoop::current()->PostTask( | 336 base::MessageLoop::current()->PostTask( |
| 336 FROM_HERE, base::Bind(&EventQueueWatcher, closure)); | 337 FROM_HERE, base::Bind(&EventQueueWatcher, closure)); |
| 337 } | 338 } |
| 338 | 339 |
| 339 bool IsFullKeyboardAccessEnabled() { | 340 bool IsFullKeyboardAccessEnabled() { |
| 340 return [NSApp isFullKeyboardAccessEnabled]; | 341 return [NSApp isFullKeyboardAccessEnabled]; |
| 341 } | 342 } |
| 342 | 343 |
| 343 } // namespace ui_controls | 344 } // namespace ui_controls |
| OLD | NEW |