windows: Fix Views test failures (fixes issue #3365)

This commit is contained in:
Marshall Greenblatt 2022-07-27 13:57:53 -04:00
parent a9043f2e80
commit 654f570b6e
6 changed files with 39 additions and 18 deletions

View File

@ -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 {
///

View File

@ -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 {

View File

@ -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());
}

View File

@ -13,6 +13,8 @@
#if defined(OS_WIN)
#include <windows.h>
#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<CefWaitableEvent> event,
std::unique_ptr<Config> 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));

View File

@ -25,6 +25,13 @@ int DeviceToLogical(int value, float device_scale_factor) {
return static_cast<int>(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);

View File

@ -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);