chrome: win/linux: Add support for browser with native parent (see issue #3294)

This change adds Chrome runtime support on Windows and Linux for creating a
browser parented to a native window supplied by the client application.
Expected API usage and window behavior is similar to what already exists with
the Alloy runtime. The parent window handle should be specified by using
CefWindowInfo::SetAsChild in combination with the CefBrowserHost::CreateBrowser
and CefLifeSpanHandler::OnBeforePopup callbacks.

The previously existing behavior of creating a fully-featured Chrome browser
window when empty CefWindowInfo is used with CreateBrowser remains unchanged
and Views is still the preferred API for creating top-level Chrome windows
with custom styling (e.g. title bar only, frameless, etc).

The cefclient Popup Window test with a native parent window continues to crash
on Linux with both the Alloy and Chrome runtimes (see issue #3165).

Also adds Chrome runtime support for CefDisplayHandler::OnCursorChange.

To test:
- Run `cefclient --enable-chrome-runtime [--use-views]` for the default (and
  previously existing) Views-based behavior.
- Run `cefclient --enable-chrome-runtime --use-native` for the new native
  parent window behavior.
- Run `cefclient --enable-chrome-runtime --use-native --no-activate` and the
  window will not be activated (take input focus) on launch (Windows only).
- Run `cefclient --enable-chrome-runtime [--use-views|--use-native]
  --mouse-cursor-change-disabled` and the mouse cursor will not change on
  mouseover of DOM elements.
This commit is contained in:
Marshall Greenblatt
2022-04-08 16:48:56 -04:00
parent 5f4bccd672
commit 3000bc8748
43 changed files with 702 additions and 245 deletions

View File

@@ -254,7 +254,7 @@ CefWindowView::CefWindowView(CefWindowDelegate* cef_delegate,
DCHECK(window_delegate_);
}
void CefWindowView::CreateWidget() {
void CefWindowView::CreateWidget(gfx::AcceleratedWidget parent_widget) {
DCHECK(!GetWidget());
// |widget| is owned by the NativeWidget and will be destroyed in response to
@@ -264,8 +264,29 @@ void CefWindowView::CreateWidget() {
views::Widget::InitParams params;
params.delegate = this;
params.type = views::Widget::InitParams::TYPE_WINDOW;
bool can_activate = true;
bool can_resize = true;
const bool has_native_parent = parent_widget != gfx::kNullAcceleratedWidget;
if (has_native_parent) {
params.parent_widget = parent_widget;
// Remove the window frame.
is_frameless_ = true;
// See CalculateWindowStylesFromInitParams in
// ui/views/widget/widget_hwnd_utils.cc for the conversion of |params| to
// Windows style flags.
// - Set the WS_CHILD flag.
params.child = true;
// - Set the WS_VISIBLE flag.
params.type = views::Widget::InitParams::TYPE_CONTROL;
// - Don't set the WS_EX_COMPOSITED flag.
params.opacity = views::Widget::InitParams::WindowOpacity::kOpaque;
} else {
params.type = views::Widget::InitParams::TYPE_WINDOW;
}
// WidgetDelegate::DeleteDelegate() will delete |this| after executing the
// registered callback.
@@ -275,47 +296,49 @@ void CefWindowView::CreateWidget() {
if (cef_delegate()) {
CefRefPtr<CefWindow> cef_window = GetCefWindow();
is_frameless_ = cef_delegate()->IsFrameless(cef_window);
auto bounds = cef_delegate()->GetInitialBounds(cef_window);
params.bounds = gfx::Rect(bounds.x, bounds.y, bounds.width, bounds.height);
SetCanResize(cef_delegate()->CanResize(cef_window));
if (has_native_parent) {
DCHECK(!params.bounds.IsEmpty());
} else {
is_frameless_ = cef_delegate()->IsFrameless(cef_window);
can_resize = cef_delegate()->CanResize(cef_window);
const auto show_state = cef_delegate()->GetInitialShowState(cef_window);
switch (show_state) {
case CEF_SHOW_STATE_NORMAL:
params.show_state = ui::SHOW_STATE_NORMAL;
break;
case CEF_SHOW_STATE_MINIMIZED:
params.show_state = ui::SHOW_STATE_MINIMIZED;
break;
case CEF_SHOW_STATE_MAXIMIZED:
params.show_state = ui::SHOW_STATE_MAXIMIZED;
break;
case CEF_SHOW_STATE_FULLSCREEN:
params.show_state = ui::SHOW_STATE_FULLSCREEN;
break;
}
const auto show_state = cef_delegate()->GetInitialShowState(cef_window);
switch (show_state) {
case CEF_SHOW_STATE_NORMAL:
params.show_state = ui::SHOW_STATE_NORMAL;
break;
case CEF_SHOW_STATE_MINIMIZED:
params.show_state = ui::SHOW_STATE_MINIMIZED;
break;
case CEF_SHOW_STATE_MAXIMIZED:
params.show_state = ui::SHOW_STATE_MAXIMIZED;
break;
case CEF_SHOW_STATE_FULLSCREEN:
params.show_state = ui::SHOW_STATE_FULLSCREEN;
break;
}
bool is_menu = false;
bool can_activate_menu = true;
CefRefPtr<CefWindow> parent_window = cef_delegate()->GetParentWindow(
cef_window, &is_menu, &can_activate_menu);
if (parent_window && !parent_window->IsSame(cef_window)) {
CefWindowImpl* parent_window_impl =
static_cast<CefWindowImpl*>(parent_window.get());
params.parent = view_util::GetNativeView(parent_window_impl->widget());
if (is_menu) {
// Don't clip the window to parent bounds.
params.type = views::Widget::InitParams::TYPE_MENU;
bool is_menu = false;
bool can_activate_menu = true;
CefRefPtr<CefWindow> parent_window = cef_delegate()->GetParentWindow(
cef_window, &is_menu, &can_activate_menu);
if (parent_window && !parent_window->IsSame(cef_window)) {
CefWindowImpl* parent_window_impl =
static_cast<CefWindowImpl*>(parent_window.get());
params.parent = view_util::GetNativeView(parent_window_impl->widget());
if (is_menu) {
// Don't clip the window to parent bounds.
params.type = views::Widget::InitParams::TYPE_MENU;
// Don't set "always on top" for the window.
params.z_order = ui::ZOrderLevel::kNormal;
// Don't set "always on top" for the window.
params.z_order = ui::ZOrderLevel::kNormal;
can_activate = can_activate_menu;
if (can_activate_menu)
params.activatable = views::Widget::InitParams::Activatable::kYes;
can_activate = can_activate_menu;
}
}
}
}
@@ -325,6 +348,13 @@ void CefWindowView::CreateWidget() {
params.bounds = gfx::Rect(CalculatePreferredSize());
}
if (can_activate) {
// Cause WidgetDelegate::CanActivate to return true.
params.activatable = views::Widget::InitParams::Activatable::kYes;
}
SetCanResize(can_resize);
#if BUILDFLAG(IS_WIN)
if (is_frameless_) {
// Don't show the native window caption. Setting this value on Linux will