| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 5 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "ui/aura/client/aura_constants.h" | 8 #include "ui/aura/client/aura_constants.h" |
| 9 #include "ui/aura/client/cursor_client.h" | 9 #include "ui/aura/client/cursor_client.h" |
| 10 #include "ui/aura/client/window_tree_client.h" | 10 #include "ui/aura/client/window_tree_client.h" |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 | 444 |
| 445 // The following code verifies we can correctly destroy a Widget from a mouse | 445 // The following code verifies we can correctly destroy a Widget from a mouse |
| 446 // enter/exit. We could test move/drag/enter/exit but in general we don't run | 446 // enter/exit. We could test move/drag/enter/exit but in general we don't run |
| 447 // nested message loops from such events, nor has the code ever really dealt | 447 // nested message loops from such events, nor has the code ever really dealt |
| 448 // with this situation. | 448 // with this situation. |
| 449 | 449 |
| 450 // Generates two moves (first generates enter, second real move), a press, drag | 450 // Generates two moves (first generates enter, second real move), a press, drag |
| 451 // and release stopping at |last_event_type|. | 451 // and release stopping at |last_event_type|. |
| 452 void GenerateMouseEvents(Widget* widget, ui::EventType last_event_type) { | 452 void GenerateMouseEvents(Widget* widget, ui::EventType last_event_type) { |
| 453 const gfx::Rect screen_bounds(widget->GetWindowBoundsInScreen()); | 453 const gfx::Rect screen_bounds(widget->GetWindowBoundsInScreen()); |
| 454 ui::MouseEvent move_event(ui::ET_MOUSE_MOVED, screen_bounds.CenterPoint(), | 454 ui::MouseEvent move_event( |
| 455 screen_bounds.CenterPoint(), ui::EventTimeForNow(), | 455 ui::ET_MOUSE_MOVED, screen_bounds.CenterPoint(), |
| 456 0, 0); | 456 screen_bounds.CenterPoint(), ui::EventTimeForNow(), 0, 0, |
| 457 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 457 ui::EventProcessor* dispatcher = WidgetTest::GetEventProcessor(widget); | 458 ui::EventProcessor* dispatcher = WidgetTest::GetEventProcessor(widget); |
| 458 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move_event); | 459 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move_event); |
| 459 if (last_event_type == ui::ET_MOUSE_ENTERED || details.dispatcher_destroyed) | 460 if (last_event_type == ui::ET_MOUSE_ENTERED || details.dispatcher_destroyed) |
| 460 return; | 461 return; |
| 461 details = dispatcher->OnEventFromSource(&move_event); | 462 details = dispatcher->OnEventFromSource(&move_event); |
| 462 if (last_event_type == ui::ET_MOUSE_MOVED || details.dispatcher_destroyed) | 463 if (last_event_type == ui::ET_MOUSE_MOVED || details.dispatcher_destroyed) |
| 463 return; | 464 return; |
| 464 | 465 |
| 465 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, screen_bounds.CenterPoint(), | 466 ui::MouseEvent press_event( |
| 466 screen_bounds.CenterPoint(), ui::EventTimeForNow(), | 467 ui::ET_MOUSE_PRESSED, screen_bounds.CenterPoint(), |
| 467 0, 0); | 468 screen_bounds.CenterPoint(), ui::EventTimeForNow(), 0, 0, |
| 469 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 468 details = dispatcher->OnEventFromSource(&press_event); | 470 details = dispatcher->OnEventFromSource(&press_event); |
| 469 if (last_event_type == ui::ET_MOUSE_PRESSED || details.dispatcher_destroyed) | 471 if (last_event_type == ui::ET_MOUSE_PRESSED || details.dispatcher_destroyed) |
| 470 return; | 472 return; |
| 471 | 473 |
| 472 gfx::Point end_point(screen_bounds.CenterPoint()); | 474 gfx::Point end_point(screen_bounds.CenterPoint()); |
| 473 end_point.Offset(1, 1); | 475 end_point.Offset(1, 1); |
| 474 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, end_point, end_point, | 476 ui::MouseEvent drag_event( |
| 475 ui::EventTimeForNow(), 0, 0); | 477 ui::ET_MOUSE_DRAGGED, end_point, end_point, ui::EventTimeForNow(), 0, 0, |
| 478 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 476 details = dispatcher->OnEventFromSource(&drag_event); | 479 details = dispatcher->OnEventFromSource(&drag_event); |
| 477 if (last_event_type == ui::ET_MOUSE_DRAGGED || details.dispatcher_destroyed) | 480 if (last_event_type == ui::ET_MOUSE_DRAGGED || details.dispatcher_destroyed) |
| 478 return; | 481 return; |
| 479 | 482 |
| 480 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, end_point, end_point, | 483 ui::MouseEvent release_event( |
| 481 ui::EventTimeForNow(), 0, 0); | 484 ui::ET_MOUSE_RELEASED, end_point, end_point, ui::EventTimeForNow(), 0, 0, |
| 485 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 482 details = dispatcher->OnEventFromSource(&release_event); | 486 details = dispatcher->OnEventFromSource(&release_event); |
| 483 if (details.dispatcher_destroyed) | 487 if (details.dispatcher_destroyed) |
| 484 return; | 488 return; |
| 485 } | 489 } |
| 486 | 490 |
| 487 // Creates a widget and invokes GenerateMouseEvents() with |last_event_type|. | 491 // Creates a widget and invokes GenerateMouseEvents() with |last_event_type|. |
| 488 void RunCloseWidgetDuringDispatchTest(WidgetTest* test, | 492 void RunCloseWidgetDuringDispatchTest(WidgetTest* test, |
| 489 ui::EventType last_event_type) { | 493 ui::EventType last_event_type) { |
| 490 // |widget| is deleted by CloseWidgetView. | 494 // |widget| is deleted by CloseWidgetView. |
| 491 Widget* widget = new Widget; | 495 Widget* widget = new Widget; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 top_level_widget.Init(init_params); | 542 top_level_widget.Init(init_params); |
| 539 top_level_widget.Show(); | 543 top_level_widget.Show(); |
| 540 EXPECT_TRUE(top_level_widget.IsVisible()); | 544 EXPECT_TRUE(top_level_widget.IsVisible()); |
| 541 | 545 |
| 542 // Create a view and validate that a mouse moves makes it to the view. | 546 // Create a view and validate that a mouse moves makes it to the view. |
| 543 EventCountView* widget_view = new EventCountView(); | 547 EventCountView* widget_view = new EventCountView(); |
| 544 widget_view->SetBounds(0, 0, 10, 10); | 548 widget_view->SetBounds(0, 0, 10, 10); |
| 545 top_level_widget.GetRootView()->AddChildView(widget_view); | 549 top_level_widget.GetRootView()->AddChildView(widget_view); |
| 546 | 550 |
| 547 gfx::Point cursor_location_main(5, 5); | 551 gfx::Point cursor_location_main(5, 5); |
| 548 ui::MouseEvent move_main(ui::ET_MOUSE_MOVED, cursor_location_main, | 552 ui::MouseEvent move_main( |
| 549 cursor_location_main, ui::EventTimeForNow(), | 553 ui::ET_MOUSE_MOVED, cursor_location_main, cursor_location_main, |
| 550 ui::EF_NONE, ui::EF_NONE); | 554 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE, |
| 555 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 551 ui::EventDispatchDetails details = | 556 ui::EventDispatchDetails details = |
| 552 GetEventProcessor(&top_level_widget)->OnEventFromSource(&move_main); | 557 GetEventProcessor(&top_level_widget)->OnEventFromSource(&move_main); |
| 553 ASSERT_FALSE(details.dispatcher_destroyed); | 558 ASSERT_FALSE(details.dispatcher_destroyed); |
| 554 | 559 |
| 555 EXPECT_EQ(1, widget_view->GetEventCount(ui::ET_MOUSE_ENTERED)); | 560 EXPECT_EQ(1, widget_view->GetEventCount(ui::ET_MOUSE_ENTERED)); |
| 556 widget_view->ResetCounts(); | 561 widget_view->ResetCounts(); |
| 557 | 562 |
| 558 // Create a modal dialog and validate that a mouse down message makes it to | 563 // Create a modal dialog and validate that a mouse down message makes it to |
| 559 // the main view within the dialog. | 564 // the main view within the dialog. |
| 560 | 565 |
| 561 // This instance will be destroyed when the dialog is destroyed. | 566 // This instance will be destroyed when the dialog is destroyed. |
| 562 ModalDialogDelegate* dialog_delegate = new ModalDialogDelegate; | 567 ModalDialogDelegate* dialog_delegate = new ModalDialogDelegate; |
| 563 | 568 |
| 564 Widget* modal_dialog_widget = views::DialogDelegate::CreateDialogWidget( | 569 Widget* modal_dialog_widget = views::DialogDelegate::CreateDialogWidget( |
| 565 dialog_delegate, NULL, top_level_widget.GetNativeView()); | 570 dialog_delegate, NULL, top_level_widget.GetNativeView()); |
| 566 modal_dialog_widget->SetBounds(gfx::Rect(100, 100, 200, 200)); | 571 modal_dialog_widget->SetBounds(gfx::Rect(100, 100, 200, 200)); |
| 567 EventCountView* dialog_widget_view = new EventCountView(); | 572 EventCountView* dialog_widget_view = new EventCountView(); |
| 568 dialog_widget_view->SetBounds(0, 0, 50, 50); | 573 dialog_widget_view->SetBounds(0, 0, 50, 50); |
| 569 modal_dialog_widget->GetRootView()->AddChildView(dialog_widget_view); | 574 modal_dialog_widget->GetRootView()->AddChildView(dialog_widget_view); |
| 570 modal_dialog_widget->Show(); | 575 modal_dialog_widget->Show(); |
| 571 EXPECT_TRUE(modal_dialog_widget->IsVisible()); | 576 EXPECT_TRUE(modal_dialog_widget->IsVisible()); |
| 572 | 577 |
| 573 gfx::Point cursor_location_dialog(100, 100); | 578 gfx::Point cursor_location_dialog(100, 100); |
| 574 ui::MouseEvent mouse_down_dialog( | 579 ui::MouseEvent mouse_down_dialog( |
| 575 ui::ET_MOUSE_PRESSED, cursor_location_dialog, cursor_location_dialog, | 580 ui::ET_MOUSE_PRESSED, cursor_location_dialog, cursor_location_dialog, |
| 576 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 581 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE, |
| 582 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 577 details = GetEventProcessor(&top_level_widget)->OnEventFromSource( | 583 details = GetEventProcessor(&top_level_widget)->OnEventFromSource( |
| 578 &mouse_down_dialog); | 584 &mouse_down_dialog); |
| 579 ASSERT_FALSE(details.dispatcher_destroyed); | 585 ASSERT_FALSE(details.dispatcher_destroyed); |
| 580 EXPECT_EQ(1, dialog_widget_view->GetEventCount(ui::ET_MOUSE_PRESSED)); | 586 EXPECT_EQ(1, dialog_widget_view->GetEventCount(ui::ET_MOUSE_PRESSED)); |
| 581 | 587 |
| 582 // Send a mouse move message to the main window. It should not be received by | 588 // Send a mouse move message to the main window. It should not be received by |
| 583 // the main window as the modal dialog is still active. | 589 // the main window as the modal dialog is still active. |
| 584 gfx::Point cursor_location_main2(6, 6); | 590 gfx::Point cursor_location_main2(6, 6); |
| 585 ui::MouseEvent mouse_down_main(ui::ET_MOUSE_MOVED, cursor_location_main2, | 591 ui::MouseEvent mouse_down_main( |
| 586 cursor_location_main2, ui::EventTimeForNow(), | 592 ui::ET_MOUSE_MOVED, cursor_location_main2, cursor_location_main2, |
| 587 ui::EF_NONE, ui::EF_NONE); | 593 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE, |
| 594 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 588 details = GetEventProcessor(&top_level_widget)->OnEventFromSource( | 595 details = GetEventProcessor(&top_level_widget)->OnEventFromSource( |
| 589 &mouse_down_main); | 596 &mouse_down_main); |
| 590 ASSERT_FALSE(details.dispatcher_destroyed); | 597 ASSERT_FALSE(details.dispatcher_destroyed); |
| 591 EXPECT_EQ(0, widget_view->GetEventCount(ui::ET_MOUSE_MOVED)); | 598 EXPECT_EQ(0, widget_view->GetEventCount(ui::ET_MOUSE_MOVED)); |
| 592 | 599 |
| 593 modal_dialog_widget->CloseNow(); | 600 modal_dialog_widget->CloseNow(); |
| 594 top_level_widget.CloseNow(); | 601 top_level_widget.CloseNow(); |
| 595 } | 602 } |
| 596 | 603 |
| 597 #if defined(OS_WIN) | 604 #if defined(OS_WIN) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 627 reinterpret_cast<WPARAM>(win32_window), | 634 reinterpret_cast<WPARAM>(win32_window), |
| 628 MAKELPARAM(WM_LBUTTONDOWN, HTCLIENT)); | 635 MAKELPARAM(WM_LBUTTONDOWN, HTCLIENT)); |
| 629 EXPECT_EQ(activate_result, MA_ACTIVATE); | 636 EXPECT_EQ(activate_result, MA_ACTIVATE); |
| 630 | 637 |
| 631 modal_dialog_widget->CloseNow(); | 638 modal_dialog_widget->CloseNow(); |
| 632 } | 639 } |
| 633 #endif // defined(OS_WIN) | 640 #endif // defined(OS_WIN) |
| 634 | 641 |
| 635 } // namespace test | 642 } // namespace test |
| 636 } // namespace views | 643 } // namespace views |
| OLD | NEW |