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 "base/check.h"
6 #include "base/macros.h"
7 #include "base/single_thread_task_runner.h"
8 #include "base/threading/thread_task_runner_handle.h"
9 #include "ui/aura/test/ui_controls_factory_aura.h"
10 #include "ui/aura/window.h"
11 #include "ui/aura/window_tree_host.h"
12 #include "ui/base/test/ui_controls_aura.h"
13 #include "ui/base/test/ui_controls_internal_win.h"
14 
15 namespace aura {
16 namespace test {
17 
18 namespace {
19 
20 using ui_controls::DOWN;
21 using ui_controls::LEFT;
22 using ui_controls::MIDDLE;
23 using ui_controls::MouseButton;
24 using ui_controls::RIGHT;
25 using ui_controls::UIControlsAura;
26 using ui_controls::UP;
27 
28 class UIControlsWin : public UIControlsAura {
29  public:
UIControlsWin()30   UIControlsWin() {}
31 
32   // UIControlsAura overrides:
SendKeyPress(gfx::NativeWindow native_window,ui::KeyboardCode key,bool control,bool shift,bool alt,bool command)33   bool SendKeyPress(gfx::NativeWindow native_window,
34                     ui::KeyboardCode key,
35                     bool control,
36                     bool shift,
37                     bool alt,
38                     bool command) override {
39     DCHECK(!command);  // No command key on Aura
40     HWND window =
41         native_window->GetHost()->GetAcceleratedWidget();
42     return ui_controls::internal::SendKeyPressImpl(window, key, control, shift,
43                                                    alt, base::OnceClosure());
44   }
SendKeyPressNotifyWhenDone(gfx::NativeWindow native_window,ui::KeyboardCode key,bool control,bool shift,bool alt,bool command,base::OnceClosure task)45   bool SendKeyPressNotifyWhenDone(gfx::NativeWindow native_window,
46                                   ui::KeyboardCode key,
47                                   bool control,
48                                   bool shift,
49                                   bool alt,
50                                   bool command,
51                                   base::OnceClosure task) override {
52     DCHECK(!command);  // No command key on Aura
53     HWND window =
54         native_window->GetHost()->GetAcceleratedWidget();
55     return ui_controls::internal::SendKeyPressImpl(window, key, control, shift,
56                                                    alt, std::move(task));
57   }
SendMouseMove(int screen_x,int screen_y)58   bool SendMouseMove(int screen_x, int screen_y) override {
59     return ui_controls::internal::SendMouseMoveImpl(screen_x, screen_y,
60                                                     base::OnceClosure());
61   }
SendMouseMoveNotifyWhenDone(int screen_x,int screen_y,base::OnceClosure task)62   bool SendMouseMoveNotifyWhenDone(int screen_x,
63                                    int screen_y,
64                                    base::OnceClosure task) override {
65     return ui_controls::internal::SendMouseMoveImpl(screen_x, screen_y,
66                                                     std::move(task));
67   }
SendMouseEvents(MouseButton type,int button_state,int accelerator_state)68   bool SendMouseEvents(MouseButton type,
69                        int button_state,
70                        int accelerator_state) override {
71     return ui_controls::internal::SendMouseEventsImpl(
72         type, button_state, base::OnceClosure(), accelerator_state);
73   }
SendMouseEventsNotifyWhenDone(MouseButton type,int button_state,base::OnceClosure task,int accelerator_state)74   bool SendMouseEventsNotifyWhenDone(MouseButton type,
75                                      int button_state,
76                                      base::OnceClosure task,
77                                      int accelerator_state) override {
78     return ui_controls::internal::SendMouseEventsImpl(
79         type, button_state, std::move(task), accelerator_state);
80   }
SendMouseClick(MouseButton type)81   bool SendMouseClick(MouseButton type) override {
82     return SendMouseEvents(type, UP | DOWN, ui_controls::kNoAccelerator);
83   }
SendTouchEvents(int action,int num,int x,int y)84   bool SendTouchEvents(int action, int num, int x, int y) override {
85     return ui_controls::internal::SendTouchEventsImpl(action, num, x, y);
86   }
87 
88  private:
89   DISALLOW_COPY_AND_ASSIGN(UIControlsWin);
90 };
91 
92 }  // namespace
93 
CreateUIControlsAura(WindowTreeHost * host)94 UIControlsAura* CreateUIControlsAura(WindowTreeHost* host) {
95   return new UIControlsWin();
96 }
97 
98 }  // namespace test
99 }  // namespace aura
100