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

@ -30,4 +30,54 @@ ScopedGdkThreadsEnter::~ScopedGdkThreadsEnter() {
}
}
CefRect GetWindowBounds(GtkWindow* window, bool include_frame) {
GdkWindow* gdk_window = gtk_widget_get_window(GTK_WIDGET(window));
gint x = 0;
gint y = 0;
gdk_window_get_origin(gdk_window, &x, &y);
gint width = 0;
gint height = 0;
gdk_window_get_geometry(gdk_window, nullptr, nullptr, &width, &height);
if (include_frame) {
GdkRectangle frame_rect = {};
gdk_window_get_frame_extents(gdk_window, &frame_rect);
// This calculation assumes that all added frame height is at the top of the
// window, which may be incorrect for some window managers.
y -= frame_rect.height - height;
}
return {x, y, width, height};
}
bool IsWindowMaximized(GtkWindow* window) {
GdkWindow* gdk_window = gtk_widget_get_window(GTK_WIDGET(window));
gint state = gdk_window_get_state(gdk_window);
return (state & GDK_WINDOW_STATE_MAXIMIZED) ? true : false;
}
void MinimizeWindow(GtkWindow* window) {
// Unmaximize the window before minimizing so restore behaves correctly.
if (IsWindowMaximized(window)) {
gtk_window_unmaximize(window);
}
gtk_window_iconify(window);
}
void MaximizeWindow(GtkWindow* window) {
gtk_window_maximize(window);
}
void RestoreWindow(GtkWindow* window) {
if (IsWindowMaximized(window)) {
gtk_window_unmaximize(window);
} else {
gtk_window_present(window);
}
}
} // namespace client