diff --git a/chrome/browser/ui/views/frame/immersive_mode_controller_mac.mm b/chrome/browser/ui/views/frame/immersive_mode_controller_mac.mm index 247ab9a41c3be..22396868f5eeb 100644 --- a/chrome/browser/ui/views/frame/immersive_mode_controller_mac.mm +++ b/chrome/browser/ui/views/frame/immersive_mode_controller_mac.mm @@ -25,6 +25,7 @@ #include "chrome/browser/ui/web_applications/app_browser_controller.h" #include "chrome/common/chrome_features.h" #include "chrome/common/pref_names.h" +#include "components/constrained_window/constrained_window_views.h" #include "ui/gfx/geometry/insets.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/size.h" @@ -34,6 +35,7 @@ #include "ui/views/focus/focus_manager.h" #include "ui/views/focus/focus_search.h" #include "ui/views/view_observer.h" +#include "ui/views/widget/native_widget.h" #include "ui/views/widget/widget.h" namespace { @@ -498,6 +500,11 @@ bool ImmersiveModeControllerMac::ShouldMoveChild(views::Widget* child) { } } + if (child->GetNativeWindowProperty(views::kWidgetIdentifierKey) == + constrained_window::kConstrainedWindowWidgetIdentifier) { + return true; + } + // Widgets that have an anchor view contained within top chrome should be // reparented. views::WidgetDelegate* widget_delegate = child->widget_delegate(); diff --git a/components/constrained_window/constrained_window_views.cc b/components/constrained_window/constrained_window_views.cc index dc648ad1ae595..819da6b0bff94 100644 --- a/components/constrained_window/constrained_window_views.cc +++ b/components/constrained_window/constrained_window_views.cc @@ -19,6 +19,7 @@ #include "ui/display/display.h" #include "ui/display/screen.h" #include "ui/views/bubble/bubble_dialog_model_host.h" +#include "ui/views/widget/native_widget.h" #include "ui/views/widget/widget.h" #include "ui/views/widget/widget_observer.h" #include "ui/views/window/dialog_delegate.h" @@ -32,6 +33,9 @@ using web_modal::ModalDialogHost; using web_modal::ModalDialogHostObserver; namespace constrained_window { + +const void* kConstrainedWindowWidgetIdentifier = "ConstrainedWindowWidget"; + namespace { // Storage access for the currently active ConstrainedWindowViewsClient. @@ -213,9 +217,14 @@ views::Widget* CreateWebModalDialogViews(views::WidgetDelegate* dialog, << ", scheme=" << url.scheme_piece() << ", host=" << url.host_piece(); } - return views::DialogDelegate::CreateDialogWidget( + views::Widget* widget = views::DialogDelegate::CreateDialogWidget( dialog, nullptr, manager->delegate()->GetWebContentsModalDialogHost()->GetHostView()); + widget->SetNativeWindowProperty( + views::kWidgetIdentifierKey, + const_cast<void*>(kConstrainedWindowWidgetIdentifier)); + + return widget; } views::Widget* CreateBrowserModalDialogViews( @@ -234,6 +243,9 @@ views::Widget* CreateBrowserModalDialogViews(views::DialogDelegate* dialog, parent ? CurrentClient()->GetDialogHostView(parent) : nullptr; views::Widget* widget = views::DialogDelegate::CreateDialogWidget(dialog, nullptr, parent_view); + widget->SetNativeWindowProperty( + views::kWidgetIdentifierKey, + const_cast<void*>(kConstrainedWindowWidgetIdentifier)); bool requires_positioning = dialog->use_custom_frame(); diff --git a/components/constrained_window/constrained_window_views.h b/components/constrained_window/constrained_window_views.h index e69b44dd42c3a..5810ddce28dcd 100644 --- a/components/constrained_window/constrained_window_views.h +++ b/components/constrained_window/constrained_window_views.h @@ -31,6 +31,8 @@ class WebContentsModalDialogHost; namespace constrained_window { +extern const void* kConstrainedWindowWidgetIdentifier; + class ConstrainedWindowViewsClient; // Sets the ConstrainedWindowClient impl. diff --git a/ui/views/widget/native_widget.h b/ui/views/widget/native_widget.h index 1bc4690f5fa5f..23c191952626c 100644 --- a/ui/views/widget/native_widget.h +++ b/ui/views/widget/native_widget.h @@ -11,6 +11,9 @@ namespace views { class Widget; +// Used with Widget::GetNativeWindowProperty() to identify a widget. +VIEWS_EXPORT extern const char kWidgetIdentifierKey[]; + namespace internal { class NativeWidgetPrivate; } diff --git a/ui/views/widget/native_widget_private.cc b/ui/views/widget/native_widget_private.cc index a7097e5d4242b..a3032d2d31809 100644 --- a/ui/views/widget/native_widget_private.cc +++ b/ui/views/widget/native_widget_private.cc @@ -8,7 +8,11 @@ #include "ui/display/display.h" #include "ui/display/screen.h" -namespace views::internal { +namespace views { + +const char kWidgetIdentifierKey[] = "kWidgetIdentifierKey"; + +namespace internal { // static gfx::Rect NativeWidgetPrivate::ConstrainBoundsToDisplayWorkArea( @@ -31,4 +35,6 @@ bool NativeWidgetPrivate::IsMoveLoopSupported() const { return true; } -} // namespace views::internal +} // namespace internal + +} // namespace views