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_aura.h"
6
7#include "base/logging.h"
8
9namespace ui_controls {
10namespace {
11UIControlsAura* instance_ = NULL;
12bool g_ui_controls_enabled = false;
13}  // namespace
14
15void EnableUIControls() {
16  g_ui_controls_enabled = true;
17}
18
19// An interface to provide Aura implementation of UI control.
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  return instance_->SendKeyPress(
28      window, key, control, shift, alt, command);
29}
30
31// static
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  return instance_->SendKeyPressNotifyWhenDone(
41      window, key, control, shift, alt, command, task);
42}
43
44// static
45bool SendMouseMove(long x, long y) {
46  CHECK(g_ui_controls_enabled);
47  return instance_->SendMouseMove(x, y);
48}
49
50// static
51bool SendMouseMoveNotifyWhenDone(long x,
52                                 long y,
53                                 const base::Closure& task) {
54  CHECK(g_ui_controls_enabled);
55  return instance_->SendMouseMoveNotifyWhenDone(x, y, task);
56}
57
58// static
59bool SendMouseEvents(MouseButton type, int state) {
60  CHECK(g_ui_controls_enabled);
61  return instance_->SendMouseEvents(type, state);
62}
63
64// static
65bool SendMouseEventsNotifyWhenDone(MouseButton type,
66                                   int state,
67                                   const base::Closure& task) {
68  CHECK(g_ui_controls_enabled);
69  return instance_->SendMouseEventsNotifyWhenDone(type, state, task);
70}
71
72// static
73bool SendMouseClick(MouseButton type) {
74  CHECK(g_ui_controls_enabled);
75  return instance_->SendMouseClick(type);
76}
77
78// static
79void RunClosureAfterAllPendingUIEvents(const base::Closure& closure) {
80  instance_->RunClosureAfterAllPendingUIEvents(closure);
81}
82
83UIControlsAura::UIControlsAura() {
84}
85
86UIControlsAura::~UIControlsAura() {
87}
88
89// static. declared in ui_controls.h
90void InstallUIControlsAura(UIControlsAura* instance) {
91  delete instance_;
92  instance_ = instance;
93}
94
95}  // namespace ui_controls
96