Sort unlaunched apps on app list start page by apps grid order.
[chromium-blink-merge.git] / ui / views / window / dialog_delegate.h
blobc84fb82af43a5bc94a8370dfbc4bc854a3a5c0fe
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 display an extra view in the titlebar.
53 // Overrides may construct the view; this will only be called once per dialog.
54 // Note: this only works for new style dialogs.
55 virtual View* CreateTitlebarExtraView();
57 // Override this function to display a footnote view below the buttons.
58 // Overrides may construct the view; this will only be called once per dialog.
59 virtual View* CreateFootnoteView();
61 // For Dialog boxes, if there is a "Cancel" button or no dialog button at all,
62 // this is called when the user presses the "Cancel" button or the Esc key.
63 // It can also be called on a close action if |Close| has not been
64 // overridden. This function should return true if the window can be closed
65 // after it returns, or false if it must remain open.
66 virtual bool Cancel();
68 // For Dialog boxes, this is called when the user presses the "OK" button,
69 // or the Enter key. It can also be called on a close action if |Close|
70 // has not been overridden. This function should return true if the window
71 // can be closed after it returns, or false if it must remain open.
72 // If |window_closing| is true, it means that this handler is
73 // being called because the window is being closed (e.g. by Window::Close)
74 // and there is no Cancel handler, so Accept is being called instead.
75 virtual bool Accept(bool window_closing);
76 virtual bool Accept();
78 // Called when the user closes the window without selecting an option,
79 // e.g. by pressing the close button on the window or using a window manager
80 // gesture. By default, this calls Accept() if the only button in the dialog
81 // is Accept, Cancel() otherwise. This function should return true if the
82 // window can be closed after it returns, or false if it must remain open.
83 virtual bool Close();
85 // Overridden from ui::DialogModel:
86 base::string16 GetDialogTitle() const override;
87 int GetDialogButtons() const override;
88 int GetDefaultDialogButton() const override;
89 bool ShouldDefaultButtonBeBlue() const override;
90 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
91 bool IsDialogButtonEnabled(ui::DialogButton button) const override;
93 // Overridden from WidgetDelegate:
94 View* GetInitiallyFocusedView() override;
95 DialogDelegate* AsDialogDelegate() override;
96 ClientView* CreateClientView(Widget* widget) override;
97 NonClientFrameView* CreateNonClientFrameView(Widget* widget) override;
99 // Create a frame view using the new dialog style.
100 static NonClientFrameView* CreateDialogFrameView(Widget* widget);
102 // Returns whether this particular dialog should use the new dialog style.
103 virtual bool UseNewStyleForThisDialog() const;
105 // Called when the window has been closed.
106 virtual void OnClosed() {}
108 // A helper for accessing the DialogClientView object contained by this
109 // delegate's Window.
110 const DialogClientView* GetDialogClientView() const;
111 DialogClientView* GetDialogClientView();
113 protected:
114 // Overridden from WidgetDelegate:
115 ui::AXRole GetAccessibleWindowRole() const override;
117 private:
118 // A flag indicating whether this dialog supports the new style.
119 bool supports_new_style_;
122 // A DialogDelegate implementation that is-a View. Used to override GetWidget()
123 // to call View's GetWidget() for the common case where a DialogDelegate
124 // implementation is-a View. Note that DialogDelegateView is not owned by
125 // view's hierarchy and is expected to be deleted on DeleteDelegate call.
126 class VIEWS_EXPORT DialogDelegateView : public DialogDelegate,
127 public View {
128 public:
129 DialogDelegateView();
130 ~DialogDelegateView() override;
132 // Overridden from DialogDelegate:
133 void DeleteDelegate() override;
134 Widget* GetWidget() override;
135 const Widget* GetWidget() const override;
136 View* GetContentsView() override;
138 // Overridden from View:
139 void GetAccessibleState(ui::AXViewState* state) override;
140 void ViewHierarchyChanged(
141 const ViewHierarchyChangedDetails& details) override;
143 private:
144 DISALLOW_COPY_AND_ASSIGN(DialogDelegateView);
147 } // namespace views
149 #endif // UI_VIEWS_WINDOW_DIALOG_DELEGATE_H_