OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/mus/ws/event_dispatcher.h" | 5 #include "components/mus/ws/event_dispatcher.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 static_cast<ui::MouseEvent*>(dispatched_event.get()); | 168 static_cast<ui::MouseEvent*>(dispatched_event.get()); |
169 EXPECT_EQ(gfx::Point(20, 25), dispatched_mouse_event->root_location()); | 169 EXPECT_EQ(gfx::Point(20, 25), dispatched_mouse_event->root_location()); |
170 EXPECT_EQ(gfx::Point(10, 15), dispatched_mouse_event->location()); | 170 EXPECT_EQ(gfx::Point(10, 15), dispatched_mouse_event->location()); |
171 } | 171 } |
172 | 172 |
173 TEST(EventDispatcherTest, AcceleratorBasic) { | 173 TEST(EventDispatcherTest, AcceleratorBasic) { |
174 TestEventDispatcherDelegate event_dispatcher_delegate(nullptr); | 174 TestEventDispatcherDelegate event_dispatcher_delegate(nullptr); |
175 EventDispatcher dispatcher(&event_dispatcher_delegate); | 175 EventDispatcher dispatcher(&event_dispatcher_delegate); |
176 uint32_t accelerator_1 = 1; | 176 uint32_t accelerator_1 = 1; |
177 mojom::EventMatcherPtr matcher = mus::CreateKeyMatcher( | 177 mojom::EventMatcherPtr matcher = mus::CreateKeyMatcher( |
178 mus::mojom::KEYBOARD_CODE_W, mus::mojom::EVENT_FLAGS_CONTROL_DOWN); | 178 mus::mojom::KeyboardCode::W, mus::mojom::kEventFlagControlDown); |
179 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_1, std::move(matcher))); | 179 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_1, std::move(matcher))); |
180 | 180 |
181 uint32_t accelerator_2 = 2; | 181 uint32_t accelerator_2 = 2; |
182 matcher = mus::CreateKeyMatcher(mus::mojom::KEYBOARD_CODE_N, | 182 matcher = mus::CreateKeyMatcher(mus::mojom::KeyboardCode::N, |
183 mus::mojom::EVENT_FLAGS_NONE); | 183 mus::mojom::kEventFlagNone); |
184 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_2, std::move(matcher))); | 184 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_2, std::move(matcher))); |
185 | 185 |
186 // Attempting to add a new accelerator with the same id should fail. | 186 // Attempting to add a new accelerator with the same id should fail. |
187 matcher = mus::CreateKeyMatcher(mus::mojom::KEYBOARD_CODE_T, | 187 matcher = mus::CreateKeyMatcher(mus::mojom::KeyboardCode::T, |
188 mus::mojom::EVENT_FLAGS_NONE); | 188 mus::mojom::kEventFlagNone); |
189 EXPECT_FALSE(dispatcher.AddAccelerator(accelerator_2, std::move(matcher))); | 189 EXPECT_FALSE(dispatcher.AddAccelerator(accelerator_2, std::move(matcher))); |
190 | 190 |
191 // Adding the accelerator with the same id should succeed once the existing | 191 // Adding the accelerator with the same id should succeed once the existing |
192 // accelerator is removed. | 192 // accelerator is removed. |
193 dispatcher.RemoveAccelerator(accelerator_2); | 193 dispatcher.RemoveAccelerator(accelerator_2); |
194 matcher = mus::CreateKeyMatcher(mus::mojom::KEYBOARD_CODE_T, | 194 matcher = mus::CreateKeyMatcher(mus::mojom::KeyboardCode::T, |
195 mus::mojom::EVENT_FLAGS_NONE); | 195 mus::mojom::kEventFlagNone); |
196 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_2, std::move(matcher))); | 196 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_2, std::move(matcher))); |
197 | 197 |
198 // Attempting to add an accelerator with the same matcher should fail. | 198 // Attempting to add an accelerator with the same matcher should fail. |
199 uint32_t accelerator_3 = 3; | 199 uint32_t accelerator_3 = 3; |
200 matcher = mus::CreateKeyMatcher(mus::mojom::KEYBOARD_CODE_T, | 200 matcher = mus::CreateKeyMatcher(mus::mojom::KeyboardCode::T, |
201 mus::mojom::EVENT_FLAGS_NONE); | 201 mus::mojom::kEventFlagNone); |
202 EXPECT_FALSE(dispatcher.AddAccelerator(accelerator_3, std::move(matcher))); | 202 EXPECT_FALSE(dispatcher.AddAccelerator(accelerator_3, std::move(matcher))); |
203 | 203 |
204 matcher = mus::CreateKeyMatcher(mus::mojom::KEYBOARD_CODE_T, | 204 matcher = mus::CreateKeyMatcher(mus::mojom::KeyboardCode::T, |
205 mus::mojom::EVENT_FLAGS_CONTROL_DOWN); | 205 mus::mojom::kEventFlagControlDown); |
206 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_3, std::move(matcher))); | 206 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_3, std::move(matcher))); |
207 } | 207 } |
208 | 208 |
209 TEST(EventDispatcherTest, EventMatching) { | 209 TEST(EventDispatcherTest, EventMatching) { |
210 TestServerWindowDelegate window_delegate; | 210 TestServerWindowDelegate window_delegate; |
211 ServerWindow root(&window_delegate, WindowId(1, 2)); | 211 ServerWindow root(&window_delegate, WindowId(1, 2)); |
212 TestEventDispatcherDelegate event_dispatcher_delegate(&root); | 212 TestEventDispatcherDelegate event_dispatcher_delegate(&root); |
213 EventDispatcher dispatcher(&event_dispatcher_delegate); | 213 EventDispatcher dispatcher(&event_dispatcher_delegate); |
214 dispatcher.set_root(&root); | 214 dispatcher.set_root(&root); |
215 | 215 |
216 mojom::EventMatcherPtr matcher = mus::CreateKeyMatcher( | 216 mojom::EventMatcherPtr matcher = mus::CreateKeyMatcher( |
217 mus::mojom::KEYBOARD_CODE_W, mus::mojom::EVENT_FLAGS_CONTROL_DOWN); | 217 mus::mojom::KeyboardCode::W, mus::mojom::kEventFlagControlDown); |
218 uint32_t accelerator_1 = 1; | 218 uint32_t accelerator_1 = 1; |
219 dispatcher.AddAccelerator(accelerator_1, std::move(matcher)); | 219 dispatcher.AddAccelerator(accelerator_1, std::move(matcher)); |
220 | 220 |
221 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); | 221 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
222 dispatcher.OnEvent(mojom::Event::From(key)); | 222 dispatcher.OnEvent(mojom::Event::From(key)); |
223 EXPECT_EQ(accelerator_1, | 223 EXPECT_EQ(accelerator_1, |
224 event_dispatcher_delegate.GetAndClearLastAccelerator()); | 224 event_dispatcher_delegate.GetAndClearLastAccelerator()); |
225 | 225 |
226 // EF_NUM_LOCK_DOWN should be ignored since CreateKeyMatcher defaults to | 226 // EF_NUM_LOCK_DOWN should be ignored since CreateKeyMatcher defaults to |
227 // ignoring. | 227 // ignoring. |
228 key = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_W, | 228 key = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_W, |
229 ui::EF_CONTROL_DOWN | ui::EF_NUM_LOCK_DOWN); | 229 ui::EF_CONTROL_DOWN | ui::EF_NUM_LOCK_DOWN); |
230 dispatcher.OnEvent(mojom::Event::From(key)); | 230 dispatcher.OnEvent(mojom::Event::From(key)); |
231 EXPECT_EQ(accelerator_1, | 231 EXPECT_EQ(accelerator_1, |
232 event_dispatcher_delegate.GetAndClearLastAccelerator()); | 232 event_dispatcher_delegate.GetAndClearLastAccelerator()); |
233 | 233 |
234 key = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_NONE); | 234 key = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_NONE); |
235 dispatcher.OnEvent(mojom::Event::From(key)); | 235 dispatcher.OnEvent(mojom::Event::From(key)); |
236 EXPECT_EQ(0u, event_dispatcher_delegate.GetAndClearLastAccelerator()); | 236 EXPECT_EQ(0u, event_dispatcher_delegate.GetAndClearLastAccelerator()); |
237 | 237 |
238 uint32_t accelerator_2 = 2; | 238 uint32_t accelerator_2 = 2; |
239 matcher = mus::CreateKeyMatcher(mus::mojom::KEYBOARD_CODE_W, | 239 matcher = mus::CreateKeyMatcher(mus::mojom::KeyboardCode::W, |
240 mus::mojom::EVENT_FLAGS_NONE); | 240 mus::mojom::kEventFlagNone); |
241 dispatcher.AddAccelerator(accelerator_2, std::move(matcher)); | 241 dispatcher.AddAccelerator(accelerator_2, std::move(matcher)); |
242 dispatcher.OnEvent(mojom::Event::From(key)); | 242 dispatcher.OnEvent(mojom::Event::From(key)); |
243 EXPECT_EQ(accelerator_2, | 243 EXPECT_EQ(accelerator_2, |
244 event_dispatcher_delegate.GetAndClearLastAccelerator()); | 244 event_dispatcher_delegate.GetAndClearLastAccelerator()); |
245 | 245 |
246 dispatcher.RemoveAccelerator(accelerator_2); | 246 dispatcher.RemoveAccelerator(accelerator_2); |
247 dispatcher.OnEvent(mojom::Event::From(key)); | 247 dispatcher.OnEvent(mojom::Event::From(key)); |
248 EXPECT_EQ(0u, event_dispatcher_delegate.GetAndClearLastAccelerator()); | 248 EXPECT_EQ(0u, event_dispatcher_delegate.GetAndClearLastAccelerator()); |
249 } | 249 } |
250 | 250 |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 dispatched_event_mojo.To<scoped_ptr<ui::Event>>()); | 645 dispatched_event_mojo.To<scoped_ptr<ui::Event>>()); |
646 ASSERT_TRUE(dispatched_event.get()); | 646 ASSERT_TRUE(dispatched_event.get()); |
647 ASSERT_TRUE(dispatched_event->IsMouseEvent()); | 647 ASSERT_TRUE(dispatched_event->IsMouseEvent()); |
648 ui::MouseEvent* dispatched_mouse_event = | 648 ui::MouseEvent* dispatched_mouse_event = |
649 static_cast<ui::MouseEvent*>(dispatched_event.get()); | 649 static_cast<ui::MouseEvent*>(dispatched_event.get()); |
650 EXPECT_EQ(gfx::Point(-2, -1), dispatched_mouse_event->location()); | 650 EXPECT_EQ(gfx::Point(-2, -1), dispatched_mouse_event->location()); |
651 } | 651 } |
652 | 652 |
653 } // namespace ws | 653 } // namespace ws |
654 } // namespace mus | 654 } // namespace mus |
OLD | NEW |