1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_VIEWS_H_
6 #define COMPONENTS_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_VIEWS_H_
10 #include "build/build_config.h"
11 #include "ui/gfx/native_widget_types.h"
28 class ModalDialogHost;
29 class WebContentsModalDialogHost;
32 namespace constrained_window {
34 extern const void* kConstrainedWindowWidgetIdentifier;
36 class ConstrainedWindowViewsClient;
38 // Sets the ConstrainedWindowClient impl.
39 void SetConstrainedWindowViewsClient(
40 std::unique_ptr<ConstrainedWindowViewsClient> client);
42 // Update the position of dialog |widget| against |dialog_host|. This is used to
43 // reposition widgets e.g. when the host dimensions change.
44 void UpdateWebContentsModalDialogPosition(
45 views::Widget* widget,
46 web_modal::WebContentsModalDialogHost* dialog_host);
48 void UpdateWidgetModalDialogPosition(
49 views::Widget* widget,
50 web_modal::ModalDialogHost* dialog_host);
52 // Returns the top level WebContents of |initiator_web_contents|.
53 content::WebContents* GetTopLevelWebContents(
54 content::WebContents* initiator_web_contents);
56 // Shows the dialog with a new SingleWebContentsDialogManager. The dialog will
57 // notify via WillClose() when it is being destroyed.
58 void ShowModalDialog(gfx::NativeWindow dialog,
59 content::WebContents* web_contents);
61 // Calls CreateWebModalDialogViews, shows the dialog, and returns its widget.
62 views::Widget* ShowWebModalDialogViews(
63 views::WidgetDelegate* dialog,
64 content::WebContents* initiator_web_contents);
66 // Create a widget for |dialog| that is modal to |web_contents|.
67 // The modal type of |dialog->GetModalType()| must be ui::MODAL_TYPE_CHILD.
68 views::Widget* CreateWebModalDialogViews(views::WidgetDelegate* dialog,
69 content::WebContents* web_contents);
71 // Create a widget for |dialog| that has a modality given by
72 // |dialog->GetModalType()|. The modal type must be either
73 // ui::MODAL_TYPE_SYSTEM or ui::MODAL_TYPE_WINDOW. This places the dialog
74 // appropriately if |parent| is a valid browser window. Currently, |parent| may
75 // be null for MODAL_TYPE_WINDOW, but that's a bug and callers shouldn't rely on
76 // that working. See http://crbug.com/657293. Instead of calling this function
77 // with null |parent| and MODAL_TYPE_WINDOW, consider calling views::
78 // DialogDelegate::CreateDialogWidget(dialog, nullptr, nullptr) instead.
79 // For dialogs that may appear without direct user interaction (i.e., that may
80 // appear while a user is busily accomplishing some other task in the browser),
81 // consider providing an override of GetDefaultDialogButton on |dialog| to
82 // suppress the normal behavior of choosing a focused-by-default button. This is
83 // especially important if the action of the default button has consequences on
84 // the user's task at hand.
85 views::Widget* CreateBrowserModalDialogViews(
86 std::unique_ptr<views::DialogDelegate> dialog,
87 gfx::NativeWindow parent);
89 // TODO(pbos): Transition calls to this to the unique_ptr<> version above.
90 views::Widget* CreateBrowserModalDialogViews(views::DialogDelegate* dialog,
91 gfx::NativeWindow parent);
93 // Shows a browser-modal dialog based on `dialog_model`, returns pointer
94 // to the created widget.
95 views::Widget* ShowBrowserModal(std::unique_ptr<ui::DialogModel> dialog_model,
96 gfx::NativeWindow parent);
98 // Shows a web/tab-modal dialog based on `dialog_model` and returns its widget.
99 views::Widget* ShowWebModal(std::unique_ptr<ui::DialogModel> dialog_model,
100 content::WebContents* web_contents);
102 } // namespace constrained_window
104 #endif // COMPONENTS_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_VIEWS_H_