| 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/root_view.h" | 5 #include "ui/views/widget/root_view.h" |
| 6 | 6 |
| 7 #include "ui/events/event_utils.h" | 7 #include "ui/events/event_utils.h" |
| 8 #include "ui/views/context_menu_controller.h" | 8 #include "ui/views/context_menu_controller.h" |
| 9 #include "ui/views/test/views_test_base.h" | 9 #include "ui/views/test/views_test_base.h" |
| 10 #include "ui/views/view_targeter.h" | 10 #include "ui/views/view_targeter.h" |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 bool view_destroyed = false; | 384 bool view_destroyed = false; |
| 385 View* child = new DeleteViewOnEvent(ui::ET_MOUSE_EXITED, &view_destroyed); | 385 View* child = new DeleteViewOnEvent(ui::ET_MOUSE_EXITED, &view_destroyed); |
| 386 content->AddChildView(child); | 386 content->AddChildView(child); |
| 387 child->SetBounds(10, 10, 500, 500); | 387 child->SetBounds(10, 10, 500, 500); |
| 388 | 388 |
| 389 internal::RootView* root_view = | 389 internal::RootView* root_view = |
| 390 static_cast<internal::RootView*>(widget.GetRootView()); | 390 static_cast<internal::RootView*>(widget.GetRootView()); |
| 391 | 391 |
| 392 // Generate a mouse move event which ensures that the mouse_moved_handler_ | 392 // Generate a mouse move event which ensures that the mouse_moved_handler_ |
| 393 // member is set in the RootView class. | 393 // member is set in the RootView class. |
| 394 ui::MouseEvent moved_event(ui::ET_MOUSE_MOVED, gfx::Point(15, 15), | 394 ui::MouseEvent moved_event(ui::ET_MOUSE_MOVED, gfx::PointF(15.f, 15.f), |
| 395 gfx::Point(15, 15), ui::EventTimeForNow(), 0, | 395 gfx::PointF(15.f, 15.f), ui::EventTimeForNow(), 0, |
| 396 0); | 396 0); |
| 397 root_view->OnMouseMoved(moved_event); | 397 root_view->OnMouseMoved(moved_event); |
| 398 ASSERT_FALSE(view_destroyed); | 398 ASSERT_FALSE(view_destroyed); |
| 399 | 399 |
| 400 // Generate a mouse exit event which in turn will delete the child view which | 400 // Generate a mouse exit event which in turn will delete the child view which |
| 401 // was the target of the mouse move event above. This should not crash when | 401 // was the target of the mouse move event above. This should not crash when |
| 402 // the mouse exit handler returns from the child. | 402 // the mouse exit handler returns from the child. |
| 403 ui::MouseEvent exit_event(ui::ET_MOUSE_EXITED, gfx::Point(), gfx::Point(), | 403 ui::MouseEvent exit_event(ui::ET_MOUSE_EXITED, gfx::PointF(), gfx::PointF(), |
| 404 ui::EventTimeForNow(), 0, 0); | 404 ui::EventTimeForNow(), 0, 0); |
| 405 root_view->OnMouseExited(exit_event); | 405 root_view->OnMouseExited(exit_event); |
| 406 | 406 |
| 407 EXPECT_TRUE(view_destroyed); | 407 EXPECT_TRUE(view_destroyed); |
| 408 EXPECT_FALSE(content->has_children()); | 408 EXPECT_FALSE(content->has_children()); |
| 409 } | 409 } |
| 410 | 410 |
| 411 // Verifies deleting a View in OnMouseEntered() doesn't crash. | 411 // Verifies deleting a View in OnMouseEntered() doesn't crash. |
| 412 TEST_F(RootViewTest, DeleteViewOnMouseEnterDispatch) { | 412 TEST_F(RootViewTest, DeleteViewOnMouseEnterDispatch) { |
| 413 Widget widget; | 413 Widget widget; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 424 View* child = new DeleteViewOnEvent(ui::ET_MOUSE_ENTERED, &view_destroyed); | 424 View* child = new DeleteViewOnEvent(ui::ET_MOUSE_ENTERED, &view_destroyed); |
| 425 content->AddChildView(child); | 425 content->AddChildView(child); |
| 426 | 426 |
| 427 // Make |child| smaller than the containing Widget and RootView. | 427 // Make |child| smaller than the containing Widget and RootView. |
| 428 child->SetBounds(100, 100, 100, 100); | 428 child->SetBounds(100, 100, 100, 100); |
| 429 | 429 |
| 430 internal::RootView* root_view = | 430 internal::RootView* root_view = |
| 431 static_cast<internal::RootView*>(widget.GetRootView()); | 431 static_cast<internal::RootView*>(widget.GetRootView()); |
| 432 | 432 |
| 433 // Move the mouse within |widget| but outside of |child|. | 433 // Move the mouse within |widget| but outside of |child|. |
| 434 ui::MouseEvent moved_event(ui::ET_MOUSE_MOVED, gfx::Point(15, 15), | 434 ui::MouseEvent moved_event(ui::ET_MOUSE_MOVED, gfx::PointF(15.f, 15.f), |
| 435 gfx::Point(15, 15), ui::EventTimeForNow(), 0, | 435 gfx::PointF(15.f, 15.f), ui::EventTimeForNow(), 0, |
| 436 0); | 436 0); |
| 437 root_view->OnMouseMoved(moved_event); | 437 root_view->OnMouseMoved(moved_event); |
| 438 ASSERT_FALSE(view_destroyed); | 438 ASSERT_FALSE(view_destroyed); |
| 439 | 439 |
| 440 // Move the mouse within |child|, which should dispatch a mouse enter event to | 440 // Move the mouse within |child|, which should dispatch a mouse enter event to |
| 441 // |child| and destroy the view. This should not crash when the mouse enter | 441 // |child| and destroy the view. This should not crash when the mouse enter |
| 442 // handler returns from the child. | 442 // handler returns from the child. |
| 443 ui::MouseEvent moved_event2(ui::ET_MOUSE_MOVED, gfx::Point(115, 115), | 443 ui::MouseEvent moved_event2(ui::ET_MOUSE_MOVED, gfx::PointF(115.f, 115.f), |
| 444 gfx::Point(115, 115), ui::EventTimeForNow(), 0, | 444 gfx::PointF(115.f, 115.f), ui::EventTimeForNow(), |
| 445 0); | 445 0, 0); |
| 446 root_view->OnMouseMoved(moved_event2); | 446 root_view->OnMouseMoved(moved_event2); |
| 447 | 447 |
| 448 EXPECT_TRUE(view_destroyed); | 448 EXPECT_TRUE(view_destroyed); |
| 449 EXPECT_FALSE(content->has_children()); | 449 EXPECT_FALSE(content->has_children()); |
| 450 } | 450 } |
| 451 | 451 |
| 452 namespace { | 452 namespace { |
| 453 | 453 |
| 454 // View class which deletes its owning Widget when it gets a mouse exit event. | 454 // View class which deletes its owning Widget when it gets a mouse exit event. |
| 455 class DeleteWidgetOnMouseExit : public View { | 455 class DeleteWidgetOnMouseExit : public View { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 content->AddChildView(child); | 488 content->AddChildView(child); |
| 489 widget->SetContentsView(content); | 489 widget->SetContentsView(content); |
| 490 | 490 |
| 491 // Make |child| smaller than the containing Widget and RootView. | 491 // Make |child| smaller than the containing Widget and RootView. |
| 492 child->SetBounds(100, 100, 100, 100); | 492 child->SetBounds(100, 100, 100, 100); |
| 493 | 493 |
| 494 internal::RootView* root_view = | 494 internal::RootView* root_view = |
| 495 static_cast<internal::RootView*>(widget->GetRootView()); | 495 static_cast<internal::RootView*>(widget->GetRootView()); |
| 496 | 496 |
| 497 // Move the mouse within |child|. | 497 // Move the mouse within |child|. |
| 498 ui::MouseEvent moved_event(ui::ET_MOUSE_MOVED, gfx::Point(115, 115), | 498 ui::MouseEvent moved_event(ui::ET_MOUSE_MOVED, gfx::PointF(115.f, 115.f), |
| 499 gfx::Point(115, 115), ui::EventTimeForNow(), 0, | 499 gfx::PointF(115.f, 115), ui::EventTimeForNow(), 0, |
| 500 0); | 500 0); |
| 501 root_view->OnMouseMoved(moved_event); | 501 root_view->OnMouseMoved(moved_event); |
| 502 ASSERT_TRUE(widget_deletion_observer.IsWidgetAlive()); | 502 ASSERT_TRUE(widget_deletion_observer.IsWidgetAlive()); |
| 503 | 503 |
| 504 // Move the mouse outside of |child| which should dispatch a mouse exit event | 504 // Move the mouse outside of |child| which should dispatch a mouse exit event |
| 505 // to |child| and destroy the widget. This should not crash when the mouse | 505 // to |child| and destroy the widget. This should not crash when the mouse |
| 506 // exit handler returns from the child. | 506 // exit handler returns from the child. |
| 507 ui::MouseEvent move_event2(ui::ET_MOUSE_MOVED, gfx::Point(15, 15), | 507 ui::MouseEvent move_event2(ui::ET_MOUSE_MOVED, gfx::PointF(15.f, 15.f), |
| 508 gfx::Point(15, 15), ui::EventTimeForNow(), 0, 0); | 508 gfx::PointF(15.f, 15.f), ui::EventTimeForNow(), 0, |
| 509 0); |
| 509 root_view->OnMouseMoved(move_event2); | 510 root_view->OnMouseMoved(move_event2); |
| 510 EXPECT_FALSE(widget_deletion_observer.IsWidgetAlive()); | 511 EXPECT_FALSE(widget_deletion_observer.IsWidgetAlive()); |
| 511 } | 512 } |
| 512 | 513 |
| 513 // Test that there is no crash if a View deletes its parent widget as a result | 514 // Test that there is no crash if a View deletes its parent widget as a result |
| 514 // of a mouse exited event which was propagated from one of its children. | 515 // of a mouse exited event which was propagated from one of its children. |
| 515 TEST_F(RootViewTest, DeleteWidgetOnMouseExitDispatchFromChild) { | 516 TEST_F(RootViewTest, DeleteWidgetOnMouseExitDispatchFromChild) { |
| 516 Widget* widget = new Widget; | 517 Widget* widget = new Widget; |
| 517 Widget::InitParams init_params = | 518 Widget::InitParams init_params = |
| 518 CreateParams(Widget::InitParams::TYPE_POPUP); | 519 CreateParams(Widget::InitParams::TYPE_POPUP); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 533 child->SetBounds(100, 100, 100, 100); | 534 child->SetBounds(100, 100, 100, 100); |
| 534 subchild->SetBounds(0, 0, 100, 100); | 535 subchild->SetBounds(0, 0, 100, 100); |
| 535 | 536 |
| 536 // Make mouse enter and exit events get propagated from |subchild| to |child|. | 537 // Make mouse enter and exit events get propagated from |subchild| to |child|. |
| 537 child->set_notify_enter_exit_on_child(true); | 538 child->set_notify_enter_exit_on_child(true); |
| 538 | 539 |
| 539 internal::RootView* root_view = | 540 internal::RootView* root_view = |
| 540 static_cast<internal::RootView*>(widget->GetRootView()); | 541 static_cast<internal::RootView*>(widget->GetRootView()); |
| 541 | 542 |
| 542 // Move the mouse within |subchild| and |child|. | 543 // Move the mouse within |subchild| and |child|. |
| 543 ui::MouseEvent moved_event(ui::ET_MOUSE_MOVED, gfx::Point(115, 115), | 544 ui::MouseEvent moved_event(ui::ET_MOUSE_MOVED, gfx::PointF(115.f, 115.f), |
| 544 gfx::Point(115, 115), ui::EventTimeForNow(), 0, 0); | 545 gfx::PointF(115.f, 115.f), ui::EventTimeForNow(), |
| 546 0, 0); |
| 545 root_view->OnMouseMoved(moved_event); | 547 root_view->OnMouseMoved(moved_event); |
| 546 ASSERT_TRUE(widget_deletion_observer.IsWidgetAlive()); | 548 ASSERT_TRUE(widget_deletion_observer.IsWidgetAlive()); |
| 547 | 549 |
| 548 // Move the mouse outside of |subchild| and |child| which should dispatch a | 550 // Move the mouse outside of |subchild| and |child| which should dispatch a |
| 549 // mouse exit event to |subchild| and destroy the widget. This should not | 551 // mouse exit event to |subchild| and destroy the widget. This should not |
| 550 // crash when the mouse exit handler returns from |subchild|. | 552 // crash when the mouse exit handler returns from |subchild|. |
| 551 ui::MouseEvent move_event2(ui::ET_MOUSE_MOVED, gfx::Point(15, 15), | 553 ui::MouseEvent move_event2(ui::ET_MOUSE_MOVED, gfx::PointF(15.f, 15.f), |
| 552 gfx::Point(15, 15), ui::EventTimeForNow(), 0, 0); | 554 gfx::PointF(15.f, 15.f), ui::EventTimeForNow(), 0, |
| 555 0); |
| 553 root_view->OnMouseMoved(move_event2); | 556 root_view->OnMouseMoved(move_event2); |
| 554 EXPECT_FALSE(widget_deletion_observer.IsWidgetAlive()); | 557 EXPECT_FALSE(widget_deletion_observer.IsWidgetAlive()); |
| 555 } | 558 } |
| 556 | 559 |
| 557 } // namespace test | 560 } // namespace test |
| 558 } // namespace views | 561 } // namespace views |
| OLD | NEW |