dbus: Remove MockShillDeviceClient and MockShillIPConfigClient
[chromium-blink-merge.git] / ash / test / ui_controls_factory_ash.cc
blob458a4cb1191ec27dee9e53ac3792fc0b8e62b0da
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 "ash/shell.h"
6 #include "ash/shell_factory.h"
7 #include "ash/wm/coordinate_conversion.h"
8 #include "ash/wm/window_properties.h"
9 #include "ui/aura/client/capture_client.h"
10 #include "ui/aura/client/screen_position_client.h"
11 #include "ui/aura/env.h"
12 #include "ui/aura/root_window.h"
13 #include "ui/aura/test/ui_controls_factory_aura.h"
14 #include "ui/aura/window_property.h"
15 #include "ui/base/test/ui_controls.h"
16 #include "ui/base/test/ui_controls_aura.h"
17 #include "ui/gfx/screen.h"
19 DECLARE_WINDOW_PROPERTY_TYPE(ui_controls::UIControlsAura*)
21 namespace ash {
22 namespace test {
23 namespace {
25 using ui_controls::UIControlsAura;
26 using ui_controls::MouseButton;
28 DEFINE_OWNED_WINDOW_PROPERTY_KEY(UIControlsAura, kUIControlsKey, NULL);
30 // Returns the UIControls object for RootWindow.
31 // kUIControlsKey is owned property and UIControls object
32 // will be deleted when the root window is deleted.
33 UIControlsAura* GetUIControlsForRootWindow(aura::RootWindow* root_window) {
34 UIControlsAura* native_ui_control =
35 root_window->GetProperty(kUIControlsKey);
36 if (!native_ui_control) {
37 native_ui_control = aura::test::CreateUIControlsAura(root_window);
38 // Pass the ownership to the |root_window|.
39 root_window->SetProperty(kUIControlsKey, native_ui_control);
41 return native_ui_control;
44 // Returns the UIControls object for the RootWindow at the |point_in_screen|
45 // in virtual screen coordinates, and updates the |point| relative to the
46 // UIControlsAura's root window. NULL if there is no RootWindow under
47 // the |point_in_screen|.
48 UIControlsAura* GetUIControlsAt(gfx::Point* point_in_screen) {
49 // TODO(mazda): Support the case passive grab is taken.
50 aura::RootWindow* root = ash::wm::GetRootWindowAt(*point_in_screen);
52 aura::client::ScreenPositionClient* screen_position_client =
53 aura::client::GetScreenPositionClient(root);
54 if (screen_position_client)
55 screen_position_client->ConvertPointFromScreen(root, point_in_screen);
57 return GetUIControlsForRootWindow(root);
60 } // namespace
62 class UIControlsAsh : public UIControlsAura {
63 public:
64 UIControlsAsh() {
66 virtual ~UIControlsAsh() {
69 // UIControslAura overrides:
70 virtual bool SendKeyPress(gfx::NativeWindow window,
71 ui::KeyboardCode key,
72 bool control,
73 bool shift,
74 bool alt,
75 bool command) OVERRIDE {
76 return SendKeyPressNotifyWhenDone(
77 window, key, control, shift, alt, command, base::Closure());
80 virtual bool SendKeyPressNotifyWhenDone(
81 gfx::NativeWindow window,
82 ui::KeyboardCode key,
83 bool control,
84 bool shift,
85 bool alt,
86 bool command,
87 const base::Closure& closure) OVERRIDE {
88 aura::RootWindow* root =
89 window ? window->GetRootWindow() : ash::Shell::GetTargetRootWindow();
90 UIControlsAura* ui_controls = GetUIControlsForRootWindow(root);
91 return ui_controls && ui_controls->SendKeyPressNotifyWhenDone(
92 window, key, control, shift, alt, command, closure);
95 virtual bool SendMouseMove(long x, long y) OVERRIDE {
96 gfx::Point p(x, y);
97 UIControlsAura* ui_controls = GetUIControlsAt(&p);
98 return ui_controls && ui_controls->SendMouseMove(p.x(), p.y());
101 virtual bool SendMouseMoveNotifyWhenDone(
102 long x,
103 long y,
104 const base::Closure& closure) OVERRIDE {
105 gfx::Point p(x, y);
106 UIControlsAura* ui_controls = GetUIControlsAt(&p);
107 return ui_controls &&
108 ui_controls->SendMouseMoveNotifyWhenDone(p.x(), p.y(), closure);
111 virtual bool SendMouseEvents(MouseButton type, int state) OVERRIDE {
112 gfx::Point p(ash::Shell::GetScreen()->GetCursorScreenPoint());
113 UIControlsAura* ui_controls = GetUIControlsAt(&p);
114 return ui_controls && ui_controls->SendMouseEvents(type, state);
117 virtual bool SendMouseEventsNotifyWhenDone(
118 MouseButton type, int state, const base::Closure& closure) OVERRIDE {
119 gfx::Point p(aura::Env::GetInstance()->last_mouse_location());
120 UIControlsAura* ui_controls = GetUIControlsAt(&p);
121 return ui_controls && ui_controls->SendMouseEventsNotifyWhenDone(
122 type, state, closure);
125 virtual bool SendMouseClick(MouseButton type) OVERRIDE {
126 gfx::Point p(ash::Shell::GetScreen()->GetCursorScreenPoint());
127 UIControlsAura* ui_controls = GetUIControlsAt(&p);
128 return ui_controls && ui_controls->SendMouseClick(type);
131 virtual void RunClosureAfterAllPendingUIEvents(
132 const base::Closure& closure) OVERRIDE {
133 UIControlsAura* ui_controls = GetUIControlsForRootWindow(
134 ash::Shell::GetTargetRootWindow());
135 if (ui_controls)
136 ui_controls->RunClosureAfterAllPendingUIEvents(closure);
139 private:
140 DISALLOW_COPY_AND_ASSIGN(UIControlsAsh);
143 ui_controls::UIControlsAura* CreateAshUIControls() {
144 return new ash::test::UIControlsAsh();
147 } // namespace test
148 } // namespace ash