OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "ui/aura/client/screen_position_client.h" | 7 #include "ui/aura/client/screen_position_client.h" |
8 #include "ui/aura/env.h" | 8 #include "ui/aura/env.h" |
9 #include "ui/aura/test/aura_test_utils.h" | 9 #include "ui/aura/test/aura_test_utils.h" |
10 #include "ui/aura/test/ui_controls_factory_aura.h" | 10 #include "ui/aura/test/ui_controls_factory_aura.h" |
11 #include "ui/aura/window_tree_host.h" | 11 #include "ui/aura/window_tree_host.h" |
12 #include "ui/base/test/ui_controls_aura.h" | 12 #include "ui/base/test/ui_controls_aura.h" |
13 | 13 |
14 namespace aura { | 14 namespace aura { |
15 namespace test { | 15 namespace test { |
16 namespace { | 16 namespace { |
17 | 17 |
18 class UIControlsOzone : public ui_controls::UIControlsAura { | 18 class UIControlsOzone : public ui_controls::UIControlsAura { |
19 public: | 19 public: |
20 UIControlsOzone(WindowTreeHost* host) : host_(host) {} | 20 UIControlsOzone(WindowTreeHost* host) : host_(host) {} |
21 | 21 |
22 virtual bool SendKeyPress(gfx::NativeWindow window, | 22 virtual bool SendKeyPress(gfx::NativeWindow window, |
23 ui::KeyboardCode key, | 23 ui::KeyboardCode key, |
24 bool control, | 24 bool control, |
25 bool shift, | 25 bool shift, |
26 bool alt, | 26 bool alt, |
27 bool command) OVERRIDE { | 27 bool command) override { |
28 return SendKeyPressNotifyWhenDone( | 28 return SendKeyPressNotifyWhenDone( |
29 window, key, control, shift, alt, command, base::Closure()); | 29 window, key, control, shift, alt, command, base::Closure()); |
30 } | 30 } |
31 virtual bool SendKeyPressNotifyWhenDone( | 31 virtual bool SendKeyPressNotifyWhenDone( |
32 gfx::NativeWindow window, | 32 gfx::NativeWindow window, |
33 ui::KeyboardCode key, | 33 ui::KeyboardCode key, |
34 bool control, | 34 bool control, |
35 bool shift, | 35 bool shift, |
36 bool alt, | 36 bool alt, |
37 bool command, | 37 bool command, |
38 const base::Closure& closure) OVERRIDE { | 38 const base::Closure& closure) override { |
39 int flags = button_down_mask_; | 39 int flags = button_down_mask_; |
40 | 40 |
41 if (control) { | 41 if (control) { |
42 flags |= ui::EF_CONTROL_DOWN; | 42 flags |= ui::EF_CONTROL_DOWN; |
43 PostKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_CONTROL, flags); | 43 PostKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_CONTROL, flags); |
44 } | 44 } |
45 | 45 |
46 if (shift) { | 46 if (shift) { |
47 flags |= ui::EF_SHIFT_DOWN; | 47 flags |= ui::EF_SHIFT_DOWN; |
48 PostKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_SHIFT, flags); | 48 PostKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_SHIFT, flags); |
(...skipping 29 matching lines...) Expand all Loading... |
78 | 78 |
79 if (command) { | 79 if (command) { |
80 flags &= ~ui::EF_COMMAND_DOWN; | 80 flags &= ~ui::EF_COMMAND_DOWN; |
81 PostKeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_LWIN, flags); | 81 PostKeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_LWIN, flags); |
82 } | 82 } |
83 | 83 |
84 RunClosureAfterAllPendingUIEvents(closure); | 84 RunClosureAfterAllPendingUIEvents(closure); |
85 return true; | 85 return true; |
86 } | 86 } |
87 | 87 |
88 virtual bool SendMouseMove(long screen_x, long screen_y) OVERRIDE { | 88 virtual bool SendMouseMove(long screen_x, long screen_y) override { |
89 return SendMouseMoveNotifyWhenDone(screen_x, screen_y, base::Closure()); | 89 return SendMouseMoveNotifyWhenDone(screen_x, screen_y, base::Closure()); |
90 } | 90 } |
91 virtual bool SendMouseMoveNotifyWhenDone( | 91 virtual bool SendMouseMoveNotifyWhenDone( |
92 long screen_x, | 92 long screen_x, |
93 long screen_y, | 93 long screen_y, |
94 const base::Closure& closure) OVERRIDE { | 94 const base::Closure& closure) override { |
95 gfx::Point root_location(screen_x, screen_y); | 95 gfx::Point root_location(screen_x, screen_y); |
96 aura::client::ScreenPositionClient* screen_position_client = | 96 aura::client::ScreenPositionClient* screen_position_client = |
97 aura::client::GetScreenPositionClient(host_->window()); | 97 aura::client::GetScreenPositionClient(host_->window()); |
98 if (screen_position_client) { | 98 if (screen_position_client) { |
99 screen_position_client->ConvertPointFromScreen(host_->window(), | 99 screen_position_client->ConvertPointFromScreen(host_->window(), |
100 &root_location); | 100 &root_location); |
101 } | 101 } |
102 gfx::Point root_current_location = | 102 gfx::Point root_current_location = |
103 QueryLatestMousePositionRequestInHost(host_); | 103 QueryLatestMousePositionRequestInHost(host_); |
104 host_->ConvertPointFromHost(&root_current_location); | 104 host_->ConvertPointFromHost(&root_current_location); |
105 | 105 |
106 if (button_down_mask_) | 106 if (button_down_mask_) |
107 PostMouseEvent(ui::ET_MOUSE_DRAGGED, root_location, 0, 0); | 107 PostMouseEvent(ui::ET_MOUSE_DRAGGED, root_location, 0, 0); |
108 else | 108 else |
109 PostMouseEvent(ui::ET_MOUSE_MOVED, root_location, 0, 0); | 109 PostMouseEvent(ui::ET_MOUSE_MOVED, root_location, 0, 0); |
110 | 110 |
111 RunClosureAfterAllPendingUIEvents(closure); | 111 RunClosureAfterAllPendingUIEvents(closure); |
112 return true; | 112 return true; |
113 } | 113 } |
114 virtual bool SendMouseEvents(ui_controls::MouseButton type, | 114 virtual bool SendMouseEvents(ui_controls::MouseButton type, |
115 int state) OVERRIDE { | 115 int state) override { |
116 return SendMouseEventsNotifyWhenDone(type, state, base::Closure()); | 116 return SendMouseEventsNotifyWhenDone(type, state, base::Closure()); |
117 } | 117 } |
118 virtual bool SendMouseEventsNotifyWhenDone( | 118 virtual bool SendMouseEventsNotifyWhenDone( |
119 ui_controls::MouseButton type, | 119 ui_controls::MouseButton type, |
120 int state, | 120 int state, |
121 const base::Closure& closure) OVERRIDE { | 121 const base::Closure& closure) override { |
122 gfx::Point loc = aura::Env::GetInstance()->last_mouse_location(); | 122 gfx::Point loc = aura::Env::GetInstance()->last_mouse_location(); |
123 aura::client::ScreenPositionClient* screen_position_client = | 123 aura::client::ScreenPositionClient* screen_position_client = |
124 aura::client::GetScreenPositionClient(host_->window()); | 124 aura::client::GetScreenPositionClient(host_->window()); |
125 if (screen_position_client) { | 125 if (screen_position_client) { |
126 screen_position_client->ConvertPointFromScreen(host_->window(), &loc); | 126 screen_position_client->ConvertPointFromScreen(host_->window(), &loc); |
127 } | 127 } |
128 int flag = 0; | 128 int flag = 0; |
129 | 129 |
130 switch (type) { | 130 switch (type) { |
131 case ui_controls::LEFT: | 131 case ui_controls::LEFT: |
(...skipping 16 matching lines...) Expand all Loading... |
148 } | 148 } |
149 if (state & ui_controls::UP) { | 149 if (state & ui_controls::UP) { |
150 button_down_mask_ &= ~flag; | 150 button_down_mask_ &= ~flag; |
151 PostMouseEvent( | 151 PostMouseEvent( |
152 ui::ET_MOUSE_RELEASED, loc, button_down_mask_ | flag, flag); | 152 ui::ET_MOUSE_RELEASED, loc, button_down_mask_ | flag, flag); |
153 } | 153 } |
154 | 154 |
155 RunClosureAfterAllPendingUIEvents(closure); | 155 RunClosureAfterAllPendingUIEvents(closure); |
156 return true; | 156 return true; |
157 } | 157 } |
158 virtual bool SendMouseClick(ui_controls::MouseButton type) OVERRIDE { | 158 virtual bool SendMouseClick(ui_controls::MouseButton type) override { |
159 return SendMouseEvents(type, ui_controls::UP | ui_controls::DOWN); | 159 return SendMouseEvents(type, ui_controls::UP | ui_controls::DOWN); |
160 } | 160 } |
161 virtual void RunClosureAfterAllPendingUIEvents( | 161 virtual void RunClosureAfterAllPendingUIEvents( |
162 const base::Closure& closure) OVERRIDE { | 162 const base::Closure& closure) override { |
163 if (!closure.is_null()) | 163 if (!closure.is_null()) |
164 base::MessageLoop::current()->PostTask(FROM_HERE, closure); | 164 base::MessageLoop::current()->PostTask(FROM_HERE, closure); |
165 } | 165 } |
166 | 166 |
167 private: | 167 private: |
168 void PostKeyEvent(ui::EventType type, ui::KeyboardCode key_code, int flags) { | 168 void PostKeyEvent(ui::EventType type, ui::KeyboardCode key_code, int flags) { |
169 base::MessageLoop::current()->PostTask( | 169 base::MessageLoop::current()->PostTask( |
170 FROM_HERE, | 170 FROM_HERE, |
171 base::Bind(&UIControlsOzone::PostKeyEventTask, | 171 base::Bind(&UIControlsOzone::PostKeyEventTask, |
172 base::Unretained(this), | 172 base::Unretained(this), |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 }; | 221 }; |
222 | 222 |
223 } // namespace | 223 } // namespace |
224 | 224 |
225 ui_controls::UIControlsAura* CreateUIControlsAura(WindowTreeHost* host) { | 225 ui_controls::UIControlsAura* CreateUIControlsAura(WindowTreeHost* host) { |
226 return new UIControlsOzone(host); | 226 return new UIControlsOzone(host); |
227 } | 227 } |
228 | 228 |
229 } // namespace test | 229 } // namespace test |
230 } // namespace aura | 230 } // namespace aura |
OLD | NEW |