ui_controls_win.cc revision 868fa2fe829687343ffae624259930155e16dbd8
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.
4
5#include "ui/base/test/ui_controls.h"
6
7#include "base/callback.h"
8#include "base/message_loop.h"
9#include "ui/base/test/ui_controls_internal_win.h"
10#include "ui/gfx/point.h"
11#include "ui/views/view.h"
12
13namespace ui_controls {
14bool g_ui_controls_enabled = false;
15
16void EnableUIControls() {
17  g_ui_controls_enabled = true;
18}
19
20bool SendKeyPress(gfx::NativeWindow window,
21                  ui::KeyboardCode key,
22                  bool control,
23                  bool shift,
24                  bool alt,
25                  bool command) {
26  CHECK(g_ui_controls_enabled);
27  DCHECK(!command);  // No command key on Windows
28  return internal::SendKeyPressImpl(window, key, control, shift, alt,
29                                    base::Closure());
30}
31
32bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window,
33                                ui::KeyboardCode key,
34                                bool control,
35                                bool shift,
36                                bool alt,
37                                bool command,
38                                const base::Closure& task) {
39  CHECK(g_ui_controls_enabled);
40  DCHECK(!command);  // No command key on Windows
41  return internal::SendKeyPressImpl(window, key, control, shift, alt, task);
42}
43
44bool SendMouseMove(long x, long y) {
45  CHECK(g_ui_controls_enabled);
46  return internal::SendMouseMoveImpl(x, y, base::Closure());
47}
48
49bool SendMouseMoveNotifyWhenDone(long x, long y, const base::Closure& task) {
50  CHECK(g_ui_controls_enabled);
51  return internal::SendMouseMoveImpl(x, y, task);
52}
53
54bool SendMouseEvents(MouseButton type, int state) {
55  CHECK(g_ui_controls_enabled);
56  return internal::SendMouseEventsImpl(type, state, base::Closure());
57}
58
59bool SendMouseEventsNotifyWhenDone(MouseButton type, int state,
60                                   const base::Closure& task) {
61  CHECK(g_ui_controls_enabled);
62  return internal::SendMouseEventsImpl(type, state, task);
63}
64
65bool SendMouseClick(MouseButton type) {
66  CHECK(g_ui_controls_enabled);
67  return internal::SendMouseEventsImpl(type, UP | DOWN, base::Closure());
68}
69
70void RunClosureAfterAllPendingUIEvents(const base::Closure& closure) {
71  // On windows, posting UI events is synchronous so just post the closure.
72  base::MessageLoopForUI::current()->PostTask(FROM_HERE, closure);
73}
74
75}  // namespace ui_controls
76