Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

Side by Side Diff: ui/views/widget/widget_interactive_uitest.cc

Issue 2786693002: Add PointerDetails to ui::MouseEvent's constructors (Closed)
Patch Set: mouse event constructor Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 Widget* toplevel = CreateTopLevelFramelessPlatformWidget(); 329 Widget* toplevel = CreateTopLevelFramelessPlatformWidget();
330 View* container = new View; 330 View* container = new View;
331 toplevel->SetContentsView(container); 331 toplevel->SetContentsView(container);
332 332
333 EXPECT_FALSE(toplevel->HasCapture()); 333 EXPECT_FALSE(toplevel->HasCapture());
334 toplevel->SetCapture(NULL); 334 toplevel->SetCapture(NULL);
335 EXPECT_TRUE(toplevel->HasCapture()); 335 EXPECT_TRUE(toplevel->HasCapture());
336 336
337 // By default, mouse release removes capture. 337 // By default, mouse release removes capture.
338 gfx::Point click_location(45, 15); 338 gfx::Point click_location(45, 15);
339 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, click_location, click_location, 339 ui::MouseEvent release(
340 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 340 ui::ET_MOUSE_RELEASED, click_location, click_location,
341 ui::EF_LEFT_MOUSE_BUTTON); 341 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
342 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
342 toplevel->OnMouseEvent(&release); 343 toplevel->OnMouseEvent(&release);
343 EXPECT_FALSE(toplevel->HasCapture()); 344 EXPECT_FALSE(toplevel->HasCapture());
344 345
345 // Now a mouse release shouldn't remove capture. 346 // Now a mouse release shouldn't remove capture.
346 toplevel->set_auto_release_capture(false); 347 toplevel->set_auto_release_capture(false);
347 toplevel->SetCapture(NULL); 348 toplevel->SetCapture(NULL);
348 EXPECT_TRUE(toplevel->HasCapture()); 349 EXPECT_TRUE(toplevel->HasCapture());
349 toplevel->OnMouseEvent(&release); 350 toplevel->OnMouseEvent(&release);
350 EXPECT_TRUE(toplevel->HasCapture()); 351 EXPECT_TRUE(toplevel->HasCapture());
351 toplevel->ReleaseCapture(); 352 toplevel->ReleaseCapture();
(...skipping 23 matching lines...) Expand all
375 ui::GestureEvent tap_down(15, 15, 0, base::TimeTicks(), 376 ui::GestureEvent tap_down(15, 15, 0, base::TimeTicks(),
376 ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN)); 377 ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN));
377 ui::GestureEvent end(15, 15, 0, base::TimeTicks(), 378 ui::GestureEvent end(15, 15, 0, base::TimeTicks(),
378 ui::GestureEventDetails(ui::ET_GESTURE_END)); 379 ui::GestureEventDetails(ui::ET_GESTURE_END));
379 toplevel->OnGestureEvent(&tap_down); 380 toplevel->OnGestureEvent(&tap_down);
380 381
381 // Now try to click on |mouse|. Since |gesture| will have capture, |mouse| 382 // Now try to click on |mouse|. Since |gesture| will have capture, |mouse|
382 // will not receive the event. 383 // will not receive the event.
383 gfx::Point click_location(45, 15); 384 gfx::Point click_location(45, 15);
384 385
385 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, click_location, click_location, 386 ui::MouseEvent press(
386 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 387 ui::ET_MOUSE_PRESSED, click_location, click_location,
387 ui::EF_LEFT_MOUSE_BUTTON); 388 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
388 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, click_location, click_location, 389 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
389 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 390 ui::MouseEvent release(
390 ui::EF_LEFT_MOUSE_BUTTON); 391 ui::ET_MOUSE_RELEASED, click_location, click_location,
392 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
393 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
391 394
392 EXPECT_TRUE(toplevel->HasCapture()); 395 EXPECT_TRUE(toplevel->HasCapture());
393 396
394 toplevel->OnMouseEvent(&press); 397 toplevel->OnMouseEvent(&press);
395 toplevel->OnMouseEvent(&release); 398 toplevel->OnMouseEvent(&release);
396 EXPECT_EQ(0, mouse->pressed()); 399 EXPECT_EQ(0, mouse->pressed());
397 400
398 EXPECT_FALSE(toplevel->HasCapture()); 401 EXPECT_FALSE(toplevel->HasCapture());
399 402
400 // The end of the gesture should release the capture, and pressing on |mouse| 403 // The end of the gesture should release the capture, and pressing on |mouse|
(...skipping 25 matching lines...) Expand all
426 View* container = new NestedLoopCaptureView(second); 429 View* container = new NestedLoopCaptureView(second);
427 first->SetContentsView(container); 430 first->SetContentsView(container);
428 431
429 second->SetContentsView(new ExitLoopOnRelease()); 432 second->SetContentsView(new ExitLoopOnRelease());
430 433
431 first->SetSize(gfx::Size(100, 100)); 434 first->SetSize(gfx::Size(100, 100));
432 first->Show(); 435 first->Show();
433 436
434 gfx::Point location(20, 20); 437 gfx::Point location(20, 20);
435 base::ThreadTaskRunnerHandle::Get()->PostTask( 438 base::ThreadTaskRunnerHandle::Get()->PostTask(
436 FROM_HERE, base::Bind(&Widget::OnMouseEvent, base::Unretained(second), 439 FROM_HERE,
437 base::Owned(new ui::MouseEvent( 440 base::Bind(
438 ui::ET_MOUSE_RELEASED, location, location, 441 &Widget::OnMouseEvent, base::Unretained(second),
439 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 442 base::Owned(new ui::MouseEvent(
440 ui::EF_LEFT_MOUSE_BUTTON)))); 443 ui::ET_MOUSE_RELEASED, location, location, ui::EventTimeForNow(),
441 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, location, location, 444 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
442 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 445 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)))));
443 ui::EF_LEFT_MOUSE_BUTTON); 446 ui::MouseEvent press(
447 ui::ET_MOUSE_PRESSED, location, location, ui::EventTimeForNow(),
448 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
449 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
444 first->OnMouseEvent(&press); 450 first->OnMouseEvent(&press);
445 EXPECT_FALSE(first->HasCapture()); 451 EXPECT_FALSE(first->HasCapture());
446 first->Close(); 452 first->Close();
447 RunPendingMessages(); 453 RunPendingMessages();
448 } 454 }
449 455
450 // Tests some grab/ungrab events. 456 // Tests some grab/ungrab events.
451 // TODO(estade): can this be enabled now that this is an interactive ui test? 457 // TODO(estade): can this be enabled now that this is an interactive ui test?
452 TEST_F(WidgetTestInteractive, DISABLED_GrabUngrab) { 458 TEST_F(WidgetTestInteractive, DISABLED_GrabUngrab) {
453 Widget* toplevel = CreateTopLevelPlatformWidget(); 459 Widget* toplevel = CreateTopLevelPlatformWidget();
(...skipping 10 matching lines...) Expand all
464 child2->SetBounds(gfx::Rect(200, 10, 200, 200)); 470 child2->SetBounds(gfx::Rect(200, 10, 200, 200));
465 view = new MouseView(); 471 view = new MouseView();
466 view->SetBounds(0, 0, 200, 200); 472 view->SetBounds(0, 0, 200, 200);
467 child2->GetRootView()->AddChildView(view); 473 child2->GetRootView()->AddChildView(view);
468 474
469 toplevel->Show(); 475 toplevel->Show();
470 RunPendingMessages(); 476 RunPendingMessages();
471 477
472 // Click on child1 478 // Click on child1
473 gfx::Point p1(45, 45); 479 gfx::Point p1(45, 45);
474 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, p1, p1, ui::EventTimeForNow(), 480 ui::MouseEvent pressed(
475 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); 481 ui::ET_MOUSE_PRESSED, p1, p1, ui::EventTimeForNow(),
482 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
483 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
476 toplevel->OnMouseEvent(&pressed); 484 toplevel->OnMouseEvent(&pressed);
477 485
478 EXPECT_TRUE(toplevel->HasCapture()); 486 EXPECT_TRUE(toplevel->HasCapture());
479 EXPECT_TRUE(child1->HasCapture()); 487 EXPECT_TRUE(child1->HasCapture());
480 EXPECT_FALSE(child2->HasCapture()); 488 EXPECT_FALSE(child2->HasCapture());
481 489
482 ui::MouseEvent released(ui::ET_MOUSE_RELEASED, p1, p1, ui::EventTimeForNow(), 490 ui::MouseEvent released(
483 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); 491 ui::ET_MOUSE_RELEASED, p1, p1, ui::EventTimeForNow(),
492 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
493 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
484 toplevel->OnMouseEvent(&released); 494 toplevel->OnMouseEvent(&released);
485 495
486 EXPECT_FALSE(toplevel->HasCapture()); 496 EXPECT_FALSE(toplevel->HasCapture());
487 EXPECT_FALSE(child1->HasCapture()); 497 EXPECT_FALSE(child1->HasCapture());
488 EXPECT_FALSE(child2->HasCapture()); 498 EXPECT_FALSE(child2->HasCapture());
489 499
490 RunPendingMessages(); 500 RunPendingMessages();
491 501
492 // Click on child2 502 // Click on child2
493 gfx::Point p2(315, 45); 503 gfx::Point p2(315, 45);
494 ui::MouseEvent pressed2(ui::ET_MOUSE_PRESSED, p2, p2, ui::EventTimeForNow(), 504 ui::MouseEvent pressed2(
495 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); 505 ui::ET_MOUSE_PRESSED, p2, p2, ui::EventTimeForNow(),
506 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
507 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
496 toplevel->OnMouseEvent(&pressed2); 508 toplevel->OnMouseEvent(&pressed2);
497 EXPECT_TRUE(pressed2.handled()); 509 EXPECT_TRUE(pressed2.handled());
498 EXPECT_TRUE(toplevel->HasCapture()); 510 EXPECT_TRUE(toplevel->HasCapture());
499 EXPECT_TRUE(child2->HasCapture()); 511 EXPECT_TRUE(child2->HasCapture());
500 EXPECT_FALSE(child1->HasCapture()); 512 EXPECT_FALSE(child1->HasCapture());
501 513
502 ui::MouseEvent released2(ui::ET_MOUSE_RELEASED, p2, p2, ui::EventTimeForNow(), 514 ui::MouseEvent released2(
503 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); 515 ui::ET_MOUSE_RELEASED, p2, p2, ui::EventTimeForNow(),
516 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
517 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
504 toplevel->OnMouseEvent(&released2); 518 toplevel->OnMouseEvent(&released2);
505 EXPECT_FALSE(toplevel->HasCapture()); 519 EXPECT_FALSE(toplevel->HasCapture());
506 EXPECT_FALSE(child1->HasCapture()); 520 EXPECT_FALSE(child1->HasCapture());
507 EXPECT_FALSE(child2->HasCapture()); 521 EXPECT_FALSE(child2->HasCapture());
508 522
509 toplevel->CloseNow(); 523 toplevel->CloseNow();
510 } 524 }
511 525
512 // Tests mouse move outside of the window into the "resize controller" and back 526 // Tests mouse move outside of the window into the "resize controller" and back
513 // will still generate an OnMouseEntered and OnMouseExited event.. 527 // will still generate an OnMouseEntered and OnMouseExited event..
514 TEST_F(WidgetTestInteractive, CheckResizeControllerEvents) { 528 TEST_F(WidgetTestInteractive, CheckResizeControllerEvents) {
515 Widget* toplevel = CreateTopLevelPlatformWidget(); 529 Widget* toplevel = CreateTopLevelPlatformWidget();
516 530
517 toplevel->SetBounds(gfx::Rect(0, 0, 100, 100)); 531 toplevel->SetBounds(gfx::Rect(0, 0, 100, 100));
518 532
519 MouseView* view = new MouseView(); 533 MouseView* view = new MouseView();
520 view->SetBounds(90, 90, 10, 10); 534 view->SetBounds(90, 90, 10, 10);
521 toplevel->GetRootView()->AddChildView(view); 535 toplevel->GetRootView()->AddChildView(view);
522 536
523 toplevel->Show(); 537 toplevel->Show();
524 RunPendingMessages(); 538 RunPendingMessages();
525 539
526 // Move to an outside position. 540 // Move to an outside position.
527 gfx::Point p1(200, 200); 541 gfx::Point p1(200, 200);
528 ui::MouseEvent moved_out(ui::ET_MOUSE_MOVED, p1, p1, ui::EventTimeForNow(), 542 ui::MouseEvent moved_out(
529 ui::EF_NONE, ui::EF_NONE); 543 ui::ET_MOUSE_MOVED, p1, p1, ui::EventTimeForNow(), ui::EF_NONE,
544 ui::EF_NONE,
545 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
530 toplevel->OnMouseEvent(&moved_out); 546 toplevel->OnMouseEvent(&moved_out);
531 EXPECT_EQ(0, view->EnteredCalls()); 547 EXPECT_EQ(0, view->EnteredCalls());
532 EXPECT_EQ(0, view->ExitedCalls()); 548 EXPECT_EQ(0, view->ExitedCalls());
533 549
534 // Move onto the active view. 550 // Move onto the active view.
535 gfx::Point p2(95, 95); 551 gfx::Point p2(95, 95);
536 ui::MouseEvent moved_over(ui::ET_MOUSE_MOVED, p2, p2, ui::EventTimeForNow(), 552 ui::MouseEvent moved_over(
537 ui::EF_NONE, ui::EF_NONE); 553 ui::ET_MOUSE_MOVED, p2, p2, ui::EventTimeForNow(), ui::EF_NONE,
554 ui::EF_NONE,
555 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
538 toplevel->OnMouseEvent(&moved_over); 556 toplevel->OnMouseEvent(&moved_over);
539 EXPECT_EQ(1, view->EnteredCalls()); 557 EXPECT_EQ(1, view->EnteredCalls());
540 EXPECT_EQ(0, view->ExitedCalls()); 558 EXPECT_EQ(0, view->ExitedCalls());
541 559
542 // Move onto the outer resizing border. 560 // Move onto the outer resizing border.
543 gfx::Point p3(102, 95); 561 gfx::Point p3(102, 95);
544 ui::MouseEvent moved_resizer(ui::ET_MOUSE_MOVED, p3, p3, 562 ui::MouseEvent moved_resizer(
545 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); 563 ui::ET_MOUSE_MOVED, p3, p3, ui::EventTimeForNow(), ui::EF_NONE,
564 ui::EF_NONE,
565 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
546 toplevel->OnMouseEvent(&moved_resizer); 566 toplevel->OnMouseEvent(&moved_resizer);
547 EXPECT_EQ(0, view->EnteredCalls()); 567 EXPECT_EQ(0, view->EnteredCalls());
548 EXPECT_EQ(1, view->ExitedCalls()); 568 EXPECT_EQ(1, view->ExitedCalls());
549 569
550 // Move onto the view again. 570 // Move onto the view again.
551 toplevel->OnMouseEvent(&moved_over); 571 toplevel->OnMouseEvent(&moved_over);
552 EXPECT_EQ(1, view->EnteredCalls()); 572 EXPECT_EQ(1, view->EnteredCalls());
553 EXPECT_EQ(0, view->ExitedCalls()); 573 EXPECT_EQ(0, view->ExitedCalls());
554 574
555 RunPendingMessages(); 575 RunPendingMessages();
(...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after
1596 1616
1597 // Set capture to widget2 and verity it gets it. 1617 // Set capture to widget2 and verity it gets it.
1598 widget2.SetCapture(widget2.GetRootView()); 1618 widget2.SetCapture(widget2.GetRootView());
1599 EXPECT_FALSE(widget1.HasCapture()); 1619 EXPECT_FALSE(widget1.HasCapture());
1600 EXPECT_TRUE(widget2.HasCapture()); 1620 EXPECT_TRUE(widget2.HasCapture());
1601 1621
1602 widget1.GetAndClearGotMouseEvent(); 1622 widget1.GetAndClearGotMouseEvent();
1603 widget2.GetAndClearGotMouseEvent(); 1623 widget2.GetAndClearGotMouseEvent();
1604 // Send a mouse event to the RootWindow associated with |widget1|. Even though 1624 // Send a mouse event to the RootWindow associated with |widget1|. Even though
1605 // |widget2| has capture, |widget1| should still get the event. 1625 // |widget2| has capture, |widget1| should still get the event.
1606 ui::MouseEvent mouse_event(ui::ET_MOUSE_EXITED, gfx::Point(), gfx::Point(), 1626 ui::MouseEvent mouse_event(
1607 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); 1627 ui::ET_MOUSE_EXITED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(),
1628 ui::EF_NONE, ui::EF_NONE,
1629 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
1608 ui::EventDispatchDetails details = 1630 ui::EventDispatchDetails details =
1609 widget1.GetNativeWindow()->GetHost()->event_sink()->OnEventFromSource( 1631 widget1.GetNativeWindow()->GetHost()->event_sink()->OnEventFromSource(
1610 &mouse_event); 1632 &mouse_event);
1611 ASSERT_FALSE(details.dispatcher_destroyed); 1633 ASSERT_FALSE(details.dispatcher_destroyed);
1612 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); 1634 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent());
1613 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); 1635 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent());
1614 } 1636 }
1615 #endif // defined(OS_WIN) 1637 #endif // defined(OS_WIN)
1616 1638
1617 class WidgetInputMethodInteractiveTest : public WidgetTestInteractive { 1639 class WidgetInputMethodInteractiveTest : public WidgetTestInteractive {
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1807 1829
1808 ui::KeyEvent key_event2(key_event); 1830 ui::KeyEvent key_event2(key_event);
1809 widget->OnKeyEvent(&key_event2); 1831 widget->OnKeyEvent(&key_event2);
1810 EXPECT_FALSE(key_event2.stopped_propagation()); 1832 EXPECT_FALSE(key_event2.stopped_propagation());
1811 1833
1812 widget->CloseNow(); 1834 widget->CloseNow();
1813 } 1835 }
1814 1836
1815 } // namespace test 1837 } // namespace test
1816 } // namespace views 1838 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698