| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/automation/ui_controls.h" | |
| 6 | |
| 7 #include "ash/shell.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "base/message_loop.h" | |
| 10 #include "chrome/browser/automation/ui_controls_internal.h" | |
| 11 #include "ui/aura/root_window.h" | |
| 12 #include "ui/views/view.h" | |
| 13 | |
| 14 namespace ui_controls { | |
| 15 | |
| 16 bool SendKeyPress(gfx::NativeWindow window, | |
| 17 ui::KeyboardCode key, | |
| 18 bool control, | |
| 19 bool shift, | |
| 20 bool alt, | |
| 21 bool command) { | |
| 22 DCHECK(!command); // No command key on Aura | |
| 23 return internal::SendKeyPressImpl(window, key, control, shift, alt, | |
| 24 base::Closure()); | |
| 25 } | |
| 26 | |
| 27 bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, | |
| 28 ui::KeyboardCode key, | |
| 29 bool control, | |
| 30 bool shift, | |
| 31 bool alt, | |
| 32 bool command, | |
| 33 const base::Closure& task) { | |
| 34 DCHECK(!command); // No command key on Aura | |
| 35 return internal::SendKeyPressImpl(window, key, control, shift, alt, task); | |
| 36 } | |
| 37 | |
| 38 bool SendMouseMove(long x, long y) { | |
| 39 gfx::Point point(x, y); | |
| 40 ash::Shell::GetRootWindow()->ConvertPointToNativeScreen(&point); | |
| 41 return internal::SendMouseMoveImpl(point.x(), point.y(), base::Closure()); | |
| 42 } | |
| 43 | |
| 44 bool SendMouseMoveNotifyWhenDone(long x, long y, const base::Closure& task) { | |
| 45 gfx::Point point(x, y); | |
| 46 ash::Shell::GetRootWindow()->ConvertPointToNativeScreen(&point); | |
| 47 return internal::SendMouseMoveImpl(point.x(), point.y(), task); | |
| 48 } | |
| 49 | |
| 50 bool SendMouseEvents(MouseButton type, int state) { | |
| 51 return internal::SendMouseEventsImpl(type, state, base::Closure()); | |
| 52 } | |
| 53 | |
| 54 bool SendMouseEventsNotifyWhenDone(MouseButton type, int state, | |
| 55 const base::Closure& task) { | |
| 56 return internal::SendMouseEventsImpl(type, state, task); | |
| 57 } | |
| 58 | |
| 59 bool SendMouseClick(MouseButton type) { | |
| 60 return SendMouseEvents(type, UP | DOWN); | |
| 61 } | |
| 62 | |
| 63 void MoveMouseToCenterAndPress(views::View* view, | |
| 64 MouseButton button, | |
| 65 int state, | |
| 66 const base::Closure& task) { | |
| 67 DCHECK(view); | |
| 68 DCHECK(view->GetWidget()); | |
| 69 gfx::Point view_center(view->width() / 2, view->height() / 2); | |
| 70 views::View::ConvertPointToScreen(view, &view_center); | |
| 71 SendMouseMove(view_center.x(), view_center.y()); | |
| 72 SendMouseEventsNotifyWhenDone(button, state, task); | |
| 73 } | |
| 74 | |
| 75 void RunClosureAfterAllPendingUIEvents(const base::Closure& task) { | |
| 76 // On windows, posting UI events is synchronous so just post the closure. | |
| 77 MessageLoopForUI::current()->PostTask(FROM_HERE, task); | |
| 78 } | |
| 79 | |
| 80 } // namespace ui_controls | |
| OLD | NEW |