From 654f570b6ed6d22c04ae87b4ef5786e170556688 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Wed, 27 Jul 2022 13:57:53 -0400 Subject: [PATCH] windows: Fix Views test failures (fixes issue #3365) --- include/capi/views/cef_view_delegate_capi.h | 9 ++++--- include/views/cef_view_delegate.h | 6 +++-- libcef/browser/views/window_impl.cc | 6 +---- tests/ceftests/views/test_window_delegate.cc | 28 +++++++++++++++----- tests/shared/browser/geometry_util.cc | 7 +++++ tests/shared/browser/geometry_util.h | 1 + 6 files changed, 39 insertions(+), 18 deletions(-) diff --git a/include/capi/views/cef_view_delegate_capi.h b/include/capi/views/cef_view_delegate_capi.h index 09971e2a2..e1307978d 100644 --- a/include/capi/views/cef_view_delegate_capi.h +++ b/include/capi/views/cef_view_delegate_capi.h @@ -33,7 +33,7 @@ // by hand. See the translator.README.txt file in the tools directory for // more information. // -// $hash=6a8166eca76513b59a4f6355f4f765dc1d77e4ee$ +// $hash=a75487288913e4646f67ee8aded4bc9ef328bb79$ // #ifndef CEF_INCLUDE_CAPI_VIEWS_CEF_VIEW_DELEGATE_CAPI_H_ @@ -49,9 +49,10 @@ extern "C" { struct _cef_view_t; /// -// Implement this structure to handle view events. The functions of this -// structure will be called on the browser process UI thread unless otherwise -// indicated. +// Implement this structure to handle view events. All size and position values +// are in density independent pixels (DIP) unless otherwise indicated. The +// functions of this structure will be called on the browser process UI thread +// unless otherwise indicated. /// typedef struct _cef_view_delegate_t { /// diff --git a/include/views/cef_view_delegate.h b/include/views/cef_view_delegate.h index 03b8b6893..6b3b30efb 100644 --- a/include/views/cef_view_delegate.h +++ b/include/views/cef_view_delegate.h @@ -43,8 +43,10 @@ class CefView; /// -// Implement this interface to handle view events. The methods of this class -// will be called on the browser process UI thread unless otherwise indicated. +// Implement this interface to handle view events. All size and position values +// are in density independent pixels (DIP) unless otherwise indicated. The +// methods of this class will be called on the browser process UI thread unless +// otherwise indicated. /// /*--cef(source=client)--*/ class CefViewDelegate : public virtual CefBaseRefCounted { diff --git a/libcef/browser/views/window_impl.cc b/libcef/browser/views/window_impl.cc index b256822d4..e9c4084af 100644 --- a/libcef/browser/views/window_impl.cc +++ b/libcef/browser/views/window_impl.cc @@ -552,12 +552,8 @@ void CefWindowImpl::SendMouseMove(int screen_x, int screen_y) { CEF_REQUIRE_VALID_RETURN_VOID(); InitializeUITesting(); + // Converts to pixel coordinates internally on Windows. gfx::Point point(screen_x, screen_y); -#if BUILDFLAG(IS_WIN) - // Windows expects pixel coordinates. - point = display::win::ScreenWin::DIPToScreenPoint(point); -#endif - ui_controls::SendMouseMove(point.x(), point.y()); } diff --git a/tests/ceftests/views/test_window_delegate.cc b/tests/ceftests/views/test_window_delegate.cc index 59877755f..c0ea3c0d5 100644 --- a/tests/ceftests/views/test_window_delegate.cc +++ b/tests/ceftests/views/test_window_delegate.cc @@ -13,6 +13,8 @@ #if defined(OS_WIN) #include +#include "tests/shared/browser/geometry_util.h" +#include "tests/shared/browser/util_win.h" #endif namespace { @@ -28,18 +30,30 @@ const int TestWindowDelegate::kWSize = 400; // static void TestWindowDelegate::RunTest(CefRefPtr event, std::unique_ptr config) { + CefSize window_size{config->window_size, config->window_size}; + #if defined(OS_WIN) - RECT rect = {0, 0, config->window_size, config->window_size}; if (!config->frameless) { - // The size value is for the client area. Calculate the whole window size - // based on the default frame window style. + // Expand the client area size to full window size based on the default + // frame window style. AdjustWindowRect expects pixel coordinates, so + // perform the necessary conversions. + auto scale_factor = client::GetDeviceScaleFactor(); + auto scaled_size = + client::LogicalToDevice(config->window_size, scale_factor); + + // Convert from DIP to pixel coords. + RECT rect = {0, 0, scaled_size, scaled_size}; + AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, false /* has_menu */); + + // Convert from pixel to DIP coords. + auto scaled_rect = client::DeviceToLogical( + {rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top}, + scale_factor); + window_size = {scaled_rect.width, scaled_rect.height}; } - CefSize window_size = CefSize(rect.right - rect.left, rect.bottom - rect.top); -#else - CefSize window_size = CefSize(config->window_size, config->window_size); -#endif +#endif // defined(OS_WIN) CefWindow::CreateTopLevelWindow( new TestWindowDelegate(event, std::move(config), window_size)); diff --git a/tests/shared/browser/geometry_util.cc b/tests/shared/browser/geometry_util.cc index f7c3210b9..60962b2b4 100644 --- a/tests/shared/browser/geometry_util.cc +++ b/tests/shared/browser/geometry_util.cc @@ -25,6 +25,13 @@ int DeviceToLogical(int value, float device_scale_factor) { return static_cast(std::floor(scaled_val)); } +CefRect DeviceToLogical(const CefRect& value, float device_scale_factor) { + return CefRect(DeviceToLogical(value.x, device_scale_factor), + DeviceToLogical(value.y, device_scale_factor), + DeviceToLogical(value.width, device_scale_factor), + DeviceToLogical(value.height, device_scale_factor)); +} + void DeviceToLogical(CefMouseEvent& value, float device_scale_factor) { value.x = DeviceToLogical(value.x, device_scale_factor); value.y = DeviceToLogical(value.y, device_scale_factor); diff --git a/tests/shared/browser/geometry_util.h b/tests/shared/browser/geometry_util.h index fc2c476aa..1853aa04f 100644 --- a/tests/shared/browser/geometry_util.h +++ b/tests/shared/browser/geometry_util.h @@ -16,6 +16,7 @@ CefRect LogicalToDevice(const CefRect& value, float device_scale_factor); // Convert |value| from device coordinates to logical coordinates. int DeviceToLogical(int value, float device_scale_factor); +CefRect DeviceToLogical(const CefRect& value, float device_scale_factor); void DeviceToLogical(CefMouseEvent& value, float device_scale_factor); void DeviceToLogical(CefTouchEvent& value, float device_scale_factor);