Skip to content

Commit

Permalink
views: mac: Fix overlay association with host CefWindow (fixes #3456)
Browse files Browse the repository at this point in the history
  • Loading branch information
magreenblatt committed Apr 20, 2023
1 parent cad2498 commit 17cab6d
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 26 deletions.
13 changes: 2 additions & 11 deletions libcef/browser/views/overlay_view_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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().
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions libcef/browser/views/overlay_view_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 2 additions & 12 deletions libcef/browser/views/view_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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|
Expand Down
9 changes: 9 additions & 0 deletions libcef/browser/views/view_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Point;

namespace views {
class NativeWidget;
class View;
class Widget;
namespace internal {
class NativeWidgetDelegate;
Expand Down Expand Up @@ -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_
9 changes: 9 additions & 0 deletions libcef/browser/views/view_util_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
16 changes: 16 additions & 0 deletions libcef/browser/views/view_util_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@

namespace view_util {

namespace {

constexpr char kNativeHostViewKey[] = "CefNativeHostViewKey";

} // namespace

gfx::NativeWindow GetNativeWindow(views::Widget* widget) {
if (widget) {
return widget->GetNativeWindow();
Expand Down Expand Up @@ -51,4 +57,14 @@ CefWindowHandle GetWindowHandle(gfx::NativeWindow window) {
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

0 comments on commit 17cab6d

Please sign in to comment.