2022-06-02 11:49:50 +02:00
|
|
|
diff --git chrome/browser/ui/views/chrome_javascript_app_modal_view_factory_views.cc chrome/browser/ui/views/chrome_javascript_app_modal_view_factory_views.cc
|
2022-11-15 18:50:53 +01:00
|
|
|
index d62e9fa67d534..e7bdaeb7b5e19 100644
|
2022-06-02 11:49:50 +02:00
|
|
|
--- chrome/browser/ui/views/chrome_javascript_app_modal_view_factory_views.cc
|
|
|
|
+++ chrome/browser/ui/views/chrome_javascript_app_modal_view_factory_views.cc
|
|
|
|
@@ -97,7 +97,7 @@ javascript_dialogs::AppModalDialogView* CreateViewsJavaScriptDialog(
|
|
|
|
gfx::NativeWindow parent_window =
|
|
|
|
controller->web_contents()->GetTopLevelNativeWindow();
|
|
|
|
#if defined(USE_AURA)
|
|
|
|
- if (!parent_window->GetRootWindow()) {
|
|
|
|
+ if (parent_window && !parent_window->GetRootWindow()) {
|
|
|
|
// When we are part of a WebContents that isn't actually being displayed
|
|
|
|
// on the screen, we can't actually attach to it.
|
|
|
|
parent_window = nullptr;
|
|
|
|
diff --git components/constrained_window/constrained_window_views.cc components/constrained_window/constrained_window_views.cc
|
2022-11-15 18:50:53 +01:00
|
|
|
index aa0bbc8ae1a0f..d862340edfb0b 100644
|
2022-06-02 11:49:50 +02:00
|
|
|
--- components/constrained_window/constrained_window_views.cc
|
|
|
|
+++ components/constrained_window/constrained_window_views.cc
|
2022-06-17 15:28:55 +02:00
|
|
|
@@ -101,15 +101,24 @@ void UpdateModalDialogPosition(views::Widget* widget,
|
2022-06-02 11:49:50 +02:00
|
|
|
if (widget->HasCapture())
|
|
|
|
return;
|
|
|
|
|
|
|
|
+ // |host_view| will be nullptr with CEF windowless rendering.
|
|
|
|
+ auto host_view = dialog_host->GetHostView();
|
|
|
|
views::Widget* host_widget =
|
|
|
|
- views::Widget::GetWidgetForNativeView(dialog_host->GetHostView());
|
|
|
|
+ host_view ? views::Widget::GetWidgetForNativeView(host_view) : nullptr;
|
|
|
|
|
|
|
|
// If the host view is not backed by a Views::Widget, just update the widget
|
|
|
|
// size. This can happen on MacViews under the Cocoa browser where the window
|
|
|
|
// modal dialogs are displayed as sheets, and their position is managed by a
|
|
|
|
// ConstrainedWindowSheetController instance.
|
|
|
|
if (!host_widget) {
|
|
|
|
+#if BUILDFLAG(IS_MAC)
|
|
|
|
widget->SetSize(size);
|
|
|
|
+#elif BUILDFLAG(IS_POSIX)
|
|
|
|
+ // Set the bounds here instead of relying on the default behavior of
|
|
|
|
+ // DesktopWindowTreeHostPlatform::CenterWindow which incorrectly centers
|
|
|
|
+ // the window on the screen.
|
|
|
|
+ widget->SetBounds(gfx::Rect(dialog_host->GetDialogPosition(size), size));
|
|
|
|
+#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-17 15:28:55 +02:00
|
|
|
@@ -215,7 +224,8 @@ views::Widget* CreateWebModalDialogViews(views::WidgetDelegate* dialog,
|
2022-06-02 11:49:50 +02:00
|
|
|
|
|
|
|
return views::DialogDelegate::CreateDialogWidget(
|
|
|
|
dialog, nullptr,
|
|
|
|
- manager->delegate()->GetWebContentsModalDialogHost()->GetHostView());
|
|
|
|
+ manager->delegate()->GetWebContentsModalDialogHost()->GetHostView(),
|
|
|
|
+ manager->delegate()->GetWebContentsModalDialogHost()->GetHostWidget());
|
|
|
|
}
|
|
|
|
|
|
|
|
views::Widget* CreateBrowserModalDialogViews(
|
2022-06-17 15:28:55 +02:00
|
|
|
@@ -232,8 +242,13 @@ views::Widget* CreateBrowserModalDialogViews(views::DialogDelegate* dialog,
|
2022-06-02 11:49:50 +02:00
|
|
|
|
|
|
|
gfx::NativeView parent_view =
|
|
|
|
parent ? CurrentClient()->GetDialogHostView(parent) : nullptr;
|
|
|
|
+ // Use with CEF windowless rendering.
|
|
|
|
+ gfx::AcceleratedWidget parent_widget =
|
|
|
|
+ parent ? gfx::kNullAcceleratedWidget :
|
|
|
|
+ CurrentClient()->GetModalDialogHost(parent)->GetHostWidget();
|
|
|
|
views::Widget* widget =
|
|
|
|
- views::DialogDelegate::CreateDialogWidget(dialog, nullptr, parent_view);
|
|
|
|
+ views::DialogDelegate::CreateDialogWidget(dialog, nullptr, parent_view,
|
|
|
|
+ parent_widget);
|
|
|
|
|
|
|
|
bool requires_positioning = dialog->use_custom_frame();
|
|
|
|
|
2022-06-17 15:28:55 +02:00
|
|
|
@@ -246,8 +261,7 @@ views::Widget* CreateBrowserModalDialogViews(views::DialogDelegate* dialog,
|
2022-06-02 11:49:50 +02:00
|
|
|
if (!requires_positioning)
|
|
|
|
return widget;
|
|
|
|
|
|
|
|
- ModalDialogHost* host =
|
|
|
|
- parent ? CurrentClient()->GetModalDialogHost(parent) : nullptr;
|
|
|
|
+ ModalDialogHost* host = CurrentClient()->GetModalDialogHost(parent);
|
|
|
|
if (host) {
|
|
|
|
DCHECK_EQ(parent_view, host->GetHostView());
|
|
|
|
ModalDialogHostObserver* dialog_host_observer =
|
|
|
|
diff --git components/constrained_window/native_web_contents_modal_dialog_manager_views.cc components/constrained_window/native_web_contents_modal_dialog_manager_views.cc
|
2022-09-26 21:30:45 +02:00
|
|
|
index 647391095306e..02aea9b01f59b 100644
|
2022-06-02 11:49:50 +02:00
|
|
|
--- components/constrained_window/native_web_contents_modal_dialog_manager_views.cc
|
|
|
|
+++ components/constrained_window/native_web_contents_modal_dialog_manager_views.cc
|
|
|
|
@@ -184,9 +184,12 @@ void NativeWebContentsModalDialogManagerViews::HostChanged(
|
|
|
|
if (host_) {
|
|
|
|
host_->AddObserver(this);
|
|
|
|
|
|
|
|
- for (auto* widget : observed_widgets_) {
|
|
|
|
- views::Widget::ReparentNativeView(widget->GetNativeView(),
|
|
|
|
- host_->GetHostView());
|
|
|
|
+ // |host_view| will be nullptr with CEF windowless rendering.
|
|
|
|
+ if (auto host_view = host_->GetHostView()) {
|
|
|
|
+ for (auto* widget : observed_widgets_) {
|
|
|
|
+ views::Widget::ReparentNativeView(widget->GetNativeView(),
|
|
|
|
+ host_view);
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
|
|
|
|
OnPositionRequiresUpdate();
|
|
|
|
diff --git components/web_modal/modal_dialog_host.h components/web_modal/modal_dialog_host.h
|
2022-09-26 21:30:45 +02:00
|
|
|
index 51ed6bcf6b540..9ae4737e0737e 100644
|
2022-06-02 11:49:50 +02:00
|
|
|
--- components/web_modal/modal_dialog_host.h
|
|
|
|
+++ components/web_modal/modal_dialog_host.h
|
|
|
|
@@ -34,6 +34,10 @@ class WEB_MODAL_EXPORT ModalDialogHost {
|
|
|
|
|
|
|
|
// Returns the view against which the dialog is positioned and parented.
|
|
|
|
virtual gfx::NativeView GetHostView() const = 0;
|
|
|
|
+ // Returns the widget against which the dialog is positioned and parented.
|
|
|
|
+ // Used with CEF windowless rendering.
|
|
|
|
+ virtual gfx::AcceleratedWidget GetHostWidget() const {
|
|
|
|
+ return gfx::kNullAcceleratedWidget; }
|
|
|
|
// Gets the position for the dialog in coordinates relative to the host view.
|
|
|
|
virtual gfx::Point GetDialogPosition(const gfx::Size& size) = 0;
|
|
|
|
// Returns whether a dialog currently about to be shown should be activated.
|
|
|
|
diff --git ui/views/window/dialog_delegate.cc ui/views/window/dialog_delegate.cc
|
2023-01-03 00:34:43 +01:00
|
|
|
index 54cd17c85983d..c8c276169eaec 100644
|
2022-06-02 11:49:50 +02:00
|
|
|
--- ui/views/window/dialog_delegate.cc
|
|
|
|
+++ ui/views/window/dialog_delegate.cc
|
|
|
|
@@ -60,10 +60,12 @@ DialogDelegate::DialogDelegate() {
|
|
|
|
// static
|
|
|
|
Widget* DialogDelegate::CreateDialogWidget(WidgetDelegate* delegate,
|
|
|
|
gfx::NativeWindow context,
|
|
|
|
- gfx::NativeView parent) {
|
|
|
|
+ gfx::NativeView parent,
|
|
|
|
+ gfx::AcceleratedWidget parent_widget) {
|
|
|
|
views::Widget* widget = new views::Widget;
|
|
|
|
views::Widget::InitParams params =
|
|
|
|
- GetDialogWidgetInitParams(delegate, context, parent, gfx::Rect());
|
|
|
|
+ GetDialogWidgetInitParams(delegate, context, parent, gfx::Rect(),
|
|
|
|
+ parent_widget);
|
|
|
|
widget->Init(std::move(params));
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
@@ -72,22 +74,24 @@ Widget* DialogDelegate::CreateDialogWidget(WidgetDelegate* delegate,
|
|
|
|
Widget* DialogDelegate::CreateDialogWidget(
|
|
|
|
std::unique_ptr<WidgetDelegate> delegate,
|
|
|
|
gfx::NativeWindow context,
|
|
|
|
- gfx::NativeView parent) {
|
|
|
|
+ gfx::NativeView parent,
|
|
|
|
+ gfx::AcceleratedWidget parent_widget) {
|
|
|
|
DCHECK(delegate->owned_by_widget());
|
|
|
|
- return CreateDialogWidget(delegate.release(), context, parent);
|
|
|
|
+ return CreateDialogWidget(delegate.release(), context, parent, parent_widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
-bool DialogDelegate::CanSupportCustomFrame(gfx::NativeView parent) {
|
|
|
|
+bool DialogDelegate::CanSupportCustomFrame(gfx::NativeView parent,
|
|
|
|
+ gfx::AcceleratedWidget parent_widget) {
|
|
|
|
#if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && \
|
|
|
|
BUILDFLAG(ENABLE_DESKTOP_AURA)
|
|
|
|
// The new style doesn't support unparented dialogs on Linux desktop.
|
|
|
|
- return parent != nullptr;
|
|
|
|
+ return parent != nullptr || parent_widget != gfx::kNullAcceleratedWidget;
|
|
|
|
#else
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
|
|
|
// The new style doesn't support unparented dialogs on Windows Classic themes.
|
|
|
|
if (!ui::win::IsAeroGlassEnabled())
|
|
|
|
- return parent != nullptr;
|
|
|
|
+ return parent != nullptr || parent_widget != gfx::kNullAcceleratedWidget;
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
@@ -98,14 +102,15 @@ Widget::InitParams DialogDelegate::GetDialogWidgetInitParams(
|
|
|
|
WidgetDelegate* delegate,
|
|
|
|
gfx::NativeWindow context,
|
|
|
|
gfx::NativeView parent,
|
|
|
|
- const gfx::Rect& bounds) {
|
|
|
|
+ const gfx::Rect& bounds,
|
|
|
|
+ gfx::AcceleratedWidget parent_widget) {
|
|
|
|
views::Widget::InitParams params;
|
|
|
|
params.delegate = delegate;
|
|
|
|
params.bounds = bounds;
|
|
|
|
DialogDelegate* dialog = delegate->AsDialogDelegate();
|
|
|
|
|
|
|
|
if (dialog)
|
|
|
|
- dialog->params_.custom_frame &= CanSupportCustomFrame(parent);
|
|
|
|
+ dialog->params_.custom_frame &= CanSupportCustomFrame(parent, parent_widget);
|
|
|
|
|
|
|
|
if (!dialog || dialog->use_custom_frame()) {
|
|
|
|
params.opacity = Widget::InitParams::WindowOpacity::kTranslucent;
|
|
|
|
@@ -118,6 +123,7 @@ Widget::InitParams DialogDelegate::GetDialogWidgetInitParams(
|
|
|
|
}
|
|
|
|
params.context = context;
|
|
|
|
params.parent = parent;
|
|
|
|
+ params.parent_widget = parent_widget;
|
|
|
|
#if !BUILDFLAG(IS_APPLE)
|
|
|
|
// Web-modal (ui::MODAL_TYPE_CHILD) dialogs with parents are marked as child
|
|
|
|
// widgets to prevent top-level window behavior (independent movement, etc).
|
|
|
|
diff --git ui/views/window/dialog_delegate.h ui/views/window/dialog_delegate.h
|
2023-01-03 00:34:43 +01:00
|
|
|
index b0923fe17e355..2b0545061e0e9 100644
|
2022-06-02 11:49:50 +02:00
|
|
|
--- ui/views/window/dialog_delegate.h
|
|
|
|
+++ ui/views/window/dialog_delegate.h
|
|
|
|
@@ -94,13 +94,18 @@ class VIEWS_EXPORT DialogDelegate : public WidgetDelegate {
|
|
|
|
// your use case.
|
|
|
|
static Widget* CreateDialogWidget(std::unique_ptr<WidgetDelegate> delegate,
|
|
|
|
gfx::NativeWindow context,
|
|
|
|
- gfx::NativeView parent);
|
|
|
|
+ gfx::NativeView parent,
|
|
|
|
+ gfx::AcceleratedWidget parent_widget =
|
|
|
|
+ gfx::kNullAcceleratedWidget);
|
|
|
|
static Widget* CreateDialogWidget(WidgetDelegate* delegate,
|
|
|
|
gfx::NativeWindow context,
|
|
|
|
- gfx::NativeView parent);
|
|
|
|
+ gfx::NativeView parent,
|
|
|
|
+ gfx::AcceleratedWidget parent_widget =
|
|
|
|
+ gfx::kNullAcceleratedWidget);
|
|
|
|
|
|
|
|
// Whether using custom dialog frame is supported for this dialog.
|
|
|
|
- static bool CanSupportCustomFrame(gfx::NativeView parent);
|
|
|
|
+ static bool CanSupportCustomFrame(gfx::NativeView parent,
|
|
|
|
+ gfx::AcceleratedWidget parent_widget);
|
|
|
|
|
|
|
|
// Returns the dialog widget InitParams for a given |context| or |parent|.
|
|
|
|
// If |bounds| is not empty, used to initially place the dialog, otherwise
|
|
|
|
@@ -108,7 +113,9 @@ class VIEWS_EXPORT DialogDelegate : public WidgetDelegate {
|
|
|
|
static Widget::InitParams GetDialogWidgetInitParams(WidgetDelegate* delegate,
|
|
|
|
gfx::NativeWindow context,
|
|
|
|
gfx::NativeView parent,
|
|
|
|
- const gfx::Rect& bounds);
|
|
|
|
+ const gfx::Rect& bounds,
|
|
|
|
+ gfx::AcceleratedWidget parent_widget =
|
|
|
|
+ gfx::kNullAcceleratedWidget);
|
|
|
|
|
|
|
|
// Returns a mask specifying which of the available DialogButtons are visible
|
|
|
|
// for the dialog.
|