| 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 "components/mus/public/cpp/event_matcher.h" | 13 #include "components/mus/public/cpp/event_matcher.h" |
| 14 #include "components/mus/ws/event_dispatcher_delegate.h" | 14 #include "components/mus/ws/event_dispatcher_delegate.h" |
| 15 #include "components/mus/ws/server_window.h" | 15 #include "components/mus/ws/server_window.h" |
| 16 #include "components/mus/ws/server_window_surface_manager_test_api.h" | 16 #include "components/mus/ws/server_window_surface_manager_test_api.h" |
| 17 #include "components/mus/ws/test_server_window_delegate.h" | 17 #include "components/mus/ws/test_server_window_delegate.h" |
| 18 #include "components/mus/ws/test_utils.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "ui/events/event.h" | 20 #include "ui/events/event.h" |
| 20 | 21 |
| 21 namespace mus { | 22 namespace mus { |
| 22 namespace ws { | 23 namespace ws { |
| 24 namespace test { |
| 23 namespace { | 25 namespace { |
| 24 | 26 |
| 25 // Identifies a generated event. | 27 // Identifies a generated event. |
| 26 struct DispatchedEventDetails { | 28 struct DispatchedEventDetails { |
| 27 DispatchedEventDetails() : window(nullptr), in_nonclient_area(false) {} | 29 DispatchedEventDetails() : window(nullptr), in_nonclient_area(false) {} |
| 28 | 30 |
| 29 ServerWindow* window; | 31 ServerWindow* window; |
| 30 bool in_nonclient_area; | 32 bool in_nonclient_area; |
| 31 scoped_ptr<ui::Event> event; | 33 scoped_ptr<ui::Event> event; |
| 32 }; | 34 }; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 private: | 197 private: |
| 196 scoped_ptr<TestServerWindowDelegate> window_delegate_; | 198 scoped_ptr<TestServerWindowDelegate> window_delegate_; |
| 197 scoped_ptr<ServerWindow> root_window_; | 199 scoped_ptr<ServerWindow> root_window_; |
| 198 scoped_ptr<TestEventDispatcherDelegate> test_event_dispatcher_delegate_; | 200 scoped_ptr<TestEventDispatcherDelegate> test_event_dispatcher_delegate_; |
| 199 scoped_ptr<EventDispatcher> event_dispatcher_; | 201 scoped_ptr<EventDispatcher> event_dispatcher_; |
| 200 | 202 |
| 201 DISALLOW_COPY_AND_ASSIGN(EventDispatcherTest); | 203 DISALLOW_COPY_AND_ASSIGN(EventDispatcherTest); |
| 202 }; | 204 }; |
| 203 | 205 |
| 204 bool EventDispatcherTest::AreAnyPointersDown() const { | 206 bool EventDispatcherTest::AreAnyPointersDown() const { |
| 205 return event_dispatcher_->AreAnyPointersDown(); | 207 return EventDispatcherTestApi(event_dispatcher_.get()).AreAnyPointersDown(); |
| 206 } | 208 } |
| 207 | 209 |
| 208 void EventDispatcherTest::ClearSetup() { | 210 void EventDispatcherTest::ClearSetup() { |
| 209 window_delegate_.reset(); | 211 window_delegate_.reset(); |
| 210 root_window_.reset(); | 212 root_window_.reset(); |
| 211 test_event_dispatcher_delegate_.reset(); | 213 test_event_dispatcher_delegate_.reset(); |
| 212 event_dispatcher_.reset(); | 214 event_dispatcher_.reset(); |
| 213 } | 215 } |
| 214 | 216 |
| 215 ServerWindow* EventDispatcherTest::CreateChildWindow(const WindowId& id) { | 217 ServerWindow* EventDispatcherTest::CreateChildWindow(const WindowId& id) { |
| 216 ServerWindow* child = new ServerWindow(window_delegate_.get(), id); | 218 ServerWindow* child = new ServerWindow(window_delegate_.get(), id); |
| 217 root_window_->Add(child); | 219 root_window_->Add(child); |
| 218 child->SetVisible(true); | 220 child->SetVisible(true); |
| 219 EnableHitTest(child); | 221 EnableHitTest(child); |
| 220 return child; | 222 return child; |
| 221 } | 223 } |
| 222 | 224 |
| 223 bool EventDispatcherTest::IsMouseButtonDown() const { | 225 bool EventDispatcherTest::IsMouseButtonDown() const { |
| 224 return event_dispatcher_->mouse_button_down_; | 226 return EventDispatcherTestApi(event_dispatcher_.get()).is_mouse_button_down(); |
| 225 } | 227 } |
| 226 | 228 |
| 227 bool EventDispatcherTest::IsWindowPointerTarget(ServerWindow* window) const { | 229 bool EventDispatcherTest::IsWindowPointerTarget(ServerWindow* window) const { |
| 228 return event_dispatcher_->IsObservingWindow(window); | 230 return EventDispatcherTestApi(event_dispatcher_.get()) |
| 231 .IsObservingWindow(window); |
| 229 } | 232 } |
| 230 | 233 |
| 231 int EventDispatcherTest::NumberPointerTargetsForWindow( | 234 int EventDispatcherTest::NumberPointerTargetsForWindow( |
| 232 ServerWindow* window) const { | 235 ServerWindow* window) const { |
| 233 int count = 0; | 236 return EventDispatcherTestApi(event_dispatcher_.get()) |
| 234 for (const auto& pair : event_dispatcher_->pointer_targets_) | 237 .NumberPointerTargetsForWindow(window); |
| 235 if (pair.second.window == window) | |
| 236 count++; | |
| 237 return count; | |
| 238 } | 238 } |
| 239 | 239 |
| 240 void EventDispatcherTest::SetUp() { | 240 void EventDispatcherTest::SetUp() { |
| 241 testing::Test::SetUp(); | 241 testing::Test::SetUp(); |
| 242 | 242 |
| 243 window_delegate_.reset(new TestServerWindowDelegate()); | 243 window_delegate_.reset(new TestServerWindowDelegate()); |
| 244 root_window_.reset(new ServerWindow(window_delegate_.get(), WindowId(1, 2))); | 244 root_window_.reset(new ServerWindow(window_delegate_.get(), WindowId(1, 2))); |
| 245 window_delegate_->set_root_window(root_window_.get()); | 245 window_delegate_->set_root_window(root_window_.get()); |
| 246 root_window_->SetVisible(true); | 246 root_window_->SetVisible(true); |
| 247 | 247 |
| (...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1081 ASSERT_TRUE(details->event); | 1081 ASSERT_TRUE(details->event); |
| 1082 ASSERT_TRUE(details->event->IsPointerEvent()); | 1082 ASSERT_TRUE(details->event->IsPointerEvent()); |
| 1083 | 1083 |
| 1084 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); | 1084 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); |
| 1085 EXPECT_EQ(gfx::Point(25, 20), dispatched_event->root_location()); | 1085 EXPECT_EQ(gfx::Point(25, 20), dispatched_event->root_location()); |
| 1086 EXPECT_EQ(gfx::Point(15, 10), dispatched_event->location()); | 1086 EXPECT_EQ(gfx::Point(15, 10), dispatched_event->location()); |
| 1087 EXPECT_EQ(touch_id, dispatched_event->pointer_id()); | 1087 EXPECT_EQ(touch_id, dispatched_event->pointer_id()); |
| 1088 } | 1088 } |
| 1089 } | 1089 } |
| 1090 | 1090 |
| 1091 TEST_F(EventDispatcherTest, ResetClearsPointerDown) { |
| 1092 scoped_ptr<ServerWindow> child(CreateChildWindow(WindowId(1, 3))); |
| 1093 |
| 1094 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 1095 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 1096 |
| 1097 // Send event that is over child. |
| 1098 const ui::PointerEvent ui_event(ui::MouseEvent( |
| 1099 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25), |
| 1100 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 1101 event_dispatcher()->ProcessEvent(ui_event); |
| 1102 |
| 1103 scoped_ptr<DispatchedEventDetails> details = |
| 1104 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); |
| 1105 ASSERT_TRUE(details); |
| 1106 ASSERT_EQ(child.get(), details->window); |
| 1107 |
| 1108 EXPECT_TRUE(AreAnyPointersDown()); |
| 1109 |
| 1110 event_dispatcher()->Reset(); |
| 1111 EXPECT_FALSE(test_event_dispatcher_delegate()->has_queued_events()); |
| 1112 EXPECT_FALSE(AreAnyPointersDown()); |
| 1113 } |
| 1114 |
| 1115 TEST_F(EventDispatcherTest, ResetClearsCapture) { |
| 1116 ServerWindow* root = root_window(); |
| 1117 root->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 1118 |
| 1119 root->SetClientArea(gfx::Insets(5, 5, 5, 5), std::vector<gfx::Rect>()); |
| 1120 EventDispatcher* dispatcher = event_dispatcher(); |
| 1121 dispatcher->SetCaptureWindow(root, true); |
| 1122 |
| 1123 event_dispatcher()->Reset(); |
| 1124 EXPECT_FALSE(test_event_dispatcher_delegate()->has_queued_events()); |
| 1125 EXPECT_EQ(nullptr, event_dispatcher()->capture_window()); |
| 1126 } |
| 1127 |
| 1128 } // namespace test |
| 1091 } // namespace ws | 1129 } // namespace ws |
| 1092 } // namespace mus | 1130 } // namespace mus |
| OLD | NEW |