views: mac: Fix overlay association with host CefWindow (fixes #3456)

This commit is contained in:
Marshall Greenblatt 2023-04-14 12:58:21 -04:00
parent cad2498d87
commit 17cab6d955
6 changed files with 41 additions and 26 deletions

View File

@ -14,11 +14,6 @@
#include "ui/compositor/compositor.h" #include "ui/compositor/compositor.h"
#include "ui/compositor/layer.h" #include "ui/compositor/layer.h"
#if defined(USE_AURA)
#include "ui/aura/window.h"
#include "ui/views/view_constants_aura.h"
#endif
namespace { namespace {
class CefOverlayControllerImpl : public CefOverlayController { class CefOverlayControllerImpl : public CefOverlayController {
@ -172,8 +167,7 @@ CefOverlayViewHost::CefOverlayViewHost(CefWindowView* window_view,
cef_docking_mode_t docking_mode) cef_docking_mode_t docking_mode)
: window_view_(window_view), docking_mode_(docking_mode) {} : window_view_(window_view), docking_mode_(docking_mode) {}
void CefOverlayViewHost::Init(views::View* widget_view, void CefOverlayViewHost::Init(views::View* host_view, CefRefPtr<CefView> view) {
CefRefPtr<CefView> view) {
DCHECK(view); DCHECK(view);
// Match the logic in CEF_PANEL_IMPL_D::AddChildView(). // Match the logic in CEF_PANEL_IMPL_D::AddChildView().
@ -202,10 +196,7 @@ void CefOverlayViewHost::Init(views::View* widget_view,
widget_->GetCompositor()->SetBackgroundColor(SK_ColorTRANSPARENT); widget_->GetCompositor()->SetBackgroundColor(SK_ColorTRANSPARENT);
} }
#if defined(USE_AURA) view_util::SetHostView(widget_.get(), host_view);
// See matching logic in view_util::GetWindowFor.
widget_->GetNativeView()->SetProperty(views::kHostViewKey, widget_view);
#endif
if (cef::IsChromeRuntimeEnabled()) { if (cef::IsChromeRuntimeEnabled()) {
// Some attributes associated with a Chrome toolbar are located via the // Some attributes associated with a Chrome toolbar are located via the

View File

@ -29,9 +29,9 @@ class CefOverlayViewHost : public views::WidgetDelegate,
CefOverlayViewHost& operator=(const CefOverlayViewHost&) = delete; CefOverlayViewHost& operator=(const CefOverlayViewHost&) = delete;
// Initializes the CefOverlayViewHost. This creates the Widget that |view| // Initializes the CefOverlayViewHost. This creates the Widget that |view|
// paints into. |host_view| is the view whose position in the |window_view_| // paints into. On Aura platforms, |host_view| is the view whose position in
// view hierarchy determines the z-order of the widget relative to views with // the |window_view_| view hierarchy determines the z-order of the widget
// layers and views with associated NativeViews. // relative to views with layers and views with associated NativeViews.
void Init(views::View* host_view, CefRefPtr<CefView> view); void Init(views::View* host_view, CefRefPtr<CefView> view);
void Destroy(); void Destroy();

View File

@ -20,11 +20,6 @@
#include "ui/display/win/screen_win.h" #include "ui/display/win/screen_win.h"
#endif #endif
#if defined(USE_AURA)
#include "ui/aura/window.h"
#include "ui/views/view_constants_aura.h"
#endif
namespace view_util { namespace view_util {
namespace { namespace {
@ -169,17 +164,12 @@ void ResumeOwnership(CefRefPtr<CefView> view) {
CefRefPtr<CefWindow> GetWindowFor(views::Widget* widget) { CefRefPtr<CefWindow> GetWindowFor(views::Widget* widget) {
CefRefPtr<CefWindow> window; CefRefPtr<CefWindow> window;
#if defined(USE_AURA) // If |widget| is an overlay, retrieve the host Widget.
// Retrieve the parent Widget for an overlay.
if (widget) { if (widget) {
// See matching logic in CefOverlayViewHost::Init. if (auto widget_view = GetHostView(widget)) {
auto widget_view =
widget->GetNativeView()->GetProperty(views::kHostViewKey);
if (widget_view) {
widget = widget_view->GetWidget(); widget = widget_view->GetWidget();
} }
} }
#endif // defined(USE_AURA)
if (widget) { if (widget) {
// The views::WidgetDelegate should be a CefWindowView and |content_view| // The views::WidgetDelegate should be a CefWindowView and |content_view|

View File

@ -22,6 +22,7 @@ class Point;
namespace views { namespace views {
class NativeWidget; class NativeWidget;
class View;
class Widget; class Widget;
namespace internal { namespace internal {
class NativeWidgetDelegate; class NativeWidgetDelegate;
@ -152,6 +153,14 @@ views::NativeWidget* CreateNativeWidget(
CefRefPtr<CefWindow> window, CefRefPtr<CefWindow> window,
CefWindowDelegate* window_delegate); CefWindowDelegate* window_delegate);
// Called from CefOverlayViewHost::Init to associate |host_view| with |widget|.
// This is necessary for GetWindowFor() to correctly return the CefWindow
// associated with the host Widget. On Aura platforms, |host_view| is the view
// whose position in the view hierarchy determines the z-order of the widget
// relative to views with layers and views with associated NativeViews.
void SetHostView(views::Widget* widget, views::View* host_view);
views::View* GetHostView(views::Widget* widget);
} // namespace view_util } // namespace view_util
#endif // CEF_LIBCEF_BROWSER_VIEWS_VIEW_UTIL_H_ #endif // CEF_LIBCEF_BROWSER_VIEWS_VIEW_UTIL_H_

View File

@ -6,6 +6,7 @@
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h" #include "ui/aura/window_tree_host.h"
#include "ui/views/view_constants_aura.h"
#include "ui/views/widget/native_widget.h" #include "ui/views/widget/native_widget.h"
#include "ui/views/widget/native_widget_delegate.h" #include "ui/views/widget/native_widget_delegate.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
@ -49,4 +50,12 @@ views::NativeWidget* CreateNativeWidget(
return nullptr; return nullptr;
} }
void SetHostView(views::Widget* widget, views::View* host_view) {
widget->GetNativeView()->SetProperty(views::kHostViewKey, host_view);
}
views::View* GetHostView(views::Widget* widget) {
return widget->GetNativeView()->GetProperty(views::kHostViewKey);
}
} // namespace view_util } // namespace view_util

View File

@ -13,6 +13,12 @@
namespace view_util { namespace view_util {
namespace {
constexpr char kNativeHostViewKey[] = "CefNativeHostViewKey";
} // namespace
gfx::NativeWindow GetNativeWindow(views::Widget* widget) { gfx::NativeWindow GetNativeWindow(views::Widget* widget) {
if (widget) { if (widget) {
return widget->GetNativeWindow(); return widget->GetNativeWindow();
@ -51,4 +57,14 @@ views::NativeWidget* CreateNativeWidget(
CefWindowDelegate* window_delegate) { CefWindowDelegate* window_delegate) {
return new CefNativeWidgetMac(delegate, window, window_delegate); return new CefNativeWidgetMac(delegate, window, window_delegate);
} }
void SetHostView(views::Widget* widget, views::View* host_view) {
widget->SetNativeWindowProperty(kNativeHostViewKey, host_view);
}
views::View* GetHostView(views::Widget* widget) {
return static_cast<views::View*>(
widget->GetNativeWindowProperty(kNativeHostViewKey));
}
} // namespace view_util } // namespace view_util