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

@@ -137,11 +137,18 @@ void RootWindowViews::Hide() {
}
}
void RootWindowViews::SetBounds(int x, int y, size_t width, size_t height) {
void RootWindowViews::SetBounds(int x,
int y,
size_t width,
size_t height,
bool content_bounds) {
// We always expect Window bounds with Views-hosted browsers.
DCHECK(!content_bounds);
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
CefPostTask(TID_UI, base::BindOnce(&RootWindowViews::SetBounds, this, x, y,
width, height));
width, height, content_bounds));
return;
}
@@ -151,6 +158,11 @@ void RootWindowViews::SetBounds(int x, int y, size_t width, size_t height) {
}
}
bool RootWindowViews::DefaultToContentBounds() const {
// Views-hosted browsers always receive CefWindow bounds.
return false;
}
void RootWindowViews::Close(bool force) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
@@ -169,11 +181,11 @@ void RootWindowViews::SetDeviceScaleFactor(float device_scale_factor) {
NOTREACHED();
}
float RootWindowViews::GetDeviceScaleFactor() const {
std::optional<float> RootWindowViews::GetDeviceScaleFactor() const {
REQUIRE_MAIN_THREAD();
// Windowless rendering is not supported.
NOTREACHED();
return 0.0;
return std::nullopt;
}
CefRefPtr<CefBrowser> RootWindowViews::GetBrowser() const {