diff --git a/libcef/browser/views/overlay_view_host.cc b/libcef/browser/views/overlay_view_host.cc index ec61fd656..43ca479f7 100644 --- a/libcef/browser/views/overlay_view_host.cc +++ b/libcef/browser/views/overlay_view_host.cc @@ -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 view) { +void CefOverlayViewHost::Init(views::View* host_view, CefRefPtr 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 diff --git a/libcef/browser/views/overlay_view_host.h b/libcef/browser/views/overlay_view_host.h index 32c7d6013..e761d6cfa 100644 --- a/libcef/browser/views/overlay_view_host.h +++ b/libcef/browser/views/overlay_view_host.h @@ -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 view); void Destroy(); diff --git a/libcef/browser/views/view_util.cc b/libcef/browser/views/view_util.cc index 5283f48c0..13f42ac90 100644 --- a/libcef/browser/views/view_util.cc +++ b/libcef/browser/views/view_util.cc @@ -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 view) { CefRefPtr GetWindowFor(views::Widget* widget) { CefRefPtr 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| diff --git a/libcef/browser/views/view_util.h b/libcef/browser/views/view_util.h index 50828da92..16841f54a 100644 --- a/libcef/browser/views/view_util.h +++ b/libcef/browser/views/view_util.h @@ -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 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_ diff --git a/libcef/browser/views/view_util_aura.cc b/libcef/browser/views/view_util_aura.cc index f28d55264..f72e053f5 100644 --- a/libcef/browser/views/view_util_aura.cc +++ b/libcef/browser/views/view_util_aura.cc @@ -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 diff --git a/libcef/browser/views/view_util_mac.mm b/libcef/browser/views/view_util_mac.mm index 2bab6b473..f7e51cbec 100644 --- a/libcef/browser/views/view_util_mac.mm +++ b/libcef/browser/views/view_util_mac.mm @@ -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( + widget->GetNativeWindowProperty(kNativeHostViewKey)); +} + } // namespace view_util