diff options
Diffstat (limited to 'chromium/ui/views/window')
5 files changed, 54 insertions, 46 deletions
diff --git a/chromium/ui/views/window/custom_frame_view_unittest.cc b/chromium/ui/views/window/custom_frame_view_unittest.cc index d04752c1b4d..37ed1a60201 100644 --- a/chromium/ui/views/window/custom_frame_view_unittest.cc +++ b/chromium/ui/views/window/custom_frame_view_unittest.cc @@ -17,33 +17,6 @@ namespace views { -namespace { - -// Allows for the control of whether or not the widget can minimize/maximize or -// not. This can be set after initial setup in order to allow testing of both -// forms of delegates. By default this can minimize and maximize. -class MinimizeAndMaximizeStateControlDelegate : public WidgetDelegateView { - public: - MinimizeAndMaximizeStateControlDelegate() = default; - ~MinimizeAndMaximizeStateControlDelegate() override = default; - - void set_can_maximize(bool can_maximize) { can_maximize_ = can_maximize; } - - void set_can_minimize(bool can_minimize) { can_minimize_ = can_minimize; } - - // WidgetDelegate: - bool CanMaximize() const override { return can_maximize_; } - bool CanMinimize() const override { return can_minimize_; } - - private: - bool can_maximize_ = true; - bool can_minimize_ = true; - - DISALLOW_COPY_AND_ASSIGN(MinimizeAndMaximizeStateControlDelegate); -}; - -} // namespace - class CustomFrameViewTest : public ViewsTestBase { public: CustomFrameViewTest() = default; @@ -51,11 +24,6 @@ class CustomFrameViewTest : public ViewsTestBase { CustomFrameView* custom_frame_view() { return custom_frame_view_; } - MinimizeAndMaximizeStateControlDelegate* - minimize_and_maximize_state_control_delegate() { - return minimize_and_maximize_state_control_delegate_; - } - Widget* widget() { return widget_; } // ViewsTestBase: @@ -90,27 +58,26 @@ class CustomFrameViewTest : public ViewsTestBase { const std::vector<views::FrameButton> trailing_buttons); private: + std::unique_ptr<WidgetDelegate> widget_delegate_; + // Parent container for |custom_frame_view_| Widget* widget_; // Owned by |widget_| CustomFrameView* custom_frame_view_; - // Delegate of |widget_| which controls minimizing and maximizing - MinimizeAndMaximizeStateControlDelegate* - minimize_and_maximize_state_control_delegate_; - DISALLOW_COPY_AND_ASSIGN(CustomFrameViewTest); }; void CustomFrameViewTest::SetUp() { ViewsTestBase::SetUp(); - minimize_and_maximize_state_control_delegate_ = - new MinimizeAndMaximizeStateControlDelegate; widget_ = new Widget; Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); - params.delegate = minimize_and_maximize_state_control_delegate_; + widget_delegate_ = std::make_unique<WidgetDelegate>(); + params.delegate = widget_delegate_.get(); + params.delegate->SetCanMaximize(true); + params.delegate->SetCanMinimize(true); params.remove_standard_frame = true; widget_->Init(std::move(params)); @@ -214,9 +181,7 @@ TEST_F(CustomFrameViewTest, MaximizeRevealsRestoreButton) { TEST_F(CustomFrameViewTest, CannotMaximizeHidesButton) { Widget* parent = widget(); CustomFrameView* view = custom_frame_view(); - MinimizeAndMaximizeStateControlDelegate* delegate = - minimize_and_maximize_state_control_delegate(); - delegate->set_can_maximize(false); + widget()->widget_delegate()->SetCanMaximize(false); view->Init(parent); parent->SetBounds(gfx::Rect(0, 0, 300, 100)); @@ -231,9 +196,7 @@ TEST_F(CustomFrameViewTest, CannotMaximizeHidesButton) { TEST_F(CustomFrameViewTest, CannotMinimizeHidesButton) { Widget* parent = widget(); CustomFrameView* view = custom_frame_view(); - MinimizeAndMaximizeStateControlDelegate* delegate = - minimize_and_maximize_state_control_delegate(); - delegate->set_can_minimize(false); + widget()->widget_delegate()->SetCanMinimize(false); view->Init(parent); parent->SetBounds(gfx::Rect(0, 0, 300, 100)); diff --git a/chromium/ui/views/window/dialog_delegate.cc b/chromium/ui/views/window/dialog_delegate.cc index 6afc661f5a2..21fea394e44 100644 --- a/chromium/ui/views/window/dialog_delegate.cc +++ b/chromium/ui/views/window/dialog_delegate.cc @@ -162,6 +162,9 @@ void DialogDelegate::RunCloseCallback(base::OnceClosure callback) { } View* DialogDelegate::GetInitiallyFocusedView() { + if (params_.initially_focused_view.has_value()) + return *params_.initially_focused_view; + // Focus the default button if any. const DialogClientView* dcv = GetDialogClientView(); if (!dcv) @@ -370,6 +373,10 @@ void DialogDelegate::SetCloseCallback(base::OnceClosure callback) { close_callback_ = std::move(callback); } +void DialogDelegate::SetInitiallyFocusedView(View* view) { + params_.initially_focused_view = view; +} + std::unique_ptr<View> DialogDelegate::DisownExtraView() { return std::move(extra_view_); } diff --git a/chromium/ui/views/window/dialog_delegate.h b/chromium/ui/views/window/dialog_delegate.h index 04bc5b4cdce..2b35fd9e2c2 100644 --- a/chromium/ui/views/window/dialog_delegate.h +++ b/chromium/ui/views/window/dialog_delegate.h @@ -64,6 +64,11 @@ class VIEWS_EXPORT DialogDelegate : public WidgetDelegate { // dialog. It's legal for a button to be marked enabled that isn't present // in |buttons| (see above). int enabled_buttons = ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; + + // The view that should receive initial focus in the dialog. If not set, the + // default button will receive initial focus. If explicitly set to nullptr, + // no view will receive focus. + base::Optional<View*> initially_focused_view; }; DialogDelegate(); @@ -192,8 +197,23 @@ class VIEWS_EXPORT DialogDelegate : public WidgetDelegate { void SetButtons(int buttons); void SetButtonLabel(ui::DialogButton button, base::string16 label); void SetButtonEnabled(ui::DialogButton button, bool enabled); + void SetInitiallyFocusedView(View* view); + + // Called when the user presses the dialog's "OK" button or presses the dialog + // accept accelerator, if there is one. void SetAcceptCallback(base::OnceClosure callback); + + // Called when the user presses the dialog's "Cancel" button or presses the + // dialog close accelerator (which is always VKEY_ESCAPE). void SetCancelCallback(base::OnceClosure callback); + + // Called when: + // * The user presses the dialog's close button, if it has one + // * The dialog's widget is closed via Widget::Close() + // NOT called when the dialog's widget is closed via Widget::CloseNow() - in + // that case, the normal widget close path is skipped, so no orderly teardown + // of the dialog's widget happens. The main way that can happen in production + // use is if the dialog's parent widget is closed. void SetCloseCallback(base::OnceClosure callback); // Returns ownership of the extra view for this dialog, if one was provided diff --git a/chromium/ui/views/window/dialog_delegate_unittest.cc b/chromium/ui/views/window/dialog_delegate_unittest.cc index 6096431dc6b..33e49328132 100644 --- a/chromium/ui/views/window/dialog_delegate_unittest.cc +++ b/chromium/ui/views/window/dialog_delegate_unittest.cc @@ -515,4 +515,23 @@ TEST_F(DialogDelegateCloseTest, OldClosePathDoesNotDoubleClose) { EXPECT_FALSE(cancelled); } +TEST_F(DialogDelegateCloseTest, CloseParentWidgetDoesNotInvokeCloseCallback) { + auto* dialog = new DialogDelegateView(); + std::unique_ptr<Widget> parent = CreateTestWidget(); + Widget* widget = DialogDelegate::CreateDialogWidget(dialog, GetContext(), + parent->GetNativeView()); + + bool closed = false; + dialog->SetCloseCallback( + base::BindLambdaForTesting([&closed]() { closed = true; })); + + views::test::WidgetDestroyedWaiter parent_waiter(parent.get()); + views::test::WidgetDestroyedWaiter dialog_waiter(widget); + parent->Close(); + parent_waiter.Wait(); + dialog_waiter.Wait(); + + EXPECT_FALSE(closed); +} + } // namespace views diff --git a/chromium/ui/views/window/vector_icons/vector_icons.cc.template b/chromium/ui/views/window/vector_icons/vector_icons.cc.template index e3457f998b2..ca986041784 100644 --- a/chromium/ui/views/window/vector_icons/vector_icons.cc.template +++ b/chromium/ui/views/window/vector_icons/vector_icons.cc.template @@ -7,7 +7,6 @@ #include "ui/views/window/vector_icons/vector_icons.h" -#include "base/logging.h" #include "components/vector_icons/cc_macros.h" #include "ui/gfx/vector_icon_types.h" |