| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/gtk/gtk_window_util.h" | 5 #include "chrome/browser/ui/gtk/gtk_window_util.h" |
| 6 | 6 |
| 7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
| 8 #include "content/public/browser/render_view_host.h" | 8 #include "content/public/browser/render_view_host.h" |
| 9 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
| 10 | 10 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 case GDK_WINDOW_EDGE_SOUTH: | 87 case GDK_WINDOW_EDGE_SOUTH: |
| 88 return GDK_BOTTOM_SIDE; | 88 return GDK_BOTTOM_SIDE; |
| 89 case GDK_WINDOW_EDGE_SOUTH_EAST: | 89 case GDK_WINDOW_EDGE_SOUTH_EAST: |
| 90 return GDK_BOTTOM_RIGHT_CORNER; | 90 return GDK_BOTTOM_RIGHT_CORNER; |
| 91 default: | 91 default: |
| 92 NOTREACHED(); | 92 NOTREACHED(); |
| 93 } | 93 } |
| 94 return GDK_LAST_CURSOR; | 94 return GDK_LAST_CURSOR; |
| 95 } | 95 } |
| 96 | 96 |
| 97 bool BoundsMatchMonitorSize(GtkWindow* window, gfx::Rect bounds) { |
| 98 // A screen can be composed of multiple monitors. |
| 99 GdkScreen* screen = gtk_window_get_screen(window); |
| 100 gint monitor_num = gdk_screen_get_monitor_at_window(screen, |
| 101 gtk_widget_get_window(GTK_WIDGET(window))); |
| 102 |
| 103 GdkRectangle monitor_size; |
| 104 gdk_screen_get_monitor_geometry(screen, monitor_num, &monitor_size); |
| 105 return bounds.size() == gfx::Size(monitor_size.width, monitor_size.height); |
| 106 } |
| 107 |
| 108 bool HandleTitleBarLeftMousePress( |
| 109 GtkWindow* window, |
| 110 gfx::Rect bounds, |
| 111 GdkEventButton* event, |
| 112 guint32 last_click_time, |
| 113 gfx::Point last_click_position) { |
| 114 // We want to start a move when the user single clicks, but not start a |
| 115 // move when the user double clicks. However, a double click sends the |
| 116 // following GDK events: GDK_BUTTON_PRESS, GDK_BUTTON_RELEASE, |
| 117 // GDK_BUTTON_PRESS, GDK_2BUTTON_PRESS, GDK_BUTTON_RELEASE. If we |
| 118 // start a gtk_window_begin_move_drag on the second GDK_BUTTON_PRESS, |
| 119 // the call to gtk_window_maximize fails. To work around this, we |
| 120 // keep track of the last click and if it's going to be a double click, |
| 121 // we don't call gtk_window_begin_move_drag. |
| 122 static GtkSettings* settings = gtk_settings_get_default(); |
| 123 gint double_click_time = 250; |
| 124 gint double_click_distance = 5; |
| 125 g_object_get(G_OBJECT(settings), |
| 126 "gtk-double-click-time", &double_click_time, |
| 127 "gtk-double-click-distance", &double_click_distance, |
| 128 NULL); |
| 129 |
| 130 guint32 click_time = event->time - last_click_time; |
| 131 int click_move_x = abs(event->x - last_click_position.x()); |
| 132 int click_move_y = abs(event->y - last_click_position.y()); |
| 133 |
| 134 if (click_time > static_cast<guint32>(double_click_time) || |
| 135 click_move_x > double_click_distance || |
| 136 click_move_y > double_click_distance) { |
| 137 // Ignore drag requests if the window is the size of the screen. |
| 138 // We do this to avoid triggering fullscreen mode in metacity |
| 139 // (without the --no-force-fullscreen flag) and in compiz (with |
| 140 // Legacy Fullscreen Mode enabled). |
| 141 if (!BoundsMatchMonitorSize(window, bounds)) { |
| 142 gtk_window_begin_move_drag(window, event->button, |
| 143 static_cast<gint>(event->x_root), |
| 144 static_cast<gint>(event->y_root), |
| 145 event->time); |
| 146 } |
| 147 return TRUE; |
| 148 } |
| 149 return FALSE; |
| 150 } |
| 151 |
| 97 } // namespace gtk_window_util | 152 } // namespace gtk_window_util |
| OLD | NEW |