Support JavaScript window.moveTo/By() and resizeTo/By() (fixes #698)

Adds new CefDisplayHandler::OnContentsBoundsChange and
CefDisplayHandler::GetRootWindowScreenRect callbacks.

cefclient: Implement the above callbacks and call
CefBrowserHost::NotifyScreenInfoChanged when the root window
bounds change.

cefclient: osr: Use real screen bounds by default. Pass
`--fake-screen-bounds` for the old default behavior.

Load https://tests/window in cefclient for additional
implementation details and usage examples.
This commit is contained in:
Marshall Greenblatt
2025-04-23 20:33:07 -04:00
parent f59112d839
commit faa85bf980
68 changed files with 1725 additions and 700 deletions

View File

@ -571,12 +571,7 @@ ClientHandler::ClientHandler(Delegate* delegate,
}
void ClientHandler::DetachDelegate() {
if (!CURRENTLY_ON_MAIN_THREAD()) {
// Execute this method on the main thread.
MAIN_POST_CLOSURE(base::BindOnce(&ClientHandler::DetachDelegate, this));
return;
}
REQUIRE_MAIN_THREAD();
DCHECK(delegate_);
delegate_ = nullptr;
}
@ -869,6 +864,24 @@ bool ClientHandler::OnCursorChange(CefRefPtr<CefBrowser> browser,
return mouse_cursor_change_disabled_;
}
#if CEF_API_ADDED(CEF_NEXT)
bool ClientHandler::OnContentsBoundsChange(CefRefPtr<CefBrowser> browser,
const CefRect& new_bounds) {
CEF_REQUIRE_UI_THREAD();
NotifyContentsBounds(new_bounds);
return true;
}
bool ClientHandler::GetRootWindowScreenRect(CefRefPtr<CefBrowser> browser,
CefRect& rect) {
CEF_REQUIRE_UI_THREAD();
if (delegate_) {
return delegate_->GetRootWindowScreenRect(rect);
}
return false;
}
#endif
bool ClientHandler::CanDownload(CefRefPtr<CefBrowser> browser,
const CefString& url,
const CefString& request_method) {
@ -1465,6 +1478,19 @@ void ClientHandler::NotifyAutoResize(const CefSize& new_size) {
}
}
void ClientHandler::NotifyContentsBounds(const CefRect& new_bounds) {
if (!CURRENTLY_ON_MAIN_THREAD()) {
// Execute this method on the main thread.
MAIN_POST_CLOSURE(
base::BindOnce(&ClientHandler::NotifyContentsBounds, this, new_bounds));
return;
}
if (delegate_) {
delegate_->OnContentsBounds(new_bounds);
}
}
void ClientHandler::NotifyLoadingState(bool isLoading,
bool canGoBack,
bool canGoForward) {