| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/aura/window_event_dispatcher.h" | 5 #include "ui/aura/window_event_dispatcher.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 int mouse_event_count_; | 82 int mouse_event_count_; |
| 83 gfx::Point mouse_event_location_; | 83 gfx::Point mouse_event_location_; |
| 84 int mouse_event_flags_; | 84 int mouse_event_flags_; |
| 85 | 85 |
| 86 DISALLOW_COPY_AND_ASSIGN(NonClientDelegate); | 86 DISALLOW_COPY_AND_ASSIGN(NonClientDelegate); |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 // A simple event handler that consumes key events. | 89 // A simple event handler that consumes key events. |
| 90 class ConsumeKeyHandler : public ui::test::TestEventHandler { | 90 class ConsumeKeyHandler : public ui::test::TestEventHandler { |
| 91 public: | 91 public: |
| 92 ConsumeKeyHandler() {} | 92 ConsumeKeyHandler() : num_post_ime_key_events_(0) {} |
| 93 ~ConsumeKeyHandler() override {} | 93 ~ConsumeKeyHandler() override {} |
| 94 | 94 |
| 95 int num_post_ime_key_events() const { return num_post_ime_key_events_; } |
| 96 |
| 95 // Overridden from ui::EventHandler: | 97 // Overridden from ui::EventHandler: |
| 96 void OnKeyEvent(ui::KeyEvent* event) override { | 98 void OnKeyEvent(ui::KeyEvent* event) override { |
| 97 ui::test::TestEventHandler::OnKeyEvent(event); | 99 ui::test::TestEventHandler::OnKeyEvent(event); |
| 98 event->StopPropagation(); | 100 event->StopPropagation(); |
| 101 if (event->should_skip_ime()) |
| 102 num_post_ime_key_events_++; |
| 99 } | 103 } |
| 100 | 104 |
| 101 private: | 105 private: |
| 106 int num_post_ime_key_events_; |
| 107 |
| 102 DISALLOW_COPY_AND_ASSIGN(ConsumeKeyHandler); | 108 DISALLOW_COPY_AND_ASSIGN(ConsumeKeyHandler); |
| 103 }; | 109 }; |
| 104 | 110 |
| 105 bool IsFocusedWindow(aura::Window* window) { | 111 bool IsFocusedWindow(aura::Window* window) { |
| 106 return client::GetFocusClient(window)->GetFocusedWindow() == window; | 112 return client::GetFocusClient(window)->GetFocusedWindow() == window; |
| 107 } | 113 } |
| 108 | 114 |
| 109 } // namespace | 115 } // namespace |
| 110 | 116 |
| 111 using WindowEventDispatcherTest = test::AuraTestBaseWithType; | 117 using WindowEventDispatcherTest = test::AuraTestBaseWithType; |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 ui::test::TestEventHandler handler; | 419 ui::test::TestEventHandler handler; |
| 414 w1->AddPreTargetHandler(&handler); | 420 w1->AddPreTargetHandler(&handler); |
| 415 ui::KeyEvent key_press(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); | 421 ui::KeyEvent key_press(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); |
| 416 DispatchEventUsingWindowDispatcher(&key_press); | 422 DispatchEventUsingWindowDispatcher(&key_press); |
| 417 EXPECT_TRUE(key_press.handled()); | 423 EXPECT_TRUE(key_press.handled()); |
| 418 EXPECT_EQ(1, handler.num_key_events()); | 424 EXPECT_EQ(1, handler.num_key_events()); |
| 419 | 425 |
| 420 w1->RemovePreTargetHandler(&handler); | 426 w1->RemovePreTargetHandler(&handler); |
| 421 } | 427 } |
| 422 | 428 |
| 429 TEST_P(WindowEventDispatcherTest, KeyEventsSentToIME) { |
| 430 ConsumeKeyHandler handler; |
| 431 root_window()->AddPostTargetHandler(&handler); |
| 432 |
| 433 // Ctrl-C should be sent to Input Method. Since it cannot handle it, it will |
| 434 // be sent to DispatchKeyEventPostIME() and handled by |handler|. |
| 435 ui::KeyEvent key_press(ui::ET_KEY_PRESSED, ui::VKEY_C, ui::EF_CONTROL_DOWN); |
| 436 DispatchEventUsingWindowDispatcher(&key_press); |
| 437 EXPECT_TRUE(key_press.handled()); |
| 438 EXPECT_EQ(1, handler.num_key_events()); |
| 439 EXPECT_EQ(1, handler.num_post_ime_key_events()); |
| 440 |
| 441 root_window()->RemovePostTargetHandler(&handler); |
| 442 } |
| 443 |
| 423 // Tests that touch-events that are beyond the bounds of the root-window do get | 444 // Tests that touch-events that are beyond the bounds of the root-window do get |
| 424 // propagated to the event filters correctly with the root as the target. | 445 // propagated to the event filters correctly with the root as the target. |
| 425 TEST_P(WindowEventDispatcherTest, TouchEventsOutsideBounds) { | 446 TEST_P(WindowEventDispatcherTest, TouchEventsOutsideBounds) { |
| 426 ui::test::TestEventHandler handler; | 447 ui::test::TestEventHandler handler; |
| 427 root_window()->AddPreTargetHandler(&handler); | 448 root_window()->AddPreTargetHandler(&handler); |
| 428 | 449 |
| 429 gfx::Point position = root_window()->bounds().origin(); | 450 gfx::Point position = root_window()->bounds().origin(); |
| 430 position.Offset(-10, -10); | 451 position.Offset(-10, -10); |
| 431 ui::TouchEvent press( | 452 ui::TouchEvent press( |
| 432 ui::ET_TOUCH_PRESSED, position, ui::EventTimeForNow(), | 453 ui::ET_TOUCH_PRESSED, position, ui::EventTimeForNow(), |
| (...skipping 2514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2947 EXPECT_EQ(1, last_event_location_delegate.mouse_event_count()); | 2968 EXPECT_EQ(1, last_event_location_delegate.mouse_event_count()); |
| 2948 EXPECT_EQ(1, last_event_location_delegate.nested_message_loop_count()); | 2969 EXPECT_EQ(1, last_event_location_delegate.nested_message_loop_count()); |
| 2949 EXPECT_EQ(mouse_location, last_event_location_delegate.last_mouse_location()); | 2970 EXPECT_EQ(mouse_location, last_event_location_delegate.last_mouse_location()); |
| 2950 | 2971 |
| 2951 // After dispatch the location should fallback to that of the | 2972 // After dispatch the location should fallback to that of the |
| 2952 // WindowTreeClient, which defaults to 0,0. | 2973 // WindowTreeClient, which defaults to 0,0. |
| 2953 EXPECT_EQ(gfx::Point(0, 0), Env::GetInstance()->last_mouse_location()); | 2974 EXPECT_EQ(gfx::Point(0, 0), Env::GetInstance()->last_mouse_location()); |
| 2954 } | 2975 } |
| 2955 | 2976 |
| 2956 } // namespace aura | 2977 } // namespace aura |
| OLD | NEW |