Chromium Code Reviews| 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..53346c42dd098b297b2a9153c4bad9ec2b7ad300 100644 |
| --- a/chrome/browser/ui/gtk/gtk_window_util.cc |
| +++ b/chrome/browser/ui/gtk/gtk_window_util.cc |
| @@ -13,6 +13,10 @@ using content::WebContents; |
| namespace gtk_window_util { |
| +// Keep track of the last click event so we can filter out |
| +// extra GDK_BUTTON_PRESS events when a double click happens. |
| +static GdkEventButton last_click_event; |
|
Evan Stade
2012/08/16 18:48:07
non non-POD statics.
Evan Stade
2012/08/16 19:04:21
this was supposed to say "no non-POD statics".
|
| + |
| // 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 +98,74 @@ 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, |
| + gfx::Rect bounds, |
|
Evan Stade
2012/08/16 18:48:07
const ref
|
| + 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. |
| + 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); |
| + |
| + GdkWindow* last_click_window = last_click_event.window; |
| + guint32 click_time = event->time - last_click_event.time; |
| + int click_move_x = abs(event->x - last_click_event.x); |
| + int click_move_y = abs(event->y - last_click_event.y); |
| + |
| + last_click_event = *event; |
| + |
| + if (event->window != last_click_window || |
| + 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, |
| + gfx::Rect bounds, |
|
Evan Stade
2012/08/16 18:48:07
const ref x2
|
| + 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 |