Chromium Code Reviews| 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 |
| 11 using content::RenderWidgetHost; | 11 using content::RenderWidgetHost; |
| 12 using content::WebContents; | 12 using content::WebContents; |
| 13 | 13 |
| 14 namespace gtk_window_util { | 14 namespace gtk_window_util { |
| 15 | 15 |
| 16 // Keep track of the last click event so we can filter out | |
| 17 // extra GDK_BUTTON_PRESS events when a double click happens. | |
| 18 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".
| |
| 19 | |
| 16 // Performs Cut/Copy/Paste operation on the |window|. | 20 // Performs Cut/Copy/Paste operation on the |window|. |
| 17 // If the current render view is focused, then just call the specified |method| | 21 // If the current render view is focused, then just call the specified |method| |
| 18 // against the current render view host, otherwise emit the specified |signal| | 22 // against the current render view host, otherwise emit the specified |signal| |
| 19 // against the focused widget. | 23 // against the focused widget. |
| 20 // TODO(suzhe): This approach does not work for plugins. | 24 // TODO(suzhe): This approach does not work for plugins. |
| 21 void DoCutCopyPaste(GtkWindow* window, | 25 void DoCutCopyPaste(GtkWindow* window, |
| 22 WebContents* web_contents, | 26 WebContents* web_contents, |
| 23 void (RenderWidgetHost::*method)(), | 27 void (RenderWidgetHost::*method)(), |
| 24 const char* signal) { | 28 const char* signal) { |
| 25 GtkWidget* widget = gtk_window_get_focus(window); | 29 GtkWidget* widget = gtk_window_get_focus(window); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 case GDK_WINDOW_EDGE_SOUTH: | 91 case GDK_WINDOW_EDGE_SOUTH: |
| 88 return GDK_BOTTOM_SIDE; | 92 return GDK_BOTTOM_SIDE; |
| 89 case GDK_WINDOW_EDGE_SOUTH_EAST: | 93 case GDK_WINDOW_EDGE_SOUTH_EAST: |
| 90 return GDK_BOTTOM_RIGHT_CORNER; | 94 return GDK_BOTTOM_RIGHT_CORNER; |
| 91 default: | 95 default: |
| 92 NOTREACHED(); | 96 NOTREACHED(); |
| 93 } | 97 } |
| 94 return GDK_LAST_CURSOR; | 98 return GDK_LAST_CURSOR; |
| 95 } | 99 } |
| 96 | 100 |
| 101 bool BoundsMatchMonitorSize(GtkWindow* window, gfx::Rect bounds) { | |
| 102 // A screen can be composed of multiple monitors. | |
| 103 GdkScreen* screen = gtk_window_get_screen(window); | |
| 104 gint monitor_num = gdk_screen_get_monitor_at_window(screen, | |
| 105 gtk_widget_get_window(GTK_WIDGET(window))); | |
| 106 | |
| 107 GdkRectangle monitor_size; | |
| 108 gdk_screen_get_monitor_geometry(screen, monitor_num, &monitor_size); | |
| 109 return bounds.size() == gfx::Size(monitor_size.width, monitor_size.height); | |
| 110 } | |
| 111 | |
| 112 bool HandleTitleBarLeftMousePress( | |
| 113 GtkWindow* window, | |
| 114 gfx::Rect bounds, | |
|
Evan Stade
2012/08/16 18:48:07
const ref
| |
| 115 GdkEventButton* event) { | |
| 116 // We want to start a move when the user single clicks, but not start a | |
| 117 // move when the user double clicks. However, a double click sends the | |
| 118 // following GDK events: GDK_BUTTON_PRESS, GDK_BUTTON_RELEASE, | |
| 119 // GDK_BUTTON_PRESS, GDK_2BUTTON_PRESS, GDK_BUTTON_RELEASE. If we | |
| 120 // start a gtk_window_begin_move_drag on the second GDK_BUTTON_PRESS, | |
| 121 // the call to gtk_window_maximize fails. To work around this, we | |
| 122 // keep track of the last click and if it's going to be a double click, | |
| 123 // we don't call gtk_window_begin_move_drag. | |
| 124 static GtkSettings* settings = gtk_settings_get_default(); | |
| 125 gint double_click_time = 250; | |
| 126 gint double_click_distance = 5; | |
| 127 g_object_get(G_OBJECT(settings), | |
| 128 "gtk-double-click-time", &double_click_time, | |
| 129 "gtk-double-click-distance", &double_click_distance, | |
| 130 NULL); | |
| 131 | |
| 132 GdkWindow* last_click_window = last_click_event.window; | |
| 133 guint32 click_time = event->time - last_click_event.time; | |
| 134 int click_move_x = abs(event->x - last_click_event.x); | |
| 135 int click_move_y = abs(event->y - last_click_event.y); | |
| 136 | |
| 137 last_click_event = *event; | |
| 138 | |
| 139 if (event->window != last_click_window || | |
| 140 click_time > static_cast<guint32>(double_click_time) || | |
| 141 click_move_x > double_click_distance || | |
| 142 click_move_y > double_click_distance) { | |
| 143 // Ignore drag requests if the window is the size of the screen. | |
| 144 // We do this to avoid triggering fullscreen mode in metacity | |
| 145 // (without the --no-force-fullscreen flag) and in compiz (with | |
| 146 // Legacy Fullscreen Mode enabled). | |
| 147 if (!BoundsMatchMonitorSize(window, bounds)) { | |
| 148 gtk_window_begin_move_drag(window, event->button, | |
| 149 static_cast<gint>(event->x_root), | |
| 150 static_cast<gint>(event->y_root), | |
| 151 event->time); | |
| 152 } | |
| 153 return TRUE; | |
| 154 } | |
| 155 return FALSE; | |
| 156 } | |
| 157 | |
| 158 void UnMaximize(GtkWindow* window, | |
| 159 gfx::Rect bounds, | |
|
Evan Stade
2012/08/16 18:48:07
const ref x2
| |
| 160 gfx::Rect restored_bounds) { | |
| 161 gtk_window_unmaximize(window); | |
| 162 | |
| 163 // It can happen that you end up with a window whose restore size is the same | |
| 164 // as the size of the screen, so unmaximizing it merely remaximizes it due to | |
| 165 // the same WM feature that SetWindowSize() works around. We try to detect | |
| 166 // this and resize the window to work around the issue. | |
| 167 if (bounds.size() == restored_bounds.size()) | |
| 168 gtk_window_resize(window, bounds.width(), bounds.height() - 1); | |
| 169 } | |
| 170 | |
| 97 } // namespace gtk_window_util | 171 } // namespace gtk_window_util |
| OLD | NEW |