| 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 "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 // nested message loops from such events, nor has the code ever really dealt | 462 // nested message loops from such events, nor has the code ever really dealt |
| 463 // with this situation. | 463 // with this situation. |
| 464 | 464 |
| 465 // Generates two moves (first generates enter, second real move), a press, drag | 465 // Generates two moves (first generates enter, second real move), a press, drag |
| 466 // and release stopping at |last_event_type|. | 466 // and release stopping at |last_event_type|. |
| 467 void GenerateMouseEvents(Widget* widget, ui::EventType last_event_type) { | 467 void GenerateMouseEvents(Widget* widget, ui::EventType last_event_type) { |
| 468 const gfx::Rect screen_bounds(widget->GetWindowBoundsInScreen()); | 468 const gfx::Rect screen_bounds(widget->GetWindowBoundsInScreen()); |
| 469 ui::MouseEvent move_event(ui::ET_MOUSE_MOVED, screen_bounds.CenterPoint(), | 469 ui::MouseEvent move_event(ui::ET_MOUSE_MOVED, screen_bounds.CenterPoint(), |
| 470 screen_bounds.CenterPoint(), ui::EventTimeForNow(), | 470 screen_bounds.CenterPoint(), ui::EventTimeForNow(), |
| 471 0, 0); | 471 0, 0); |
| 472 ui::EventProcessor* dispatcher = WidgetTest::GetEventProcessor(widget); | 472 ui::EventSink* sink = WidgetTest::GetEventSink(widget); |
| 473 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move_event); | 473 ui::EventDispatchDetails details = sink->OnEventFromSource(&move_event); |
| 474 if (last_event_type == ui::ET_MOUSE_ENTERED || details.dispatcher_destroyed) | 474 if (last_event_type == ui::ET_MOUSE_ENTERED || details.dispatcher_destroyed) |
| 475 return; | 475 return; |
| 476 details = dispatcher->OnEventFromSource(&move_event); | 476 details = sink->OnEventFromSource(&move_event); |
| 477 if (last_event_type == ui::ET_MOUSE_MOVED || details.dispatcher_destroyed) | 477 if (last_event_type == ui::ET_MOUSE_MOVED || details.dispatcher_destroyed) |
| 478 return; | 478 return; |
| 479 | 479 |
| 480 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, screen_bounds.CenterPoint(), | 480 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, screen_bounds.CenterPoint(), |
| 481 screen_bounds.CenterPoint(), ui::EventTimeForNow(), | 481 screen_bounds.CenterPoint(), ui::EventTimeForNow(), |
| 482 0, 0); | 482 0, 0); |
| 483 details = dispatcher->OnEventFromSource(&press_event); | 483 details = sink->OnEventFromSource(&press_event); |
| 484 if (last_event_type == ui::ET_MOUSE_PRESSED || details.dispatcher_destroyed) | 484 if (last_event_type == ui::ET_MOUSE_PRESSED || details.dispatcher_destroyed) |
| 485 return; | 485 return; |
| 486 | 486 |
| 487 gfx::Point end_point(screen_bounds.CenterPoint()); | 487 gfx::Point end_point(screen_bounds.CenterPoint()); |
| 488 end_point.Offset(1, 1); | 488 end_point.Offset(1, 1); |
| 489 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, end_point, end_point, | 489 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, end_point, end_point, |
| 490 ui::EventTimeForNow(), 0, 0); | 490 ui::EventTimeForNow(), 0, 0); |
| 491 details = dispatcher->OnEventFromSource(&drag_event); | 491 details = sink->OnEventFromSource(&drag_event); |
| 492 if (last_event_type == ui::ET_MOUSE_DRAGGED || details.dispatcher_destroyed) | 492 if (last_event_type == ui::ET_MOUSE_DRAGGED || details.dispatcher_destroyed) |
| 493 return; | 493 return; |
| 494 | 494 |
| 495 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, end_point, end_point, | 495 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, end_point, end_point, |
| 496 ui::EventTimeForNow(), 0, 0); | 496 ui::EventTimeForNow(), 0, 0); |
| 497 details = dispatcher->OnEventFromSource(&release_event); | 497 details = sink->OnEventFromSource(&release_event); |
| 498 if (details.dispatcher_destroyed) | 498 if (details.dispatcher_destroyed) |
| 499 return; | 499 return; |
| 500 } | 500 } |
| 501 | 501 |
| 502 // Creates a widget and invokes GenerateMouseEvents() with |last_event_type|. | 502 // Creates a widget and invokes GenerateMouseEvents() with |last_event_type|. |
| 503 void RunCloseWidgetDuringDispatchTest(WidgetTest* test, | 503 void RunCloseWidgetDuringDispatchTest(WidgetTest* test, |
| 504 ui::EventType last_event_type) { | 504 ui::EventType last_event_type) { |
| 505 // |widget| is deleted by CloseWidgetView. | 505 // |widget| is deleted by CloseWidgetView. |
| 506 Widget* widget = new Widget; | 506 Widget* widget = new Widget; |
| 507 Widget::InitParams params = | 507 Widget::InitParams params = |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 // Create a view and validate that a mouse moves makes it to the view. | 562 // Create a view and validate that a mouse moves makes it to the view. |
| 563 EventCountView* widget_view = new EventCountView(); | 563 EventCountView* widget_view = new EventCountView(); |
| 564 widget_view->SetBounds(0, 0, 10, 10); | 564 widget_view->SetBounds(0, 0, 10, 10); |
| 565 top_level_widget.GetRootView()->AddChildView(widget_view); | 565 top_level_widget.GetRootView()->AddChildView(widget_view); |
| 566 | 566 |
| 567 gfx::Point cursor_location_main(5, 5); | 567 gfx::Point cursor_location_main(5, 5); |
| 568 ui::MouseEvent move_main(ui::ET_MOUSE_MOVED, cursor_location_main, | 568 ui::MouseEvent move_main(ui::ET_MOUSE_MOVED, cursor_location_main, |
| 569 cursor_location_main, ui::EventTimeForNow(), | 569 cursor_location_main, ui::EventTimeForNow(), |
| 570 ui::EF_NONE, ui::EF_NONE); | 570 ui::EF_NONE, ui::EF_NONE); |
| 571 ui::EventDispatchDetails details = | 571 ui::EventDispatchDetails details = |
| 572 GetEventProcessor(&top_level_widget)->OnEventFromSource(&move_main); | 572 GetEventSink(&top_level_widget)->OnEventFromSource(&move_main); |
| 573 ASSERT_FALSE(details.dispatcher_destroyed); | 573 ASSERT_FALSE(details.dispatcher_destroyed); |
| 574 | 574 |
| 575 EXPECT_EQ(1, widget_view->GetEventCount(ui::ET_MOUSE_ENTERED)); | 575 EXPECT_EQ(1, widget_view->GetEventCount(ui::ET_MOUSE_ENTERED)); |
| 576 widget_view->ResetCounts(); | 576 widget_view->ResetCounts(); |
| 577 | 577 |
| 578 // Create a modal dialog and validate that a mouse down message makes it to | 578 // Create a modal dialog and validate that a mouse down message makes it to |
| 579 // the main view within the dialog. | 579 // the main view within the dialog. |
| 580 | 580 |
| 581 // This instance will be destroyed when the dialog is destroyed. | 581 // This instance will be destroyed when the dialog is destroyed. |
| 582 ModalDialogDelegate* dialog_delegate = new ModalDialogDelegate; | 582 ModalDialogDelegate* dialog_delegate = new ModalDialogDelegate; |
| 583 | 583 |
| 584 Widget* modal_dialog_widget = views::DialogDelegate::CreateDialogWidget( | 584 Widget* modal_dialog_widget = views::DialogDelegate::CreateDialogWidget( |
| 585 dialog_delegate, NULL, top_level_widget.GetNativeView()); | 585 dialog_delegate, NULL, top_level_widget.GetNativeView()); |
| 586 modal_dialog_widget->SetBounds(gfx::Rect(100, 100, 200, 200)); | 586 modal_dialog_widget->SetBounds(gfx::Rect(100, 100, 200, 200)); |
| 587 EventCountView* dialog_widget_view = new EventCountView(); | 587 EventCountView* dialog_widget_view = new EventCountView(); |
| 588 dialog_widget_view->SetBounds(0, 0, 50, 50); | 588 dialog_widget_view->SetBounds(0, 0, 50, 50); |
| 589 modal_dialog_widget->GetRootView()->AddChildView(dialog_widget_view); | 589 modal_dialog_widget->GetRootView()->AddChildView(dialog_widget_view); |
| 590 modal_dialog_widget->Show(); | 590 modal_dialog_widget->Show(); |
| 591 EXPECT_TRUE(modal_dialog_widget->IsVisible()); | 591 EXPECT_TRUE(modal_dialog_widget->IsVisible()); |
| 592 | 592 |
| 593 gfx::Point cursor_location_dialog(100, 100); | 593 gfx::Point cursor_location_dialog(100, 100); |
| 594 ui::MouseEvent mouse_down_dialog( | 594 ui::MouseEvent mouse_down_dialog( |
| 595 ui::ET_MOUSE_PRESSED, cursor_location_dialog, cursor_location_dialog, | 595 ui::ET_MOUSE_PRESSED, cursor_location_dialog, cursor_location_dialog, |
| 596 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 596 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); |
| 597 details = GetEventProcessor(&top_level_widget)->OnEventFromSource( | 597 details = |
| 598 &mouse_down_dialog); | 598 GetEventSink(&top_level_widget)->OnEventFromSource(&mouse_down_dialog); |
| 599 ASSERT_FALSE(details.dispatcher_destroyed); | 599 ASSERT_FALSE(details.dispatcher_destroyed); |
| 600 EXPECT_EQ(1, dialog_widget_view->GetEventCount(ui::ET_MOUSE_PRESSED)); | 600 EXPECT_EQ(1, dialog_widget_view->GetEventCount(ui::ET_MOUSE_PRESSED)); |
| 601 | 601 |
| 602 // Send a mouse move message to the main window. It should not be received by | 602 // Send a mouse move message to the main window. It should not be received by |
| 603 // the main window as the modal dialog is still active. | 603 // the main window as the modal dialog is still active. |
| 604 gfx::Point cursor_location_main2(6, 6); | 604 gfx::Point cursor_location_main2(6, 6); |
| 605 ui::MouseEvent mouse_down_main(ui::ET_MOUSE_MOVED, cursor_location_main2, | 605 ui::MouseEvent mouse_down_main(ui::ET_MOUSE_MOVED, cursor_location_main2, |
| 606 cursor_location_main2, ui::EventTimeForNow(), | 606 cursor_location_main2, ui::EventTimeForNow(), |
| 607 ui::EF_NONE, ui::EF_NONE); | 607 ui::EF_NONE, ui::EF_NONE); |
| 608 details = GetEventProcessor(&top_level_widget)->OnEventFromSource( | 608 details = |
| 609 &mouse_down_main); | 609 GetEventSink(&top_level_widget)->OnEventFromSource(&mouse_down_main); |
| 610 ASSERT_FALSE(details.dispatcher_destroyed); | 610 ASSERT_FALSE(details.dispatcher_destroyed); |
| 611 EXPECT_EQ(0, widget_view->GetEventCount(ui::ET_MOUSE_MOVED)); | 611 EXPECT_EQ(0, widget_view->GetEventCount(ui::ET_MOUSE_MOVED)); |
| 612 | 612 |
| 613 modal_dialog_widget->CloseNow(); | 613 modal_dialog_widget->CloseNow(); |
| 614 top_level_widget.CloseNow(); | 614 top_level_widget.CloseNow(); |
| 615 } | 615 } |
| 616 | 616 |
| 617 #if defined(OS_WIN) | 617 #if defined(OS_WIN) |
| 618 // Tests whether we can activate the top level widget when a modal dialog is | 618 // Tests whether we can activate the top level widget when a modal dialog is |
| 619 // active. | 619 // active. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 target->HandleKeyboardMessage(WM_CHAR, 0, 0, &handled); | 674 target->HandleKeyboardMessage(WM_CHAR, 0, 0, &handled); |
| 675 target->HandleKeyboardMessage(WM_SYSCHAR, 0, 0, &handled); | 675 target->HandleKeyboardMessage(WM_SYSCHAR, 0, 0, &handled); |
| 676 target->HandleKeyboardMessage(WM_SYSDEADCHAR, 0, 0, &handled); | 676 target->HandleKeyboardMessage(WM_SYSDEADCHAR, 0, 0, &handled); |
| 677 widget.CloseNow(); | 677 widget.CloseNow(); |
| 678 } | 678 } |
| 679 | 679 |
| 680 #endif // defined(OS_WIN) | 680 #endif // defined(OS_WIN) |
| 681 | 681 |
| 682 } // namespace test | 682 } // namespace test |
| 683 } // namespace views | 683 } // namespace views |
| OLD | NEW |