| Index: chrome/browser/ui/gtk/gtk_window_util.cc
|
| diff --git a/chrome/browser/ui/gtk/gtk_window_util.cc b/chrome/browser/ui/gtk/gtk_window_util.cc
|
| index 91258b25cb3d64b93b42415c258699a5c44a3bc0..46605c213a902fa43faf5d3242f01d8b89444d1e 100644
|
| --- a/chrome/browser/ui/gtk/gtk_window_util.cc
|
| +++ b/chrome/browser/ui/gtk/gtk_window_util.cc
|
| @@ -13,6 +13,12 @@ using content::WebContents;
|
|
|
| namespace gtk_window_util {
|
|
|
| +// Keep track of the last click time and the last click position so we can
|
| +// filter out extra GDK_BUTTON_PRESS events when a double click happens.
|
| +static guint32 last_click_time;
|
| +static int last_click_x;
|
| +static int last_click_y;
|
| +
|
| // Performs Cut/Copy/Paste operation on the |window|.
|
| // If the current render view is focused, then just call the specified |method|
|
| // against the current render view host, otherwise emit the specified |signal|
|
| @@ -94,4 +100,77 @@ GdkCursorType GdkWindowEdgeToGdkCursorType(GdkWindowEdge edge) {
|
| return GDK_LAST_CURSOR;
|
| }
|
|
|
| +bool BoundsMatchMonitorSize(GtkWindow* window, gfx::Rect bounds) {
|
| + // A screen can be composed of multiple monitors.
|
| + GdkScreen* screen = gtk_window_get_screen(window);
|
| + gint monitor_num = gdk_screen_get_monitor_at_window(screen,
|
| + gtk_widget_get_window(GTK_WIDGET(window)));
|
| +
|
| + GdkRectangle monitor_size;
|
| + gdk_screen_get_monitor_geometry(screen, monitor_num, &monitor_size);
|
| + return bounds.size() == gfx::Size(monitor_size.width, monitor_size.height);
|
| +}
|
| +
|
| +bool HandleTitleBarLeftMousePress(
|
| + GtkWindow* window,
|
| + const gfx::Rect& bounds,
|
| + GdkEventButton* event) {
|
| + // We want to start a move when the user single clicks, but not start a
|
| + // move when the user double clicks. However, a double click sends the
|
| + // following GDK events: GDK_BUTTON_PRESS, GDK_BUTTON_RELEASE,
|
| + // GDK_BUTTON_PRESS, GDK_2BUTTON_PRESS, GDK_BUTTON_RELEASE. If we
|
| + // start a gtk_window_begin_move_drag on the second GDK_BUTTON_PRESS,
|
| + // the call to gtk_window_maximize fails. To work around this, we
|
| + // keep track of the last click and if it's going to be a double click,
|
| + // we don't call gtk_window_begin_move_drag.
|
| + DCHECK(event->type == GDK_BUTTON_PRESS);
|
| + DCHECK(event->button == 1);
|
| +
|
| + static GtkSettings* settings = gtk_settings_get_default();
|
| + gint double_click_time = 250;
|
| + gint double_click_distance = 5;
|
| + g_object_get(G_OBJECT(settings),
|
| + "gtk-double-click-time", &double_click_time,
|
| + "gtk-double-click-distance", &double_click_distance,
|
| + NULL);
|
| +
|
| + guint32 click_time = event->time - last_click_time;
|
| + int click_move_x = abs(event->x - last_click_x);
|
| + int click_move_y = abs(event->y - last_click_y);
|
| +
|
| + last_click_time = event->time;
|
| + last_click_x = static_cast<int>(event->x);
|
| + last_click_y = static_cast<int>(event->y);
|
| +
|
| + if (click_time > static_cast<guint32>(double_click_time) ||
|
| + click_move_x > double_click_distance ||
|
| + click_move_y > double_click_distance) {
|
| + // Ignore drag requests if the window is the size of the screen.
|
| + // We do this to avoid triggering fullscreen mode in metacity
|
| + // (without the --no-force-fullscreen flag) and in compiz (with
|
| + // Legacy Fullscreen Mode enabled).
|
| + if (!BoundsMatchMonitorSize(window, bounds)) {
|
| + gtk_window_begin_move_drag(window, event->button,
|
| + static_cast<gint>(event->x_root),
|
| + static_cast<gint>(event->y_root),
|
| + event->time);
|
| + }
|
| + return TRUE;
|
| + }
|
| + return FALSE;
|
| +}
|
| +
|
| +void UnMaximize(GtkWindow* window,
|
| + const gfx::Rect& bounds,
|
| + const gfx::Rect& restored_bounds) {
|
| + gtk_window_unmaximize(window);
|
| +
|
| + // It can happen that you end up with a window whose restore size is the same
|
| + // as the size of the screen, so unmaximizing it merely remaximizes it due to
|
| + // the same WM feature that SetWindowSize() works around. We try to detect
|
| + // this and resize the window to work around the issue.
|
| + if (bounds.size() == restored_bounds.size())
|
| + gtk_window_resize(window, bounds.width(), bounds.height() - 1);
|
| +}
|
| +
|
| } // namespace gtk_window_util
|
|
|