| 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> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "components/mus/public/cpp/event_matcher.h" | 14 #include "components/mus/public/cpp/event_matcher_util.h" |
| 15 #include "components/mus/ws/accelerator.h" | 15 #include "components/mus/ws/accelerator.h" |
| 16 #include "components/mus/ws/event_dispatcher_delegate.h" | 16 #include "components/mus/ws/event_dispatcher_delegate.h" |
| 17 #include "components/mus/ws/server_window.h" | 17 #include "components/mus/ws/server_window.h" |
| 18 #include "components/mus/ws/server_window_surface_manager_test_api.h" | 18 #include "components/mus/ws/server_window_surface_manager_test_api.h" |
| 19 #include "components/mus/ws/test_server_window_delegate.h" | 19 #include "components/mus/ws/test_server_window_delegate.h" |
| 20 #include "components/mus/ws/test_utils.h" | 20 #include "components/mus/ws/test_utils.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "ui/events/event.h" | 22 #include "ui/events/event.h" |
| 23 | 23 |
| 24 namespace mus { | 24 namespace mus { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 class TestEventDispatcherDelegate : public EventDispatcherDelegate { | 40 class TestEventDispatcherDelegate : public EventDispatcherDelegate { |
| 41 public: | 41 public: |
| 42 explicit TestEventDispatcherDelegate(ServerWindow* root) | 42 explicit TestEventDispatcherDelegate(ServerWindow* root) |
| 43 : root_(root), | 43 : root_(root), |
| 44 focused_window_(nullptr), | 44 focused_window_(nullptr), |
| 45 lost_capture_window_(nullptr), | 45 lost_capture_window_(nullptr), |
| 46 last_accelerator_(0) {} | 46 last_accelerator_(0) {} |
| 47 ~TestEventDispatcherDelegate() override {} | 47 ~TestEventDispatcherDelegate() override {} |
| 48 | 48 |
| 49 ui::Event* last_event_target_not_found() { |
| 50 return last_event_target_not_found_.get(); |
| 51 } |
| 52 |
| 49 uint32_t GetAndClearLastAccelerator() { | 53 uint32_t GetAndClearLastAccelerator() { |
| 50 uint32_t return_value = last_accelerator_; | 54 uint32_t return_value = last_accelerator_; |
| 51 last_accelerator_ = 0; | 55 last_accelerator_ = 0; |
| 52 return return_value; | 56 return return_value; |
| 53 } | 57 } |
| 54 | 58 |
| 55 // Returns the last dispatched event, or null if there are no more. | 59 // Returns the last dispatched event, or null if there are no more. |
| 56 std::unique_ptr<DispatchedEventDetails> | 60 std::unique_ptr<DispatchedEventDetails> |
| 57 GetAndAdvanceDispatchedEventDetails() { | 61 GetAndAdvanceDispatchedEventDetails() { |
| 58 if (dispatched_event_queue_.empty()) | 62 if (dispatched_event_queue_.empty()) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 bool in_nonclient_area, | 100 bool in_nonclient_area, |
| 97 const ui::Event& event, | 101 const ui::Event& event, |
| 98 Accelerator* accelerator) override { | 102 Accelerator* accelerator) override { |
| 99 std::unique_ptr<DispatchedEventDetails> details(new DispatchedEventDetails); | 103 std::unique_ptr<DispatchedEventDetails> details(new DispatchedEventDetails); |
| 100 details->window = target; | 104 details->window = target; |
| 101 details->in_nonclient_area = in_nonclient_area; | 105 details->in_nonclient_area = in_nonclient_area; |
| 102 details->event = ui::Event::Clone(event); | 106 details->event = ui::Event::Clone(event); |
| 103 details->accelerator = accelerator; | 107 details->accelerator = accelerator; |
| 104 dispatched_event_queue_.push(std::move(details)); | 108 dispatched_event_queue_.push(std::move(details)); |
| 105 } | 109 } |
| 110 void OnEventTargetNotFound(const ui::Event& event) override { |
| 111 last_event_target_not_found_ = ui::Event::Clone(event); |
| 112 } |
| 106 | 113 |
| 107 ServerWindow* root_; | 114 ServerWindow* root_; |
| 108 ServerWindow* focused_window_; | 115 ServerWindow* focused_window_; |
| 109 ServerWindow* lost_capture_window_; | 116 ServerWindow* lost_capture_window_; |
| 110 uint32_t last_accelerator_; | 117 uint32_t last_accelerator_; |
| 111 std::queue<std::unique_ptr<DispatchedEventDetails>> dispatched_event_queue_; | 118 std::queue<std::unique_ptr<DispatchedEventDetails>> dispatched_event_queue_; |
| 119 std::unique_ptr<ui::Event> last_event_target_not_found_; |
| 112 | 120 |
| 113 DISALLOW_COPY_AND_ASSIGN(TestEventDispatcherDelegate); | 121 DISALLOW_COPY_AND_ASSIGN(TestEventDispatcherDelegate); |
| 114 }; | 122 }; |
| 115 | 123 |
| 116 // Used by RunMouseEventTests(). Can identify up to two generated events. The | 124 // Used by RunMouseEventTests(). Can identify up to two generated events. The |
| 117 // first ServerWindow and two points identify the first event, the second | 125 // first ServerWindow and two points identify the first event, the second |
| 118 // ServerWindow and points identify the second event. If only one event is | 126 // ServerWindow and points identify the second event. If only one event is |
| 119 // generated set the second window to null. | 127 // generated set the second window to null. |
| 120 struct MouseEventTest { | 128 struct MouseEventTest { |
| 121 ui::MouseEvent input_event; | 129 ui::MouseEvent input_event; |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 ASSERT_EQ(child.get(), details->window); | 298 ASSERT_EQ(child.get(), details->window); |
| 291 | 299 |
| 292 ASSERT_TRUE(details->event); | 300 ASSERT_TRUE(details->event); |
| 293 ASSERT_TRUE(details->event->IsPointerEvent()); | 301 ASSERT_TRUE(details->event->IsPointerEvent()); |
| 294 | 302 |
| 295 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); | 303 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); |
| 296 EXPECT_EQ(gfx::Point(20, 25), dispatched_event->root_location()); | 304 EXPECT_EQ(gfx::Point(20, 25), dispatched_event->root_location()); |
| 297 EXPECT_EQ(gfx::Point(10, 15), dispatched_event->location()); | 305 EXPECT_EQ(gfx::Point(10, 15), dispatched_event->location()); |
| 298 } | 306 } |
| 299 | 307 |
| 308 TEST_F(EventDispatcherTest, ProcessEventNoTarget) { |
| 309 // Send event without a target. |
| 310 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); |
| 311 event_dispatcher()->ProcessEvent(key); |
| 312 |
| 313 // Event wasn't dispatched to a target. |
| 314 std::unique_ptr<DispatchedEventDetails> details = |
| 315 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); |
| 316 EXPECT_FALSE(details); |
| 317 |
| 318 // Delegate was informed that there wasn't a target. |
| 319 ui::Event* event_out = |
| 320 test_event_dispatcher_delegate()->last_event_target_not_found(); |
| 321 ASSERT_TRUE(event_out); |
| 322 EXPECT_TRUE(event_out->IsKeyEvent()); |
| 323 EXPECT_EQ(ui::VKEY_A, event_out->AsKeyEvent()->key_code()); |
| 324 } |
| 325 |
| 300 TEST_F(EventDispatcherTest, AcceleratorBasic) { | 326 TEST_F(EventDispatcherTest, AcceleratorBasic) { |
| 301 ClearSetup(); | 327 ClearSetup(); |
| 302 TestEventDispatcherDelegate event_dispatcher_delegate(nullptr); | 328 TestEventDispatcherDelegate event_dispatcher_delegate(nullptr); |
| 303 EventDispatcher dispatcher(&event_dispatcher_delegate); | 329 EventDispatcher dispatcher(&event_dispatcher_delegate); |
| 304 | 330 |
| 305 uint32_t accelerator_1 = 1; | 331 uint32_t accelerator_1 = 1; |
| 306 mojom::EventMatcherPtr matcher = mus::CreateKeyMatcher( | 332 mojom::EventMatcherPtr matcher = mus::CreateKeyMatcher( |
| 307 mus::mojom::KeyboardCode::W, mus::mojom::kEventFlagControlDown); | 333 mus::mojom::KeyboardCode::W, mus::mojom::kEventFlagControlDown); |
| 308 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_1, std::move(matcher))); | 334 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_1, std::move(matcher))); |
| 309 | 335 |
| (...skipping 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1337 w1->AddTransientWindow(w2.get()); | 1363 w1->AddTransientWindow(w2.get()); |
| 1338 w2->SetModal(); | 1364 w2->SetModal(); |
| 1339 | 1365 |
| 1340 EXPECT_TRUE(event_dispatcher()->SetCaptureWindow(w3.get(), false)); | 1366 EXPECT_TRUE(event_dispatcher()->SetCaptureWindow(w3.get(), false)); |
| 1341 EXPECT_EQ(w3.get(), event_dispatcher()->capture_window()); | 1367 EXPECT_EQ(w3.get(), event_dispatcher()->capture_window()); |
| 1342 } | 1368 } |
| 1343 | 1369 |
| 1344 } // namespace test | 1370 } // namespace test |
| 1345 } // namespace ws | 1371 } // namespace ws |
| 1346 } // namespace mus | 1372 } // namespace mus |
| OLD | NEW |