constrained_window_views.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #ifndef COMPONENTS_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_VIEWS_H_
  5. #define COMPONENTS_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_VIEWS_H_
  6. #include <memory>
  7. #include "build/build_config.h"
  8. #include "ui/gfx/native_widget_types.h"
  9. namespace content {
  10. class WebContents;
  11. }
  12. namespace ui {
  13. class DialogModel;
  14. }
  15. namespace views {
  16. class DialogDelegate;
  17. class Widget;
  18. class WidgetDelegate;
  19. }
  20. namespace web_modal {
  21. class ModalDialogHost;
  22. class WebContentsModalDialogHost;
  23. }
  24. namespace constrained_window {
  25. class ConstrainedWindowViewsClient;
  26. // Sets the ConstrainedWindowClient impl.
  27. void SetConstrainedWindowViewsClient(
  28. std::unique_ptr<ConstrainedWindowViewsClient> client);
  29. // Update the position of dialog |widget| against |dialog_host|. This is used to
  30. // reposition widgets e.g. when the host dimensions change.
  31. void UpdateWebContentsModalDialogPosition(
  32. views::Widget* widget,
  33. web_modal::WebContentsModalDialogHost* dialog_host);
  34. void UpdateWidgetModalDialogPosition(
  35. views::Widget* widget,
  36. web_modal::ModalDialogHost* dialog_host);
  37. // Returns the top level WebContents of |initiator_web_contents|.
  38. content::WebContents* GetTopLevelWebContents(
  39. content::WebContents* initiator_web_contents);
  40. // Shows the dialog with a new SingleWebContentsDialogManager. The dialog will
  41. // notify via WillClose() when it is being destroyed.
  42. void ShowModalDialog(gfx::NativeWindow dialog,
  43. content::WebContents* web_contents);
  44. // Calls CreateWebModalDialogViews, shows the dialog, and returns its widget.
  45. views::Widget* ShowWebModalDialogViews(
  46. views::WidgetDelegate* dialog,
  47. content::WebContents* initiator_web_contents);
  48. // Create a widget for |dialog| that is modal to |web_contents|.
  49. // The modal type of |dialog->GetModalType()| must be ui::MODAL_TYPE_CHILD.
  50. views::Widget* CreateWebModalDialogViews(views::WidgetDelegate* dialog,
  51. content::WebContents* web_contents);
  52. // Create a widget for |dialog| that has a modality given by
  53. // |dialog->GetModalType()|. The modal type must be either
  54. // ui::MODAL_TYPE_SYSTEM or ui::MODAL_TYPE_WINDOW. This places the dialog
  55. // appropriately if |parent| is a valid browser window. Currently, |parent| may
  56. // be null for MODAL_TYPE_WINDOW, but that's a bug and callers shouldn't rely on
  57. // that working. See http://crbug.com/657293. Instead of calling this function
  58. // with null |parent| and MODAL_TYPE_WINDOW, consider calling views::
  59. // DialogDelegate::CreateDialogWidget(dialog, nullptr, nullptr) instead.
  60. // For dialogs that may appear without direct user interaction (i.e., that may
  61. // appear while a user is busily accomplishing some other task in the browser),
  62. // consider providing an override of GetDefaultDialogButton on |dialog| to
  63. // suppress the normal behavior of choosing a focused-by-default button. This is
  64. // especially important if the action of the default button has consequences on
  65. // the user's task at hand.
  66. views::Widget* CreateBrowserModalDialogViews(
  67. std::unique_ptr<views::DialogDelegate> dialog,
  68. gfx::NativeWindow parent);
  69. // TODO(pbos): Transition calls to this to the unique_ptr<> version above.
  70. views::Widget* CreateBrowserModalDialogViews(views::DialogDelegate* dialog,
  71. gfx::NativeWindow parent);
  72. // Shows a browser-modal dialog based on `dialog_model`.
  73. void ShowBrowserModal(std::unique_ptr<ui::DialogModel> dialog_model,
  74. gfx::NativeWindow parent);
  75. // Shows a web/tab-modal dialog based on `dialog_model` and returns its widget.
  76. views::Widget* ShowWebModal(std::unique_ptr<ui::DialogModel> dialog_model,
  77. content::WebContents* web_contents);
  78. } // namespace constrained_window
  79. #endif // COMPONENTS_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_VIEWS_H_