cefclient: win: Support window state restore (see issue #3359)
The cefclient sample app on Windows will persist window state across application restart if run with cache_path and persist_user_references enabled. To test: 1. Run `cefclient --cache-path=/path/to/cache --persist-user-preferences` 2. Move or resize the window, maximize, minimize, etc. 3. Exit cefclient. 4. Run cefclient again with the same arguments. The previous window state will be restored.
This commit is contained in:
parent
882bc19fdd
commit
e2a9236106
|
@ -33,7 +33,7 @@
|
|||
// by hand. See the translator.README.txt file in the tools directory for
|
||||
// more information.
|
||||
//
|
||||
// $hash=6eed21d200bad5e898dfbe2701ad327cc1e4cc5c$
|
||||
// $hash=912c23bc842c87aeca79780746c31e3fe848013a$
|
||||
//
|
||||
|
||||
#ifndef CEF_INCLUDE_CAPI_VIEWS_CEF_DISPLAY_CAPI_H_
|
||||
|
@ -154,6 +154,20 @@ cef_display_convert_screen_point_to_pixels(const cef_point_t* point);
|
|||
CEF_EXPORT cef_point_t
|
||||
cef_display_convert_screen_point_from_pixels(const cef_point_t* point);
|
||||
|
||||
///
|
||||
/// Convert |rect| from DIP screen coordinates to pixel screen coordinates. This
|
||||
/// function is only used on Windows.
|
||||
///
|
||||
CEF_EXPORT cef_rect_t
|
||||
cef_display_convert_screen_rect_to_pixels(const cef_rect_t* rect);
|
||||
|
||||
///
|
||||
/// Convert |rect| from pixel screen coordinates to DIP screen coordinates. This
|
||||
/// function is only used on Windows.
|
||||
///
|
||||
CEF_EXPORT cef_rect_t
|
||||
cef_display_convert_screen_rect_from_pixels(const cef_rect_t* rect);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -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 "46cd296ee58a28371e4f82c52cf447c516a4dc4b"
|
||||
#define CEF_API_HASH_UNIVERSAL "e92cde673e73851d8841e2f3c4f38bcd0f6ed2bb"
|
||||
#if defined(OS_WIN)
|
||||
#define CEF_API_HASH_PLATFORM "92c7ff6ca220e1c55081d020fd2b1d96d102a8fa"
|
||||
#define CEF_API_HASH_PLATFORM "162bfdae56cbfd7f76fd4178be019f0dba512c40"
|
||||
#elif defined(OS_MAC)
|
||||
#define CEF_API_HASH_PLATFORM "7d01ca5ec82dbefa6f3f84fa4883a0059d96ccb5"
|
||||
#define CEF_API_HASH_PLATFORM "31c5680dbc8d80fffc14214dd1ce4126a08e38d3"
|
||||
#elif defined(OS_LINUX)
|
||||
#define CEF_API_HASH_PLATFORM "f0334f17e0823c7cf7ee15bb53960efb21d31468"
|
||||
#define CEF_API_HASH_PLATFORM "9682b2251f9973ee9eee0940eb9c773e522c2975"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -105,6 +105,20 @@ class CefDisplay : public CefBaseRefCounted {
|
|||
/*--cef()--*/
|
||||
static CefPoint ConvertScreenPointFromPixels(const CefPoint& point);
|
||||
|
||||
///
|
||||
/// Convert |rect| from DIP screen coordinates to pixel screen coordinates.
|
||||
/// This method is only used on Windows.
|
||||
///
|
||||
/*--cef()--*/
|
||||
static CefRect ConvertScreenRectToPixels(const CefRect& rect);
|
||||
|
||||
///
|
||||
/// Convert |rect| from pixel screen coordinates to DIP screen coordinates.
|
||||
/// This method is only used on Windows.
|
||||
///
|
||||
/*--cef()--*/
|
||||
static CefRect ConvertScreenRectFromPixels(const CefRect& rect);
|
||||
|
||||
///
|
||||
/// Returns the unique identifier for this Display.
|
||||
///
|
||||
|
|
|
@ -75,6 +75,32 @@ CefPoint CefDisplay::ConvertScreenPointFromPixels(const CefPoint& point) {
|
|||
#endif
|
||||
}
|
||||
|
||||
// static
|
||||
CefRect CefDisplay::ConvertScreenRectToPixels(const CefRect& rect) {
|
||||
CEF_REQUIRE_UIT_RETURN(CefRect());
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
const gfx::Rect pix_rect = view_util::ConvertRectToPixels(
|
||||
gfx::Rect(rect.x, rect.y, rect.width, rect.height));
|
||||
return CefRect(pix_rect.x(), pix_rect.y(), pix_rect.width(),
|
||||
pix_rect.height());
|
||||
#else
|
||||
return rect;
|
||||
#endif
|
||||
}
|
||||
|
||||
// static
|
||||
CefRect CefDisplay::ConvertScreenRectFromPixels(const CefRect& rect) {
|
||||
CEF_REQUIRE_UIT_RETURN(CefRect());
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
const gfx::Rect dip_rect = view_util::ConvertRectFromPixels(
|
||||
gfx::Rect(rect.x, rect.y, rect.width, rect.height));
|
||||
return CefRect(dip_rect.x(), dip_rect.y(), dip_rect.width(),
|
||||
dip_rect.height());
|
||||
#else
|
||||
return rect;
|
||||
#endif
|
||||
}
|
||||
|
||||
CefDisplayImpl::CefDisplayImpl(const display::Display& display)
|
||||
: display_(display) {
|
||||
CEF_REQUIRE_UIT();
|
||||
|
|
|
@ -236,6 +236,14 @@ gfx::Point ConvertPointFromPixels(const gfx::Point& point) {
|
|||
gfx::Point ConvertPointToPixels(const gfx::Point& point) {
|
||||
return display::win::ScreenWin::DIPToScreenPoint(point);
|
||||
}
|
||||
|
||||
gfx::Rect ConvertRectFromPixels(const gfx::Rect& rect) {
|
||||
return display::win::ScreenWin::ScreenToDIPRect(nullptr, rect);
|
||||
}
|
||||
|
||||
gfx::Rect ConvertRectToPixels(const gfx::Rect& rect) {
|
||||
return display::win::ScreenWin::DIPToScreenRect(nullptr, rect);
|
||||
}
|
||||
#endif // BUILDFLAG(IS_WIN)
|
||||
|
||||
bool ConvertPointToScreen(views::View* view,
|
||||
|
|
|
@ -97,6 +97,12 @@ gfx::Point ConvertPointFromPixels(const gfx::Point& point);
|
|||
|
||||
// Convert |point| from DIP screen coordinates to pixel screen coordinates.
|
||||
gfx::Point ConvertPointToPixels(const gfx::Point& point);
|
||||
|
||||
// Convert |rect| from pixel screen coordinates to DIP screen coordinates.
|
||||
gfx::Rect ConvertRectFromPixels(const gfx::Rect& rect);
|
||||
|
||||
// Convert |rect| from DIP screen coordinates to pixel screen coordinates.
|
||||
gfx::Rect ConvertRectToPixels(const gfx::Rect& rect);
|
||||
#endif // BUILDFLAG(IS_WIN)
|
||||
|
||||
// Convert |point| from |view| to screen coordinates. If |output_pixel_coords|
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
// implementations. See the translator.README.txt file in the tools directory
|
||||
// for more information.
|
||||
//
|
||||
// $hash=5e68fdaae42fe008a95bcf2672debe3cf04fa2ff$
|
||||
// $hash=d2f3054a54f514ce650101e293bf085eeba48ee7$
|
||||
//
|
||||
|
||||
#include "libcef_dll/cpptoc/views/display_cpptoc.h"
|
||||
|
@ -163,6 +163,48 @@ cef_display_convert_screen_point_from_pixels(const cef_point_t* point) {
|
|||
return _retval;
|
||||
}
|
||||
|
||||
CEF_EXPORT cef_rect_t
|
||||
cef_display_convert_screen_rect_to_pixels(const cef_rect_t* rect) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Verify param: rect; type: simple_byref_const
|
||||
DCHECK(rect);
|
||||
if (!rect)
|
||||
return CefRect();
|
||||
|
||||
// Translate param: rect; type: simple_byref_const
|
||||
CefRect rectVal = rect ? *rect : CefRect();
|
||||
|
||||
// Execute
|
||||
cef_rect_t _retval = CefDisplay::ConvertScreenRectToPixels(rectVal);
|
||||
|
||||
// Return type: simple
|
||||
return _retval;
|
||||
}
|
||||
|
||||
CEF_EXPORT cef_rect_t
|
||||
cef_display_convert_screen_rect_from_pixels(const cef_rect_t* rect) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Verify param: rect; type: simple_byref_const
|
||||
DCHECK(rect);
|
||||
if (!rect)
|
||||
return CefRect();
|
||||
|
||||
// Translate param: rect; type: simple_byref_const
|
||||
CefRect rectVal = rect ? *rect : CefRect();
|
||||
|
||||
// Execute
|
||||
cef_rect_t _retval = CefDisplay::ConvertScreenRectFromPixels(rectVal);
|
||||
|
||||
// Return type: simple
|
||||
return _retval;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// MEMBER FUNCTIONS - Body may be edited by hand.
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
// implementations. See the translator.README.txt file in the tools directory
|
||||
// for more information.
|
||||
//
|
||||
// $hash=afef323719b977c74bb86d015ad1b0f5c253c3ba$
|
||||
// $hash=d171aff72ef24ed2b85182e98b2b8d609ae25ddd$
|
||||
//
|
||||
|
||||
#include "libcef_dll/ctocpp/views/display_ctocpp.h"
|
||||
|
@ -136,6 +136,32 @@ CefPoint CefDisplay::ConvertScreenPointFromPixels(const CefPoint& point) {
|
|||
return _retval;
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi-icall")
|
||||
CefRect CefDisplay::ConvertScreenRectToPixels(const CefRect& rect) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Execute
|
||||
cef_rect_t _retval = cef_display_convert_screen_rect_to_pixels(&rect);
|
||||
|
||||
// Return type: simple
|
||||
return _retval;
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi-icall")
|
||||
CefRect CefDisplay::ConvertScreenRectFromPixels(const CefRect& rect) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Execute
|
||||
cef_rect_t _retval = cef_display_convert_screen_rect_from_pixels(&rect);
|
||||
|
||||
// Return type: simple
|
||||
return _retval;
|
||||
}
|
||||
|
||||
// VIRTUAL METHODS - Body may be edited by hand.
|
||||
|
||||
NO_SANITIZE("cfi-icall") int64 CefDisplayCToCpp::GetID() {
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
// implementations. See the translator.README.txt file in the tools directory
|
||||
// for more information.
|
||||
//
|
||||
// $hash=aa73ff15eb79f0e7f89338db9001e2876d2a3a6e$
|
||||
// $hash=aa091bc741fcefee760906fce4c8f86937dd74ca$
|
||||
//
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
@ -239,6 +239,10 @@ struct libcef_pointers {
|
|||
cef_display_convert_screen_point_to_pixels;
|
||||
decltype(&cef_display_convert_screen_point_from_pixels)
|
||||
cef_display_convert_screen_point_from_pixels;
|
||||
decltype(&cef_display_convert_screen_rect_to_pixels)
|
||||
cef_display_convert_screen_rect_to_pixels;
|
||||
decltype(&cef_display_convert_screen_rect_from_pixels)
|
||||
cef_display_convert_screen_rect_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;
|
||||
|
@ -451,6 +455,8 @@ int libcef_init_pointers(const char* path) {
|
|||
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_display_convert_screen_rect_to_pixels);
|
||||
INIT_ENTRY(cef_display_convert_screen_rect_from_pixels);
|
||||
INIT_ENTRY(cef_label_button_create);
|
||||
INIT_ENTRY(cef_menu_button_create);
|
||||
INIT_ENTRY(cef_panel_create);
|
||||
|
@ -1288,6 +1294,16 @@ cef_point_t cef_display_convert_screen_point_from_pixels(
|
|||
return g_libcef_pointers.cef_display_convert_screen_point_from_pixels(point);
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi-icall")
|
||||
cef_rect_t cef_display_convert_screen_rect_to_pixels(const cef_rect_t* rect) {
|
||||
return g_libcef_pointers.cef_display_convert_screen_rect_to_pixels(rect);
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi-icall")
|
||||
cef_rect_t cef_display_convert_screen_rect_from_pixels(const cef_rect_t* rect) {
|
||||
return g_libcef_pointers.cef_display_convert_screen_rect_from_pixels(rect);
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi-icall")
|
||||
struct _cef_label_button_t* cef_label_button_create(
|
||||
struct _cef_button_delegate_t* delegate,
|
||||
|
|
|
@ -49,8 +49,8 @@ struct RootWindowConfig {
|
|||
// based windows when |initially_hidden| is also true.
|
||||
CefRect source_bounds;
|
||||
|
||||
// Requested window show state. This is currently only implemented for Views-
|
||||
// based windows when |bounds| is non-empty and |initially_hidden| is false.
|
||||
// Requested window show state. Only used when |bounds| is non-empty and
|
||||
// |initially_hidden| is false.
|
||||
cef_show_state_t show_state = CEF_SHOW_STATE_NORMAL;
|
||||
|
||||
// Parent window. Only used for Views-based windows.
|
||||
|
|
|
@ -6,11 +6,15 @@
|
|||
|
||||
#include <shellscalingapi.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "include/base/cef_build.h"
|
||||
#include "include/base/cef_callback.h"
|
||||
#include "include/cef_app.h"
|
||||
#include "include/views/cef_display.h"
|
||||
#include "tests/cefclient/browser/browser_window_osr_win.h"
|
||||
#include "tests/cefclient/browser/browser_window_std_win.h"
|
||||
#include "tests/cefclient/browser/client_prefs.h"
|
||||
#include "tests/cefclient/browser/main_context.h"
|
||||
#include "tests/cefclient/browser/resource.h"
|
||||
#include "tests/cefclient/browser/temp_window.h"
|
||||
|
@ -101,35 +105,7 @@ int GetURLBarHeight(HWND hwnd) {
|
|||
|
||||
} // namespace
|
||||
|
||||
RootWindowWin::RootWindowWin()
|
||||
: with_controls_(false),
|
||||
always_on_top_(false),
|
||||
with_osr_(false),
|
||||
with_extension_(false),
|
||||
is_popup_(false),
|
||||
start_rect_(),
|
||||
initialized_(false),
|
||||
hwnd_(nullptr),
|
||||
draggable_region_(nullptr),
|
||||
font_(nullptr),
|
||||
font_height_(0),
|
||||
back_hwnd_(nullptr),
|
||||
forward_hwnd_(nullptr),
|
||||
reload_hwnd_(nullptr),
|
||||
stop_hwnd_(nullptr),
|
||||
edit_hwnd_(nullptr),
|
||||
edit_wndproc_old_(nullptr),
|
||||
find_hwnd_(nullptr),
|
||||
find_message_id_(0),
|
||||
find_wndproc_old_(nullptr),
|
||||
find_state_(),
|
||||
find_next_(false),
|
||||
find_match_case_last_(false),
|
||||
window_destroyed_(false),
|
||||
browser_destroyed_(false),
|
||||
called_enable_non_client_dpi_scaling_(false) {
|
||||
find_buff_[0] = 0;
|
||||
|
||||
RootWindowWin::RootWindowWin() {
|
||||
// Create a HRGN representing the draggable window area.
|
||||
draggable_region_ = ::CreateRectRgn(0, 0, 0, 0);
|
||||
}
|
||||
|
@ -157,22 +133,47 @@ void RootWindowWin::Init(RootWindow::Delegate* delegate,
|
|||
with_osr_ = config->with_osr;
|
||||
with_extension_ = config->with_extension;
|
||||
|
||||
start_rect_.left = config->bounds.x;
|
||||
start_rect_.top = config->bounds.y;
|
||||
start_rect_.right = config->bounds.x + config->bounds.width;
|
||||
start_rect_.bottom = config->bounds.y + config->bounds.height;
|
||||
|
||||
CreateBrowserWindow(config->url);
|
||||
|
||||
if (CefCurrentlyOn(TID_UI)) {
|
||||
ContinueInitOnUIThread(std::move(config), settings);
|
||||
} else {
|
||||
CefPostTask(TID_UI, base::BindOnce(&RootWindowWin::ContinueInitOnUIThread,
|
||||
this, std::move(config), settings));
|
||||
}
|
||||
}
|
||||
|
||||
void RootWindowWin::ContinueInitOnUIThread(
|
||||
std::unique_ptr<RootWindowConfig> config,
|
||||
const CefBrowserSettings& settings) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
|
||||
if (!config->bounds.IsEmpty()) {
|
||||
// Initial state was specified via the config object.
|
||||
initial_bounds_ = config->bounds;
|
||||
initial_show_state_ = config->show_state;
|
||||
} else {
|
||||
// Initial state may be specified via the command-line or global
|
||||
// preferences.
|
||||
std::optional<CefRect> bounds;
|
||||
if (prefs::LoadWindowRestorePreferences(initial_show_state_, bounds) &&
|
||||
bounds) {
|
||||
initial_bounds_ = CefDisplay::ConvertScreenRectToPixels(*bounds);
|
||||
}
|
||||
}
|
||||
|
||||
MAIN_POST_CLOSURE(base::BindOnce(&RootWindowWin::ContinueInitOnMainThread,
|
||||
this, std::move(config), settings));
|
||||
}
|
||||
|
||||
void RootWindowWin::ContinueInitOnMainThread(
|
||||
std::unique_ptr<RootWindowConfig> config,
|
||||
const CefBrowserSettings& settings) {
|
||||
REQUIRE_MAIN_THREAD();
|
||||
|
||||
initialized_ = true;
|
||||
|
||||
// Create the native root window on the main thread.
|
||||
if (CURRENTLY_ON_MAIN_THREAD()) {
|
||||
CreateRootWindow(settings, config->initially_hidden);
|
||||
} else {
|
||||
MAIN_POST_CLOSURE(base::BindOnce(&RootWindowWin::CreateRootWindow, this,
|
||||
settings, config->initially_hidden));
|
||||
}
|
||||
}
|
||||
|
||||
void RootWindowWin::InitAsPopup(RootWindow::Delegate* delegate,
|
||||
|
@ -193,13 +194,13 @@ void RootWindowWin::InitAsPopup(RootWindow::Delegate* delegate,
|
|||
is_popup_ = true;
|
||||
|
||||
if (popupFeatures.xSet)
|
||||
start_rect_.left = popupFeatures.x;
|
||||
initial_bounds_.x = popupFeatures.x;
|
||||
if (popupFeatures.ySet)
|
||||
start_rect_.top = popupFeatures.y;
|
||||
initial_bounds_.y = popupFeatures.y;
|
||||
if (popupFeatures.widthSet)
|
||||
start_rect_.right = start_rect_.left + popupFeatures.width;
|
||||
initial_bounds_.width = popupFeatures.width;
|
||||
if (popupFeatures.heightSet)
|
||||
start_rect_.bottom = start_rect_.top + popupFeatures.height;
|
||||
initial_bounds_.height = popupFeatures.height;
|
||||
|
||||
CreateBrowserWindow(std::string());
|
||||
|
||||
|
@ -234,6 +235,7 @@ void RootWindowWin::Show(ShowMode mode) {
|
|||
}
|
||||
|
||||
ShowWindow(hwnd_, nCmdShow);
|
||||
if (mode != ShowMinimized)
|
||||
UpdateWindow(hwnd_);
|
||||
}
|
||||
|
||||
|
@ -343,27 +345,38 @@ void RootWindowWin::CreateRootWindow(const CefBrowserSettings& settings,
|
|||
CefCommandLine::GetGlobalCommandLine();
|
||||
const bool no_activate = command_line->HasSwitch(switches::kNoActivate);
|
||||
|
||||
const DWORD dwStyle = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN;
|
||||
DWORD dwStyle = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN;
|
||||
DWORD dwExStyle = always_on_top_ ? WS_EX_TOPMOST : 0;
|
||||
if (no_activate) {
|
||||
// Don't activate the browser window on creation.
|
||||
dwExStyle |= WS_EX_NOACTIVATE;
|
||||
}
|
||||
|
||||
if (initial_show_state_ == CEF_SHOW_STATE_MAXIMIZED) {
|
||||
dwStyle |= WS_MAXIMIZE;
|
||||
} else if (initial_show_state_ == CEF_SHOW_STATE_MINIMIZED) {
|
||||
dwStyle |= WS_MINIMIZE;
|
||||
}
|
||||
|
||||
int x, y, width, height;
|
||||
if (::IsRectEmpty(&start_rect_)) {
|
||||
if (initial_bounds_.IsEmpty()) {
|
||||
// Use the default window position/size.
|
||||
x = y = width = height = CW_USEDEFAULT;
|
||||
} else {
|
||||
// Adjust the window size to account for window frame and controls.
|
||||
RECT window_rect = start_rect_;
|
||||
::AdjustWindowRectEx(&window_rect, dwStyle, with_controls_, dwExStyle);
|
||||
x = initial_bounds_.x;
|
||||
y = initial_bounds_.y;
|
||||
width = initial_bounds_.width;
|
||||
height = initial_bounds_.height;
|
||||
|
||||
x = start_rect_.left;
|
||||
y = start_rect_.top;
|
||||
if (is_popup_) {
|
||||
// Adjust the window size to account for window frame and controls. Keep
|
||||
// the origin unchanged.
|
||||
RECT window_rect = {x, y, x + width, y + height};
|
||||
::AdjustWindowRectEx(&window_rect, dwStyle, with_controls_, dwExStyle);
|
||||
width = window_rect.right - window_rect.left;
|
||||
height = window_rect.bottom - window_rect.top;
|
||||
}
|
||||
}
|
||||
|
||||
browser_settings_ = settings;
|
||||
|
||||
|
@ -385,8 +398,17 @@ void RootWindowWin::CreateRootWindow(const CefBrowserSettings& settings,
|
|||
}
|
||||
|
||||
if (!initially_hidden) {
|
||||
ShowMode mode = ShowNormal;
|
||||
if (no_activate) {
|
||||
mode = ShowNoActivate;
|
||||
} else if (initial_show_state_ == CEF_SHOW_STATE_MAXIMIZED) {
|
||||
mode = ShowMaximized;
|
||||
} else if (initial_show_state_ == CEF_SHOW_STATE_MINIMIZED) {
|
||||
mode = ShowMinimized;
|
||||
}
|
||||
|
||||
// Show this window.
|
||||
Show(no_activate ? ShowNoActivate : ShowNormal);
|
||||
Show(mode);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -983,6 +1005,18 @@ bool RootWindowWin::OnClose() {
|
|||
}
|
||||
}
|
||||
|
||||
// Retrieve current window placement information.
|
||||
WINDOWPLACEMENT placement;
|
||||
::GetWindowPlacement(hwnd_, &placement);
|
||||
|
||||
if (CefCurrentlyOn(TID_UI)) {
|
||||
SaveWindowRestoreOnUIThread(placement);
|
||||
} else {
|
||||
CefPostTask(
|
||||
TID_UI,
|
||||
base::BindOnce(&RootWindowWin::SaveWindowRestoreOnUIThread, placement));
|
||||
}
|
||||
|
||||
// Allow the close.
|
||||
return false;
|
||||
}
|
||||
|
@ -1219,4 +1253,25 @@ void RootWindowWin::NotifyDestroyedIfDone() {
|
|||
delegate_->OnRootWindowDestroyed(this);
|
||||
}
|
||||
|
||||
// static
|
||||
void RootWindowWin::SaveWindowRestoreOnUIThread(
|
||||
const WINDOWPLACEMENT& placement) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
|
||||
cef_show_state_t show_state = CEF_SHOW_STATE_NORMAL;
|
||||
if (placement.showCmd == SW_SHOWMINIMIZED) {
|
||||
show_state = CEF_SHOW_STATE_MINIMIZED;
|
||||
} else if (placement.showCmd == SW_SHOWMAXIMIZED) {
|
||||
show_state = CEF_SHOW_STATE_MAXIMIZED;
|
||||
}
|
||||
|
||||
// Coordinates when the window is in the restored position.
|
||||
const auto rect = placement.rcNormalPosition;
|
||||
CefRect pixel_bounds(rect.left, rect.top, rect.right - rect.left,
|
||||
rect.bottom - rect.top);
|
||||
const auto dip_bounds = CefDisplay::ConvertScreenRectFromPixels(pixel_bounds);
|
||||
|
||||
prefs::SaveWindowRestorePreferences(show_state, dip_bounds);
|
||||
}
|
||||
|
||||
} // namespace client
|
||||
|
|
|
@ -50,6 +50,11 @@ class RootWindowWin : public RootWindow, public BrowserWindow::Delegate {
|
|||
bool WithExtension() const override;
|
||||
|
||||
private:
|
||||
void ContinueInitOnUIThread(std::unique_ptr<RootWindowConfig> config,
|
||||
const CefBrowserSettings& settings);
|
||||
void ContinueInitOnMainThread(std::unique_ptr<RootWindowConfig> config,
|
||||
const CefBrowserSettings& settings);
|
||||
|
||||
void CreateBrowserWindow(const std::string& startup_url);
|
||||
void CreateRootWindow(const CefBrowserSettings& settings,
|
||||
bool initially_hidden);
|
||||
|
@ -109,54 +114,57 @@ class RootWindowWin : public RootWindow, public BrowserWindow::Delegate {
|
|||
|
||||
void NotifyDestroyedIfDone();
|
||||
|
||||
static void SaveWindowRestoreOnUIThread(const WINDOWPLACEMENT& placement);
|
||||
|
||||
// After initialization all members are only accessed on the main thread.
|
||||
// Members set during initialization.
|
||||
bool with_controls_;
|
||||
bool always_on_top_;
|
||||
bool with_osr_;
|
||||
bool with_extension_;
|
||||
bool is_popup_;
|
||||
RECT start_rect_;
|
||||
bool with_controls_ = false;
|
||||
bool always_on_top_ = false;
|
||||
bool with_osr_ = false;
|
||||
bool with_extension_ = false;
|
||||
bool is_popup_ = false;
|
||||
CefRect initial_bounds_;
|
||||
cef_show_state_t initial_show_state_ = CEF_SHOW_STATE_NORMAL;
|
||||
std::unique_ptr<BrowserWindow> browser_window_;
|
||||
CefBrowserSettings browser_settings_;
|
||||
bool initialized_;
|
||||
bool initialized_ = false;
|
||||
|
||||
// Main window.
|
||||
HWND hwnd_;
|
||||
HWND hwnd_ = nullptr;
|
||||
|
||||
// Draggable region.
|
||||
HRGN draggable_region_;
|
||||
HRGN draggable_region_ = nullptr;
|
||||
|
||||
// Font for buttons and text fields.
|
||||
HFONT font_;
|
||||
int font_height_;
|
||||
HFONT font_ = nullptr;
|
||||
int font_height_ = 0;
|
||||
|
||||
// Buttons.
|
||||
HWND back_hwnd_;
|
||||
HWND forward_hwnd_;
|
||||
HWND reload_hwnd_;
|
||||
HWND stop_hwnd_;
|
||||
HWND back_hwnd_ = nullptr;
|
||||
HWND forward_hwnd_ = nullptr;
|
||||
HWND reload_hwnd_ = nullptr;
|
||||
HWND stop_hwnd_ = nullptr;
|
||||
|
||||
// URL text field.
|
||||
HWND edit_hwnd_;
|
||||
WNDPROC edit_wndproc_old_;
|
||||
HWND edit_hwnd_ = nullptr;
|
||||
WNDPROC edit_wndproc_old_ = nullptr;
|
||||
|
||||
// Find dialog.
|
||||
HWND find_hwnd_;
|
||||
UINT find_message_id_;
|
||||
WNDPROC find_wndproc_old_;
|
||||
HWND find_hwnd_ = nullptr;
|
||||
UINT find_message_id_ = 0;
|
||||
WNDPROC find_wndproc_old_ = nullptr;
|
||||
|
||||
// Find dialog state.
|
||||
FINDREPLACE find_state_;
|
||||
WCHAR find_buff_[80];
|
||||
FINDREPLACE find_state_ = {0};
|
||||
WCHAR find_buff_[80] = {0};
|
||||
std::wstring find_what_last_;
|
||||
bool find_next_;
|
||||
bool find_match_case_last_;
|
||||
bool find_next_ = false;
|
||||
bool find_match_case_last_ = false;
|
||||
|
||||
bool window_destroyed_;
|
||||
bool browser_destroyed_;
|
||||
bool window_destroyed_ = false;
|
||||
bool browser_destroyed_ = false;
|
||||
|
||||
bool called_enable_non_client_dpi_scaling_;
|
||||
bool called_enable_non_client_dpi_scaling_ = false;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(RootWindowWin);
|
||||
};
|
||||
|
|
|
@ -54,7 +54,8 @@ void SetPosImpl(CefRefPtr<CefBrowser> browser,
|
|||
CefRect window_rect(x, y, width, height);
|
||||
WindowTestRunner::ModifyBounds(display_rect, window_rect);
|
||||
|
||||
if (placement.showCmd == SW_MINIMIZE || placement.showCmd == SW_MAXIMIZE) {
|
||||
if (placement.showCmd == SW_SHOWMINIMIZED ||
|
||||
placement.showCmd == SW_SHOWMAXIMIZED) {
|
||||
// The window is currently minimized or maximized. Restore it to the desired
|
||||
// position.
|
||||
placement.rcNormalPosition.left = window_rect.x;
|
||||
|
|
Loading…
Reference in New Issue