| 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 <queue> | 10 #include <queue> |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 static_cast<ui::MouseEvent*>(dispatched_event.get()); | 197 static_cast<ui::MouseEvent*>(dispatched_event.get()); |
| 198 EXPECT_EQ(gfx::Point(20, 25), dispatched_mouse_event->root_location()); | 198 EXPECT_EQ(gfx::Point(20, 25), dispatched_mouse_event->root_location()); |
| 199 EXPECT_EQ(gfx::Point(10, 15), dispatched_mouse_event->location()); | 199 EXPECT_EQ(gfx::Point(10, 15), dispatched_mouse_event->location()); |
| 200 } | 200 } |
| 201 | 201 |
| 202 TEST(EventDispatcherTest, AcceleratorBasic) { | 202 TEST(EventDispatcherTest, AcceleratorBasic) { |
| 203 TestEventDispatcherDelegate event_dispatcher_delegate(nullptr); | 203 TestEventDispatcherDelegate event_dispatcher_delegate(nullptr); |
| 204 EventDispatcher dispatcher(&event_dispatcher_delegate); | 204 EventDispatcher dispatcher(&event_dispatcher_delegate); |
| 205 uint32_t accelerator_1 = 1; | 205 uint32_t accelerator_1 = 1; |
| 206 mojom::EventMatcherPtr matcher = mus::CreateKeyMatcher( | 206 mojom::EventMatcherPtr matcher = mus::CreateKeyMatcher( |
| 207 mus::mojom::KEYBOARD_CODE_W, mus::mojom::EVENT_FLAGS_CONTROL_DOWN); | 207 mus::mojom::KeyboardCode::W, mus::mojom::kEventFlagControlDown); |
| 208 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_1, std::move(matcher))); | 208 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_1, std::move(matcher))); |
| 209 | 209 |
| 210 uint32_t accelerator_2 = 2; | 210 uint32_t accelerator_2 = 2; |
| 211 matcher = mus::CreateKeyMatcher(mus::mojom::KEYBOARD_CODE_N, | 211 matcher = mus::CreateKeyMatcher(mus::mojom::KeyboardCode::N, |
| 212 mus::mojom::EVENT_FLAGS_NONE); | 212 mus::mojom::kEventFlagNone); |
| 213 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_2, std::move(matcher))); | 213 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_2, std::move(matcher))); |
| 214 | 214 |
| 215 // Attempting to add a new accelerator with the same id should fail. | 215 // Attempting to add a new accelerator with the same id should fail. |
| 216 matcher = mus::CreateKeyMatcher(mus::mojom::KEYBOARD_CODE_T, | 216 matcher = mus::CreateKeyMatcher(mus::mojom::KeyboardCode::T, |
| 217 mus::mojom::EVENT_FLAGS_NONE); | 217 mus::mojom::kEventFlagNone); |
| 218 EXPECT_FALSE(dispatcher.AddAccelerator(accelerator_2, std::move(matcher))); | 218 EXPECT_FALSE(dispatcher.AddAccelerator(accelerator_2, std::move(matcher))); |
| 219 | 219 |
| 220 // Adding the accelerator with the same id should succeed once the existing | 220 // Adding the accelerator with the same id should succeed once the existing |
| 221 // accelerator is removed. | 221 // accelerator is removed. |
| 222 dispatcher.RemoveAccelerator(accelerator_2); | 222 dispatcher.RemoveAccelerator(accelerator_2); |
| 223 matcher = mus::CreateKeyMatcher(mus::mojom::KEYBOARD_CODE_T, | 223 matcher = mus::CreateKeyMatcher(mus::mojom::KeyboardCode::T, |
| 224 mus::mojom::EVENT_FLAGS_NONE); | 224 mus::mojom::kEventFlagNone); |
| 225 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_2, std::move(matcher))); | 225 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_2, std::move(matcher))); |
| 226 | 226 |
| 227 // Attempting to add an accelerator with the same matcher should fail. | 227 // Attempting to add an accelerator with the same matcher should fail. |
| 228 uint32_t accelerator_3 = 3; | 228 uint32_t accelerator_3 = 3; |
| 229 matcher = mus::CreateKeyMatcher(mus::mojom::KEYBOARD_CODE_T, | 229 matcher = mus::CreateKeyMatcher(mus::mojom::KeyboardCode::T, |
| 230 mus::mojom::EVENT_FLAGS_NONE); | 230 mus::mojom::kEventFlagNone); |
| 231 EXPECT_FALSE(dispatcher.AddAccelerator(accelerator_3, std::move(matcher))); | 231 EXPECT_FALSE(dispatcher.AddAccelerator(accelerator_3, std::move(matcher))); |
| 232 | 232 |
| 233 matcher = mus::CreateKeyMatcher(mus::mojom::KEYBOARD_CODE_T, | 233 matcher = mus::CreateKeyMatcher(mus::mojom::KeyboardCode::T, |
| 234 mus::mojom::EVENT_FLAGS_CONTROL_DOWN); | 234 mus::mojom::kEventFlagControlDown); |
| 235 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_3, std::move(matcher))); | 235 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_3, std::move(matcher))); |
| 236 } | 236 } |
| 237 | 237 |
| 238 TEST(EventDispatcherTest, EventMatching) { | 238 TEST(EventDispatcherTest, EventMatching) { |
| 239 TestServerWindowDelegate window_delegate; | 239 TestServerWindowDelegate window_delegate; |
| 240 ServerWindow root(&window_delegate, WindowId(1, 2)); | 240 ServerWindow root(&window_delegate, WindowId(1, 2)); |
| 241 TestEventDispatcherDelegate event_dispatcher_delegate(&root); | 241 TestEventDispatcherDelegate event_dispatcher_delegate(&root); |
| 242 EventDispatcher dispatcher(&event_dispatcher_delegate); | 242 EventDispatcher dispatcher(&event_dispatcher_delegate); |
| 243 dispatcher.set_root(&root); | 243 dispatcher.set_root(&root); |
| 244 | 244 |
| 245 mojom::EventMatcherPtr matcher = mus::CreateKeyMatcher( | 245 mojom::EventMatcherPtr matcher = mus::CreateKeyMatcher( |
| 246 mus::mojom::KEYBOARD_CODE_W, mus::mojom::EVENT_FLAGS_CONTROL_DOWN); | 246 mus::mojom::KeyboardCode::W, mus::mojom::kEventFlagControlDown); |
| 247 uint32_t accelerator_1 = 1; | 247 uint32_t accelerator_1 = 1; |
| 248 dispatcher.AddAccelerator(accelerator_1, std::move(matcher)); | 248 dispatcher.AddAccelerator(accelerator_1, std::move(matcher)); |
| 249 | 249 |
| 250 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); | 250 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
| 251 dispatcher.ProcessEvent(mojom::Event::From(key)); | 251 dispatcher.ProcessEvent(mojom::Event::From(key)); |
| 252 EXPECT_EQ(accelerator_1, | 252 EXPECT_EQ(accelerator_1, |
| 253 event_dispatcher_delegate.GetAndClearLastAccelerator()); | 253 event_dispatcher_delegate.GetAndClearLastAccelerator()); |
| 254 | 254 |
| 255 // EF_NUM_LOCK_ON should be ignored since CreateKeyMatcher defaults to | 255 // EF_NUM_LOCK_ON should be ignored since CreateKeyMatcher defaults to |
| 256 // ignoring. | 256 // ignoring. |
| 257 key = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_W, | 257 key = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_W, |
| 258 ui::EF_CONTROL_DOWN | ui::EF_NUM_LOCK_ON); | 258 ui::EF_CONTROL_DOWN | ui::EF_NUM_LOCK_ON); |
| 259 dispatcher.ProcessEvent(mojom::Event::From(key)); | 259 dispatcher.ProcessEvent(mojom::Event::From(key)); |
| 260 EXPECT_EQ(accelerator_1, | 260 EXPECT_EQ(accelerator_1, |
| 261 event_dispatcher_delegate.GetAndClearLastAccelerator()); | 261 event_dispatcher_delegate.GetAndClearLastAccelerator()); |
| 262 | 262 |
| 263 key = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_NONE); | 263 key = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_NONE); |
| 264 dispatcher.ProcessEvent(mojom::Event::From(key)); | 264 dispatcher.ProcessEvent(mojom::Event::From(key)); |
| 265 EXPECT_EQ(0u, event_dispatcher_delegate.GetAndClearLastAccelerator()); | 265 EXPECT_EQ(0u, event_dispatcher_delegate.GetAndClearLastAccelerator()); |
| 266 | 266 |
| 267 uint32_t accelerator_2 = 2; | 267 uint32_t accelerator_2 = 2; |
| 268 matcher = mus::CreateKeyMatcher(mus::mojom::KEYBOARD_CODE_W, | 268 matcher = mus::CreateKeyMatcher(mus::mojom::KeyboardCode::W, |
| 269 mus::mojom::EVENT_FLAGS_NONE); | 269 mus::mojom::kEventFlagNone); |
| 270 dispatcher.AddAccelerator(accelerator_2, std::move(matcher)); | 270 dispatcher.AddAccelerator(accelerator_2, std::move(matcher)); |
| 271 dispatcher.ProcessEvent(mojom::Event::From(key)); | 271 dispatcher.ProcessEvent(mojom::Event::From(key)); |
| 272 EXPECT_EQ(accelerator_2, | 272 EXPECT_EQ(accelerator_2, |
| 273 event_dispatcher_delegate.GetAndClearLastAccelerator()); | 273 event_dispatcher_delegate.GetAndClearLastAccelerator()); |
| 274 | 274 |
| 275 dispatcher.RemoveAccelerator(accelerator_2); | 275 dispatcher.RemoveAccelerator(accelerator_2); |
| 276 dispatcher.ProcessEvent(mojom::Event::From(key)); | 276 dispatcher.ProcessEvent(mojom::Event::From(key)); |
| 277 EXPECT_EQ(0u, event_dispatcher_delegate.GetAndClearLastAccelerator()); | 277 EXPECT_EQ(0u, event_dispatcher_delegate.GetAndClearLastAccelerator()); |
| 278 } | 278 } |
| 279 | 279 |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 // should get an exit first. | 451 // should get an exit first. |
| 452 const ui::MouseEvent press_event2( | 452 const ui::MouseEvent press_event2( |
| 453 ui::ET_MOUSE_PRESSED, gfx::Point(21, 22), gfx::Point(21, 22), | 453 ui::ET_MOUSE_PRESSED, gfx::Point(21, 22), gfx::Point(21, 22), |
| 454 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 454 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 455 dispatcher.ProcessEvent( | 455 dispatcher.ProcessEvent( |
| 456 mojom::Event::From(static_cast<const ui::Event&>(press_event2))); | 456 mojom::Event::From(static_cast<const ui::Event&>(press_event2))); |
| 457 details = event_dispatcher_delegate.GetAndAdvanceDispatchedEventDetails(); | 457 details = event_dispatcher_delegate.GetAndAdvanceDispatchedEventDetails(); |
| 458 EXPECT_TRUE(event_dispatcher_delegate.has_queued_events()); | 458 EXPECT_TRUE(event_dispatcher_delegate.has_queued_events()); |
| 459 ASSERT_EQ(&child, details->window); | 459 ASSERT_EQ(&child, details->window); |
| 460 EXPECT_TRUE(details->in_nonclient_area); | 460 EXPECT_TRUE(details->in_nonclient_area); |
| 461 EXPECT_EQ(mojom::EVENT_TYPE_MOUSE_EXIT, details->event->action); | 461 EXPECT_EQ(mojom::EventType::MOUSE_EXIT, details->event->action); |
| 462 | 462 |
| 463 details = event_dispatcher_delegate.GetAndAdvanceDispatchedEventDetails(); | 463 details = event_dispatcher_delegate.GetAndAdvanceDispatchedEventDetails(); |
| 464 EXPECT_FALSE(event_dispatcher_delegate.has_queued_events()); | 464 EXPECT_FALSE(event_dispatcher_delegate.has_queued_events()); |
| 465 ASSERT_EQ(&child, details->window); | 465 ASSERT_EQ(&child, details->window); |
| 466 EXPECT_FALSE(details->in_nonclient_area); | 466 EXPECT_FALSE(details->in_nonclient_area); |
| 467 EXPECT_EQ(mojom::EVENT_TYPE_POINTER_DOWN, details->event->action); | 467 EXPECT_EQ(mojom::EventType::POINTER_DOWN, details->event->action); |
| 468 } | 468 } |
| 469 | 469 |
| 470 TEST(EventDispatcherTest, AdditionalClientArea) { | 470 TEST(EventDispatcherTest, AdditionalClientArea) { |
| 471 TestServerWindowDelegate window_delegate; | 471 TestServerWindowDelegate window_delegate; |
| 472 ServerWindow root(&window_delegate, WindowId(1, 2)); | 472 ServerWindow root(&window_delegate, WindowId(1, 2)); |
| 473 window_delegate.set_root_window(&root); | 473 window_delegate.set_root_window(&root); |
| 474 root.SetVisible(true); | 474 root.SetVisible(true); |
| 475 | 475 |
| 476 ServerWindow child(&window_delegate, WindowId(1, 3)); | 476 ServerWindow child(&window_delegate, WindowId(1, 3)); |
| 477 root.Add(&child); | 477 root.Add(&child); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 ASSERT_EQ(&root, details->window); | 709 ASSERT_EQ(&root, details->window); |
| 710 EXPECT_FALSE(details->in_nonclient_area); | 710 EXPECT_FALSE(details->in_nonclient_area); |
| 711 | 711 |
| 712 // Change the extended hit test region and send event in extended hit test | 712 // Change the extended hit test region and send event in extended hit test |
| 713 // region. Should result in exit for root, followed by press for child. | 713 // region. Should result in exit for root, followed by press for child. |
| 714 child.set_extended_hit_test_region(gfx::Insets(5, 5, 5, 5)); | 714 child.set_extended_hit_test_region(gfx::Insets(5, 5, 5, 5)); |
| 715 dispatcher.ProcessEvent( | 715 dispatcher.ProcessEvent( |
| 716 mojom::Event::From(static_cast<const ui::Event&>(ui_event))); | 716 mojom::Event::From(static_cast<const ui::Event&>(ui_event))); |
| 717 details = event_dispatcher_delegate.GetAndAdvanceDispatchedEventDetails(); | 717 details = event_dispatcher_delegate.GetAndAdvanceDispatchedEventDetails(); |
| 718 EXPECT_EQ(&root, details->window); | 718 EXPECT_EQ(&root, details->window); |
| 719 EXPECT_EQ(mojom::EVENT_TYPE_MOUSE_EXIT, details->event->action); | 719 EXPECT_EQ(mojom::EventType::MOUSE_EXIT, details->event->action); |
| 720 details = event_dispatcher_delegate.GetAndAdvanceDispatchedEventDetails(); | 720 details = event_dispatcher_delegate.GetAndAdvanceDispatchedEventDetails(); |
| 721 ASSERT_TRUE(details); | 721 ASSERT_TRUE(details); |
| 722 | 722 |
| 723 EXPECT_FALSE(event_dispatcher_delegate.has_queued_events()); | 723 EXPECT_FALSE(event_dispatcher_delegate.has_queued_events()); |
| 724 EXPECT_TRUE(details->in_nonclient_area); | 724 EXPECT_TRUE(details->in_nonclient_area); |
| 725 ASSERT_EQ(&child, details->window); | 725 ASSERT_EQ(&child, details->window); |
| 726 EXPECT_EQ(mojom::EVENT_TYPE_POINTER_DOWN, details->event->action); | 726 EXPECT_EQ(mojom::EventType::POINTER_DOWN, details->event->action); |
| 727 scoped_ptr<ui::Event> dispatched_event( | 727 scoped_ptr<ui::Event> dispatched_event( |
| 728 details->event.To<scoped_ptr<ui::Event>>()); | 728 details->event.To<scoped_ptr<ui::Event>>()); |
| 729 ASSERT_TRUE(dispatched_event.get()); | 729 ASSERT_TRUE(dispatched_event.get()); |
| 730 ASSERT_TRUE(dispatched_event->IsMouseEvent()); | 730 ASSERT_TRUE(dispatched_event->IsMouseEvent()); |
| 731 ui::MouseEvent* dispatched_mouse_event = | 731 ui::MouseEvent* dispatched_mouse_event = |
| 732 static_cast<ui::MouseEvent*>(dispatched_event.get()); | 732 static_cast<ui::MouseEvent*>(dispatched_event.get()); |
| 733 EXPECT_EQ(gfx::Point(-2, -1), dispatched_mouse_event->location()); | 733 EXPECT_EQ(gfx::Point(-2, -1), dispatched_mouse_event->location()); |
| 734 } | 734 } |
| 735 | 735 |
| 736 TEST(EventDispatcherTest, WheelWhileDown) { | 736 TEST(EventDispatcherTest, WheelWhileDown) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 ui::EF_NONE), | 770 ui::EF_NONE), |
| 771 &child1, gfx::Point(53, 54), gfx::Point(43, 44), nullptr, gfx::Point(), | 771 &child1, gfx::Point(53, 54), gfx::Point(43, 44), nullptr, gfx::Point(), |
| 772 gfx::Point()}, | 772 gfx::Point()}, |
| 773 }; | 773 }; |
| 774 RunMouseEventTests(&dispatcher, &event_dispatcher_delegate, tests, | 774 RunMouseEventTests(&dispatcher, &event_dispatcher_delegate, tests, |
| 775 arraysize(tests)); | 775 arraysize(tests)); |
| 776 } | 776 } |
| 777 | 777 |
| 778 } // namespace ws | 778 } // namespace ws |
| 779 } // namespace mus | 779 } // namespace mus |
| OLD | NEW |