| 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 "components/mus/public/cpp/event_matcher.h" | 7 #include "components/mus/public/cpp/event_matcher.h" |
| 8 #include "components/mus/ws/event_dispatcher_delegate.h" | 8 #include "components/mus/ws/event_dispatcher_delegate.h" |
| 9 #include "components/mus/ws/server_window.h" | 9 #include "components/mus/ws/server_window.h" |
| 10 #include "components/mus/ws/test_server_window_delegate.h" | 10 #include "components/mus/ws/test_server_window_delegate.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 137 |
| 138 root.SetBounds(gfx::Rect(0, 0, 100, 100)); | 138 root.SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 139 child.SetBounds(gfx::Rect(10, 10, 20, 20)); | 139 child.SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 140 | 140 |
| 141 TestEventDispatcherDelegate event_dispatcher_delegate(&root); | 141 TestEventDispatcherDelegate event_dispatcher_delegate(&root); |
| 142 EventDispatcher dispatcher(&event_dispatcher_delegate); | 142 EventDispatcher dispatcher(&event_dispatcher_delegate); |
| 143 dispatcher.set_root(&root); | 143 dispatcher.set_root(&root); |
| 144 | 144 |
| 145 // Send event that is over child. | 145 // Send event that is over child. |
| 146 const ui::MouseEvent ui_event( | 146 const ui::MouseEvent ui_event( |
| 147 ui::ET_MOUSE_PRESSED, gfx::PointF(20.f, 25.f), gfx::PointF(20.f, 25.f), | 147 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25), |
| 148 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 148 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 149 dispatcher.OnEvent( | 149 dispatcher.OnEvent( |
| 150 mojom::Event::From(static_cast<const ui::Event&>(ui_event))); | 150 mojom::Event::From(static_cast<const ui::Event&>(ui_event))); |
| 151 | 151 |
| 152 ASSERT_EQ(&child, event_dispatcher_delegate.last_target()); | 152 ASSERT_EQ(&child, event_dispatcher_delegate.last_target()); |
| 153 | 153 |
| 154 mojom::EventPtr dispatched_event_mojo = | 154 mojom::EventPtr dispatched_event_mojo = |
| 155 event_dispatcher_delegate.GetAndClearLastDispatchedEvent(); | 155 event_dispatcher_delegate.GetAndClearLastDispatchedEvent(); |
| 156 ASSERT_TRUE(dispatched_event_mojo.get()); | 156 ASSERT_TRUE(dispatched_event_mojo.get()); |
| 157 scoped_ptr<ui::Event> dispatched_event( | 157 scoped_ptr<ui::Event> dispatched_event( |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 210 |
| 211 root.SetBounds(gfx::Rect(0, 0, 100, 100)); | 211 root.SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 212 child.SetBounds(gfx::Rect(10, 10, 20, 20)); | 212 child.SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 213 | 213 |
| 214 TestEventDispatcherDelegate event_dispatcher_delegate(&root); | 214 TestEventDispatcherDelegate event_dispatcher_delegate(&root); |
| 215 EventDispatcher dispatcher(&event_dispatcher_delegate); | 215 EventDispatcher dispatcher(&event_dispatcher_delegate); |
| 216 dispatcher.set_root(&root); | 216 dispatcher.set_root(&root); |
| 217 | 217 |
| 218 MouseEventTest tests[] = { | 218 MouseEventTest tests[] = { |
| 219 // Send a mouse down event over child. | 219 // Send a mouse down event over child. |
| 220 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::PointF(20.f, 25.f), | 220 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), |
| 221 gfx::PointF(20.f, 25.f), base::TimeDelta(), | 221 gfx::Point(20, 25), base::TimeDelta(), |
| 222 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), | 222 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), |
| 223 &child, gfx::Point(20, 25), gfx::Point(10, 15)}, | 223 &child, gfx::Point(20, 25), gfx::Point(10, 15)}, |
| 224 // Capture should be activated. Let's send a mouse move outside the bounds | 224 // Capture should be activated. Let's send a mouse move outside the bounds |
| 225 // of the child. | 225 // of the child. |
| 226 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::PointF(50.f, 50.f), | 226 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(50, 50), |
| 227 gfx::PointF(50.f, 50.f), base::TimeDelta(), | 227 gfx::Point(50, 50), base::TimeDelta(), |
| 228 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), | 228 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), |
| 229 &child, gfx::Point(50, 50), gfx::Point(40, 40)}, | 229 &child, gfx::Point(50, 50), gfx::Point(40, 40)}, |
| 230 // Release the mouse and verify that the mouse up event goes to the child. | 230 // Release the mouse and verify that the mouse up event goes to the child. |
| 231 {ui::MouseEvent(ui::ET_MOUSE_RELEASED, gfx::PointF(50.f, 50.f), | 231 {ui::MouseEvent(ui::ET_MOUSE_RELEASED, gfx::Point(50, 50), |
| 232 gfx::PointF(50.f, 50.f), base::TimeDelta(), | 232 gfx::Point(50, 50), base::TimeDelta(), |
| 233 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), | 233 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), |
| 234 &child, gfx::Point(50, 50), gfx::Point(40, 40)}, | 234 &child, gfx::Point(50, 50), gfx::Point(40, 40)}, |
| 235 // A mouse move at (50, 50) should now go to the root window. | 235 // A mouse move at (50, 50) should now go to the root window. |
| 236 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::PointF(50.f, 50.f), | 236 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(50, 50), |
| 237 gfx::PointF(50.f, 50.f), base::TimeDelta(), | 237 gfx::Point(50, 50), base::TimeDelta(), |
| 238 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), | 238 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), |
| 239 &root, gfx::Point(50, 50), gfx::Point(50, 50)}, | 239 &root, gfx::Point(50, 50), gfx::Point(50, 50)}, |
| 240 | 240 |
| 241 }; | 241 }; |
| 242 RunMouseEventTests(&dispatcher, &event_dispatcher_delegate, tests, | 242 RunMouseEventTests(&dispatcher, &event_dispatcher_delegate, tests, |
| 243 arraysize(tests)); | 243 arraysize(tests)); |
| 244 } | 244 } |
| 245 | 245 |
| 246 TEST(EventDispatcherTest, CaptureMultipleMouseButtons) { | 246 TEST(EventDispatcherTest, CaptureMultipleMouseButtons) { |
| 247 TestServerWindowDelegate window_delegate; | 247 TestServerWindowDelegate window_delegate; |
| 248 ServerWindow root(&window_delegate, WindowId(1, 2)); | 248 ServerWindow root(&window_delegate, WindowId(1, 2)); |
| 249 window_delegate.set_root_window(&root); | 249 window_delegate.set_root_window(&root); |
| 250 root.SetVisible(true); | 250 root.SetVisible(true); |
| 251 | 251 |
| 252 ServerWindow child(&window_delegate, WindowId(1, 3)); | 252 ServerWindow child(&window_delegate, WindowId(1, 3)); |
| 253 root.Add(&child); | 253 root.Add(&child); |
| 254 child.SetVisible(true); | 254 child.SetVisible(true); |
| 255 | 255 |
| 256 root.SetBounds(gfx::Rect(0, 0, 100, 100)); | 256 root.SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 257 child.SetBounds(gfx::Rect(10, 10, 20, 20)); | 257 child.SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 258 | 258 |
| 259 TestEventDispatcherDelegate event_dispatcher_delegate(&root); | 259 TestEventDispatcherDelegate event_dispatcher_delegate(&root); |
| 260 EventDispatcher dispatcher(&event_dispatcher_delegate); | 260 EventDispatcher dispatcher(&event_dispatcher_delegate); |
| 261 dispatcher.set_root(&root); | 261 dispatcher.set_root(&root); |
| 262 | 262 |
| 263 MouseEventTest tests[] = { | 263 MouseEventTest tests[] = { |
| 264 // Send a mouse down event over child with a left mouse button | 264 // Send a mouse down event over child with a left mouse button |
| 265 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::PointF(20.f, 25.f), | 265 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), |
| 266 gfx::PointF(20.f, 25.f), base::TimeDelta(), | 266 gfx::Point(20, 25), base::TimeDelta(), |
| 267 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), | 267 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), |
| 268 &child, gfx::Point(20, 25), gfx::Point(10, 15)}, | 268 &child, gfx::Point(20, 25), gfx::Point(10, 15)}, |
| 269 // Capture should be activated. Let's send a mouse move outside the bounds | 269 // Capture should be activated. Let's send a mouse move outside the bounds |
| 270 // of the child and press the right mouse button too. | 270 // of the child and press the right mouse button too. |
| 271 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::PointF(50.f, 50.f), | 271 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(50, 50), |
| 272 gfx::PointF(50.f, 50.f), base::TimeDelta(), | 272 gfx::Point(50, 50), base::TimeDelta(), |
| 273 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON, 0), | 273 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON, 0), |
| 274 &child, gfx::Point(50, 50), gfx::Point(40, 40)}, | 274 &child, gfx::Point(50, 50), gfx::Point(40, 40)}, |
| 275 // Release the left mouse button and verify that the mouse up event goes | 275 // Release the left mouse button and verify that the mouse up event goes |
| 276 // to the child. | 276 // to the child. |
| 277 {ui::MouseEvent(ui::ET_MOUSE_RELEASED, gfx::PointF(50.f, 50.f), | 277 {ui::MouseEvent(ui::ET_MOUSE_RELEASED, gfx::Point(50, 50), |
| 278 gfx::PointF(50.f, 50.f), base::TimeDelta(), | 278 gfx::Point(50, 50), base::TimeDelta(), |
| 279 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON, | 279 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON, |
| 280 ui::EF_RIGHT_MOUSE_BUTTON), | 280 ui::EF_RIGHT_MOUSE_BUTTON), |
| 281 &child, gfx::Point(50, 50), gfx::Point(40, 40)}, | 281 &child, gfx::Point(50, 50), gfx::Point(40, 40)}, |
| 282 // A mouse move at (50, 50) should still go to the child. | 282 // A mouse move at (50, 50) should still go to the child. |
| 283 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::PointF(50.f, 50.f), | 283 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(50, 50), |
| 284 gfx::PointF(50.f, 50.f), base::TimeDelta(), | 284 gfx::Point(50, 50), base::TimeDelta(), |
| 285 ui::EF_LEFT_MOUSE_BUTTON, 0), | 285 ui::EF_LEFT_MOUSE_BUTTON, 0), |
| 286 &child, gfx::Point(50, 50), gfx::Point(40, 40)}, | 286 &child, gfx::Point(50, 50), gfx::Point(40, 40)}, |
| 287 | 287 |
| 288 }; | 288 }; |
| 289 RunMouseEventTests(&dispatcher, &event_dispatcher_delegate, tests, | 289 RunMouseEventTests(&dispatcher, &event_dispatcher_delegate, tests, |
| 290 arraysize(tests)); | 290 arraysize(tests)); |
| 291 } | 291 } |
| 292 | 292 |
| 293 TEST(EventDispatcherTest, ClientAreaGoesToOwner) { | 293 TEST(EventDispatcherTest, ClientAreaGoesToOwner) { |
| 294 TestServerWindowDelegate window_delegate; | 294 TestServerWindowDelegate window_delegate; |
| 295 ServerWindow root(&window_delegate, WindowId(1, 2)); | 295 ServerWindow root(&window_delegate, WindowId(1, 2)); |
| 296 window_delegate.set_root_window(&root); | 296 window_delegate.set_root_window(&root); |
| 297 root.SetVisible(true); | 297 root.SetVisible(true); |
| 298 | 298 |
| 299 ServerWindow child(&window_delegate, WindowId(1, 3)); | 299 ServerWindow child(&window_delegate, WindowId(1, 3)); |
| 300 root.Add(&child); | 300 root.Add(&child); |
| 301 child.SetVisible(true); | 301 child.SetVisible(true); |
| 302 | 302 |
| 303 root.SetBounds(gfx::Rect(0, 0, 100, 100)); | 303 root.SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 304 child.SetBounds(gfx::Rect(10, 10, 20, 20)); | 304 child.SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 305 | 305 |
| 306 child.SetClientArea(gfx::Rect(5, 5, 10, 10)); | 306 child.SetClientArea(gfx::Rect(5, 5, 10, 10)); |
| 307 | 307 |
| 308 TestEventDispatcherDelegate event_dispatcher_delegate(&root); | 308 TestEventDispatcherDelegate event_dispatcher_delegate(&root); |
| 309 EventDispatcher dispatcher(&event_dispatcher_delegate); | 309 EventDispatcher dispatcher(&event_dispatcher_delegate); |
| 310 dispatcher.set_root(&root); | 310 dispatcher.set_root(&root); |
| 311 | 311 |
| 312 // Start move loop by sending mouse event over non-client area. | 312 // Start move loop by sending mouse event over non-client area. |
| 313 const ui::MouseEvent press_event( | 313 const ui::MouseEvent press_event( |
| 314 ui::ET_MOUSE_PRESSED, gfx::PointF(12.f, 12.f), gfx::PointF(12.f, 12.f), | 314 ui::ET_MOUSE_PRESSED, gfx::Point(12, 12), gfx::Point(12, 12), |
| 315 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 315 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 316 dispatcher.OnEvent( | 316 dispatcher.OnEvent( |
| 317 mojom::Event::From(static_cast<const ui::Event&>(press_event))); | 317 mojom::Event::From(static_cast<const ui::Event&>(press_event))); |
| 318 | 318 |
| 319 // Events should target child and be in the non-client area. | 319 // Events should target child and be in the non-client area. |
| 320 ASSERT_EQ(&child, event_dispatcher_delegate.last_target()); | 320 ASSERT_EQ(&child, event_dispatcher_delegate.last_target()); |
| 321 EXPECT_TRUE(event_dispatcher_delegate.GetAndClearLastInNonclientArea()); | 321 EXPECT_TRUE(event_dispatcher_delegate.GetAndClearLastInNonclientArea()); |
| 322 | 322 |
| 323 // Move the mouse 5,6 pixels and target is the same. | 323 // Move the mouse 5,6 pixels and target is the same. |
| 324 const ui::MouseEvent move_event(ui::ET_MOUSE_MOVED, gfx::PointF(17.f, 18.f), | 324 const ui::MouseEvent move_event(ui::ET_MOUSE_MOVED, gfx::Point(17, 18), |
| 325 gfx::PointF(17.f, 18.f), base::TimeDelta(), | 325 gfx::Point(17, 18), base::TimeDelta(), |
| 326 ui::EF_LEFT_MOUSE_BUTTON, 0); | 326 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 327 dispatcher.OnEvent( | 327 dispatcher.OnEvent( |
| 328 mojom::Event::From(static_cast<const ui::Event&>(move_event))); | 328 mojom::Event::From(static_cast<const ui::Event&>(move_event))); |
| 329 | 329 |
| 330 // Still same target. | 330 // Still same target. |
| 331 ASSERT_EQ(&child, event_dispatcher_delegate.last_target()); | 331 ASSERT_EQ(&child, event_dispatcher_delegate.last_target()); |
| 332 EXPECT_TRUE(event_dispatcher_delegate.GetAndClearLastInNonclientArea()); | 332 EXPECT_TRUE(event_dispatcher_delegate.GetAndClearLastInNonclientArea()); |
| 333 | 333 |
| 334 // Release the mouse. | 334 // Release the mouse. |
| 335 const ui::MouseEvent release_event( | 335 const ui::MouseEvent release_event( |
| 336 ui::ET_MOUSE_RELEASED, gfx::PointF(17.f, 18.f), gfx::PointF(17.f, 18.f), | 336 ui::ET_MOUSE_RELEASED, gfx::Point(17, 18), gfx::Point(17, 18), |
| 337 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 337 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 338 dispatcher.OnEvent( | 338 dispatcher.OnEvent( |
| 339 mojom::Event::From(static_cast<const ui::Event&>(release_event))); | 339 mojom::Event::From(static_cast<const ui::Event&>(release_event))); |
| 340 | 340 |
| 341 // The event should not have been dispatched to the delegate. | 341 // The event should not have been dispatched to the delegate. |
| 342 ASSERT_EQ(&child, event_dispatcher_delegate.last_target()); | 342 ASSERT_EQ(&child, event_dispatcher_delegate.last_target()); |
| 343 EXPECT_TRUE(event_dispatcher_delegate.GetAndClearLastInNonclientArea()); | 343 EXPECT_TRUE(event_dispatcher_delegate.GetAndClearLastInNonclientArea()); |
| 344 | 344 |
| 345 // Press in the client area and verify target/client area. | 345 // Press in the client area and verify target/client area. |
| 346 const ui::MouseEvent press_event2( | 346 const ui::MouseEvent press_event2( |
| 347 ui::ET_MOUSE_PRESSED, gfx::PointF(21.f, 22.f), gfx::PointF(21.f, 22.f), | 347 ui::ET_MOUSE_PRESSED, gfx::Point(21, 22), gfx::Point(21, 22), |
| 348 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 348 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 349 dispatcher.OnEvent( | 349 dispatcher.OnEvent( |
| 350 mojom::Event::From(static_cast<const ui::Event&>(press_event2))); | 350 mojom::Event::From(static_cast<const ui::Event&>(press_event2))); |
| 351 ASSERT_EQ(&child, event_dispatcher_delegate.last_target()); | 351 ASSERT_EQ(&child, event_dispatcher_delegate.last_target()); |
| 352 EXPECT_FALSE(event_dispatcher_delegate.GetAndClearLastInNonclientArea()); | 352 EXPECT_FALSE(event_dispatcher_delegate.GetAndClearLastInNonclientArea()); |
| 353 } | 353 } |
| 354 | 354 |
| 355 TEST(EventDispatcherTest, DontFocusOnSecondDown) { | 355 TEST(EventDispatcherTest, DontFocusOnSecondDown) { |
| 356 TestServerWindowDelegate window_delegate; | 356 TestServerWindowDelegate window_delegate; |
| 357 ServerWindow root(&window_delegate, WindowId(1, 2)); | 357 ServerWindow root(&window_delegate, WindowId(1, 2)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 369 root.SetBounds(gfx::Rect(0, 0, 100, 100)); | 369 root.SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 370 child1.SetBounds(gfx::Rect(10, 10, 20, 20)); | 370 child1.SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 371 child2.SetBounds(gfx::Rect(50, 51, 11, 12)); | 371 child2.SetBounds(gfx::Rect(50, 51, 11, 12)); |
| 372 | 372 |
| 373 TestEventDispatcherDelegate event_dispatcher_delegate(&root); | 373 TestEventDispatcherDelegate event_dispatcher_delegate(&root); |
| 374 EventDispatcher dispatcher(&event_dispatcher_delegate); | 374 EventDispatcher dispatcher(&event_dispatcher_delegate); |
| 375 dispatcher.set_root(&root); | 375 dispatcher.set_root(&root); |
| 376 | 376 |
| 377 // Press on child1. First press event should change focus. | 377 // Press on child1. First press event should change focus. |
| 378 const ui::MouseEvent press_event( | 378 const ui::MouseEvent press_event( |
| 379 ui::ET_MOUSE_PRESSED, gfx::PointF(12.f, 12.f), gfx::PointF(12.f, 12.f), | 379 ui::ET_MOUSE_PRESSED, gfx::Point(12, 12), gfx::Point(12, 12), |
| 380 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 380 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 381 dispatcher.OnEvent( | 381 dispatcher.OnEvent( |
| 382 mojom::Event::From(static_cast<const ui::Event&>(press_event))); | 382 mojom::Event::From(static_cast<const ui::Event&>(press_event))); |
| 383 EXPECT_EQ(&child1, event_dispatcher_delegate.last_target()); | 383 EXPECT_EQ(&child1, event_dispatcher_delegate.last_target()); |
| 384 EXPECT_EQ(&child1, event_dispatcher_delegate.GetAndClearLastFocusedWindow()); | 384 EXPECT_EQ(&child1, event_dispatcher_delegate.GetAndClearLastFocusedWindow()); |
| 385 | 385 |
| 386 // Press (with a different pointer id) on child2. Event should go to child2, | 386 // Press (with a different pointer id) on child2. Event should go to child2, |
| 387 // but focus should not change. | 387 // but focus should not change. |
| 388 const ui::TouchEvent touch_event( | 388 const ui::TouchEvent touch_event(ui::ET_TOUCH_PRESSED, gfx::Point(53, 54), 2, |
| 389 ui::ET_TOUCH_PRESSED, gfx::PointF(53.f, 54.f), 2, base::TimeDelta()); | 389 base::TimeDelta()); |
| 390 dispatcher.OnEvent( | 390 dispatcher.OnEvent( |
| 391 mojom::Event::From(static_cast<const ui::Event&>(touch_event))); | 391 mojom::Event::From(static_cast<const ui::Event&>(touch_event))); |
| 392 EXPECT_EQ(&child2, event_dispatcher_delegate.last_target()); | 392 EXPECT_EQ(&child2, event_dispatcher_delegate.last_target()); |
| 393 EXPECT_EQ(nullptr, event_dispatcher_delegate.GetAndClearLastFocusedWindow()); | 393 EXPECT_EQ(nullptr, event_dispatcher_delegate.GetAndClearLastFocusedWindow()); |
| 394 } | 394 } |
| 395 | 395 |
| 396 TEST(EventDispatcherTest, TwoPointersActive) { | 396 TEST(EventDispatcherTest, TwoPointersActive) { |
| 397 TestServerWindowDelegate window_delegate; | 397 TestServerWindowDelegate window_delegate; |
| 398 ServerWindow root(&window_delegate, WindowId(1, 2)); | 398 ServerWindow root(&window_delegate, WindowId(1, 2)); |
| 399 window_delegate.set_root_window(&root); | 399 window_delegate.set_root_window(&root); |
| 400 root.SetVisible(true); | 400 root.SetVisible(true); |
| 401 | 401 |
| 402 ServerWindow child1(&window_delegate, WindowId(1, 3)); | 402 ServerWindow child1(&window_delegate, WindowId(1, 3)); |
| 403 root.Add(&child1); | 403 root.Add(&child1); |
| 404 child1.SetVisible(true); | 404 child1.SetVisible(true); |
| 405 | 405 |
| 406 ServerWindow child2(&window_delegate, WindowId(1, 4)); | 406 ServerWindow child2(&window_delegate, WindowId(1, 4)); |
| 407 root.Add(&child2); | 407 root.Add(&child2); |
| 408 child2.SetVisible(true); | 408 child2.SetVisible(true); |
| 409 | 409 |
| 410 root.SetBounds(gfx::Rect(0, 0, 100, 100)); | 410 root.SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 411 child1.SetBounds(gfx::Rect(10, 10, 20, 20)); | 411 child1.SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 412 child2.SetBounds(gfx::Rect(50, 51, 11, 12)); | 412 child2.SetBounds(gfx::Rect(50, 51, 11, 12)); |
| 413 | 413 |
| 414 TestEventDispatcherDelegate event_dispatcher_delegate(&root); | 414 TestEventDispatcherDelegate event_dispatcher_delegate(&root); |
| 415 EventDispatcher dispatcher(&event_dispatcher_delegate); | 415 EventDispatcher dispatcher(&event_dispatcher_delegate); |
| 416 dispatcher.set_root(&root); | 416 dispatcher.set_root(&root); |
| 417 | 417 |
| 418 // Press on child1. | 418 // Press on child1. |
| 419 const ui::TouchEvent touch_event1( | 419 const ui::TouchEvent touch_event1(ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), 1, |
| 420 ui::ET_TOUCH_PRESSED, gfx::PointF(12.f, 13.f), 1, base::TimeDelta()); | 420 base::TimeDelta()); |
| 421 dispatcher.OnEvent( | 421 dispatcher.OnEvent( |
| 422 mojom::Event::From(static_cast<const ui::Event&>(touch_event1))); | 422 mojom::Event::From(static_cast<const ui::Event&>(touch_event1))); |
| 423 EXPECT_EQ(&child1, event_dispatcher_delegate.GetAndClearLastTarget()); | 423 EXPECT_EQ(&child1, event_dispatcher_delegate.GetAndClearLastTarget()); |
| 424 | 424 |
| 425 // Drag over child2, child1 should get the drag. | 425 // Drag over child2, child1 should get the drag. |
| 426 const ui::TouchEvent drag_event1(ui::ET_TOUCH_MOVED, gfx::PointF(53.f, 54.f), | 426 const ui::TouchEvent drag_event1(ui::ET_TOUCH_MOVED, gfx::Point(53, 54), 1, |
| 427 1, base::TimeDelta()); | 427 base::TimeDelta()); |
| 428 dispatcher.OnEvent( | 428 dispatcher.OnEvent( |
| 429 mojom::Event::From(static_cast<const ui::Event&>(drag_event1))); | 429 mojom::Event::From(static_cast<const ui::Event&>(drag_event1))); |
| 430 EXPECT_EQ(&child1, event_dispatcher_delegate.GetAndClearLastTarget()); | 430 EXPECT_EQ(&child1, event_dispatcher_delegate.GetAndClearLastTarget()); |
| 431 | 431 |
| 432 // Press on child2 with a different touch id. | 432 // Press on child2 with a different touch id. |
| 433 const ui::TouchEvent touch_event2( | 433 const ui::TouchEvent touch_event2(ui::ET_TOUCH_PRESSED, gfx::Point(54, 55), 2, |
| 434 ui::ET_TOUCH_PRESSED, gfx::PointF(54.f, 55.f), 2, base::TimeDelta()); | 434 base::TimeDelta()); |
| 435 dispatcher.OnEvent( | 435 dispatcher.OnEvent( |
| 436 mojom::Event::From(static_cast<const ui::Event&>(touch_event2))); | 436 mojom::Event::From(static_cast<const ui::Event&>(touch_event2))); |
| 437 EXPECT_EQ(&child2, event_dispatcher_delegate.GetAndClearLastTarget()); | 437 EXPECT_EQ(&child2, event_dispatcher_delegate.GetAndClearLastTarget()); |
| 438 | 438 |
| 439 // Drag over child1 with id 2, child2 should continue to get the drag. | 439 // Drag over child1 with id 2, child2 should continue to get the drag. |
| 440 const ui::TouchEvent drag_event2(ui::ET_TOUCH_MOVED, gfx::PointF(13.f, 14.f), | 440 const ui::TouchEvent drag_event2(ui::ET_TOUCH_MOVED, gfx::Point(13, 14), 2, |
| 441 2, base::TimeDelta()); | 441 base::TimeDelta()); |
| 442 dispatcher.OnEvent( | 442 dispatcher.OnEvent( |
| 443 mojom::Event::From(static_cast<const ui::Event&>(drag_event2))); | 443 mojom::Event::From(static_cast<const ui::Event&>(drag_event2))); |
| 444 EXPECT_EQ(&child2, event_dispatcher_delegate.GetAndClearLastTarget()); | 444 EXPECT_EQ(&child2, event_dispatcher_delegate.GetAndClearLastTarget()); |
| 445 | 445 |
| 446 // Drag again with id 1, child1 should continue to get it. | 446 // Drag again with id 1, child1 should continue to get it. |
| 447 dispatcher.OnEvent( | 447 dispatcher.OnEvent( |
| 448 mojom::Event::From(static_cast<const ui::Event&>(drag_event1))); | 448 mojom::Event::From(static_cast<const ui::Event&>(drag_event1))); |
| 449 EXPECT_EQ(&child1, event_dispatcher_delegate.GetAndClearLastTarget()); | 449 EXPECT_EQ(&child1, event_dispatcher_delegate.GetAndClearLastTarget()); |
| 450 | 450 |
| 451 // Release touch id 1, and click on 2. 2 should get it. | 451 // Release touch id 1, and click on 2. 2 should get it. |
| 452 const ui::TouchEvent touch_release( | 452 const ui::TouchEvent touch_release(ui::ET_TOUCH_RELEASED, gfx::Point(54, 55), |
| 453 ui::ET_TOUCH_RELEASED, gfx::PointF(54.f, 55.f), 1, base::TimeDelta()); | 453 1, base::TimeDelta()); |
| 454 dispatcher.OnEvent( | 454 dispatcher.OnEvent( |
| 455 mojom::Event::From(static_cast<const ui::Event&>(touch_release))); | 455 mojom::Event::From(static_cast<const ui::Event&>(touch_release))); |
| 456 EXPECT_EQ(&child1, event_dispatcher_delegate.GetAndClearLastTarget()); | 456 EXPECT_EQ(&child1, event_dispatcher_delegate.GetAndClearLastTarget()); |
| 457 const ui::TouchEvent touch_event3( | 457 const ui::TouchEvent touch_event3(ui::ET_TOUCH_PRESSED, gfx::Point(54, 55), 2, |
| 458 ui::ET_TOUCH_PRESSED, gfx::PointF(54.f, 55.f), 2, base::TimeDelta()); | 458 base::TimeDelta()); |
| 459 dispatcher.OnEvent( | 459 dispatcher.OnEvent( |
| 460 mojom::Event::From(static_cast<const ui::Event&>(touch_event3))); | 460 mojom::Event::From(static_cast<const ui::Event&>(touch_event3))); |
| 461 EXPECT_EQ(&child2, event_dispatcher_delegate.GetAndClearLastTarget()); | 461 EXPECT_EQ(&child2, event_dispatcher_delegate.GetAndClearLastTarget()); |
| 462 } | 462 } |
| 463 | 463 |
| 464 TEST(EventDispatcherTest, DestroyWindowWhileGettingEvents) { | 464 TEST(EventDispatcherTest, DestroyWindowWhileGettingEvents) { |
| 465 TestServerWindowDelegate window_delegate; | 465 TestServerWindowDelegate window_delegate; |
| 466 ServerWindow root(&window_delegate, WindowId(1, 2)); | 466 ServerWindow root(&window_delegate, WindowId(1, 2)); |
| 467 window_delegate.set_root_window(&root); | 467 window_delegate.set_root_window(&root); |
| 468 root.SetVisible(true); | 468 root.SetVisible(true); |
| 469 | 469 |
| 470 scoped_ptr<ServerWindow> child( | 470 scoped_ptr<ServerWindow> child( |
| 471 new ServerWindow(&window_delegate, WindowId(1, 3))); | 471 new ServerWindow(&window_delegate, WindowId(1, 3))); |
| 472 root.Add(child.get()); | 472 root.Add(child.get()); |
| 473 child->SetVisible(true); | 473 child->SetVisible(true); |
| 474 | 474 |
| 475 root.SetBounds(gfx::Rect(0, 0, 100, 100)); | 475 root.SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 476 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 476 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 477 | 477 |
| 478 TestEventDispatcherDelegate event_dispatcher_delegate(&root); | 478 TestEventDispatcherDelegate event_dispatcher_delegate(&root); |
| 479 EventDispatcher dispatcher(&event_dispatcher_delegate); | 479 EventDispatcher dispatcher(&event_dispatcher_delegate); |
| 480 dispatcher.set_root(&root); | 480 dispatcher.set_root(&root); |
| 481 | 481 |
| 482 // Press on child. | 482 // Press on child. |
| 483 const ui::TouchEvent touch_event1( | 483 const ui::TouchEvent touch_event1(ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), 1, |
| 484 ui::ET_TOUCH_PRESSED, gfx::PointF(12.f, 13.f), 1, base::TimeDelta()); | 484 base::TimeDelta()); |
| 485 dispatcher.OnEvent( | 485 dispatcher.OnEvent( |
| 486 mojom::Event::From(static_cast<const ui::Event&>(touch_event1))); | 486 mojom::Event::From(static_cast<const ui::Event&>(touch_event1))); |
| 487 EXPECT_EQ(child.get(), event_dispatcher_delegate.GetAndClearLastTarget()); | 487 EXPECT_EQ(child.get(), event_dispatcher_delegate.GetAndClearLastTarget()); |
| 488 | 488 |
| 489 event_dispatcher_delegate.GetAndClearLastDispatchedEvent(); | 489 event_dispatcher_delegate.GetAndClearLastDispatchedEvent(); |
| 490 | 490 |
| 491 // Delete child, and continue the drag. Event should not be dispatched. | 491 // Delete child, and continue the drag. Event should not be dispatched. |
| 492 child.reset(); | 492 child.reset(); |
| 493 | 493 |
| 494 const ui::TouchEvent drag_event1(ui::ET_TOUCH_MOVED, gfx::PointF(53.f, 54.f), | 494 const ui::TouchEvent drag_event1(ui::ET_TOUCH_MOVED, gfx::Point(53, 54), 1, |
| 495 1, base::TimeDelta()); | 495 base::TimeDelta()); |
| 496 dispatcher.OnEvent( | 496 dispatcher.OnEvent( |
| 497 mojom::Event::From(static_cast<const ui::Event&>(drag_event1))); | 497 mojom::Event::From(static_cast<const ui::Event&>(drag_event1))); |
| 498 EXPECT_EQ(nullptr, event_dispatcher_delegate.GetAndClearLastTarget()); | 498 EXPECT_EQ(nullptr, event_dispatcher_delegate.GetAndClearLastTarget()); |
| 499 EXPECT_EQ(nullptr, | 499 EXPECT_EQ(nullptr, |
| 500 event_dispatcher_delegate.GetAndClearLastDispatchedEvent().get()); | 500 event_dispatcher_delegate.GetAndClearLastDispatchedEvent().get()); |
| 501 } | 501 } |
| 502 | 502 |
| 503 } // namespace ws | 503 } // namespace ws |
| 504 } // namespace mus | 504 } // namespace mus |
| OLD | NEW |