mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2024-12-12 17:46:04 +01:00
dca0435d2f
Split the Alloy runtime into bootstrap and style components. Support creation of Alloy style browsers and windows with the Chrome runtime. Chrome runtime (`--enable-chrome-runtime`) + Alloy style (`--use-alloy-style`) supports Views (`--use-views`), native parent (`--use-native`) and windowless rendering (`--off-screen-rendering-enabled`). Print preview is supported in all cases except with windowless rendering on all platforms and native parent on MacOS. It is disabled by default with Alloy style for legacy compatibility. Where supported it can be enabled or disabled globally using `--[enable|disable]-print-preview` or configured on a per-RequestContext basis using the `printing.print_preview_disabled` preference. It also behaves as expected when triggered via the PDF viewer print button. Chrome runtime + Alloy style behavior differs from Alloy runtime in the following significant ways: - Supports Chrome error pages by default. - DevTools popups are Chrome style only (cannot be windowless). - The Alloy extension API will not supported. Chrome runtime + Alloy style passes all expected Alloy ceftests except the following: - `DisplayTest.AutoResize` (Alloy extension API not supported) - `DownloadTest.*` (Download API not yet supported) - `ExtensionTest.*` (Alloy extension API not supported) This change also adds Chrome runtime support for CefContextMenuHandler::RunContextMenu (see #3293). This change also explicitly blocks (and doesn't retry) FrameAttached requests from PDF viewer and print preview excluded frames (see #3664). Known issues specific to Chrome runtime + Alloy style: - DevTools popup with windowless rendering doesn't load successfully. Use windowed rendering or remote debugging as a workaround. - Chrome style Window with Alloy style BrowserView (`--use-alloy-style --use-chrome-style-window`) does not show Chrome theme changes. To test: - Run `ceftests --enable-chrome-runtime --use-alloy-style [--use-chrome-style-window] [--use-views|--use-native] --gtest_filter=...` - Run `cefclient --enable-chrome-runtime --use-alloy-style [--use-chrome-style-window] [--use-views|--use-native|--off-screen-rendering-enabled]` - Run `cefsimple --enable-chrome-runtime --use-alloy-style [--use-views]`
157 lines
4.9 KiB
C++
157 lines
4.9 KiB
C++
// Copyright 2023 The Chromium Embedded Framework Authors. Portions copyright
|
|
// 2012 The Chromium Authors. All rights reserved. Use of this source code is
|
|
// governed by a BSD-style license that can be found in the LICENSE file.
|
|
|
|
#include "libcef/browser/native/cursor_util.h"
|
|
|
|
#include "libcef/browser/browser_host_base.h"
|
|
|
|
#include "content/common/cursors/webcursor.h"
|
|
#include "content/public/browser/render_widget_host_view.h"
|
|
#include "ui/base/cursor/cursor_factory.h"
|
|
#include "ui/base/cursor/mojom/cursor_type.mojom.h"
|
|
#include "ui/display/display.h"
|
|
#include "ui/display/display_util.h"
|
|
#include "ui/display/screen.h"
|
|
#include "ui/wm/core/cursor_loader.h"
|
|
|
|
#if BUILDFLAG(IS_LINUX)
|
|
#include "ui/base/ozone_buildflags.h"
|
|
#if BUILDFLAG(IS_OZONE_X11)
|
|
#include "ui/base/x/x11_cursor.h"
|
|
#elif BUILDFLAG(IS_OZONE)
|
|
#include "ui/ozone/common/bitmap_cursor.h"
|
|
#endif
|
|
#endif // BUILDFLAG(IS_LINUX)
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
|
#include "ui/base/win/win_cursor.h"
|
|
#endif
|
|
|
|
namespace cursor_util {
|
|
|
|
namespace {
|
|
|
|
display::Display::Rotation OrientationAngleToRotation(
|
|
uint16_t orientation_angle) {
|
|
// The Display rotation and the ScreenInfo orientation are not the same
|
|
// angle. The former is the physical display rotation while the later is the
|
|
// rotation required by the content to be shown properly on the screen, in
|
|
// other words, relative to the physical display.
|
|
if (orientation_angle == 0) {
|
|
return display::Display::ROTATE_0;
|
|
}
|
|
if (orientation_angle == 90) {
|
|
return display::Display::ROTATE_270;
|
|
}
|
|
if (orientation_angle == 180) {
|
|
return display::Display::ROTATE_180;
|
|
}
|
|
if (orientation_angle == 270) {
|
|
return display::Display::ROTATE_90;
|
|
}
|
|
DCHECK(false);
|
|
return display::Display::ROTATE_0;
|
|
}
|
|
|
|
// It would be better if CursorLoader took a ScreenInfo argument.
|
|
// See https://crbug.com/1149906#c33.
|
|
display::Display GetDisplay(CefRefPtr<CefBrowser> browser) {
|
|
auto browser_impl = CefBrowserHostBase::FromBrowser(browser);
|
|
if (auto web_contents = browser_impl->GetWebContents()) {
|
|
if (auto view = web_contents->GetRenderWidgetHostView()) {
|
|
// Windowless browsers always return nullptr from GetNativeView().
|
|
if (!browser_impl->IsWindowless()) {
|
|
return display::Screen::GetScreen()->GetDisplayNearestView(
|
|
view->GetNativeView());
|
|
}
|
|
|
|
// Make a minimal-effort fake Display object to satisfy the actual usage
|
|
// by CursorLoader::SetDisplay.
|
|
display::Display fake_display;
|
|
auto screen_info = view->GetScreenInfo();
|
|
fake_display.set_device_scale_factor(screen_info.device_scale_factor);
|
|
fake_display.set_rotation(
|
|
OrientationAngleToRotation(screen_info.orientation_angle));
|
|
return fake_display;
|
|
}
|
|
}
|
|
|
|
return display::Display::GetDefaultDisplay();
|
|
}
|
|
|
|
scoped_refptr<ui::PlatformCursor> ToPlatformCursor(
|
|
CefRefPtr<CefBrowser> browser,
|
|
const ui::Cursor& ui_cursor) {
|
|
wm::CursorLoader cursor_loader;
|
|
scoped_refptr<ui::PlatformCursor> platform_cursor;
|
|
|
|
ui::Cursor loaded_cursor = ui_cursor;
|
|
|
|
if (ui_cursor.type() == ui::mojom::CursorType::kCustom) {
|
|
platform_cursor = ui::CursorFactory::GetInstance()->CreateImageCursor(
|
|
ui::mojom::CursorType::kCustom, ui_cursor.custom_bitmap(),
|
|
ui_cursor.custom_hotspot(), ui_cursor.image_scale_factor());
|
|
} else {
|
|
cursor_loader.SetDisplay(GetDisplay(browser));
|
|
|
|
// Attempts to load the cursor via the platform or from pak resources.
|
|
cursor_loader.SetPlatformCursor(&loaded_cursor);
|
|
platform_cursor = loaded_cursor.platform();
|
|
}
|
|
|
|
return platform_cursor;
|
|
}
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
|
using CursorType = ui::WinCursor;
|
|
inline cef_cursor_handle_t GetCursorHandleImpl(CursorType* cursor) {
|
|
return cursor->hcursor();
|
|
}
|
|
#elif BUILDFLAG(IS_OZONE_X11)
|
|
// See https://crbug.com/1029142 for background.
|
|
using CursorType = ui::X11Cursor;
|
|
inline cef_cursor_handle_t GetCursorHandleImpl(CursorType* cursor) {
|
|
return static_cast<cef_cursor_handle_t>(cursor->xcursor());
|
|
}
|
|
#elif BUILDFLAG(IS_OZONE)
|
|
using CursorType = ui::BitmapCursor;
|
|
inline cef_cursor_handle_t GetCursorHandleImpl(CursorType* cursor) {
|
|
return static_cast<cef_cursor_handle_t>(cursor->platform_data());
|
|
}
|
|
#else
|
|
#error Unsupported platform
|
|
#endif
|
|
|
|
class ScopedCursorHandleImpl : public ScopedCursorHandle {
|
|
public:
|
|
explicit ScopedCursorHandleImpl(
|
|
scoped_refptr<ui::PlatformCursor> platform_cursor) {
|
|
if (platform_cursor) {
|
|
cursor_ = CursorType::FromPlatformCursor(platform_cursor);
|
|
}
|
|
}
|
|
|
|
cef_cursor_handle_t GetCursorHandle() override {
|
|
if (cursor_) {
|
|
return GetCursorHandleImpl(cursor_.get());
|
|
}
|
|
return kNullCursorHandle;
|
|
}
|
|
|
|
private:
|
|
scoped_refptr<CursorType> cursor_;
|
|
};
|
|
|
|
} // namespace
|
|
|
|
// static
|
|
std::unique_ptr<ScopedCursorHandle> ScopedCursorHandle::Create(
|
|
CefRefPtr<CefBrowser> browser,
|
|
const ui::Cursor& ui_cursor) {
|
|
return std::make_unique<ScopedCursorHandleImpl>(
|
|
ToPlatformCursor(browser, ui_cursor));
|
|
}
|
|
|
|
} // namespace cursor_util
|