Use CefRect for CefWindowInfo bounds (fixes issue #1515)

This commit is contained in:
Marshall Greenblatt
2021-09-27 11:48:30 +03:00
parent 41b64e428c
commit 23be17f693
16 changed files with 148 additions and 121 deletions

View File

@ -56,6 +56,7 @@
'include/internal/cef_time.h', 'include/internal/cef_time.h',
'include/internal/cef_trace_event_internal.h', 'include/internal/cef_trace_event_internal.h',
'include/internal/cef_types.h', 'include/internal/cef_types.h',
'include/internal/cef_types_geometry.h',
], ],
'includes_capi': [ 'includes_capi': [
'include/capi/cef_base_capi.h', 'include/capi/cef_base_capi.h',

View File

@ -42,13 +42,13 @@
// way that may cause binary incompatibility with other builds. The universal // way that may cause binary incompatibility with other builds. The universal
// hash value will change if any platform is affected whereas the platform hash // hash value will change if any platform is affected whereas the platform hash
// values will change only if that particular platform is affected. // 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) #if defined(OS_WIN)
#define CEF_API_HASH_PLATFORM "f66e7db3f60e0ed5dd389277c9351c31ee71752b" #define CEF_API_HASH_PLATFORM "4c2476c02471c6efbff092d4dc6c25dd79237e69"
#elif defined(OS_MAC) #elif defined(OS_MAC)
#define CEF_API_HASH_PLATFORM "1911de75fc8837d4bf9dbab275406ca2b284be69" #define CEF_API_HASH_PLATFORM "179a654c191179792e2d38d54eacbf0ff7169db4"
#elif defined(OS_LINUX) #elif defined(OS_LINUX)
#define CEF_API_HASH_PLATFORM "2aecfcaaf2e017e4b56c38ab814b6d9b29b584e6" #define CEF_API_HASH_PLATFORM "3766b0601ad47bef0325cde35c33f9b739f5b32a"
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -81,10 +81,7 @@ struct CefWindowInfoTraits {
bool copy) { bool copy) {
cef_string_set(src->window_name.str, src->window_name.length, cef_string_set(src->window_name.str, src->window_name.length,
&target->window_name, copy); &target->window_name, copy);
target->x = src->x; target->bounds = src->bounds;
target->y = src->y;
target->width = src->width;
target->height = src->height;
target->parent_window = src->parent_window; target->parent_window = src->parent_window;
target->windowless_rendering_enabled = src->windowless_rendering_enabled; target->windowless_rendering_enabled = src->windowless_rendering_enabled;
target->shared_texture_enabled = src->shared_texture_enabled; target->shared_texture_enabled = src->shared_texture_enabled;
@ -105,12 +102,9 @@ class CefWindowInfo : public CefStructBase<CefWindowInfoTraits> {
/// ///
// Create the browser as a child window. // Create the browser as a child window.
/// ///
void SetAsChild(CefWindowHandle parent, const CefRect& windowRect) { void SetAsChild(CefWindowHandle parent, const CefRect& bounds) {
parent_window = parent; parent_window = parent;
x = windowRect.x; this->bounds = bounds;
y = windowRect.y;
width = windowRect.width;
height = windowRect.height;
} }
/// ///

View File

@ -81,10 +81,7 @@ struct CefWindowInfoTraits {
bool copy) { bool copy) {
cef_string_set(src->window_name.str, src->window_name.length, cef_string_set(src->window_name.str, src->window_name.length,
&target->window_name, copy); &target->window_name, copy);
target->x = src->x; target->bounds = src->bounds;
target->y = src->y;
target->width = src->width;
target->height = src->height;
target->hidden = src->hidden; target->hidden = src->hidden;
target->parent_view = src->parent_view; target->parent_view = src->parent_view;
target->windowless_rendering_enabled = src->windowless_rendering_enabled; target->windowless_rendering_enabled = src->windowless_rendering_enabled;
@ -106,12 +103,9 @@ class CefWindowInfo : public CefStructBase<CefWindowInfoTraits> {
/// ///
// Create the browser as a child view. // 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; parent_view = parent;
this->x = x; this->bounds = bounds;
this->y = y;
this->width = width;
this->height = height;
hidden = false; hidden = false;
} }

View File

@ -35,6 +35,7 @@
#include "include/internal/cef_string.h" #include "include/internal/cef_string.h"
#include "include/internal/cef_string_list.h" #include "include/internal/cef_string_list.h"
#include "include/internal/cef_time.h" #include "include/internal/cef_time.h"
#include "include/internal/cef_types_geometry.h"
// Bring in platform-specific definitions. // Bring in platform-specific definitions.
#if defined(OS_WIN) #if defined(OS_WIN)
@ -1372,51 +1373,6 @@ typedef enum {
UR_FAILED, UR_FAILED,
} cef_urlrequest_status_t; } 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. // Structure representing a draggable region.
/// ///
typedef struct _cef_draggable_region_t { typedef struct _cef_draggable_region_t {
@ -2958,6 +2914,14 @@ typedef enum {
CEF_SCHEME_OPTION_FETCH_ENABLED = 1 << 6, CEF_SCHEME_OPTION_FETCH_ENABLED = 1 << 6,
} cef_scheme_options_t; } cef_scheme_options_t;
///
// Structure representing a range.
///
typedef struct _cef_range_t {
int from;
int to;
} cef_range_t;
/// ///
// Composition underline style. // Composition underline style.
/// ///

View File

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

View File

@ -43,6 +43,7 @@ typedef struct _XDisplay XDisplay;
#include "include/internal/cef_export.h" #include "include/internal/cef_export.h"
#include "include/internal/cef_string.h" #include "include/internal/cef_string.h"
#include "include/internal/cef_types_geometry.h"
// Handle types. // Handle types.
#if defined(CEF_X11) #if defined(CEF_X11)
@ -93,10 +94,10 @@ typedef struct _cef_window_info_t {
/// ///
cef_string_t window_name; cef_string_t window_name;
unsigned int x; ///
unsigned int y; // Initial window bounds.
unsigned int width; ///
unsigned int height; cef_rect_t bounds;
/// ///
// Pointer for the parent window. // Pointer for the parent window.

View File

@ -35,6 +35,7 @@
#if defined(OS_MAC) #if defined(OS_MAC)
#include "include/internal/cef_string.h" #include "include/internal/cef_string.h"
#include "include/internal/cef_types_geometry.h"
// Handle types. // Handle types.
// Actually NSCursor* // Actually NSCursor*
@ -85,10 +86,11 @@ typedef struct _cef_main_args_t {
/// ///
typedef struct _cef_window_info_t { typedef struct _cef_window_info_t {
cef_string_t window_name; cef_string_t window_name;
int x;
int y; ///
int width; // Initial window bounds.
int height; ///
cef_rect_t bounds;
/// ///
// Set to true (1) to create the view initially hidden. // Set to true (1) to create the view initially hidden.

View File

@ -35,7 +35,9 @@
#if defined(OS_WIN) #if defined(OS_WIN)
#include <windows.h> #include <windows.h>
#include "include/internal/cef_string.h" #include "include/internal/cef_string.h"
#include "include/internal/cef_types_geometry.h"
// Handle types. // Handle types.
#define cef_cursor_handle_t HCURSOR #define cef_cursor_handle_t HCURSOR
@ -53,7 +55,9 @@ extern "C" {
/// ///
// Structure representing CefExecuteProcess arguments. // 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. // Structure representing window information.
@ -63,10 +67,7 @@ typedef struct _cef_window_info_t {
DWORD ex_style; DWORD ex_style;
cef_string_t window_name; cef_string_t window_name;
DWORD style; DWORD style;
int x; cef_rect_t bounds;
int y;
int width;
int height;
cef_window_handle_t parent_window; cef_window_handle_t parent_window;
HMENU menu; HMENU menu;

View File

@ -81,10 +81,7 @@ struct CefWindowInfoTraits {
cef_string_set(src->window_name.str, src->window_name.length, cef_string_set(src->window_name.str, src->window_name.length,
&target->window_name, copy); &target->window_name, copy);
target->style = src->style; target->style = src->style;
target->x = src->x; target->bounds = src->bounds;
target->y = src->y;
target->width = src->width;
target->height = src->height;
target->parent_window = src->parent_window; target->parent_window = src->parent_window;
target->menu = src->menu; target->menu = src->menu;
target->windowless_rendering_enabled = src->windowless_rendering_enabled; target->windowless_rendering_enabled = src->windowless_rendering_enabled;
@ -108,14 +105,11 @@ class CefWindowInfo : public CefStructBase<CefWindowInfoTraits> {
/// ///
// Create the browser as a child window. // Create the browser as a child window.
/// ///
void SetAsChild(CefWindowHandle parent, RECT windowRect) { void SetAsChild(CefWindowHandle parent, const CefRect& bounds) {
style = style =
WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_TABSTOP | WS_VISIBLE; WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_TABSTOP | WS_VISIBLE;
parent_window = parent; parent_window = parent;
x = windowRect.left; this->bounds = bounds;
y = windowRect.top;
width = windowRect.right - windowRect.left;
height = windowRect.bottom - windowRect.top;
} }
/// ///
@ -125,10 +119,10 @@ class CefWindowInfo : public CefStructBase<CefWindowInfoTraits> {
style = style =
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE; WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE;
parent_window = parent; parent_window = parent;
x = CW_USEDEFAULT; bounds.x = CW_USEDEFAULT;
y = CW_USEDEFAULT; bounds.y = CW_USEDEFAULT;
width = CW_USEDEFAULT; bounds.width = CW_USEDEFAULT;
height = CW_USEDEFAULT; bounds.height = CW_USEDEFAULT;
cef_string_copy(windowName.c_str(), windowName.length(), &window_name); cef_string_copy(windowName.c_str(), windowName.length(), &window_name);
} }

View File

@ -157,13 +157,13 @@ bool CefBrowserInfoManager::CanCreateWindow(
#if (defined(OS_WIN) || defined(OS_MAC)) #if (defined(OS_WIN) || defined(OS_MAC))
// Default to the size from the popup features. // Default to the size from the popup features.
if (cef_features.xSet) if (cef_features.xSet)
window_info->x = cef_features.x; window_info->bounds.x = cef_features.x;
if (cef_features.ySet) if (cef_features.ySet)
window_info->y = cef_features.y; window_info->bounds.y = cef_features.y;
if (cef_features.widthSet) if (cef_features.widthSet)
window_info->width = cef_features.width; window_info->bounds.width = cef_features.width;
if (cef_features.heightSet) if (cef_features.heightSet)
window_info->height = cef_features.height; window_info->bounds.height = cef_features.height;
#endif #endif
allow = !handler->OnBeforePopup( allow = !handler->OnBeforePopup(

View File

@ -48,13 +48,13 @@ void CefBrowserPlatformDelegateNativeLinux::BrowserDestroyed(
bool CefBrowserPlatformDelegateNativeLinux::CreateHostWindow() { bool CefBrowserPlatformDelegateNativeLinux::CreateHostWindow() {
DCHECK(!window_widget_); DCHECK(!window_widget_);
if (window_info_.width == 0) if (window_info_.bounds.width == 0)
window_info_.width = 800; window_info_.bounds.width = 800;
if (window_info_.height == 0) if (window_info_.bounds.height == 0)
window_info_.height = 600; window_info_.bounds.height = 600;
gfx::Rect rect(window_info_.x, window_info_.y, window_info_.width, gfx::Rect rect(window_info_.bounds.x, window_info_.bounds.y,
window_info_.height); window_info_.bounds.width, window_info_.bounds.height);
#if defined(USE_X11) #if defined(USE_X11)
DCHECK(!window_x11_); DCHECK(!window_x11_);

View File

@ -166,18 +166,18 @@ bool CefBrowserPlatformDelegateNativeMac::CreateHostWindow() {
NSView* parentView = NSView* parentView =
CAST_CEF_WINDOW_HANDLE_TO_NSVIEW(window_info_.parent_view); CAST_CEF_WINDOW_HANDLE_TO_NSVIEW(window_info_.parent_view);
NSRect contentRect = {{static_cast<CGFloat>(window_info_.x), NSRect contentRect = {{static_cast<CGFloat>(window_info_.bounds.x),
static_cast<CGFloat>(window_info_.y)}, static_cast<CGFloat>(window_info_.bounds.y)},
{static_cast<CGFloat>(window_info_.width), {static_cast<CGFloat>(window_info_.bounds.width),
static_cast<CGFloat>(window_info_.height)}}; static_cast<CGFloat>(window_info_.bounds.height)}};
if (parentView == nil) { if (parentView == nil) {
// Create a new window. // Create a new window.
NSRect screen_rect = [[NSScreen mainScreen] visibleFrame]; NSRect screen_rect = [[NSScreen mainScreen] visibleFrame];
NSRect window_rect = { NSRect window_rect = {
{static_cast<CGFloat>(window_info_.x), {static_cast<CGFloat>(window_info_.bounds.x),
screen_rect.size.height - static_cast<CGFloat>(window_info_.y)}, screen_rect.size.height - static_cast<CGFloat>(window_info_.bounds.y)},
{static_cast<CGFloat>(window_info_.width), {static_cast<CGFloat>(window_info_.bounds.width),
static_cast<CGFloat>(window_info_.height)}}; static_cast<CGFloat>(window_info_.bounds.height)}};
if (window_rect.size.width == 0) if (window_rect.size.width == 0)
window_rect.size.width = 750; window_rect.size.width = 750;
if (window_rect.size.height == 0) if (window_rect.size.height == 0)

View File

@ -148,10 +148,10 @@ bool CefBrowserPlatformDelegateNativeWin::CreateHostWindow() {
// Create the new browser window. // Create the new browser window.
CreateWindowEx(window_info_.ex_style, GetWndClass(), windowName.c_str(), CreateWindowEx(window_info_.ex_style, GetWndClass(), windowName.c_str(),
window_info_.style, window_info_.x, window_info_.y, window_info_.style, window_info_.bounds.x,
window_info_.width, window_info_.height, window_info_.bounds.y, window_info_.bounds.width,
window_info_.parent_window, window_info_.menu, window_info_.bounds.height, window_info_.parent_window,
::GetModuleHandle(NULL), this); window_info_.menu, ::GetModuleHandle(NULL), this);
// It's possible for CreateWindowEx to fail if the parent window was // It's possible for CreateWindowEx to fail if the parent window was
// destroyed between the call to CreateBrowser and the above one. // destroyed between the call to CreateBrowser and the above one.

View File

@ -27,8 +27,7 @@ void BrowserWindowStdMac::CreateBrowser(
REQUIRE_MAIN_THREAD(); REQUIRE_MAIN_THREAD();
CefWindowInfo window_info; CefWindowInfo window_info;
window_info.SetAsChild(parent_handle, rect.x, rect.y, rect.width, window_info.SetAsChild(parent_handle, rect);
rect.height);
CefBrowserHost::CreateBrowser(window_info, client_handler_, CefBrowserHost::CreateBrowser(window_info, client_handler_,
client_handler_->startup_url(), settings, client_handler_->startup_url(), settings,
@ -42,7 +41,7 @@ void BrowserWindowStdMac::GetPopupConfig(CefWindowHandle temp_handle,
CEF_REQUIRE_UI_THREAD(); CEF_REQUIRE_UI_THREAD();
// The window will be properly sized after the browser is created. // 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_; client = client_handler_;
} }

View File

@ -24,8 +24,7 @@ void BrowserWindowStdWin::CreateBrowser(
REQUIRE_MAIN_THREAD(); REQUIRE_MAIN_THREAD();
CefWindowInfo window_info; CefWindowInfo window_info;
RECT wnd_rect = {rect.x, rect.y, rect.x + rect.width, rect.y + rect.height}; window_info.SetAsChild(parent_handle, rect);
window_info.SetAsChild(parent_handle, wnd_rect);
if (GetWindowLongPtr(parent_handle, GWL_EXSTYLE) & WS_EX_NOACTIVATE) { if (GetWindowLongPtr(parent_handle, GWL_EXSTYLE) & WS_EX_NOACTIVATE) {
// Don't activate the browser window on creation. // Don't activate the browser window on creation.
@ -44,7 +43,7 @@ void BrowserWindowStdWin::GetPopupConfig(CefWindowHandle temp_handle,
CEF_REQUIRE_UI_THREAD(); CEF_REQUIRE_UI_THREAD();
// The window will be properly sized after the browser is created. // 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. // Don't activate the hidden browser window on creation.
windowInfo.ex_style |= WS_EX_NOACTIVATE; windowInfo.ex_style |= WS_EX_NOACTIVATE;