dialog_delegate.h revision ca12bfac764ba476d6cd062bf1dde12cc64c3f40
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.
4
5#ifndef UI_VIEWS_WINDOW_DIALOG_DELEGATE_H_
6#define UI_VIEWS_WINDOW_DIALOG_DELEGATE_H_
7
8#include "base/compiler_specific.h"
9#include "base/strings/string16.h"
10#include "ui/base/accessibility/accessibility_types.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"
14
15namespace views {
16
17class DialogClientView;
18
19///////////////////////////////////////////////////////////////////////////////
20//
21// DialogDelegate
22//
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.
27//
28///////////////////////////////////////////////////////////////////////////////
29class VIEWS_EXPORT DialogDelegate : public ui::DialogModel,
30                                    public WidgetDelegate {
31 public:
32  virtual ~DialogDelegate();
33
34  // Returns whether to use the new dialog style in general.
35  // See UseNewStyleForThisDialog() for dialog-specific styling.
36  static bool UseNewStyle();
37
38  // Create a |dialog| window Widget with the specified |context| or |parent|.
39  static Widget* CreateDialogWidget(DialogDelegate* dialog,
40                                    gfx::NativeWindow context,
41                                    gfx::NativeWindow parent);
42
43  // Override this function to display an extra view adjacent to the buttons.
44  // Overrides may construct the view; this will only be called once per dialog.
45  virtual View* CreateExtraView();
46
47  // Override this function to display an extra view in the titlebar.
48  // Overrides may construct the view; this will only be called once per dialog.
49  // Note: this only works for new style dialogs.
50  virtual View* CreateTitlebarExtraView();
51
52  // Override this function to display a footnote view below the buttons.
53  // Overrides may construct the view; this will only be called once per dialog.
54  virtual View* CreateFootnoteView();
55
56  // For Dialog boxes, if there is a "Cancel" button or no dialog button at all,
57  // this is called when the user presses the "Cancel" button or the Close
58  // button on the window or in the system menu, or presses the Esc key.
59  // This function should return true if the window can be closed after it
60  // returns, or false if it must remain open.
61  virtual bool Cancel();
62
63  // For Dialog boxes, this is called when the user presses the "OK" button,
64  // or the Enter key.  Can also be called on Esc key or close button
65  // presses if there is no "Cancel" button.  This function should return
66  // true if the window can be closed after it returns, or false if it must
67  // remain open.  If |window_closing| is true, it means that this handler is
68  // being called because the window is being closed (e.g.  by Window::Close)
69  // and there is no Cancel handler, so Accept is being called instead.
70  virtual bool Accept(bool window_closing);
71  virtual bool Accept();
72
73  // Overridden from ui::DialogModel:
74  virtual base::string16 GetDialogLabel() const OVERRIDE;
75  virtual base::string16 GetDialogTitle() const OVERRIDE;
76  virtual int GetDialogButtons() const OVERRIDE;
77  virtual int GetDefaultDialogButton() const OVERRIDE;
78  virtual bool ShouldDefaultButtonBeBlue() const OVERRIDE;
79  virtual base::string16 GetDialogButtonLabel(
80      ui::DialogButton button) const OVERRIDE;
81  virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE;
82
83  // Overridden from WidgetDelegate:
84  virtual View* GetInitiallyFocusedView() OVERRIDE;
85  virtual DialogDelegate* AsDialogDelegate() OVERRIDE;
86  virtual ClientView* CreateClientView(Widget* widget) OVERRIDE;
87  virtual NonClientFrameView* CreateNonClientFrameView(Widget* widget) OVERRIDE;
88
89  // Create a frame view using the new dialog style.
90  static NonClientFrameView* CreateNewStyleFrameView(Widget* widget);
91  // The semi-transparent border and shadow of the new style frame view does not
92  // work on child windows under Views/Win32. This is a kludge to get a
93  // reasonable-looking opaque border for the dialog. Note that this does not
94  // support arrows.
95  //
96  // TODO(wittman): Remove once WinAura is in place.
97  static NonClientFrameView* CreateNewStyleFrameView(Widget* widget,
98                                                     bool force_opaque_border);
99
100  // Returns whether this particular dialog should use the new dialog style.
101  virtual bool UseNewStyleForThisDialog() const;
102
103  // Called when the window has been closed.
104  virtual void OnClose() {}
105
106  // A helper for accessing the DialogClientView object contained by this
107  // delegate's Window.
108  const DialogClientView* GetDialogClientView() const;
109  DialogClientView* GetDialogClientView();
110
111 protected:
112  // Overridden from WidgetDelegate:
113  virtual ui::AccessibilityTypes::Role GetAccessibleWindowRole() const OVERRIDE;
114};
115
116// A DialogDelegate implementation that is-a View. Used to override GetWidget()
117// to call View's GetWidget() for the common case where a DialogDelegate
118// implementation is-a View. Note that DialogDelegateView is not owned by
119// view's hierarchy and is expected to be deleted on DeleteDelegate call.
120class VIEWS_EXPORT DialogDelegateView : public DialogDelegate,
121                                        public View {
122 public:
123  DialogDelegateView();
124  virtual ~DialogDelegateView();
125
126  // Overridden from DialogDelegate:
127  virtual void DeleteDelegate() OVERRIDE;
128  virtual Widget* GetWidget() OVERRIDE;
129  virtual const Widget* GetWidget() const OVERRIDE;
130  virtual View* GetContentsView() OVERRIDE;
131
132 private:
133  DISALLOW_COPY_AND_ASSIGN(DialogDelegateView);
134};
135
136}  // namespace views
137
138#endif  // UI_VIEWS_WINDOW_DIALOG_DELEGATE_H_
139