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/layer.h"
#if defined(USE_AURA)
#include "ui/aura/window.h"
#include "ui/views/view_constants_aura.h"
#endif
namespace {
class CefOverlayControllerImpl : public CefOverlayController {
@ -172,8 +167,7 @@ CefOverlayViewHost::CefOverlayViewHost(CefWindowView* window_view,
cef_docking_mode_t docking_mode)
: window_view_(window_view), docking_mode_(docking_mode) {}
void CefOverlayViewHost::Init(views::View* widget_view,
CefRefPtr<CefView> view) {
void CefOverlayViewHost::Init(views::View* host_view, CefRefPtr<CefView> view) {
DCHECK(view);
// 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);
}
#if defined(USE_AURA)
// See matching logic in view_util::GetWindowFor.
widget_->GetNativeView()->SetProperty(views::kHostViewKey, widget_view);
#endif
view_util::SetHostView(widget_.get(), host_view);
if (cef::IsChromeRuntimeEnabled()) {
// 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;
// Initializes the CefOverlayViewHost. This creates the Widget that |view|
// paints into. |host_view| is the view whose position in the |window_view_|
// view hierarchy determines the z-order of the widget relative to views with
// layers and views with associated NativeViews.
// paints into. On Aura platforms, |host_view| is the view whose position in
// the |window_view_| view hierarchy determines the z-order of the widget
// relative to views with layers and views with associated NativeViews.
void Init(views::View* host_view, CefRefPtr<CefView> view);
void Destroy();

View File

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

View File

@ -22,6 +22,7 @@ class Point;
namespace views {
class NativeWidget;
class View;
class Widget;
namespace internal {
class NativeWidgetDelegate;
@ -152,6 +153,14 @@ views::NativeWidget* CreateNativeWidget(
CefRefPtr<CefWindow> window,
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
#endif // CEF_LIBCEF_BROWSER_VIEWS_VIEW_UTIL_H_

View File

@ -6,6 +6,7 @@
#include "ui/aura/window.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_delegate.h"
#include "ui/views/widget/widget.h"
@ -49,4 +50,12 @@ views::NativeWidget* CreateNativeWidget(
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

View File

@ -13,6 +13,12 @@
namespace view_util {
namespace {
constexpr char kNativeHostViewKey[] = "CefNativeHostViewKey";
} // namespace
gfx::NativeWindow GetNativeWindow(views::Widget* widget) {
if (widget) {
return widget->GetNativeWindow();
@ -51,4 +57,14 @@ views::NativeWidget* CreateNativeWidget(
CefWindowDelegate* 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