From 23be17f6938357a350d31a4f3e5cb01b70069702 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Mon, 27 Sep 2021 11:48:30 +0300 Subject: [PATCH] Use CefRect for CefWindowInfo bounds (fixes issue #1515) --- cef_paths2.gypi | 1 + include/cef_api_hash.h | 8 +- include/internal/cef_linux.h | 12 +-- include/internal/cef_mac.h | 12 +-- include/internal/cef_types.h | 54 +++---------- include/internal/cef_types_geometry.h | 78 +++++++++++++++++++ include/internal/cef_types_linux.h | 9 ++- include/internal/cef_types_mac.h | 10 ++- include/internal/cef_types_win.h | 11 +-- include/internal/cef_win.h | 20 ++--- libcef/browser/browser_info_manager.cc | 8 +- .../browser_platform_delegate_native_linux.cc | 12 +-- .../browser_platform_delegate_native_mac.mm | 16 ++-- .../browser_platform_delegate_native_win.cc | 8 +- .../browser/browser_window_std_mac.mm | 5 +- .../browser/browser_window_std_win.cc | 5 +- 16 files changed, 148 insertions(+), 121 deletions(-) create mode 100644 include/internal/cef_types_geometry.h diff --git a/cef_paths2.gypi b/cef_paths2.gypi index 66e46d283..251a05471 100644 --- a/cef_paths2.gypi +++ b/cef_paths2.gypi @@ -56,6 +56,7 @@ 'include/internal/cef_time.h', 'include/internal/cef_trace_event_internal.h', 'include/internal/cef_types.h', + 'include/internal/cef_types_geometry.h', ], 'includes_capi': [ 'include/capi/cef_base_capi.h', diff --git a/include/cef_api_hash.h b/include/cef_api_hash.h index 96ab62d66..0bd6c4484 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 "1e47eac2e964bf96bdbe3b0d358f28d7a2057f51" +#define CEF_API_HASH_UNIVERSAL "1783cba4ad54d26940bea3dab4d5210d0ebda9db" #if defined(OS_WIN) -#define CEF_API_HASH_PLATFORM "f66e7db3f60e0ed5dd389277c9351c31ee71752b" +#define CEF_API_HASH_PLATFORM "4c2476c02471c6efbff092d4dc6c25dd79237e69" #elif defined(OS_MAC) -#define CEF_API_HASH_PLATFORM "1911de75fc8837d4bf9dbab275406ca2b284be69" +#define CEF_API_HASH_PLATFORM "179a654c191179792e2d38d54eacbf0ff7169db4" #elif defined(OS_LINUX) -#define CEF_API_HASH_PLATFORM "2aecfcaaf2e017e4b56c38ab814b6d9b29b584e6" +#define CEF_API_HASH_PLATFORM "3766b0601ad47bef0325cde35c33f9b739f5b32a" #endif #ifdef __cplusplus diff --git a/include/internal/cef_linux.h b/include/internal/cef_linux.h index a247d4482..004df6f60 100644 --- a/include/internal/cef_linux.h +++ b/include/internal/cef_linux.h @@ -81,10 +81,7 @@ struct CefWindowInfoTraits { bool copy) { cef_string_set(src->window_name.str, src->window_name.length, &target->window_name, copy); - target->x = src->x; - target->y = src->y; - target->width = src->width; - target->height = src->height; + target->bounds = src->bounds; target->parent_window = src->parent_window; target->windowless_rendering_enabled = src->windowless_rendering_enabled; target->shared_texture_enabled = src->shared_texture_enabled; @@ -105,12 +102,9 @@ class CefWindowInfo : public CefStructBase { /// // Create the browser as a child window. /// - void SetAsChild(CefWindowHandle parent, const CefRect& windowRect) { + void SetAsChild(CefWindowHandle parent, const CefRect& bounds) { parent_window = parent; - x = windowRect.x; - y = windowRect.y; - width = windowRect.width; - height = windowRect.height; + this->bounds = bounds; } /// diff --git a/include/internal/cef_mac.h b/include/internal/cef_mac.h index 3123fb5ae..77d5b4eb0 100644 --- a/include/internal/cef_mac.h +++ b/include/internal/cef_mac.h @@ -81,10 +81,7 @@ struct CefWindowInfoTraits { bool copy) { cef_string_set(src->window_name.str, src->window_name.length, &target->window_name, copy); - target->x = src->x; - target->y = src->y; - target->width = src->width; - target->height = src->height; + target->bounds = src->bounds; target->hidden = src->hidden; target->parent_view = src->parent_view; target->windowless_rendering_enabled = src->windowless_rendering_enabled; @@ -106,12 +103,9 @@ class CefWindowInfo : public CefStructBase { /// // Create the browser as a child view. /// - void SetAsChild(CefWindowHandle parent, int x, int y, int width, int height) { + void SetAsChild(CefWindowHandle parent, const CefRect& bounds) { parent_view = parent; - this->x = x; - this->y = y; - this->width = width; - this->height = height; + this->bounds = bounds; hidden = false; } diff --git a/include/internal/cef_types.h b/include/internal/cef_types.h index a58a5bd35..43d462da6 100644 --- a/include/internal/cef_types.h +++ b/include/internal/cef_types.h @@ -35,6 +35,7 @@ #include "include/internal/cef_string.h" #include "include/internal/cef_string_list.h" #include "include/internal/cef_time.h" +#include "include/internal/cef_types_geometry.h" // Bring in platform-specific definitions. #if defined(OS_WIN) @@ -1372,51 +1373,6 @@ typedef enum { UR_FAILED, } cef_urlrequest_status_t; -/// -// Structure representing a point. -/// -typedef struct _cef_point_t { - int x; - int y; -} cef_point_t; - -/// -// Structure representing a rectangle. -/// -typedef struct _cef_rect_t { - int x; - int y; - int width; - int height; -} cef_rect_t; - -/// -// Structure representing a size. -/// -typedef struct _cef_size_t { - int width; - int height; -} cef_size_t; - -/// -// Structure representing a range. -/// -typedef struct _cef_range_t { - int from; - int to; -} cef_range_t; - -/// -// Structure representing insets. -/// -typedef struct _cef_insets_t { - int top; - int left; - int bottom; - int right; -} cef_insets_t; - -/// // Structure representing a draggable region. /// typedef struct _cef_draggable_region_t { @@ -2958,6 +2914,14 @@ typedef enum { CEF_SCHEME_OPTION_FETCH_ENABLED = 1 << 6, } cef_scheme_options_t; +/// +// Structure representing a range. +/// +typedef struct _cef_range_t { + int from; + int to; +} cef_range_t; + /// // Composition underline style. /// diff --git a/include/internal/cef_types_geometry.h b/include/internal/cef_types_geometry.h new file mode 100644 index 000000000..c642d20c7 --- /dev/null +++ b/include/internal/cef_types_geometry.h @@ -0,0 +1,78 @@ +// Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef CEF_INCLUDE_INTERNAL_CEF_TYPES_GEOMETRY_H_ +#define CEF_INCLUDE_INTERNAL_CEF_TYPES_GEOMETRY_H_ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +/// +// Structure representing a point. +/// +typedef struct _cef_point_t { + int x; + int y; +} cef_point_t; + +/// +// Structure representing a rectangle. +/// +typedef struct _cef_rect_t { + int x; + int y; + int width; + int height; +} cef_rect_t; + +/// +// Structure representing a size. +/// +typedef struct _cef_size_t { + int width; + int height; +} cef_size_t; + +/// +// Structure representing insets. +/// +typedef struct _cef_insets_t { + int top; + int left; + int bottom; + int right; +} cef_insets_t; + +#ifdef __cplusplus +} +#endif + +#endif // CEF_INCLUDE_INTERNAL_CEF_TYPES_GEOMETRY_H_ diff --git a/include/internal/cef_types_linux.h b/include/internal/cef_types_linux.h index b21d6551e..e12853be0 100644 --- a/include/internal/cef_types_linux.h +++ b/include/internal/cef_types_linux.h @@ -43,6 +43,7 @@ typedef struct _XDisplay XDisplay; #include "include/internal/cef_export.h" #include "include/internal/cef_string.h" +#include "include/internal/cef_types_geometry.h" // Handle types. #if defined(CEF_X11) @@ -93,10 +94,10 @@ typedef struct _cef_window_info_t { /// cef_string_t window_name; - unsigned int x; - unsigned int y; - unsigned int width; - unsigned int height; + /// + // Initial window bounds. + /// + cef_rect_t bounds; /// // Pointer for the parent window. diff --git a/include/internal/cef_types_mac.h b/include/internal/cef_types_mac.h index 3e48dc40d..c908eaa60 100644 --- a/include/internal/cef_types_mac.h +++ b/include/internal/cef_types_mac.h @@ -35,6 +35,7 @@ #if defined(OS_MAC) #include "include/internal/cef_string.h" +#include "include/internal/cef_types_geometry.h" // Handle types. // Actually NSCursor* @@ -85,10 +86,11 @@ typedef struct _cef_main_args_t { /// typedef struct _cef_window_info_t { cef_string_t window_name; - int x; - int y; - int width; - int height; + + /// + // Initial window bounds. + /// + cef_rect_t bounds; /// // Set to true (1) to create the view initially hidden. diff --git a/include/internal/cef_types_win.h b/include/internal/cef_types_win.h index dce896724..2af525b9b 100644 --- a/include/internal/cef_types_win.h +++ b/include/internal/cef_types_win.h @@ -35,7 +35,9 @@ #if defined(OS_WIN) #include + #include "include/internal/cef_string.h" +#include "include/internal/cef_types_geometry.h" // Handle types. #define cef_cursor_handle_t HCURSOR @@ -53,7 +55,9 @@ extern "C" { /// // Structure representing CefExecuteProcess arguments. /// -typedef struct _cef_main_args_t { HINSTANCE instance; } cef_main_args_t; +typedef struct _cef_main_args_t { + HINSTANCE instance; +} cef_main_args_t; /// // Structure representing window information. @@ -63,10 +67,7 @@ typedef struct _cef_window_info_t { DWORD ex_style; cef_string_t window_name; DWORD style; - int x; - int y; - int width; - int height; + cef_rect_t bounds; cef_window_handle_t parent_window; HMENU menu; diff --git a/include/internal/cef_win.h b/include/internal/cef_win.h index 292864e63..27c09bb74 100644 --- a/include/internal/cef_win.h +++ b/include/internal/cef_win.h @@ -81,10 +81,7 @@ struct CefWindowInfoTraits { cef_string_set(src->window_name.str, src->window_name.length, &target->window_name, copy); target->style = src->style; - target->x = src->x; - target->y = src->y; - target->width = src->width; - target->height = src->height; + target->bounds = src->bounds; target->parent_window = src->parent_window; target->menu = src->menu; target->windowless_rendering_enabled = src->windowless_rendering_enabled; @@ -108,14 +105,11 @@ class CefWindowInfo : public CefStructBase { /// // Create the browser as a child window. /// - void SetAsChild(CefWindowHandle parent, RECT windowRect) { + void SetAsChild(CefWindowHandle parent, const CefRect& bounds) { style = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_TABSTOP | WS_VISIBLE; parent_window = parent; - x = windowRect.left; - y = windowRect.top; - width = windowRect.right - windowRect.left; - height = windowRect.bottom - windowRect.top; + this->bounds = bounds; } /// @@ -125,10 +119,10 @@ class CefWindowInfo : public CefStructBase { style = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE; parent_window = parent; - x = CW_USEDEFAULT; - y = CW_USEDEFAULT; - width = CW_USEDEFAULT; - height = CW_USEDEFAULT; + bounds.x = CW_USEDEFAULT; + bounds.y = CW_USEDEFAULT; + bounds.width = CW_USEDEFAULT; + bounds.height = CW_USEDEFAULT; cef_string_copy(windowName.c_str(), windowName.length(), &window_name); } diff --git a/libcef/browser/browser_info_manager.cc b/libcef/browser/browser_info_manager.cc index c1c75f74d..7c45eaa7f 100644 --- a/libcef/browser/browser_info_manager.cc +++ b/libcef/browser/browser_info_manager.cc @@ -157,13 +157,13 @@ bool CefBrowserInfoManager::CanCreateWindow( #if (defined(OS_WIN) || defined(OS_MAC)) // Default to the size from the popup features. if (cef_features.xSet) - window_info->x = cef_features.x; + window_info->bounds.x = cef_features.x; if (cef_features.ySet) - window_info->y = cef_features.y; + window_info->bounds.y = cef_features.y; if (cef_features.widthSet) - window_info->width = cef_features.width; + window_info->bounds.width = cef_features.width; if (cef_features.heightSet) - window_info->height = cef_features.height; + window_info->bounds.height = cef_features.height; #endif allow = !handler->OnBeforePopup( diff --git a/libcef/browser/native/browser_platform_delegate_native_linux.cc b/libcef/browser/native/browser_platform_delegate_native_linux.cc index f1255a7b7..22fd08533 100644 --- a/libcef/browser/native/browser_platform_delegate_native_linux.cc +++ b/libcef/browser/native/browser_platform_delegate_native_linux.cc @@ -48,13 +48,13 @@ void CefBrowserPlatformDelegateNativeLinux::BrowserDestroyed( bool CefBrowserPlatformDelegateNativeLinux::CreateHostWindow() { DCHECK(!window_widget_); - if (window_info_.width == 0) - window_info_.width = 800; - if (window_info_.height == 0) - window_info_.height = 600; + if (window_info_.bounds.width == 0) + window_info_.bounds.width = 800; + if (window_info_.bounds.height == 0) + window_info_.bounds.height = 600; - gfx::Rect rect(window_info_.x, window_info_.y, window_info_.width, - window_info_.height); + gfx::Rect rect(window_info_.bounds.x, window_info_.bounds.y, + window_info_.bounds.width, window_info_.bounds.height); #if defined(USE_X11) DCHECK(!window_x11_); diff --git a/libcef/browser/native/browser_platform_delegate_native_mac.mm b/libcef/browser/native/browser_platform_delegate_native_mac.mm index c643bb159..a19f6cd16 100644 --- a/libcef/browser/native/browser_platform_delegate_native_mac.mm +++ b/libcef/browser/native/browser_platform_delegate_native_mac.mm @@ -166,18 +166,18 @@ bool CefBrowserPlatformDelegateNativeMac::CreateHostWindow() { NSView* parentView = CAST_CEF_WINDOW_HANDLE_TO_NSVIEW(window_info_.parent_view); - NSRect contentRect = {{static_cast(window_info_.x), - static_cast(window_info_.y)}, - {static_cast(window_info_.width), - static_cast(window_info_.height)}}; + NSRect contentRect = {{static_cast(window_info_.bounds.x), + static_cast(window_info_.bounds.y)}, + {static_cast(window_info_.bounds.width), + static_cast(window_info_.bounds.height)}}; if (parentView == nil) { // Create a new window. NSRect screen_rect = [[NSScreen mainScreen] visibleFrame]; NSRect window_rect = { - {static_cast(window_info_.x), - screen_rect.size.height - static_cast(window_info_.y)}, - {static_cast(window_info_.width), - static_cast(window_info_.height)}}; + {static_cast(window_info_.bounds.x), + screen_rect.size.height - static_cast(window_info_.bounds.y)}, + {static_cast(window_info_.bounds.width), + static_cast(window_info_.bounds.height)}}; if (window_rect.size.width == 0) window_rect.size.width = 750; if (window_rect.size.height == 0) diff --git a/libcef/browser/native/browser_platform_delegate_native_win.cc b/libcef/browser/native/browser_platform_delegate_native_win.cc index 62bb81f2b..f3eb5ff67 100644 --- a/libcef/browser/native/browser_platform_delegate_native_win.cc +++ b/libcef/browser/native/browser_platform_delegate_native_win.cc @@ -148,10 +148,10 @@ bool CefBrowserPlatformDelegateNativeWin::CreateHostWindow() { // Create the new browser window. CreateWindowEx(window_info_.ex_style, GetWndClass(), windowName.c_str(), - window_info_.style, window_info_.x, window_info_.y, - window_info_.width, window_info_.height, - window_info_.parent_window, window_info_.menu, - ::GetModuleHandle(NULL), this); + window_info_.style, window_info_.bounds.x, + window_info_.bounds.y, window_info_.bounds.width, + window_info_.bounds.height, window_info_.parent_window, + window_info_.menu, ::GetModuleHandle(NULL), this); // It's possible for CreateWindowEx to fail if the parent window was // destroyed between the call to CreateBrowser and the above one. diff --git a/tests/cefclient/browser/browser_window_std_mac.mm b/tests/cefclient/browser/browser_window_std_mac.mm index 8b000a878..510fd41e6 100644 --- a/tests/cefclient/browser/browser_window_std_mac.mm +++ b/tests/cefclient/browser/browser_window_std_mac.mm @@ -27,8 +27,7 @@ void BrowserWindowStdMac::CreateBrowser( REQUIRE_MAIN_THREAD(); CefWindowInfo window_info; - window_info.SetAsChild(parent_handle, rect.x, rect.y, rect.width, - rect.height); + window_info.SetAsChild(parent_handle, rect); CefBrowserHost::CreateBrowser(window_info, client_handler_, client_handler_->startup_url(), settings, @@ -42,7 +41,7 @@ void BrowserWindowStdMac::GetPopupConfig(CefWindowHandle temp_handle, CEF_REQUIRE_UI_THREAD(); // The window will be properly sized after the browser is created. - windowInfo.SetAsChild(temp_handle, 0, 0, 0, 0); + windowInfo.SetAsChild(temp_handle, CefRect()); client = client_handler_; } diff --git a/tests/cefclient/browser/browser_window_std_win.cc b/tests/cefclient/browser/browser_window_std_win.cc index 8b17f11ee..980077748 100644 --- a/tests/cefclient/browser/browser_window_std_win.cc +++ b/tests/cefclient/browser/browser_window_std_win.cc @@ -24,8 +24,7 @@ void BrowserWindowStdWin::CreateBrowser( REQUIRE_MAIN_THREAD(); CefWindowInfo window_info; - RECT wnd_rect = {rect.x, rect.y, rect.x + rect.width, rect.y + rect.height}; - window_info.SetAsChild(parent_handle, wnd_rect); + window_info.SetAsChild(parent_handle, rect); if (GetWindowLongPtr(parent_handle, GWL_EXSTYLE) & WS_EX_NOACTIVATE) { // Don't activate the browser window on creation. @@ -44,7 +43,7 @@ void BrowserWindowStdWin::GetPopupConfig(CefWindowHandle temp_handle, CEF_REQUIRE_UI_THREAD(); // The window will be properly sized after the browser is created. - windowInfo.SetAsChild(temp_handle, RECT()); + windowInfo.SetAsChild(temp_handle, CefRect()); // Don't activate the hidden browser window on creation. windowInfo.ex_style |= WS_EX_NOACTIVATE;