Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / views / window / dialog_delegate.h
blob3f4d18d4041e69dcd7b158243065efda3d4aa4e1
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
3 // found in the LICENSE file.
5 #ifndef UI_VIEWS_WINDOW_DIALOG_DELEGATE_H_
6 #define UI_VIEWS_WINDOW_DIALOG_DELEGATE_H_
8 #include "base/compiler_specific.h"
9 #include "base/strings/string16.h"
10 #include "ui/accessibility/ax_enums.h"
11 #include "ui/base/models/dialog_model.h"
12 #include "ui/base/ui_base_types.h"
13 #include "ui/views/widget/widget_delegate.h"
15 namespace views {
17 class DialogClientView;
19 ///////////////////////////////////////////////////////////////////////////////
21 // DialogDelegate
23 // DialogDelegate is an interface implemented by objects that wish to show a
24 // dialog box Window. The window that is displayed uses this interface to
25 // determine how it should be displayed and notify the delegate object of
26 // certain events.
28 ///////////////////////////////////////////////////////////////////////////////
29 class VIEWS_EXPORT DialogDelegate : public ui::DialogModel,
30 public WidgetDelegate {
31 public:
32 DialogDelegate();
33 ~DialogDelegate() override;
35 // Same as CreateDialogWidgetWithBounds() with an empty |bounds|.
36 static Widget* CreateDialogWidget(WidgetDelegate* delegate,
37 gfx::NativeWindow context,
38 gfx::NativeView parent);
40 // Create a dialog widget with the specified |context| or |parent|.
41 // If |bounds| is not empty, used to initially place the dialog, otherwise
42 // a default location is used.
43 static Widget* CreateDialogWidgetWithBounds(WidgetDelegate* delegate,
44 gfx::NativeWindow context,
45 gfx::NativeView parent,
46 const gfx::Rect& bounds);
48 // Override this function to display an extra view adjacent to the buttons.
49 // Overrides may construct the view; this will only be called once per dialog.
50 virtual View* CreateExtraView();
52 // Override this function to adjust the padding between the extra view and
53 // the confirm/cancel buttons. Note that if there are no buttons, this will
54 // not be used.
55 // If a custom padding should be used, returns true and populates |padding|.
56 virtual bool GetExtraViewPadding(int* padding);
58 // Override this function to display an extra view in the titlebar.
59 // Overrides may construct the view; this will only be called once per dialog.
60 // Note: this only works for new style dialogs.
61 virtual View* CreateTitlebarExtraView();
63 // Override this function to display a footnote view below the buttons.
64 // Overrides may construct the view; this will only be called once per dialog.
65 virtual View* CreateFootnoteView();
67 // For Dialog boxes, if there is a "Cancel" button or no dialog button at all,
68 // this is called when the user presses the "Cancel" button or the Esc key.
69 // It can also be called on a close action if |Close| has not been
70 // overridden. This function should return true if the window can be closed
71 // after it returns, or false if it must remain open.
72 virtual bool Cancel();
74 // For Dialog boxes, this is called when the user presses the "OK" button,
75 // or the Enter key. It can also be called on a close action if |Close|
76 // has not been overridden. This function should return true if the window
77 // can be closed after it returns, or false if it must remain open.
78 // If |window_closing| is true, it means that this handler is
79 // being called because the window is being closed (e.g. by Window::Close)
80 // and there is no Cancel handler, so Accept is being called instead.
81 virtual bool Accept(bool window_closing);
82 virtual bool Accept();
84 // Called when the user closes the window without selecting an option,
85 // e.g. by pressing the close button on the window or using a window manager
86 // gesture. By default, this calls Accept() if the only button in the dialog
87 // is Accept, Cancel() otherwise. This function should return true if the
88 // window can be closed after it returns, or false if it must remain open.
89 virtual bool Close();
91 // Overridden from ui::DialogModel:
92 base::string16 GetDialogTitle() const override;
93 int GetDialogButtons() const override;
94 int GetDefaultDialogButton() const override;
95 bool ShouldDefaultButtonBeBlue() const override;
96 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
97 bool IsDialogButtonEnabled(ui::DialogButton button) const override;
99 // Overridden from WidgetDelegate:
100 View* GetInitiallyFocusedView() override;
101 DialogDelegate* AsDialogDelegate() override;
102 ClientView* CreateClientView(Widget* widget) override;
103 NonClientFrameView* CreateNonClientFrameView(Widget* widget) override;
105 // Create a frame view using the new dialog style.
106 static NonClientFrameView* CreateDialogFrameView(Widget* widget);
108 // Returns whether this particular dialog should use the new dialog style.
109 virtual bool UseNewStyleForThisDialog() const;
111 // Called when the window has been closed.
112 virtual void OnClosed() {}
114 // A helper for accessing the DialogClientView object contained by this
115 // delegate's Window.
116 const DialogClientView* GetDialogClientView() const;
117 DialogClientView* GetDialogClientView();
119 protected:
120 // Overridden from WidgetDelegate:
121 ui::AXRole GetAccessibleWindowRole() const override;
123 private:
124 // A flag indicating whether this dialog supports the new style.
125 bool supports_new_style_;
128 // A DialogDelegate implementation that is-a View. Used to override GetWidget()
129 // to call View's GetWidget() for the common case where a DialogDelegate
130 // implementation is-a View. Note that DialogDelegateView is not owned by
131 // view's hierarchy and is expected to be deleted on DeleteDelegate call.
132 class VIEWS_EXPORT DialogDelegateView : public DialogDelegate,
133 public View {
134 public:
135 DialogDelegateView();
136 ~DialogDelegateView() override;
138 // Overridden from DialogDelegate:
139 void DeleteDelegate() override;
140 Widget* GetWidget() override;
141 const Widget* GetWidget() const override;
142 View* GetContentsView() override;
144 // Overridden from View:
145 void GetAccessibleState(ui::AXViewState* state) override;
146 void ViewHierarchyChanged(
147 const ViewHierarchyChangedDetails& details) override;
149 private:
150 DISALLOW_COPY_AND_ASSIGN(DialogDelegateView);
153 } // namespace views
155 #endif // UI_VIEWS_WINDOW_DIALOG_DELEGATE_H_