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 | |
27 class UIControlsOzone : public ui_controls::UIControlsAura { | 24 class UIControlsOzone : public ui_controls::UIControlsAura { |
28 public: | 25 public: |
29 UIControlsOzone(WindowTreeHost* host) : host_(host) {} | 26 UIControlsOzone(WindowTreeHost* host) : host_(host) {} |
30 | 27 |
31 bool SendKeyPress(gfx::NativeWindow window, | 28 bool SendKeyPress(gfx::NativeWindow window, |
32 ui::KeyboardCode key, | 29 ui::KeyboardCode key, |
33 bool control, | 30 bool control, |
34 bool shift, | 31 bool shift, |
35 bool alt, | 32 bool alt, |
36 bool command) override { | 33 bool command) override { |
37 return SendKeyPressNotifyWhenDone( | 34 return SendKeyPressNotifyWhenDone( |
38 window, key, control, shift, alt, command, base::Closure()); | 35 window, key, control, shift, alt, command, base::Closure()); |
39 } | 36 } |
40 bool SendKeyPressNotifyWhenDone( | 37 bool SendKeyPressNotifyWhenDone( |
41 gfx::NativeWindow window, | 38 gfx::NativeWindow window, |
42 ui::KeyboardCode key, | 39 ui::KeyboardCode key, |
43 bool control, | 40 bool control, |
44 bool shift, | 41 bool shift, |
45 bool alt, | 42 bool alt, |
46 bool command, | 43 bool command, |
47 const base::Closure& closure) override { | 44 const base::Closure& closure) override { |
48 int flags = g_button_down_mask; | 45 int flags = button_down_mask_; |
49 | 46 |
50 if (control) { | 47 if (control) { |
51 flags |= ui::EF_CONTROL_DOWN; | 48 flags |= ui::EF_CONTROL_DOWN; |
52 PostKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_CONTROL, flags); | 49 PostKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_CONTROL, flags); |
53 } | 50 } |
54 | 51 |
55 if (shift) { | 52 if (shift) { |
56 flags |= ui::EF_SHIFT_DOWN; | 53 flags |= ui::EF_SHIFT_DOWN; |
57 PostKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_SHIFT, flags); | 54 PostKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_SHIFT, flags); |
58 } | 55 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 if (screen_position_client) { | 104 if (screen_position_client) { |
108 screen_position_client->ConvertPointFromScreen(host_->window(), | 105 screen_position_client->ConvertPointFromScreen(host_->window(), |
109 &root_location); | 106 &root_location); |
110 } | 107 } |
111 | 108 |
112 gfx::Point host_location = root_location; | 109 gfx::Point host_location = root_location; |
113 host_->ConvertDIPToPixels(&host_location); | 110 host_->ConvertDIPToPixels(&host_location); |
114 | 111 |
115 ui::EventType event_type; | 112 ui::EventType event_type; |
116 | 113 |
117 if (g_button_down_mask) | 114 if (button_down_mask_) |
118 event_type = ui::ET_MOUSE_DRAGGED; | 115 event_type = ui::ET_MOUSE_DRAGGED; |
119 else | 116 else |
120 event_type = ui::ET_MOUSE_MOVED; | 117 event_type = ui::ET_MOUSE_MOVED; |
121 | 118 |
122 PostMouseEvent(event_type, host_location, g_button_down_mask, 0); | 119 PostMouseEvent(event_type, host_location, button_down_mask_, 0); |
123 | 120 |
124 RunClosureAfterAllPendingUIEvents(closure); | 121 RunClosureAfterAllPendingUIEvents(closure); |
125 return true; | 122 return true; |
126 } | 123 } |
127 bool SendMouseEvents(ui_controls::MouseButton type, int state) override { | 124 bool SendMouseEvents(ui_controls::MouseButton type, int state) override { |
128 return SendMouseEventsNotifyWhenDone(type, state, base::Closure()); | 125 return SendMouseEventsNotifyWhenDone(type, state, base::Closure()); |
129 } | 126 } |
130 bool SendMouseEventsNotifyWhenDone( | 127 bool SendMouseEventsNotifyWhenDone( |
131 ui_controls::MouseButton type, | 128 ui_controls::MouseButton type, |
132 int state, | 129 int state, |
(...skipping 20 matching lines...) Expand all Loading... |
153 break; | 150 break; |
154 case ui_controls::RIGHT: | 151 case ui_controls::RIGHT: |
155 flag = ui::EF_RIGHT_MOUSE_BUTTON; | 152 flag = ui::EF_RIGHT_MOUSE_BUTTON; |
156 break; | 153 break; |
157 default: | 154 default: |
158 NOTREACHED(); | 155 NOTREACHED(); |
159 break; | 156 break; |
160 } | 157 } |
161 | 158 |
162 if (state & ui_controls::DOWN) { | 159 if (state & ui_controls::DOWN) { |
163 g_button_down_mask |= flag; | 160 button_down_mask_ |= flag; |
164 PostMouseEvent(ui::ET_MOUSE_PRESSED, host_location, | 161 PostMouseEvent(ui::ET_MOUSE_PRESSED, host_location, |
165 g_button_down_mask | flag, flag); | 162 button_down_mask_ | flag, flag); |
166 } | 163 } |
167 if (state & ui_controls::UP) { | 164 if (state & ui_controls::UP) { |
168 g_button_down_mask &= ~flag; | 165 button_down_mask_ &= ~flag; |
169 PostMouseEvent(ui::ET_MOUSE_RELEASED, host_location, | 166 PostMouseEvent(ui::ET_MOUSE_RELEASED, host_location, |
170 g_button_down_mask | flag, flag); | 167 button_down_mask_ | flag, flag); |
171 } | 168 } |
172 | 169 |
173 RunClosureAfterAllPendingUIEvents(closure); | 170 RunClosureAfterAllPendingUIEvents(closure); |
174 return true; | 171 return true; |
175 } | 172 } |
176 bool SendMouseClick(ui_controls::MouseButton type) override { | 173 bool SendMouseClick(ui_controls::MouseButton type) override { |
177 return SendMouseEvents(type, ui_controls::UP | ui_controls::DOWN); | 174 return SendMouseEvents(type, ui_controls::UP | ui_controls::DOWN); |
178 } | 175 } |
179 void RunClosureAfterAllPendingUIEvents( | 176 void RunClosureAfterAllPendingUIEvents( |
180 const base::Closure& closure) override { | 177 const base::Closure& closure) override { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 changed_button_flags); | 222 changed_button_flags); |
226 | 223 |
227 // This hack is necessary to set the repeat count for clicks. | 224 // This hack is necessary to set the repeat count for clicks. |
228 ui::MouseEvent mouse_event2(&mouse_event); | 225 ui::MouseEvent mouse_event2(&mouse_event); |
229 | 226 |
230 SendEventToSink(&mouse_event2); | 227 SendEventToSink(&mouse_event2); |
231 } | 228 } |
232 | 229 |
233 WindowTreeHost* host_; | 230 WindowTreeHost* host_; |
234 | 231 |
| 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 |