Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <memory> | 6 #include <memory> |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 3603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3614 EXPECT_FALSE(removals_observer.DidRemoveView(child)); | 3614 EXPECT_FALSE(removals_observer.DidRemoveView(child)); |
| 3615 | 3615 |
| 3616 // Moving the child to a different widget should call the removals observer. | 3616 // Moving the child to a different widget should call the removals observer. |
| 3617 WidgetAutoclosePtr widget2(CreateTopLevelPlatformWidget()); | 3617 WidgetAutoclosePtr widget2(CreateTopLevelPlatformWidget()); |
| 3618 widget2->client_view()->AddChildView(child); | 3618 widget2->client_view()->AddChildView(child); |
| 3619 EXPECT_TRUE(removals_observer.DidRemoveView(child)); | 3619 EXPECT_TRUE(removals_observer.DidRemoveView(child)); |
| 3620 | 3620 |
| 3621 widget->RemoveRemovalsObserver(&removals_observer); | 3621 widget->RemoveRemovalsObserver(&removals_observer); |
| 3622 } | 3622 } |
| 3623 | 3623 |
| 3624 #if defined(OS_WIN) | |
| 3625 | |
| 3626 // Provides functionality to create a window modal dialog. | |
| 3627 class ModalDialogDelegate : public DialogDelegateView { | |
| 3628 public: | |
| 3629 explicit ModalDialogDelegate(ui::ModalType type) : type_(type) {} | |
| 3630 ~ModalDialogDelegate() override {} | |
| 3631 | |
| 3632 // WidgetDelegate overrides. | |
| 3633 ui::ModalType GetModalType() const override { return type_; } | |
| 3634 | |
| 3635 private: | |
| 3636 ui::ModalType type_; | |
|
sky
2016/05/19 16:20:16
nit: const
kylix_rd
2016/05/19 16:43:10
Done.
| |
| 3637 | |
| 3638 DISALLOW_COPY_AND_ASSIGN(ModalDialogDelegate); | |
| 3639 }; | |
| 3640 | |
| 3641 // Tests the case where an intervening owner popup window is destroyed out from | |
| 3642 // under the currently active modal top-level window. In this instance, the | |
| 3643 // remaining top-level windows should be re-enabled | |
|
sky
2016/05/19 16:20:16
nit: end with '.'.
kylix_rd
2016/05/19 16:43:10
Done.
| |
| 3644 TEST_F(WidgetTest, WindowModalOwnerDestroyedEnabledTest) { | |
| 3645 // Create a top level widget. | |
| 3646 Widget top_level_widget; | |
| 3647 Widget::InitParams init_params = | |
| 3648 CreateParams(Widget::InitParams::TYPE_WINDOW); | |
| 3649 init_params.show_state = ui::SHOW_STATE_NORMAL; | |
| 3650 gfx::Rect initial_bounds(0, 0, 500, 500); | |
| 3651 init_params.bounds = initial_bounds; | |
| 3652 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 3653 init_params.native_widget = CreatePlatformDesktopNativeWidgetImpl( | |
| 3654 init_params, &top_level_widget, nullptr); | |
| 3655 top_level_widget.Init(init_params); | |
| 3656 top_level_widget.Show(); | |
| 3657 | |
| 3658 // Create a modal dialog. | |
| 3659 // This instance will be destroyed when the dialog is destroyed. | |
|
sky
2016/05/19 16:20:16
'this' is confusing here. As the comment is right
kylix_rd
2016/05/19 16:43:10
Done.
| |
| 3660 Widget owner_dialog_widget; | |
| 3661 ModalDialogDelegate* dialog_delegate = | |
| 3662 new ModalDialogDelegate(ui::MODAL_TYPE_WINDOW); | |
| 3663 | |
| 3664 init_params = CreateParams(Widget::InitParams::TYPE_WINDOW); | |
| 3665 init_params.show_state = ui::SHOW_STATE_NORMAL; | |
| 3666 init_params.bounds = gfx::Rect(100, 100, 200, 200); | |
| 3667 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 3668 init_params.delegate = dialog_delegate; | |
| 3669 init_params.parent = top_level_widget.GetNativeView(); | |
| 3670 init_params.native_widget = CreatePlatformDesktopNativeWidgetImpl( | |
| 3671 init_params, &owner_dialog_widget, nullptr); | |
| 3672 owner_dialog_widget.Init(init_params); | |
| 3673 | |
| 3674 HWND owner_hwnd = HWNDForWidget(&owner_dialog_widget); | |
| 3675 | |
| 3676 owner_dialog_widget.Show(); | |
| 3677 | |
| 3678 // Now Create an owned modal dialog | |
|
sky
2016/05/19 16:20:16
nit: end with '.'
kylix_rd
2016/05/19 16:43:10
Done.
| |
| 3679 // Like above, this instance will be destroyed when the dialog is destroyed. | |
|
sky
2016/05/19 16:20:16
Similar comment. Also, it would more clear if you
kylix_rd
2016/05/19 16:43:10
Done.
| |
| 3680 Widget owned_dialog_widget; | |
| 3681 dialog_delegate = | |
| 3682 new ModalDialogDelegate(ui::MODAL_TYPE_WINDOW); | |
| 3683 | |
| 3684 init_params = CreateParams(Widget::InitParams::TYPE_WINDOW); | |
| 3685 init_params.show_state = ui::SHOW_STATE_NORMAL; | |
| 3686 init_params.bounds = gfx::Rect(150, 150, 250, 250); | |
| 3687 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 3688 init_params.delegate = dialog_delegate; | |
| 3689 init_params.parent = owner_dialog_widget.GetNativeView(); | |
| 3690 init_params.native_widget = CreatePlatformDesktopNativeWidgetImpl( | |
| 3691 init_params, &owned_dialog_widget, nullptr); | |
| 3692 owned_dialog_widget.Init(init_params); | |
| 3693 | |
| 3694 HWND owned_hwnd = HWNDForWidget(&owned_dialog_widget); | |
| 3695 | |
| 3696 owned_dialog_widget.Show(); | |
| 3697 | |
| 3698 HWND top_hwnd = HWNDForWidget(&top_level_widget); | |
| 3699 | |
| 3700 EXPECT_FALSE(!!IsWindowEnabled(owner_hwnd)); | |
| 3701 EXPECT_FALSE(!!IsWindowEnabled(top_hwnd)); | |
| 3702 EXPECT_TRUE(!!IsWindowEnabled(owned_hwnd)); | |
| 3703 | |
| 3704 owner_dialog_widget.CloseNow(); | |
| 3705 | |
| 3706 EXPECT_FALSE(!!IsWindow(owner_hwnd)); | |
| 3707 EXPECT_FALSE(!!IsWindow(owned_hwnd)); | |
| 3708 EXPECT_TRUE(!!IsWindowEnabled(top_hwnd)); | |
| 3709 | |
| 3710 top_level_widget.CloseNow(); | |
| 3711 } | |
| 3712 | |
| 3713 #endif | |
| 3714 | |
| 3624 } // namespace test | 3715 } // namespace test |
| 3625 } // namespace views | 3716 } // namespace views |
| OLD | NEW |