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
3 // found in the LICENSE file.
5 #include "ui/base/test/ui_controls.h"
7 #include "base/callback.h"
8 #include "base/message_loop/message_loop.h"
9 #include "ui/base/test/ui_controls_internal_win.h"
10 #include "ui/gfx/geometry/point.h"
12 namespace ui_controls
{
13 bool g_ui_controls_enabled
= false;
15 void EnableUIControls() {
16 g_ui_controls_enabled
= true;
19 bool SendKeyPress(gfx::NativeWindow window
,
25 CHECK(g_ui_controls_enabled
);
26 DCHECK(!command
); // No command key on Windows
27 return internal::SendKeyPressImpl(window
, key
, control
, shift
, alt
,
31 bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window
,
37 const base::Closure
& task
) {
38 CHECK(g_ui_controls_enabled
);
39 DCHECK(!command
); // No command key on Windows
40 return internal::SendKeyPressImpl(window
, key
, control
, shift
, alt
, task
);
43 bool SendMouseMove(long x
, long y
) {
44 CHECK(g_ui_controls_enabled
);
45 return internal::SendMouseMoveImpl(x
, y
, base::Closure());
48 bool SendMouseMoveNotifyWhenDone(long x
, long y
, const base::Closure
& task
) {
49 CHECK(g_ui_controls_enabled
);
50 return internal::SendMouseMoveImpl(x
, y
, task
);
53 bool SendMouseEvents(MouseButton type
, int state
) {
54 CHECK(g_ui_controls_enabled
);
55 return internal::SendMouseEventsImpl(type
, state
, base::Closure());
58 bool SendMouseEventsNotifyWhenDone(MouseButton type
, int state
,
59 const base::Closure
& task
) {
60 CHECK(g_ui_controls_enabled
);
61 return internal::SendMouseEventsImpl(type
, state
, task
);
64 bool SendMouseClick(MouseButton type
) {
65 CHECK(g_ui_controls_enabled
);
66 return internal::SendMouseEventsImpl(type
, UP
| DOWN
, base::Closure());
69 void RunClosureAfterAllPendingUIEvents(const base::Closure
& closure
) {
70 // On windows, posting UI events is synchronous so just post the closure.
71 base::MessageLoopForUI::current()->PostTask(FROM_HERE
, closure
);
74 } // namespace ui_controls