OLD | NEW |
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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 Widget* toplevel = CreateTopLevelFramelessPlatformWidget(); | 360 Widget* toplevel = CreateTopLevelFramelessPlatformWidget(); |
361 View* container = new View; | 361 View* container = new View; |
362 toplevel->SetContentsView(container); | 362 toplevel->SetContentsView(container); |
363 | 363 |
364 EXPECT_FALSE(toplevel->HasCapture()); | 364 EXPECT_FALSE(toplevel->HasCapture()); |
365 toplevel->SetCapture(NULL); | 365 toplevel->SetCapture(NULL); |
366 EXPECT_TRUE(toplevel->HasCapture()); | 366 EXPECT_TRUE(toplevel->HasCapture()); |
367 | 367 |
368 // By default, mouse release removes capture. | 368 // By default, mouse release removes capture. |
369 gfx::Point click_location(45, 15); | 369 gfx::Point click_location(45, 15); |
370 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, click_location, click_location, | 370 ui::MouseEvent release( |
371 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 371 ui::ET_MOUSE_RELEASED, click_location, click_location, |
372 ui::EF_LEFT_MOUSE_BUTTON); | 372 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 373 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
373 toplevel->OnMouseEvent(&release); | 374 toplevel->OnMouseEvent(&release); |
374 EXPECT_FALSE(toplevel->HasCapture()); | 375 EXPECT_FALSE(toplevel->HasCapture()); |
375 | 376 |
376 // Now a mouse release shouldn't remove capture. | 377 // Now a mouse release shouldn't remove capture. |
377 toplevel->set_auto_release_capture(false); | 378 toplevel->set_auto_release_capture(false); |
378 toplevel->SetCapture(NULL); | 379 toplevel->SetCapture(NULL); |
379 EXPECT_TRUE(toplevel->HasCapture()); | 380 EXPECT_TRUE(toplevel->HasCapture()); |
380 toplevel->OnMouseEvent(&release); | 381 toplevel->OnMouseEvent(&release); |
381 EXPECT_TRUE(toplevel->HasCapture()); | 382 EXPECT_TRUE(toplevel->HasCapture()); |
382 toplevel->ReleaseCapture(); | 383 toplevel->ReleaseCapture(); |
(...skipping 29 matching lines...) Expand all Loading... |
412 15, | 413 15, |
413 0, | 414 0, |
414 base::TimeDelta(), | 415 base::TimeDelta(), |
415 ui::GestureEventDetails(ui::ET_GESTURE_END)); | 416 ui::GestureEventDetails(ui::ET_GESTURE_END)); |
416 toplevel->OnGestureEvent(&tap_down); | 417 toplevel->OnGestureEvent(&tap_down); |
417 | 418 |
418 // Now try to click on |mouse|. Since |gesture| will have capture, |mouse| | 419 // Now try to click on |mouse|. Since |gesture| will have capture, |mouse| |
419 // will not receive the event. | 420 // will not receive the event. |
420 gfx::Point click_location(45, 15); | 421 gfx::Point click_location(45, 15); |
421 | 422 |
422 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, click_location, click_location, | 423 ui::MouseEvent press( |
423 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 424 ui::ET_MOUSE_PRESSED, click_location, click_location, |
424 ui::EF_LEFT_MOUSE_BUTTON); | 425 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
425 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, click_location, click_location, | 426 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
426 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 427 ui::MouseEvent release( |
427 ui::EF_LEFT_MOUSE_BUTTON); | 428 ui::ET_MOUSE_RELEASED, click_location, click_location, |
| 429 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 430 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
428 | 431 |
429 EXPECT_TRUE(toplevel->HasCapture()); | 432 EXPECT_TRUE(toplevel->HasCapture()); |
430 | 433 |
431 toplevel->OnMouseEvent(&press); | 434 toplevel->OnMouseEvent(&press); |
432 toplevel->OnMouseEvent(&release); | 435 toplevel->OnMouseEvent(&release); |
433 EXPECT_EQ(0, mouse->pressed()); | 436 EXPECT_EQ(0, mouse->pressed()); |
434 | 437 |
435 EXPECT_FALSE(toplevel->HasCapture()); | 438 EXPECT_FALSE(toplevel->HasCapture()); |
436 | 439 |
437 // The end of the gesture should release the capture, and pressing on |mouse| | 440 // The end of the gesture should release the capture, and pressing on |mouse| |
(...skipping 25 matching lines...) Expand all Loading... |
463 View* container = new NestedLoopCaptureView(second); | 466 View* container = new NestedLoopCaptureView(second); |
464 first->SetContentsView(container); | 467 first->SetContentsView(container); |
465 | 468 |
466 second->SetContentsView(new ExitLoopOnRelease()); | 469 second->SetContentsView(new ExitLoopOnRelease()); |
467 | 470 |
468 first->SetSize(gfx::Size(100, 100)); | 471 first->SetSize(gfx::Size(100, 100)); |
469 first->Show(); | 472 first->Show(); |
470 | 473 |
471 gfx::Point location(20, 20); | 474 gfx::Point location(20, 20); |
472 base::MessageLoop::current()->PostTask( | 475 base::MessageLoop::current()->PostTask( |
473 FROM_HERE, base::Bind(&Widget::OnMouseEvent, base::Unretained(second), | 476 FROM_HERE, |
474 base::Owned(new ui::MouseEvent( | 477 base::Bind( |
475 ui::ET_MOUSE_RELEASED, location, location, | 478 &Widget::OnMouseEvent, base::Unretained(second), |
476 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 479 base::Owned(new ui::MouseEvent( |
477 ui::EF_LEFT_MOUSE_BUTTON)))); | 480 ui::ET_MOUSE_RELEASED, location, location, ui::EventTimeForNow(), |
478 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, location, location, | 481 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
479 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 482 ui::PointerEventDetails( |
480 ui::EF_LEFT_MOUSE_BUTTON); | 483 ui::EventPointerType::POINTER_TYPE_MOUSE))))); |
| 484 ui::MouseEvent press( |
| 485 ui::ET_MOUSE_PRESSED, location, location, ui::EventTimeForNow(), |
| 486 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 487 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
481 first->OnMouseEvent(&press); | 488 first->OnMouseEvent(&press); |
482 EXPECT_FALSE(first->HasCapture()); | 489 EXPECT_FALSE(first->HasCapture()); |
483 first->Close(); | 490 first->Close(); |
484 RunPendingMessages(); | 491 RunPendingMessages(); |
485 } | 492 } |
486 | 493 |
487 // Tests some grab/ungrab events. | 494 // Tests some grab/ungrab events. |
488 // TODO(estade): can this be enabled now that this is an interactive ui test? | 495 // TODO(estade): can this be enabled now that this is an interactive ui test? |
489 TEST_F(WidgetTestInteractive, DISABLED_GrabUngrab) { | 496 TEST_F(WidgetTestInteractive, DISABLED_GrabUngrab) { |
490 Widget* toplevel = CreateTopLevelPlatformWidget(); | 497 Widget* toplevel = CreateTopLevelPlatformWidget(); |
(...skipping 10 matching lines...) Expand all Loading... |
501 child2->SetBounds(gfx::Rect(200, 10, 200, 200)); | 508 child2->SetBounds(gfx::Rect(200, 10, 200, 200)); |
502 view = new MouseView(); | 509 view = new MouseView(); |
503 view->SetBounds(0, 0, 200, 200); | 510 view->SetBounds(0, 0, 200, 200); |
504 child2->GetRootView()->AddChildView(view); | 511 child2->GetRootView()->AddChildView(view); |
505 | 512 |
506 toplevel->Show(); | 513 toplevel->Show(); |
507 RunPendingMessages(); | 514 RunPendingMessages(); |
508 | 515 |
509 // Click on child1 | 516 // Click on child1 |
510 gfx::Point p1(45, 45); | 517 gfx::Point p1(45, 45); |
511 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, p1, p1, ui::EventTimeForNow(), | 518 ui::MouseEvent pressed( |
512 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 519 ui::ET_MOUSE_PRESSED, p1, p1, ui::EventTimeForNow(), |
| 520 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 521 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
513 toplevel->OnMouseEvent(&pressed); | 522 toplevel->OnMouseEvent(&pressed); |
514 | 523 |
515 EXPECT_TRUE(toplevel->HasCapture()); | 524 EXPECT_TRUE(toplevel->HasCapture()); |
516 EXPECT_TRUE(child1->HasCapture()); | 525 EXPECT_TRUE(child1->HasCapture()); |
517 EXPECT_FALSE(child2->HasCapture()); | 526 EXPECT_FALSE(child2->HasCapture()); |
518 | 527 |
519 ui::MouseEvent released(ui::ET_MOUSE_RELEASED, p1, p1, ui::EventTimeForNow(), | 528 ui::MouseEvent released( |
520 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 529 ui::ET_MOUSE_RELEASED, p1, p1, ui::EventTimeForNow(), |
| 530 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 531 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
521 toplevel->OnMouseEvent(&released); | 532 toplevel->OnMouseEvent(&released); |
522 | 533 |
523 EXPECT_FALSE(toplevel->HasCapture()); | 534 EXPECT_FALSE(toplevel->HasCapture()); |
524 EXPECT_FALSE(child1->HasCapture()); | 535 EXPECT_FALSE(child1->HasCapture()); |
525 EXPECT_FALSE(child2->HasCapture()); | 536 EXPECT_FALSE(child2->HasCapture()); |
526 | 537 |
527 RunPendingMessages(); | 538 RunPendingMessages(); |
528 | 539 |
529 // Click on child2 | 540 // Click on child2 |
530 gfx::Point p2(315, 45); | 541 gfx::Point p2(315, 45); |
531 ui::MouseEvent pressed2(ui::ET_MOUSE_PRESSED, p2, p2, ui::EventTimeForNow(), | 542 ui::MouseEvent pressed2( |
532 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 543 ui::ET_MOUSE_PRESSED, p2, p2, ui::EventTimeForNow(), |
| 544 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 545 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
533 toplevel->OnMouseEvent(&pressed2); | 546 toplevel->OnMouseEvent(&pressed2); |
534 EXPECT_TRUE(pressed2.handled()); | 547 EXPECT_TRUE(pressed2.handled()); |
535 EXPECT_TRUE(toplevel->HasCapture()); | 548 EXPECT_TRUE(toplevel->HasCapture()); |
536 EXPECT_TRUE(child2->HasCapture()); | 549 EXPECT_TRUE(child2->HasCapture()); |
537 EXPECT_FALSE(child1->HasCapture()); | 550 EXPECT_FALSE(child1->HasCapture()); |
538 | 551 |
539 ui::MouseEvent released2(ui::ET_MOUSE_RELEASED, p2, p2, ui::EventTimeForNow(), | 552 ui::MouseEvent released2( |
540 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 553 ui::ET_MOUSE_RELEASED, p2, p2, ui::EventTimeForNow(), |
| 554 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 555 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
541 toplevel->OnMouseEvent(&released2); | 556 toplevel->OnMouseEvent(&released2); |
542 EXPECT_FALSE(toplevel->HasCapture()); | 557 EXPECT_FALSE(toplevel->HasCapture()); |
543 EXPECT_FALSE(child1->HasCapture()); | 558 EXPECT_FALSE(child1->HasCapture()); |
544 EXPECT_FALSE(child2->HasCapture()); | 559 EXPECT_FALSE(child2->HasCapture()); |
545 | 560 |
546 toplevel->CloseNow(); | 561 toplevel->CloseNow(); |
547 } | 562 } |
548 | 563 |
549 // Tests mouse move outside of the window into the "resize controller" and back | 564 // Tests mouse move outside of the window into the "resize controller" and back |
550 // will still generate an OnMouseEntered and OnMouseExited event.. | 565 // will still generate an OnMouseEntered and OnMouseExited event.. |
551 TEST_F(WidgetTestInteractive, CheckResizeControllerEvents) { | 566 TEST_F(WidgetTestInteractive, CheckResizeControllerEvents) { |
552 Widget* toplevel = CreateTopLevelPlatformWidget(); | 567 Widget* toplevel = CreateTopLevelPlatformWidget(); |
553 | 568 |
554 toplevel->SetBounds(gfx::Rect(0, 0, 100, 100)); | 569 toplevel->SetBounds(gfx::Rect(0, 0, 100, 100)); |
555 | 570 |
556 MouseView* view = new MouseView(); | 571 MouseView* view = new MouseView(); |
557 view->SetBounds(90, 90, 10, 10); | 572 view->SetBounds(90, 90, 10, 10); |
558 toplevel->GetRootView()->AddChildView(view); | 573 toplevel->GetRootView()->AddChildView(view); |
559 | 574 |
560 toplevel->Show(); | 575 toplevel->Show(); |
561 RunPendingMessages(); | 576 RunPendingMessages(); |
562 | 577 |
563 // Move to an outside position. | 578 // Move to an outside position. |
564 gfx::Point p1(200, 200); | 579 gfx::Point p1(200, 200); |
565 ui::MouseEvent moved_out(ui::ET_MOUSE_MOVED, p1, p1, ui::EventTimeForNow(), | 580 ui::MouseEvent moved_out( |
566 ui::EF_NONE, ui::EF_NONE); | 581 ui::ET_MOUSE_MOVED, p1, p1, ui::EventTimeForNow(), ui::EF_NONE, |
| 582 ui::EF_NONE, |
| 583 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
567 toplevel->OnMouseEvent(&moved_out); | 584 toplevel->OnMouseEvent(&moved_out); |
568 EXPECT_EQ(0, view->EnteredCalls()); | 585 EXPECT_EQ(0, view->EnteredCalls()); |
569 EXPECT_EQ(0, view->ExitedCalls()); | 586 EXPECT_EQ(0, view->ExitedCalls()); |
570 | 587 |
571 // Move onto the active view. | 588 // Move onto the active view. |
572 gfx::Point p2(95, 95); | 589 gfx::Point p2(95, 95); |
573 ui::MouseEvent moved_over(ui::ET_MOUSE_MOVED, p2, p2, ui::EventTimeForNow(), | 590 ui::MouseEvent moved_over( |
574 ui::EF_NONE, ui::EF_NONE); | 591 ui::ET_MOUSE_MOVED, p2, p2, ui::EventTimeForNow(), ui::EF_NONE, |
| 592 ui::EF_NONE, |
| 593 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
575 toplevel->OnMouseEvent(&moved_over); | 594 toplevel->OnMouseEvent(&moved_over); |
576 EXPECT_EQ(1, view->EnteredCalls()); | 595 EXPECT_EQ(1, view->EnteredCalls()); |
577 EXPECT_EQ(0, view->ExitedCalls()); | 596 EXPECT_EQ(0, view->ExitedCalls()); |
578 | 597 |
579 // Move onto the outer resizing border. | 598 // Move onto the outer resizing border. |
580 gfx::Point p3(102, 95); | 599 gfx::Point p3(102, 95); |
581 ui::MouseEvent moved_resizer(ui::ET_MOUSE_MOVED, p3, p3, | 600 ui::MouseEvent moved_resizer( |
582 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 601 ui::ET_MOUSE_MOVED, p3, p3, ui::EventTimeForNow(), ui::EF_NONE, |
| 602 ui::EF_NONE, |
| 603 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
583 toplevel->OnMouseEvent(&moved_resizer); | 604 toplevel->OnMouseEvent(&moved_resizer); |
584 EXPECT_EQ(0, view->EnteredCalls()); | 605 EXPECT_EQ(0, view->EnteredCalls()); |
585 EXPECT_EQ(1, view->ExitedCalls()); | 606 EXPECT_EQ(1, view->ExitedCalls()); |
586 | 607 |
587 // Move onto the view again. | 608 // Move onto the view again. |
588 toplevel->OnMouseEvent(&moved_over); | 609 toplevel->OnMouseEvent(&moved_over); |
589 EXPECT_EQ(1, view->EnteredCalls()); | 610 EXPECT_EQ(1, view->EnteredCalls()); |
590 EXPECT_EQ(0, view->ExitedCalls()); | 611 EXPECT_EQ(0, view->ExitedCalls()); |
591 | 612 |
592 RunPendingMessages(); | 613 RunPendingMessages(); |
(...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1408 | 1429 |
1409 // Set capture to widget2 and verity it gets it. | 1430 // Set capture to widget2 and verity it gets it. |
1410 widget2.SetCapture(widget2.GetRootView()); | 1431 widget2.SetCapture(widget2.GetRootView()); |
1411 EXPECT_FALSE(widget1.HasCapture()); | 1432 EXPECT_FALSE(widget1.HasCapture()); |
1412 EXPECT_TRUE(widget2.HasCapture()); | 1433 EXPECT_TRUE(widget2.HasCapture()); |
1413 | 1434 |
1414 widget1.GetAndClearGotMouseEvent(); | 1435 widget1.GetAndClearGotMouseEvent(); |
1415 widget2.GetAndClearGotMouseEvent(); | 1436 widget2.GetAndClearGotMouseEvent(); |
1416 // Send a mouse event to the RootWindow associated with |widget1|. Even though | 1437 // Send a mouse event to the RootWindow associated with |widget1|. Even though |
1417 // |widget2| has capture, |widget1| should still get the event. | 1438 // |widget2| has capture, |widget1| should still get the event. |
1418 ui::MouseEvent mouse_event(ui::ET_MOUSE_EXITED, gfx::Point(), gfx::Point(), | 1439 ui::MouseEvent mouse_event( |
1419 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 1440 ui::ET_MOUSE_EXITED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(), |
| 1441 ui::EF_NONE, ui::EF_NONE, |
| 1442 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
1420 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> | 1443 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> |
1421 GetHost()->event_processor()->OnEventFromSource(&mouse_event); | 1444 GetHost()->event_processor()->OnEventFromSource(&mouse_event); |
1422 ASSERT_FALSE(details.dispatcher_destroyed); | 1445 ASSERT_FALSE(details.dispatcher_destroyed); |
1423 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); | 1446 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); |
1424 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); | 1447 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); |
1425 } | 1448 } |
1426 #endif // defined(OS_WIN) | 1449 #endif // defined(OS_WIN) |
1427 | 1450 |
1428 class WidgetInputMethodInteractiveTest : public WidgetTestInteractive { | 1451 class WidgetInputMethodInteractiveTest : public WidgetTestInteractive { |
1429 public: | 1452 public: |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1587 widget->GetInputMethod()->GetTextInputType()); | 1610 widget->GetInputMethod()->GetTextInputType()); |
1588 | 1611 |
1589 textfield->SetReadOnly(true); | 1612 textfield->SetReadOnly(true); |
1590 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, | 1613 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, |
1591 widget->GetInputMethod()->GetTextInputType()); | 1614 widget->GetInputMethod()->GetTextInputType()); |
1592 widget->CloseNow(); | 1615 widget->CloseNow(); |
1593 } | 1616 } |
1594 | 1617 |
1595 } // namespace test | 1618 } // namespace test |
1596 } // namespace views | 1619 } // namespace views |
OLD | NEW |