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/location.h" | 6 #include "base/location.h" |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
11 #include "ui/aura/client/screen_position_client.h" | 11 #include "ui/aura/client/screen_position_client.h" |
12 #include "ui/aura/env.h" | 12 #include "ui/aura/env.h" |
13 #include "ui/aura/test/aura_test_utils.h" | 13 #include "ui/aura/test/aura_test_utils.h" |
14 #include "ui/aura/test/ui_controls_factory_aura.h" | 14 #include "ui/aura/test/ui_controls_factory_aura.h" |
15 #include "ui/aura/window_tree_host.h" | 15 #include "ui/aura/window_tree_host.h" |
16 #include "ui/base/test/ui_controls_aura.h" | 16 #include "ui/base/test/ui_controls_aura.h" |
17 #include "ui/events/event_utils.h" | 17 #include "ui/events/event_utils.h" |
18 #include "ui/events/test/events_test_utils.h" | 18 #include "ui/events/test/events_test_utils.h" |
19 | 19 |
20 namespace aura { | 20 namespace aura { |
21 namespace test { | 21 namespace test { |
22 namespace { | 22 namespace { |
23 | 23 |
| 24 // Mask of the mouse buttons currently down. |
| 25 unsigned g_button_down_mask = 0; |
| 26 |
24 class UIControlsOzone : public ui_controls::UIControlsAura { | 27 class UIControlsOzone : public ui_controls::UIControlsAura { |
25 public: | 28 public: |
26 UIControlsOzone(WindowTreeHost* host) : host_(host) {} | 29 UIControlsOzone(WindowTreeHost* host) : host_(host) {} |
27 | 30 |
28 bool SendKeyPress(gfx::NativeWindow window, | 31 bool SendKeyPress(gfx::NativeWindow window, |
29 ui::KeyboardCode key, | 32 ui::KeyboardCode key, |
30 bool control, | 33 bool control, |
31 bool shift, | 34 bool shift, |
32 bool alt, | 35 bool alt, |
33 bool command) override { | 36 bool command) override { |
34 return SendKeyPressNotifyWhenDone( | 37 return SendKeyPressNotifyWhenDone( |
35 window, key, control, shift, alt, command, base::Closure()); | 38 window, key, control, shift, alt, command, base::Closure()); |
36 } | 39 } |
37 bool SendKeyPressNotifyWhenDone( | 40 bool SendKeyPressNotifyWhenDone( |
38 gfx::NativeWindow window, | 41 gfx::NativeWindow window, |
39 ui::KeyboardCode key, | 42 ui::KeyboardCode key, |
40 bool control, | 43 bool control, |
41 bool shift, | 44 bool shift, |
42 bool alt, | 45 bool alt, |
43 bool command, | 46 bool command, |
44 const base::Closure& closure) override { | 47 const base::Closure& closure) override { |
45 int flags = button_down_mask_; | 48 int flags = g_button_down_mask; |
46 | 49 |
47 if (control) { | 50 if (control) { |
48 flags |= ui::EF_CONTROL_DOWN; | 51 flags |= ui::EF_CONTROL_DOWN; |
49 PostKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_CONTROL, flags); | 52 PostKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_CONTROL, flags); |
50 } | 53 } |
51 | 54 |
52 if (shift) { | 55 if (shift) { |
53 flags |= ui::EF_SHIFT_DOWN; | 56 flags |= ui::EF_SHIFT_DOWN; |
54 PostKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_SHIFT, flags); | 57 PostKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_SHIFT, flags); |
55 } | 58 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 if (screen_position_client) { | 107 if (screen_position_client) { |
105 screen_position_client->ConvertPointFromScreen(host_->window(), | 108 screen_position_client->ConvertPointFromScreen(host_->window(), |
106 &root_location); | 109 &root_location); |
107 } | 110 } |
108 | 111 |
109 gfx::Point host_location = root_location; | 112 gfx::Point host_location = root_location; |
110 host_->ConvertDIPToPixels(&host_location); | 113 host_->ConvertDIPToPixels(&host_location); |
111 | 114 |
112 ui::EventType event_type; | 115 ui::EventType event_type; |
113 | 116 |
114 if (button_down_mask_) | 117 if (g_button_down_mask) |
115 event_type = ui::ET_MOUSE_DRAGGED; | 118 event_type = ui::ET_MOUSE_DRAGGED; |
116 else | 119 else |
117 event_type = ui::ET_MOUSE_MOVED; | 120 event_type = ui::ET_MOUSE_MOVED; |
118 | 121 |
119 PostMouseEvent(event_type, host_location, button_down_mask_, 0); | 122 PostMouseEvent(event_type, host_location, g_button_down_mask, 0); |
120 | 123 |
121 RunClosureAfterAllPendingUIEvents(closure); | 124 RunClosureAfterAllPendingUIEvents(closure); |
122 return true; | 125 return true; |
123 } | 126 } |
124 bool SendMouseEvents(ui_controls::MouseButton type, int state) override { | 127 bool SendMouseEvents(ui_controls::MouseButton type, int state) override { |
125 return SendMouseEventsNotifyWhenDone(type, state, base::Closure()); | 128 return SendMouseEventsNotifyWhenDone(type, state, base::Closure()); |
126 } | 129 } |
127 bool SendMouseEventsNotifyWhenDone( | 130 bool SendMouseEventsNotifyWhenDone( |
128 ui_controls::MouseButton type, | 131 ui_controls::MouseButton type, |
129 int state, | 132 int state, |
(...skipping 20 matching lines...) Expand all Loading... |
150 break; | 153 break; |
151 case ui_controls::RIGHT: | 154 case ui_controls::RIGHT: |
152 flag = ui::EF_RIGHT_MOUSE_BUTTON; | 155 flag = ui::EF_RIGHT_MOUSE_BUTTON; |
153 break; | 156 break; |
154 default: | 157 default: |
155 NOTREACHED(); | 158 NOTREACHED(); |
156 break; | 159 break; |
157 } | 160 } |
158 | 161 |
159 if (state & ui_controls::DOWN) { | 162 if (state & ui_controls::DOWN) { |
160 button_down_mask_ |= flag; | 163 g_button_down_mask |= flag; |
161 PostMouseEvent(ui::ET_MOUSE_PRESSED, host_location, | 164 PostMouseEvent(ui::ET_MOUSE_PRESSED, host_location, |
162 button_down_mask_ | flag, flag); | 165 g_button_down_mask | flag, flag); |
163 } | 166 } |
164 if (state & ui_controls::UP) { | 167 if (state & ui_controls::UP) { |
165 button_down_mask_ &= ~flag; | 168 g_button_down_mask &= ~flag; |
166 PostMouseEvent(ui::ET_MOUSE_RELEASED, host_location, | 169 PostMouseEvent(ui::ET_MOUSE_RELEASED, host_location, |
167 button_down_mask_ | flag, flag); | 170 g_button_down_mask | flag, flag); |
168 } | 171 } |
169 | 172 |
170 RunClosureAfterAllPendingUIEvents(closure); | 173 RunClosureAfterAllPendingUIEvents(closure); |
171 return true; | 174 return true; |
172 } | 175 } |
173 bool SendMouseClick(ui_controls::MouseButton type) override { | 176 bool SendMouseClick(ui_controls::MouseButton type) override { |
174 return SendMouseEvents(type, ui_controls::UP | ui_controls::DOWN); | 177 return SendMouseEvents(type, ui_controls::UP | ui_controls::DOWN); |
175 } | 178 } |
176 void RunClosureAfterAllPendingUIEvents( | 179 void RunClosureAfterAllPendingUIEvents( |
177 const base::Closure& closure) override { | 180 const base::Closure& closure) override { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 changed_button_flags); | 225 changed_button_flags); |
223 | 226 |
224 // This hack is necessary to set the repeat count for clicks. | 227 // This hack is necessary to set the repeat count for clicks. |
225 ui::MouseEvent mouse_event2(&mouse_event); | 228 ui::MouseEvent mouse_event2(&mouse_event); |
226 | 229 |
227 SendEventToSink(&mouse_event2); | 230 SendEventToSink(&mouse_event2); |
228 } | 231 } |
229 | 232 |
230 WindowTreeHost* host_; | 233 WindowTreeHost* host_; |
231 | 234 |
232 // Mask of the mouse buttons currently down. | |
233 unsigned button_down_mask_ = 0; | |
234 | |
235 DISALLOW_COPY_AND_ASSIGN(UIControlsOzone); | 235 DISALLOW_COPY_AND_ASSIGN(UIControlsOzone); |
236 }; | 236 }; |
237 | 237 |
238 } // namespace | 238 } // namespace |
239 | 239 |
240 ui_controls::UIControlsAura* CreateUIControlsAura(WindowTreeHost* host) { | 240 ui_controls::UIControlsAura* CreateUIControlsAura(WindowTreeHost* host) { |
241 return new UIControlsOzone(host); | 241 return new UIControlsOzone(host); |
242 } | 242 } |
243 | 243 |
244 } // namespace test | 244 } // namespace test |
245 } // namespace aura | 245 } // namespace aura |
OLD | NEW |