diff --git a/include/capi/views/cef_display_capi.h b/include/capi/views/cef_display_capi.h index 10777a9fe..9d851b288 100644 --- a/include/capi/views/cef_display_capi.h +++ b/include/capi/views/cef_display_capi.h @@ -33,7 +33,7 @@ // by hand. See the translator.README.txt file in the tools directory for // more information. // -// $hash=3ff71283b14972df89a3c4c7c698faf887cef6d0$ +// $hash=6eed21d200bad5e898dfbe2701ad327cc1e4cc5c$ // #ifndef CEF_INCLUDE_CAPI_VIEWS_CEF_DISPLAY_CAPI_H_ @@ -140,6 +140,20 @@ CEF_EXPORT size_t cef_display_get_count(void); CEF_EXPORT void cef_display_get_alls(size_t* displaysCount, cef_display_t** displays); +/// +/// Convert |point| from DIP screen coordinates to pixel screen coordinates. +/// This function is only used on Windows. +/// +CEF_EXPORT cef_point_t +cef_display_convert_screen_point_to_pixels(const cef_point_t* point); + +/// +/// Convert |point| from pixel screen coordinates to DIP screen coordinates. +/// This function is only used on Windows. +/// +CEF_EXPORT cef_point_t +cef_display_convert_screen_point_from_pixels(const cef_point_t* point); + #ifdef __cplusplus } #endif diff --git a/include/cef_api_hash.h b/include/cef_api_hash.h index ee41f9f98..0bfa57268 100644 --- a/include/cef_api_hash.h +++ b/include/cef_api_hash.h @@ -42,13 +42,13 @@ // way that may cause binary incompatibility with other builds. The universal // hash value will change if any platform is affected whereas the platform hash // values will change only if that particular platform is affected. -#define CEF_API_HASH_UNIVERSAL "44197292401010f8fce5b053733edd8642d01095" +#define CEF_API_HASH_UNIVERSAL "a63640eaa583092b069ec9895526b3e9e4932f6a" #if defined(OS_WIN) -#define CEF_API_HASH_PLATFORM "95bf7fa1356070be95b7a6fee958355c6619fb63" +#define CEF_API_HASH_PLATFORM "510cec552fbcfb4b7d47853ddfccd91f1e4f4c7b" #elif defined(OS_MAC) -#define CEF_API_HASH_PLATFORM "8ec5426d7aa0418fca147380e97623a49cd8eaf4" +#define CEF_API_HASH_PLATFORM "ad36f5b62d9c4c2100859abb6b5b9fcedf8934ef" #elif defined(OS_LINUX) -#define CEF_API_HASH_PLATFORM "b2cbc2e6a3048d2415566d35ba434967fd796491" +#define CEF_API_HASH_PLATFORM "d9657b0023ae05b5b92787b5e7da70893caf15af" #endif #ifdef __cplusplus diff --git a/include/views/cef_display.h b/include/views/cef_display.h index 400d44833..be35ba822 100644 --- a/include/views/cef_display.h +++ b/include/views/cef_display.h @@ -91,6 +91,20 @@ class CefDisplay : public CefBaseRefCounted { /*--cef(count_func=displays:GetDisplayCount)--*/ static void GetAllDisplays(std::vector>& displays); + /// + /// Convert |point| from DIP screen coordinates to pixel screen coordinates. + /// This method is only used on Windows. + /// + /*--cef()--*/ + static CefPoint ConvertScreenPointToPixels(const CefPoint& point); + + /// + /// Convert |point| from pixel screen coordinates to DIP screen coordinates. + /// This method is only used on Windows. + /// + /*--cef()--*/ + static CefPoint ConvertScreenPointFromPixels(const CefPoint& point); + /// /// Returns the unique identifier for this Display. /// diff --git a/libcef/browser/views/display_impl.cc b/libcef/browser/views/display_impl.cc index f174c2ed1..e7e3a7da9 100644 --- a/libcef/browser/views/display_impl.cc +++ b/libcef/browser/views/display_impl.cc @@ -51,6 +51,30 @@ void CefDisplay::GetAllDisplays(std::vector>& displays) { displays.push_back(new CefDisplayImpl(vec[i])); } +// static +CefPoint CefDisplay::ConvertScreenPointToPixels(const CefPoint& point) { + CEF_REQUIRE_UIT_RETURN(CefPoint()); +#if BUILDFLAG(IS_WIN) + const gfx::Point pix_point = + view_util::ConvertPointToPixels(gfx::Point(point.x, point.y)); + return CefPoint(pix_point.x(), pix_point.y()); +#else + return point; +#endif +} + +// static +CefPoint CefDisplay::ConvertScreenPointFromPixels(const CefPoint& point) { + CEF_REQUIRE_UIT_RETURN(CefPoint()); +#if BUILDFLAG(IS_WIN) + const gfx::Point dip_point = + view_util::ConvertPointFromPixels(gfx::Point(point.x, point.y)); + return CefPoint(dip_point.x(), dip_point.y()); +#else + return point; +#endif +} + CefDisplayImpl::CefDisplayImpl(const display::Display& display) : display_(display) { CEF_REQUIRE_UIT(); diff --git a/libcef/browser/views/view_util.cc b/libcef/browser/views/view_util.cc index 55d59ca47..5a204494a 100644 --- a/libcef/browser/views/view_util.cc +++ b/libcef/browser/views/view_util.cc @@ -227,6 +227,17 @@ void ConvertPointToPixels(gfx::Point* point, float device_scale_factor) { gfx::ScalePoint(gfx::PointF(*point), device_scale_factor)); } +#if BUILDFLAG(IS_WIN) +gfx::Point ConvertPointFromPixels(const gfx::Point& point) { + return gfx::ToFlooredPoint( + display::win::ScreenWin::ScreenToDIPPoint(gfx::PointF(point))); +} + +gfx::Point ConvertPointToPixels(const gfx::Point& point) { + return display::win::ScreenWin::DIPToScreenPoint(point); +} +#endif // BUILDFLAG(IS_WIN) + bool ConvertPointToScreen(views::View* view, gfx::Point* point, bool output_pixel_coords) { diff --git a/libcef/browser/views/view_util.h b/libcef/browser/views/view_util.h index e49ae5285..a6ce14419 100644 --- a/libcef/browser/views/view_util.h +++ b/libcef/browser/views/view_util.h @@ -91,6 +91,14 @@ void ConvertPointFromPixels(gfx::Point* point, float device_scale_factor); // using |device_scale_factor|. void ConvertPointToPixels(gfx::Point* point, float device_scale_factor); +#if BUILDFLAG(IS_WIN) +// Convert |point| from pixel screen coordinates to DIP screen coordinates. +gfx::Point ConvertPointFromPixels(const gfx::Point& point); + +// Convert |point| from DIP screen coordinates to pixel screen coordinates. +gfx::Point ConvertPointToPixels(const gfx::Point& point); +#endif // BUILDFLAG(IS_WIN) + // Convert |point| from |view| to screen coordinates. If |output_pixel_coords| // is true then |point| will be output in pixel coordinates instead of density // independent pixels (DIP). Returns false if |view| does not currently belong diff --git a/libcef_dll/cpptoc/views/display_cpptoc.cc b/libcef_dll/cpptoc/views/display_cpptoc.cc index 470fee9d1..39e147e07 100644 --- a/libcef_dll/cpptoc/views/display_cpptoc.cc +++ b/libcef_dll/cpptoc/views/display_cpptoc.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=546b8f890852fb4df26a85aec6b83effe1bdc6e6$ +// $hash=5e68fdaae42fe008a95bcf2672debe3cf04fa2ff$ // #include "libcef_dll/cpptoc/views/display_cpptoc.h" @@ -121,6 +121,48 @@ CEF_EXPORT void cef_display_get_alls(size_t* displaysCount, } } +CEF_EXPORT cef_point_t +cef_display_convert_screen_point_to_pixels(const cef_point_t* point) { + shutdown_checker::AssertNotShutdown(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Verify param: point; type: simple_byref_const + DCHECK(point); + if (!point) + return CefPoint(); + + // Translate param: point; type: simple_byref_const + CefPoint pointVal = point ? *point : CefPoint(); + + // Execute + cef_point_t _retval = CefDisplay::ConvertScreenPointToPixels(pointVal); + + // Return type: simple + return _retval; +} + +CEF_EXPORT cef_point_t +cef_display_convert_screen_point_from_pixels(const cef_point_t* point) { + shutdown_checker::AssertNotShutdown(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Verify param: point; type: simple_byref_const + DCHECK(point); + if (!point) + return CefPoint(); + + // Translate param: point; type: simple_byref_const + CefPoint pointVal = point ? *point : CefPoint(); + + // Execute + cef_point_t _retval = CefDisplay::ConvertScreenPointFromPixels(pointVal); + + // Return type: simple + return _retval; +} + namespace { // MEMBER FUNCTIONS - Body may be edited by hand. diff --git a/libcef_dll/ctocpp/views/display_ctocpp.cc b/libcef_dll/ctocpp/views/display_ctocpp.cc index 9a6477c2e..c8dd10589 100644 --- a/libcef_dll/ctocpp/views/display_ctocpp.cc +++ b/libcef_dll/ctocpp/views/display_ctocpp.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=ba41b36a0cdd335f2a964665576aaf50d8be9c55$ +// $hash=afef323719b977c74bb86d015ad1b0f5c253c3ba$ // #include "libcef_dll/ctocpp/views/display_ctocpp.h" @@ -110,6 +110,32 @@ void CefDisplay::GetAllDisplays(std::vector>& displays) { } } +NO_SANITIZE("cfi-icall") +CefPoint CefDisplay::ConvertScreenPointToPixels(const CefPoint& point) { + shutdown_checker::AssertNotShutdown(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_point_t _retval = cef_display_convert_screen_point_to_pixels(&point); + + // Return type: simple + return _retval; +} + +NO_SANITIZE("cfi-icall") +CefPoint CefDisplay::ConvertScreenPointFromPixels(const CefPoint& point) { + shutdown_checker::AssertNotShutdown(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_point_t _retval = cef_display_convert_screen_point_from_pixels(&point); + + // Return type: simple + return _retval; +} + // VIRTUAL METHODS - Body may be edited by hand. NO_SANITIZE("cfi-icall") int64 CefDisplayCToCpp::GetID() { diff --git a/libcef_dll/wrapper/libcef_dll_dylib.cc b/libcef_dll/wrapper/libcef_dll_dylib.cc index abac1534a..7a0a69859 100644 --- a/libcef_dll/wrapper/libcef_dll_dylib.cc +++ b/libcef_dll/wrapper/libcef_dll_dylib.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=93d56886080f7dc864034a17ce1f794198b14259$ +// $hash=7e9918c2136d28088af105cb6678fe13b42ce5c0$ // #include @@ -232,6 +232,10 @@ struct libcef_pointers { decltype(&cef_display_get_matching_bounds) cef_display_get_matching_bounds; decltype(&cef_display_get_count) cef_display_get_count; decltype(&cef_display_get_alls) cef_display_get_alls; + decltype(&cef_display_convert_screen_point_to_pixels) + cef_display_convert_screen_point_to_pixels; + decltype(&cef_display_convert_screen_point_from_pixels) + cef_display_convert_screen_point_from_pixels; decltype(&cef_label_button_create) cef_label_button_create; decltype(&cef_menu_button_create) cef_menu_button_create; decltype(&cef_panel_create) cef_panel_create; @@ -441,6 +445,8 @@ int libcef_init_pointers(const char* path) { INIT_ENTRY(cef_display_get_matching_bounds); INIT_ENTRY(cef_display_get_count); INIT_ENTRY(cef_display_get_alls); + INIT_ENTRY(cef_display_convert_screen_point_to_pixels); + INIT_ENTRY(cef_display_convert_screen_point_from_pixels); INIT_ENTRY(cef_label_button_create); INIT_ENTRY(cef_menu_button_create); INIT_ENTRY(cef_panel_create); @@ -1257,6 +1263,18 @@ void cef_display_get_alls(size_t* displaysCount, g_libcef_pointers.cef_display_get_alls(displaysCount, displays); } +NO_SANITIZE("cfi-icall") +cef_point_t cef_display_convert_screen_point_to_pixels( + const cef_point_t* point) { + return g_libcef_pointers.cef_display_convert_screen_point_to_pixels(point); +} + +NO_SANITIZE("cfi-icall") +cef_point_t cef_display_convert_screen_point_from_pixels( + const cef_point_t* point) { + return g_libcef_pointers.cef_display_convert_screen_point_from_pixels(point); +} + NO_SANITIZE("cfi-icall") struct _cef_label_button_t* cef_label_button_create( struct _cef_button_delegate_t* delegate, diff --git a/tests/ceftests/views/window_unittest.cc b/tests/ceftests/views/window_unittest.cc index dd5cb78e1..3e85dcb66 100644 --- a/tests/ceftests/views/window_unittest.cc +++ b/tests/ceftests/views/window_unittest.cc @@ -200,6 +200,12 @@ void RunWindowLayoutAndCoords(CefRefPtr window) { display->ConvertPointFromPixels(point); EXPECT_EQ(CefPoint(client_bounds_in_screen.x, client_bounds_in_screen.y), point); + + // We don't know what the pixel values will be, but they should be reversable. + point = CefPoint(client_bounds_in_screen.x, client_bounds_in_screen.y); + const auto pixels = CefDisplay::ConvertScreenPointToPixels(point); + const auto dip = CefDisplay::ConvertScreenPointFromPixels(pixels); + EXPECT_EQ(point, dip); } void WindowLayoutAndCoordsImpl(CefRefPtr event) {