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

Side by Side Diff: ui/ui_controls/ui_controls_mac.mm

Issue 9390038: Move automation/ui_controls to ui/ui_controls (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: win_aura fix, sync Created 8 years, 9 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/ui_controls/ui_controls_internal_win.cc ('k') | ui/ui_controls/ui_controls_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/automation/ui_controls.h" 5 #include "ui/ui_controls/ui_controls.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 #include <mach/mach_time.h> 8 #include <mach/mach_time.h>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "chrome/browser/automation/ui_controls_internal.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "ui/base/keycodes/keyboard_code_conversion_mac.h" 14 #include "ui/base/keycodes/keyboard_code_conversion_mac.h"
17 15
18 using content::BrowserThread;
19 16
20 // Implementation details: We use [NSApplication sendEvent:] instead 17 // Implementation details: We use [NSApplication sendEvent:] instead
21 // of [NSApplication postEvent:atStart:] so that the event gets sent 18 // of [NSApplication postEvent:atStart:] so that the event gets sent
22 // immediately. This lets us run the post-event task right 19 // immediately. This lets us run the post-event task right
23 // immediately as well. Unfortunately I cannot subclass NSEvent (it's 20 // immediately as well. Unfortunately I cannot subclass NSEvent (it's
24 // probably a class cluster) to allow other easy answers. For 21 // probably a class cluster) to allow other easy answers. For
25 // 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
26 // dealloc routine (which necessarily happens after the event is 23 // dealloc routine (which necessarily happens after the event is
27 // dispatched). Unlike Linux, Mac does not have message loop 24 // dispatched). Unlike Linux, Mac does not have message loop
28 // observer/notification. Unlike windows, I cannot post non-events 25 // observer/notification. Unlike windows, I cannot post non-events
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 226
230 // Win and Linux implement a SendKeyPress() this as a 227 // Win and Linux implement a SendKeyPress() this as a
231 // SendKeyPressAndRelease(), so we should as well (despite the name). 228 // SendKeyPressAndRelease(), so we should as well (despite the name).
232 bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, 229 bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window,
233 ui::KeyboardCode key, 230 ui::KeyboardCode key,
234 bool control, 231 bool control,
235 bool shift, 232 bool shift,
236 bool alt, 233 bool alt,
237 bool command, 234 bool command,
238 const base::Closure& task) { 235 const base::Closure& task) {
239 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 236 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type());
240 237
241 std::vector<NSEvent*> events; 238 std::vector<NSEvent*> events;
242 SynthesizeKeyEventsSequence( 239 SynthesizeKeyEventsSequence(
243 window, key, control, shift, alt, command, &events); 240 window, key, control, shift, alt, command, &events);
244 241
245 // TODO(suzhe): Using [NSApplication postEvent:atStart:] here causes 242 // TODO(suzhe): Using [NSApplication postEvent:atStart:] here causes
246 // BrowserKeyEventsTest.CommandKeyEvents to fail. See http://crbug.com/49270 243 // BrowserKeyEventsTest.CommandKeyEvents to fail. See http://crbug.com/49270
247 // But using [NSApplication sendEvent:] should be safe for keyboard events, 244 // But using [NSApplication sendEvent:] should be safe for keyboard events,
248 // because until now, no code wants to retrieve the next event when handling 245 // because until now, no code wants to retrieve the next event when handling
249 // a keyboard event. 246 // a keyboard event.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 FROM_HERE, base::Bind(&EventQueueWatcher, task)); 350 FROM_HERE, base::Bind(&EventQueueWatcher, task));
354 } 351 }
355 352
356 return true; 353 return true;
357 } 354 }
358 355
359 bool SendMouseClick(MouseButton type) { 356 bool SendMouseClick(MouseButton type) {
360 return SendMouseEventsNotifyWhenDone(type, UP|DOWN, base::Closure()); 357 return SendMouseEventsNotifyWhenDone(type, UP|DOWN, base::Closure());
361 } 358 }
362 359
363 void MoveMouseToCenterAndPress( 360 } // namespace ui_controls
364 NSView* view,
365 MouseButton button,
366 int state,
367 const base::Closure& task) {
368 DCHECK(view);
369 NSWindow* window = [view window];
370 DCHECK(window);
371 NSScreen* screen = [window screen];
372 DCHECK(screen);
373
374 // Converts the center position of the view into the coordinates accepted
375 // by SendMouseMoveNotifyWhenDone() method.
376 NSRect bounds = [view bounds];
377 NSPoint center = NSMakePoint(NSMidX(bounds), NSMidY(bounds));
378 center = [view convertPoint:center toView:nil];
379 center = [window convertBaseToScreen:center];
380 center = NSMakePoint(center.x, [screen frame].size.height - center.y);
381
382 SendMouseMoveNotifyWhenDone(
383 center.x, center.y,
384 base::Bind(&ui_controls::internal::ClickTask, button, state, task));
385 }
386
387 } // ui_controls
OLDNEW
« no previous file with comments | « ui/ui_controls/ui_controls_internal_win.cc ('k') | ui/ui_controls/ui_controls_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698