Chromium Code Reviews| Index: ui/ui_controls/ui_controls_mac.mm |
| diff --git a/ui/ui_controls/ui_controls_mac.mm b/ui/ui_controls/ui_controls_mac.mm |
| index 71bd272d7cbf2c4c8cf893902011a633c49ad690..8739bb7646748864448a5f74ab3b33c74f3ba2e4 100644 |
| --- a/ui/ui_controls/ui_controls_mac.mm |
| +++ b/ui/ui_controls/ui_controls_mac.mm |
| @@ -213,148 +213,160 @@ NSPoint g_mouse_location = { 0, 0 }; |
| namespace ui_controls { |
| -bool SendKeyPress(gfx::NativeWindow window, |
| - ui::KeyboardCode key, |
| - bool control, |
| - bool shift, |
| - bool alt, |
| - bool command) { |
| - return SendKeyPressNotifyWhenDone(window, key, |
| - control, shift, alt, command, |
| - base::Closure()); |
| -} |
| +namespace { |
| -// Win and Linux implement a SendKeyPress() this as a |
| -// SendKeyPressAndRelease(), so we should as well (despite the name). |
| -bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, |
| - ui::KeyboardCode key, |
| - bool control, |
| - bool shift, |
| - bool alt, |
| - bool command, |
| - const base::Closure& task) { |
| - DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); |
| - |
| - std::vector<NSEvent*> events; |
| - SynthesizeKeyEventsSequence( |
| - window, key, control, shift, alt, command, &events); |
| - |
| - // TODO(suzhe): Using [NSApplication postEvent:atStart:] here causes |
| - // BrowserKeyEventsTest.CommandKeyEvents to fail. See http://crbug.com/49270 |
| - // But using [NSApplication sendEvent:] should be safe for keyboard events, |
| - // because until now, no code wants to retrieve the next event when handling |
| - // a keyboard event. |
| - for (std::vector<NSEvent*>::iterator iter = events.begin(); |
| - iter != events.end(); ++iter) |
| - [[NSApplication sharedApplication] sendEvent:*iter]; |
| - |
| - if (!task.is_null()) { |
| - MessageLoop::current()->PostTask( |
| - FROM_HERE, base::Bind(&EventQueueWatcher, task)); |
| +class UIControlsMac : public UIControls { |
| + |
| + bool SendKeyPress(gfx::NativeWindow window, |
| + ui::KeyboardCode key, |
| + bool control, |
| + bool shift, |
| + bool alt, |
| + bool command) OVERRIDE { |
| + return SendKeyPressNotifyWhenDone(window, key, |
| + control, shift, alt, command, |
| + base::Closure()); |
| } |
| - return true; |
| -} |
| - |
| -bool SendMouseMove(long x, long y) { |
| - return SendMouseMoveNotifyWhenDone(x, y, base::Closure()); |
| -} |
| + // Win and Linux implement a SendKeyPress() this as a |
| + // SendKeyPressAndRelease(), so we should as well (despite the name). |
| + bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, |
| + ui::KeyboardCode key, |
| + bool control, |
| + bool shift, |
| + bool alt, |
| + bool command, |
| + const base::Closure& task) OVERRIDE { |
| + DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); |
| + |
| + std::vector<NSEvent*> events; |
| + SynthesizeKeyEventsSequence( |
| + window, key, control, shift, alt, command, &events); |
| + |
| + // TODO(suzhe): Using [NSApplication postEvent:atStart:] here causes |
| + // BrowserKeyEventsTest.CommandKeyEvents to fail. See http://crbug.com/49270 |
| + // But using [NSApplication sendEvent:] should be safe for keyboard events, |
| + // because until now, no code wants to retrieve the next event when handling |
| + // a keyboard event. |
| + for (std::vector<NSEvent*>::iterator iter = events.begin(); |
| + iter != events.end(); ++iter) |
| + [[NSApplication sharedApplication] sendEvent:*iter]; |
| + |
| + if (!task.is_null()) { |
| + MessageLoop::current()->PostTask( |
| + FROM_HERE, base::Bind(&EventQueueWatcher, task)); |
| + } |
| -// Input position is in screen coordinates. However, NSMouseMoved |
| -// events require them window-relative, so we adjust. We *DO* flip |
| -// the coordinate space, so input events can be the same for all |
| -// platforms. E.g. (0,0) is upper-left. |
| -bool SendMouseMoveNotifyWhenDone(long x, long y, const base::Closure& task) { |
| - NSWindow* window = [[NSApplication sharedApplication] keyWindow]; |
| - CGFloat screenHeight = |
| - [[[NSScreen screens] objectAtIndex:0] frame].size.height; |
| - g_mouse_location = NSMakePoint(x, screenHeight - y); // flip! |
| - NSPoint pointInWindow = g_mouse_location; |
| - if (window) |
| - pointInWindow = [window convertScreenToBase:pointInWindow]; |
| - NSTimeInterval timestamp = TimeIntervalSinceSystemStartup(); |
| + return true; |
| + } |
| - NSEvent* event = |
| - [NSEvent mouseEventWithType:NSMouseMoved |
| - location:pointInWindow |
| - modifierFlags:0 |
| - timestamp:timestamp |
| - windowNumber:[window windowNumber] |
| - context:nil |
| - eventNumber:0 |
| - clickCount:0 |
| - pressure:0.0]; |
| - [[NSApplication sharedApplication] postEvent:event atStart:NO]; |
| - |
| - if (!task.is_null()) { |
| - MessageLoop::current()->PostTask( |
| - FROM_HERE, base::Bind(&EventQueueWatcher, task)); |
| + bool SendMouseMove(long x, long y) OVERRIDE { |
| + return SendMouseMoveNotifyWhenDone(x, y, base::Closure()); |
| } |
| - return true; |
| -} |
| + // Input position is in screen coordinates. However, NSMouseMoved |
| + // events require them window-relative, so we adjust. We *DO* flip |
| + // the coordinate space, so input events can be the same for all |
| + // platforms. E.g. (0,0) is upper-left. |
| + bool SendMouseMoveNotifyWhenDone( |
| + long x, long y, const base::Closure& task) OVERRIDE { |
| + NSWindow* window = [[NSApplication sharedApplication] keyWindow]; |
| + CGFloat screenHeight = |
| + [[[NSScreen screens] objectAtIndex:0] frame].size.height; |
| + g_mouse_location = NSMakePoint(x, screenHeight - y); // flip! |
| + NSPoint pointInWindow = g_mouse_location; |
| + if (window) |
| + pointInWindow = [window convertScreenToBase:pointInWindow]; |
| + NSTimeInterval timestamp = TimeIntervalSinceSystemStartup(); |
| + |
| + NSEvent* event = |
| + [NSEvent mouseEventWithType:NSMouseMoved |
| + location:pointInWindow |
| + modifierFlags:0 |
| + timestamp:timestamp |
| + windowNumber:[window windowNumber] |
| + context:nil |
| + eventNumber:0 |
| + clickCount:0 |
| + pressure:0.0]; |
| + [[NSApplication sharedApplication] postEvent:event atStart:NO]; |
| + |
| + if (!task.is_null()) { |
| + MessageLoop::current()->PostTask( |
| + FROM_HERE, base::Bind(&EventQueueWatcher, task)); |
| + } |
| -bool SendMouseEvents(MouseButton type, int state) { |
| - return SendMouseEventsNotifyWhenDone(type, state, base::Closure()); |
| -} |
| + return true; |
| + } |
| -bool SendMouseEventsNotifyWhenDone(MouseButton type, int state, |
| - const base::Closure& task) { |
| - // On windows it appears state can be (UP|DOWN). It is unclear if |
| - // that'll happen here but prepare for it just in case. |
| - if (state == (UP|DOWN)) { |
| - return (SendMouseEventsNotifyWhenDone(type, DOWN, base::Closure()) && |
| - SendMouseEventsNotifyWhenDone(type, UP, task)); |
| + bool SendMouseEvents(MouseButton type, int state) OVERRIDE { |
| + return SendMouseEventsNotifyWhenDone(type, state, base::Closure()); |
| } |
| - NSEventType etype = 0; |
| - if (type == LEFT) { |
| - if (state == UP) { |
| - etype = NSLeftMouseUp; |
| - } else { |
| - etype = NSLeftMouseDown; |
| + |
| + bool SendMouseEventsNotifyWhenDone(MouseButton type, int state, |
| + const base::Closure& task) OVERRIDE { |
| + // On windows it appears state can be (UP|DOWN). It is unclear if |
| + // that'll happen here but prepare for it just in case. |
| + if (state == (UP|DOWN)) { |
| + return (SendMouseEventsNotifyWhenDone(type, DOWN, base::Closure()) && |
| + SendMouseEventsNotifyWhenDone(type, UP, task)); |
| } |
| - } else if (type == MIDDLE) { |
| - if (state == UP) { |
| - etype = NSOtherMouseUp; |
| + NSEventType etype = 0; |
| + if (type == LEFT) { |
| + if (state == UP) { |
| + etype = NSLeftMouseUp; |
| + } else { |
| + etype = NSLeftMouseDown; |
| + } |
| + } else if (type == MIDDLE) { |
| + if (state == UP) { |
| + etype = NSOtherMouseUp; |
| + } else { |
| + etype = NSOtherMouseDown; |
| + } |
| + } else if (type == RIGHT) { |
| + if (state == UP) { |
| + etype = NSRightMouseUp; |
| + } else { |
| + etype = NSRightMouseDown; |
| + } |
| } else { |
| - etype = NSOtherMouseDown; |
| + return false; |
| } |
| - } else if (type == RIGHT) { |
| - if (state == UP) { |
| - etype = NSRightMouseUp; |
| - } else { |
| - etype = NSRightMouseDown; |
| + NSWindow* window = [[NSApplication sharedApplication] keyWindow]; |
| + NSPoint pointInWindow = g_mouse_location; |
| + if (window) |
| + pointInWindow = [window convertScreenToBase:pointInWindow]; |
| + |
| + NSEvent* event = |
| + [NSEvent mouseEventWithType:etype |
| + location:pointInWindow |
| + modifierFlags:0 |
| + timestamp:TimeIntervalSinceSystemStartup() |
| + windowNumber:[window windowNumber] |
| + context:nil |
| + eventNumber:0 |
| + clickCount:1 |
| + pressure:(state == DOWN ? 1.0 : 0.0 )]; |
| + [[NSApplication sharedApplication] postEvent:event atStart:NO]; |
| + |
| + if (!task.is_null()) { |
| + MessageLoop::current()->PostTask( |
| + FROM_HERE, base::Bind(&EventQueueWatcher, task)); |
| } |
| - } else { |
| - return false; |
| + |
| + return true; |
| } |
| - NSWindow* window = [[NSApplication sharedApplication] keyWindow]; |
| - NSPoint pointInWindow = g_mouse_location; |
| - if (window) |
| - pointInWindow = [window convertScreenToBase:pointInWindow]; |
| - NSEvent* event = |
| - [NSEvent mouseEventWithType:etype |
| - location:pointInWindow |
| - modifierFlags:0 |
| - timestamp:TimeIntervalSinceSystemStartup() |
| - windowNumber:[window windowNumber] |
| - context:nil |
| - eventNumber:0 |
| - clickCount:1 |
| - pressure:(state == DOWN ? 1.0 : 0.0 )]; |
| - [[NSApplication sharedApplication] postEvent:event atStart:NO]; |
| - |
| - if (!task.is_null()) { |
| - MessageLoop::current()->PostTask( |
| - FROM_HERE, base::Bind(&EventQueueWatcher, task)); |
| + bool SendMouseClick(MouseButton type) OVERRIDE { |
| + return SendMouseEventsNotifyWhenDone(type, UP|DOWN, base::Closure()); |
| } |
|
oshima
2012/11/15 23:37:41
ditto
scottmg
2012/11/16 17:58:54
Done.
|
| +}; |
| - return true; |
| -} |
| +} // namespace |
| -bool SendMouseClick(MouseButton type) { |
| - return SendMouseEventsNotifyWhenDone(type, UP|DOWN, base::Closure()); |
| +UIControls* CreateNativeUIControls() { |
| + return new UIControlsMac; |
| } |
| } // namespace ui_controls |