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"
17 class DialogClientView
;
19 ///////////////////////////////////////////////////////////////////////////////
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
28 ///////////////////////////////////////////////////////////////////////////////
29 class VIEWS_EXPORT DialogDelegate
: public ui::DialogModel
,
30 public WidgetDelegate
{
32 virtual ~DialogDelegate();
34 // Create a |dialog| window Widget with the specified |context| or |parent|.
35 static Widget
* CreateDialogWidget(DialogDelegate
* dialog
,
36 gfx::NativeView context
,
37 gfx::NativeView parent
);
39 // Override this function to display an extra view adjacent to the buttons.
40 // Overrides may construct the view; this will only be called once per dialog.
41 virtual View
* CreateExtraView();
43 // Override this function to display an extra view in the titlebar.
44 // Overrides may construct the view; this will only be called once per dialog.
45 // Note: this only works for new style dialogs.
46 virtual View
* CreateTitlebarExtraView();
48 // Override this function to display a footnote view below the buttons.
49 // Overrides may construct the view; this will only be called once per dialog.
50 virtual View
* CreateFootnoteView();
52 // For Dialog boxes, if there is a "Cancel" button or no dialog button at all,
53 // this is called when the user presses the "Cancel" button or the Esc key.
54 // It can also be called on a close action if |Close| has not been
55 // overridden. This function should return true if the window can be closed
56 // after it returns, or false if it must remain open.
57 virtual bool Cancel();
59 // For Dialog boxes, this is called when the user presses the "OK" button,
60 // or the Enter key. It can also be called on a close action if |Close|
61 // has not been overridden. This function should return true if the window
62 // can be closed after it returns, or false if it must remain open.
63 // If |window_closing| is true, it means that this handler is
64 // being called because the window is being closed (e.g. by Window::Close)
65 // and there is no Cancel handler, so Accept is being called instead.
66 virtual bool Accept(bool window_closing
);
67 virtual bool Accept();
69 // Called when the user closes the window without selecting an option,
70 // e.g. by pressing the close button on the window or using a window manager
71 // gesture. By default, this calls Accept() if the only button in the dialog
72 // is Accept, Cancel() otherwise. This function should return true if the
73 // window can be closed after it returns, or false if it must remain open.
76 // Overridden from ui::DialogModel:
77 virtual base::string16
GetDialogLabel() const OVERRIDE
;
78 virtual base::string16
GetDialogTitle() const OVERRIDE
;
79 virtual int GetDialogButtons() const OVERRIDE
;
80 virtual int GetDefaultDialogButton() const OVERRIDE
;
81 virtual bool ShouldDefaultButtonBeBlue() const OVERRIDE
;
82 virtual base::string16
GetDialogButtonLabel(
83 ui::DialogButton button
) const OVERRIDE
;
84 virtual bool IsDialogButtonEnabled(ui::DialogButton button
) const OVERRIDE
;
86 // Overridden from WidgetDelegate:
87 virtual View
* GetInitiallyFocusedView() OVERRIDE
;
88 virtual DialogDelegate
* AsDialogDelegate() OVERRIDE
;
89 virtual ClientView
* CreateClientView(Widget
* widget
) OVERRIDE
;
90 virtual NonClientFrameView
* CreateNonClientFrameView(Widget
* widget
) OVERRIDE
;
92 // Create a frame view using the new dialog style.
93 static NonClientFrameView
* CreateDialogFrameView(Widget
* widget
);
95 // Returns whether this particular dialog should use the new dialog style.
96 virtual bool UseNewStyleForThisDialog() const;
98 // Called when the window has been closed.
99 virtual void OnClosed() {}
101 // A helper for accessing the DialogClientView object contained by this
102 // delegate's Window.
103 const DialogClientView
* GetDialogClientView() const;
104 DialogClientView
* GetDialogClientView();
107 // Overridden from WidgetDelegate:
108 virtual ui::AXRole
GetAccessibleWindowRole() const OVERRIDE
;
111 // A DialogDelegate implementation that is-a View. Used to override GetWidget()
112 // to call View's GetWidget() for the common case where a DialogDelegate
113 // implementation is-a View. Note that DialogDelegateView is not owned by
114 // view's hierarchy and is expected to be deleted on DeleteDelegate call.
115 class VIEWS_EXPORT DialogDelegateView
: public DialogDelegate
,
118 DialogDelegateView();
119 virtual ~DialogDelegateView();
121 // Overridden from DialogDelegate:
122 virtual void DeleteDelegate() OVERRIDE
;
123 virtual Widget
* GetWidget() OVERRIDE
;
124 virtual const Widget
* GetWidget() const OVERRIDE
;
125 virtual View
* GetContentsView() OVERRIDE
;
128 DISALLOW_COPY_AND_ASSIGN(DialogDelegateView
);
133 #endif // UI_VIEWS_WINDOW_DIALOG_DELEGATE_H_