Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(731)

Unified Diff: ui/ui_controls/ui_controls_mac.mm

Issue 11419013: Add desktop vs. ash context to ui_controls Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..fbcf5cc841355aeb8d087a6555d7160ba54e161c 100644
--- a/ui/ui_controls/ui_controls_mac.mm
+++ b/ui/ui_controls/ui_controls_mac.mm
@@ -213,148 +213,166 @@ 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 {
+ public:
+ UIControlsMac() {}
+ virtual ~UIControlsMac() {}
+
+ 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());
}
- return true;
-}
+ private:
+ DISALLOW_COPY_AND_ASSIGN(UIControlsMac);
+};
+
+} // namespace
-bool SendMouseClick(MouseButton type) {
- return SendMouseEventsNotifyWhenDone(type, UP|DOWN, base::Closure());
+UIControls* CreateNativeUIControls() {
+ return new UIControlsMac;
}
} // namespace ui_controls

Powered by Google App Engine
This is Rietveld 408576698