mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
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:
@@ -23,8 +23,8 @@ CefRefPtr<CefBrowserView> CefBrowserView::CreateBrowserView(
|
||||
CefRefPtr<CefDictionaryValue> extra_info,
|
||||
CefRefPtr<CefRequestContext> request_context,
|
||||
CefRefPtr<CefBrowserViewDelegate> delegate) {
|
||||
return CefBrowserViewImpl::Create(client, url, settings, extra_info,
|
||||
request_context, delegate);
|
||||
return CefBrowserViewImpl::Create(CefWindowInfo(), client, url, settings,
|
||||
extra_info, request_context, delegate);
|
||||
}
|
||||
|
||||
// static
|
||||
@@ -41,6 +41,7 @@ CefRefPtr<CefBrowserView> CefBrowserView::GetForBrowser(
|
||||
|
||||
// static
|
||||
CefRefPtr<CefBrowserViewImpl> CefBrowserViewImpl::Create(
|
||||
const CefWindowInfo& window_info,
|
||||
CefRefPtr<CefClient> client,
|
||||
const CefString& url,
|
||||
const CefBrowserSettings& settings,
|
||||
@@ -62,8 +63,8 @@ CefRefPtr<CefBrowserViewImpl> CefBrowserViewImpl::Create(
|
||||
}
|
||||
|
||||
CefRefPtr<CefBrowserViewImpl> browser_view = new CefBrowserViewImpl(delegate);
|
||||
browser_view->SetPendingBrowserCreateParams(client, url, settings, extra_info,
|
||||
request_context);
|
||||
browser_view->SetPendingBrowserCreateParams(
|
||||
window_info, client, url, settings, extra_info, request_context);
|
||||
browser_view->Initialize();
|
||||
browser_view->SetDefaults(settings);
|
||||
return browser_view;
|
||||
@@ -212,6 +213,7 @@ CefBrowserViewImpl::CefBrowserViewImpl(
|
||||
: ParentClass(delegate), weak_ptr_factory_(this) {}
|
||||
|
||||
void CefBrowserViewImpl::SetPendingBrowserCreateParams(
|
||||
const CefWindowInfo& window_info,
|
||||
CefRefPtr<CefClient> client,
|
||||
const CefString& url,
|
||||
const CefBrowserSettings& settings,
|
||||
@@ -219,6 +221,7 @@ void CefBrowserViewImpl::SetPendingBrowserCreateParams(
|
||||
CefRefPtr<CefRequestContext> request_context) {
|
||||
DCHECK(!pending_browser_create_params_);
|
||||
pending_browser_create_params_.reset(new CefBrowserCreateParams());
|
||||
pending_browser_create_params_->MaybeSetWindowInfo(window_info);
|
||||
pending_browser_create_params_->client = client;
|
||||
pending_browser_create_params_->url = url;
|
||||
pending_browser_create_params_->settings = settings;
|
||||
@@ -248,6 +251,9 @@ void CefBrowserViewImpl::InitializeRootView() {
|
||||
}
|
||||
|
||||
views::WebView* CefBrowserViewImpl::web_view() const {
|
||||
if (!root_view())
|
||||
return nullptr;
|
||||
|
||||
if (cef::IsChromeRuntimeEnabled()) {
|
||||
return static_cast<ChromeBrowserView*>(root_view())->contents_web_view();
|
||||
}
|
||||
|
@@ -30,7 +30,9 @@ class CefBrowserViewImpl
|
||||
CefBrowserViewImpl& operator=(const CefBrowserViewImpl&) = delete;
|
||||
|
||||
// Create a new CefBrowserView instance. |delegate| may be nullptr.
|
||||
// |window_info| will only be used when creating a Chrome child window.
|
||||
static CefRefPtr<CefBrowserViewImpl> Create(
|
||||
const CefWindowInfo& window_info,
|
||||
CefRefPtr<CefClient> client,
|
||||
const CefString& url,
|
||||
const CefBrowserSettings& settings,
|
||||
@@ -84,6 +86,7 @@ class CefBrowserViewImpl
|
||||
explicit CefBrowserViewImpl(CefRefPtr<CefBrowserViewDelegate> delegate);
|
||||
|
||||
void SetPendingBrowserCreateParams(
|
||||
const CefWindowInfo& window_info,
|
||||
CefRefPtr<CefClient> client,
|
||||
const CefString& url,
|
||||
const CefBrowserSettings& settings,
|
||||
|
@@ -125,16 +125,17 @@ class CefUnhandledKeyEventHandler : public ui::EventHandler {
|
||||
// static
|
||||
CefRefPtr<CefWindow> CefWindow::CreateTopLevelWindow(
|
||||
CefRefPtr<CefWindowDelegate> delegate) {
|
||||
return CefWindowImpl::Create(delegate);
|
||||
return CefWindowImpl::Create(delegate, gfx::kNullAcceleratedWidget);
|
||||
}
|
||||
|
||||
// static
|
||||
CefRefPtr<CefWindowImpl> CefWindowImpl::Create(
|
||||
CefRefPtr<CefWindowDelegate> delegate) {
|
||||
CefRefPtr<CefWindowDelegate> delegate,
|
||||
gfx::AcceleratedWidget parent_widget) {
|
||||
CEF_REQUIRE_UIT_RETURN(nullptr);
|
||||
CefRefPtr<CefWindowImpl> window = new CefWindowImpl(delegate);
|
||||
window->Initialize();
|
||||
window->CreateWidget();
|
||||
window->CreateWidget(parent_widget);
|
||||
if (delegate)
|
||||
delegate->OnWindowCreated(window.get());
|
||||
return window;
|
||||
@@ -656,10 +657,10 @@ void CefWindowImpl::InitializeRootView() {
|
||||
static_cast<CefWindowView*>(root_view())->Initialize();
|
||||
}
|
||||
|
||||
void CefWindowImpl::CreateWidget() {
|
||||
void CefWindowImpl::CreateWidget(gfx::AcceleratedWidget parent_widget) {
|
||||
DCHECK(!widget_);
|
||||
|
||||
root_view()->CreateWidget();
|
||||
root_view()->CreateWidget(parent_widget);
|
||||
widget_ = root_view()->GetWidget();
|
||||
DCHECK(widget_);
|
||||
|
||||
|
@@ -33,8 +33,10 @@ class CefWindowImpl
|
||||
CefWindowImpl(const CefWindowImpl&) = delete;
|
||||
CefWindowImpl& operator=(const CefWindowImpl&) = delete;
|
||||
|
||||
// Create a new CefWindow instance. |delegate| may be nullptr.
|
||||
static CefRefPtr<CefWindowImpl> Create(CefRefPtr<CefWindowDelegate> delegate);
|
||||
// Create a new CefWindow instance. |delegate| may be nullptr. |parent_widget|
|
||||
// will be used when creating a Chrome child window.
|
||||
static CefRefPtr<CefWindowImpl> Create(CefRefPtr<CefWindowDelegate> delegate,
|
||||
gfx::AcceleratedWidget parent_widget);
|
||||
|
||||
// CefWindow methods:
|
||||
void Show() override;
|
||||
@@ -141,7 +143,7 @@ class CefWindowImpl
|
||||
void InitializeRootView() override;
|
||||
|
||||
// Initialize the Widget.
|
||||
void CreateWidget();
|
||||
void CreateWidget(gfx::AcceleratedWidget parent_widget);
|
||||
|
||||
views::Widget* widget_;
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -51,7 +51,7 @@ class CefWindowView
|
||||
CefWindowView& operator=(const CefWindowView&) = delete;
|
||||
|
||||
// Create the Widget.
|
||||
void CreateWidget();
|
||||
void CreateWidget(gfx::AcceleratedWidget parent_widget);
|
||||
|
||||
// Returns the CefWindow associated with this view. See comments on
|
||||
// CefViewView::GetCefView.
|
||||
|
Reference in New Issue
Block a user