| 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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 EXPECT_EQ(ui::VKEY_A, event_out->AsKeyEvent()->key_code()); | 347 EXPECT_EQ(ui::VKEY_A, event_out->AsKeyEvent()->key_code()); |
| 348 } | 348 } |
| 349 | 349 |
| 350 TEST_F(EventDispatcherTest, AcceleratorBasic) { | 350 TEST_F(EventDispatcherTest, AcceleratorBasic) { |
| 351 ClearSetup(); | 351 ClearSetup(); |
| 352 TestEventDispatcherDelegate event_dispatcher_delegate(nullptr); | 352 TestEventDispatcherDelegate event_dispatcher_delegate(nullptr); |
| 353 EventDispatcher dispatcher(&event_dispatcher_delegate); | 353 EventDispatcher dispatcher(&event_dispatcher_delegate); |
| 354 | 354 |
| 355 uint32_t accelerator_1 = 1; | 355 uint32_t accelerator_1 = 1; |
| 356 mojom::EventMatcherPtr matcher = mus::CreateKeyMatcher( | 356 mojom::EventMatcherPtr matcher = mus::CreateKeyMatcher( |
| 357 mus::mojom::KeyboardCode::W, mus::mojom::kEventFlagControlDown); | 357 ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown); |
| 358 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_1, std::move(matcher))); | 358 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_1, std::move(matcher))); |
| 359 | 359 |
| 360 uint32_t accelerator_2 = 2; | 360 uint32_t accelerator_2 = 2; |
| 361 matcher = mus::CreateKeyMatcher(mus::mojom::KeyboardCode::N, | 361 matcher = mus::CreateKeyMatcher(ui::mojom::KeyboardCode::N, |
| 362 mus::mojom::kEventFlagNone); | 362 ui::mojom::kEventFlagNone); |
| 363 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_2, std::move(matcher))); | 363 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_2, std::move(matcher))); |
| 364 | 364 |
| 365 // Attempting to add a new accelerator with the same id should fail. | 365 // Attempting to add a new accelerator with the same id should fail. |
| 366 matcher = mus::CreateKeyMatcher(mus::mojom::KeyboardCode::T, | 366 matcher = mus::CreateKeyMatcher(ui::mojom::KeyboardCode::T, |
| 367 mus::mojom::kEventFlagNone); | 367 ui::mojom::kEventFlagNone); |
| 368 EXPECT_FALSE(dispatcher.AddAccelerator(accelerator_2, std::move(matcher))); | 368 EXPECT_FALSE(dispatcher.AddAccelerator(accelerator_2, std::move(matcher))); |
| 369 | 369 |
| 370 // Adding the accelerator with the same id should succeed once the existing | 370 // Adding the accelerator with the same id should succeed once the existing |
| 371 // accelerator is removed. | 371 // accelerator is removed. |
| 372 dispatcher.RemoveAccelerator(accelerator_2); | 372 dispatcher.RemoveAccelerator(accelerator_2); |
| 373 matcher = mus::CreateKeyMatcher(mus::mojom::KeyboardCode::T, | 373 matcher = mus::CreateKeyMatcher(ui::mojom::KeyboardCode::T, |
| 374 mus::mojom::kEventFlagNone); | 374 ui::mojom::kEventFlagNone); |
| 375 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_2, std::move(matcher))); | 375 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_2, std::move(matcher))); |
| 376 | 376 |
| 377 // Attempting to add an accelerator with the same matcher should fail. | 377 // Attempting to add an accelerator with the same matcher should fail. |
| 378 uint32_t accelerator_3 = 3; | 378 uint32_t accelerator_3 = 3; |
| 379 matcher = mus::CreateKeyMatcher(mus::mojom::KeyboardCode::T, | 379 matcher = mus::CreateKeyMatcher(ui::mojom::KeyboardCode::T, |
| 380 mus::mojom::kEventFlagNone); | 380 ui::mojom::kEventFlagNone); |
| 381 EXPECT_FALSE(dispatcher.AddAccelerator(accelerator_3, std::move(matcher))); | 381 EXPECT_FALSE(dispatcher.AddAccelerator(accelerator_3, std::move(matcher))); |
| 382 | 382 |
| 383 matcher = mus::CreateKeyMatcher(mus::mojom::KeyboardCode::T, | 383 matcher = mus::CreateKeyMatcher(ui::mojom::KeyboardCode::T, |
| 384 mus::mojom::kEventFlagControlDown); | 384 ui::mojom::kEventFlagControlDown); |
| 385 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_3, std::move(matcher))); | 385 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_3, std::move(matcher))); |
| 386 } | 386 } |
| 387 | 387 |
| 388 TEST_F(EventDispatcherTest, EventMatching) { | 388 TEST_F(EventDispatcherTest, EventMatching) { |
| 389 TestEventDispatcherDelegate* event_dispatcher_delegate = | 389 TestEventDispatcherDelegate* event_dispatcher_delegate = |
| 390 test_event_dispatcher_delegate(); | 390 test_event_dispatcher_delegate(); |
| 391 EventDispatcher* dispatcher = event_dispatcher(); | 391 EventDispatcher* dispatcher = event_dispatcher(); |
| 392 | 392 |
| 393 mojom::EventMatcherPtr matcher = mus::CreateKeyMatcher( | 393 mojom::EventMatcherPtr matcher = mus::CreateKeyMatcher( |
| 394 mus::mojom::KeyboardCode::W, mus::mojom::kEventFlagControlDown); | 394 ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown); |
| 395 uint32_t accelerator_1 = 1; | 395 uint32_t accelerator_1 = 1; |
| 396 dispatcher->AddAccelerator(accelerator_1, std::move(matcher)); | 396 dispatcher->AddAccelerator(accelerator_1, std::move(matcher)); |
| 397 | 397 |
| 398 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); | 398 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
| 399 dispatcher->ProcessEvent(key); | 399 dispatcher->ProcessEvent(key); |
| 400 EXPECT_EQ(accelerator_1, | 400 EXPECT_EQ(accelerator_1, |
| 401 event_dispatcher_delegate->GetAndClearLastAccelerator()); | 401 event_dispatcher_delegate->GetAndClearLastAccelerator()); |
| 402 | 402 |
| 403 // EF_NUM_LOCK_ON should be ignored since CreateKeyMatcher defaults to | 403 // EF_NUM_LOCK_ON should be ignored since CreateKeyMatcher defaults to |
| 404 // ignoring. | 404 // ignoring. |
| 405 key = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_W, | 405 key = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_W, |
| 406 ui::EF_CONTROL_DOWN | ui::EF_NUM_LOCK_ON); | 406 ui::EF_CONTROL_DOWN | ui::EF_NUM_LOCK_ON); |
| 407 dispatcher->ProcessEvent(key); | 407 dispatcher->ProcessEvent(key); |
| 408 EXPECT_EQ(accelerator_1, | 408 EXPECT_EQ(accelerator_1, |
| 409 event_dispatcher_delegate->GetAndClearLastAccelerator()); | 409 event_dispatcher_delegate->GetAndClearLastAccelerator()); |
| 410 | 410 |
| 411 key = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_NONE); | 411 key = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_NONE); |
| 412 dispatcher->ProcessEvent(key); | 412 dispatcher->ProcessEvent(key); |
| 413 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator()); | 413 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator()); |
| 414 | 414 |
| 415 uint32_t accelerator_2 = 2; | 415 uint32_t accelerator_2 = 2; |
| 416 matcher = mus::CreateKeyMatcher(mus::mojom::KeyboardCode::W, | 416 matcher = mus::CreateKeyMatcher(ui::mojom::KeyboardCode::W, |
| 417 mus::mojom::kEventFlagNone); | 417 ui::mojom::kEventFlagNone); |
| 418 dispatcher->AddAccelerator(accelerator_2, std::move(matcher)); | 418 dispatcher->AddAccelerator(accelerator_2, std::move(matcher)); |
| 419 dispatcher->ProcessEvent(key); | 419 dispatcher->ProcessEvent(key); |
| 420 EXPECT_EQ(accelerator_2, | 420 EXPECT_EQ(accelerator_2, |
| 421 event_dispatcher_delegate->GetAndClearLastAccelerator()); | 421 event_dispatcher_delegate->GetAndClearLastAccelerator()); |
| 422 | 422 |
| 423 dispatcher->RemoveAccelerator(accelerator_2); | 423 dispatcher->RemoveAccelerator(accelerator_2); |
| 424 dispatcher->ProcessEvent(key); | 424 dispatcher->ProcessEvent(key); |
| 425 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator()); | 425 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator()); |
| 426 } | 426 } |
| 427 | 427 |
| 428 // Tests that a post-target accelerator is not triggered by ProcessEvent. | 428 // Tests that a post-target accelerator is not triggered by ProcessEvent. |
| 429 TEST_F(EventDispatcherTest, PostTargetAccelerator) { | 429 TEST_F(EventDispatcherTest, PostTargetAccelerator) { |
| 430 TestEventDispatcherDelegate* event_dispatcher_delegate = | 430 TestEventDispatcherDelegate* event_dispatcher_delegate = |
| 431 test_event_dispatcher_delegate(); | 431 test_event_dispatcher_delegate(); |
| 432 EventDispatcher* dispatcher = event_dispatcher(); | 432 EventDispatcher* dispatcher = event_dispatcher(); |
| 433 | 433 |
| 434 mojom::EventMatcherPtr matcher = mus::CreateKeyMatcher( | 434 mojom::EventMatcherPtr matcher = mus::CreateKeyMatcher( |
| 435 mus::mojom::KeyboardCode::W, mus::mojom::kEventFlagControlDown); | 435 ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown); |
| 436 matcher->accelerator_phase = mojom::AcceleratorPhase::POST_TARGET; | 436 matcher->accelerator_phase = ui::mojom::AcceleratorPhase::POST_TARGET; |
| 437 uint32_t accelerator_1 = 1; | 437 uint32_t accelerator_1 = 1; |
| 438 dispatcher->AddAccelerator(accelerator_1, std::move(matcher)); | 438 dispatcher->AddAccelerator(accelerator_1, std::move(matcher)); |
| 439 | 439 |
| 440 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); | 440 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
| 441 // The post-target accelerator should be fired if there is no focused window. | 441 // The post-target accelerator should be fired if there is no focused window. |
| 442 dispatcher->ProcessEvent(key); | 442 dispatcher->ProcessEvent(key); |
| 443 EXPECT_EQ(accelerator_1, | 443 EXPECT_EQ(accelerator_1, |
| 444 event_dispatcher_delegate->GetAndClearLastAccelerator()); | 444 event_dispatcher_delegate->GetAndClearLastAccelerator()); |
| 445 std::unique_ptr<DispatchedEventDetails> details = | 445 std::unique_ptr<DispatchedEventDetails> details = |
| 446 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 446 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
| (...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1574 // capture. | 1574 // capture. |
| 1575 w2->Add(w11.get()); | 1575 w2->Add(w11.get()); |
| 1576 EXPECT_TRUE(IsMouseButtonDown()); | 1576 EXPECT_TRUE(IsMouseButtonDown()); |
| 1577 EXPECT_EQ(w11.get(), | 1577 EXPECT_EQ(w11.get(), |
| 1578 EventDispatcherTestApi(event_dispatcher()).capture_window()); | 1578 EventDispatcherTestApi(event_dispatcher()).capture_window()); |
| 1579 } | 1579 } |
| 1580 | 1580 |
| 1581 } // namespace test | 1581 } // namespace test |
| 1582 } // namespace ws | 1582 } // namespace ws |
| 1583 } // namespace mus | 1583 } // namespace mus |
| OLD | NEW |